authorgravatar for adria.arrufat@gmail.comAdrià Arrufat <adria.arrufat@gmail.com> 2025-12-04 11:10:30+09:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-12-05 14:31:27+01:00
log02c5f05e2f0e8e786f0530014e35c1520efd0084
tree38b298fa7849d78c7d02294e7bd3b7aed2b7e52c
parent1a420a8dca34db8b632b0451d022ef92f78f96ac

std: replace usages of std.mem.indexOf with std.mem.find


56 files changed, 190 insertions(+), 190 deletions(-)

lib/std/Build/Step/CheckFile.zig+1-1
...@@ -60,7 +60,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void {...@@ -60,7 +60,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
60 };60 };
6161
62 for (check_file.expected_matches) |expected_match| {62 for (check_file.expected_matches) |expected_match| {
63 if (mem.indexOf(u8, contents, expected_match) == null) {63 if (mem.find(u8, contents, expected_match) == null) {
64 return step.fail(64 return step.fail(
65 \\65 \\
66 \\========= expected to find: ===================66 \\========= expected to find: ===================
lib/std/Build/Step/CheckObject.zig+3-3
...@@ -88,7 +88,7 @@ const Action = struct {...@@ -88,7 +88,7 @@ const Action = struct {
88 while (needle_it.next()) |needle_tok| {88 while (needle_it.next()) |needle_tok| {
89 const hay_tok = hay_it.next() orelse break;89 const hay_tok = hay_it.next() orelse break;
90 if (mem.startsWith(u8, needle_tok, "{")) {90 if (mem.startsWith(u8, needle_tok, "{")) {
91 const closing_brace = mem.indexOf(u8, needle_tok, "}") orelse return error.MissingClosingBrace;91 const closing_brace = mem.find(u8, needle_tok, "}") orelse return error.MissingClosingBrace;
92 if (closing_brace != needle_tok.len - 1) return error.ClosingBraceNotLast;92 if (closing_brace != needle_tok.len - 1) return error.ClosingBraceNotLast;
9393
94 const name = needle_tok[1..closing_brace];94 const name = needle_tok[1..closing_brace];
...@@ -133,7 +133,7 @@ const Action = struct {...@@ -133,7 +133,7 @@ const Action = struct {
133 assert(act.tag == .contains);133 assert(act.tag == .contains);
134 const hay = mem.trim(u8, haystack, " ");134 const hay = mem.trim(u8, haystack, " ");
135 const phrase = mem.trim(u8, act.phrase.resolve(b, step), " ");135 const phrase = mem.trim(u8, act.phrase.resolve(b, step), " ");
136 return mem.indexOf(u8, hay, phrase) != null;136 return mem.find(u8, hay, phrase) != null;
137 }137 }
138138
139 /// Returns true if the `phrase` does not exist within the haystack.139 /// Returns true if the `phrase` does not exist within the haystack.
...@@ -1662,7 +1662,7 @@ const MachODumper = struct {...@@ -1662,7 +1662,7 @@ const MachODumper = struct {
16621662
1663 .dump_section => {1663 .dump_section => {
1664 const name = mem.sliceTo(@as([*:0]const u8, @ptrCast(check.data.items.ptr + check.payload.dump_section)), 0);1664 const name = mem.sliceTo(@as([*:0]const u8, @ptrCast(check.data.items.ptr + check.payload.dump_section)), 0);
1665 const sep_index = mem.indexOfScalar(u8, name, ',') orelse1665 const sep_index = mem.findScalar(u8, name, ',') orelse
1666 return step.fail("invalid section name: {s}", .{name});1666 return step.fail("invalid section name: {s}", .{name});
1667 const segname = name[0..sep_index];1667 const segname = name[0..sep_index];
1668 const sectname = name[sep_index + 1 ..];1668 const sectname = name[sep_index + 1 ..];
lib/std/Build/Step/Compile.zig+3-3
...@@ -372,7 +372,7 @@ pub const TestRunner = struct {...@@ -372,7 +372,7 @@ pub const TestRunner = struct {
372372
373pub fn create(owner: *std.Build, options: Options) *Compile {373pub fn create(owner: *std.Build, options: Options) *Compile {
374 const name = owner.dupe(options.name);374 const name = owner.dupe(options.name);
375 if (mem.indexOf(u8, name, "/") != null or mem.indexOf(u8, name, "\\") != null) {375 if (mem.find(u8, name, "/") != null or mem.find(u8, name, "\\") != null) {
376 panic("invalid name: '{s}'. It looks like a file path, but it is supposed to be the library or application name.", .{name});376 panic("invalid name: '{s}'. It looks like a file path, but it is supposed to be the library or application name.", .{name});
377 }377 }
378378
...@@ -731,7 +731,7 @@ fn runPkgConfig(compile: *Compile, lib_name: []const u8) !PkgConfigResult {...@@ -731,7 +731,7 @@ fn runPkgConfig(compile: *Compile, lib_name: []const u8) !PkgConfigResult {
731731
732 // Prefixed "lib" or suffixed ".0".732 // Prefixed "lib" or suffixed ".0".
733 for (pkgs) |pkg| {733 for (pkgs) |pkg| {
734 if (std.ascii.indexOfIgnoreCase(pkg.name, lib_name)) |pos| {734 if (std.ascii.findIgnoreCase(pkg.name, lib_name)) |pos| {
735 const prefix = pkg.name[0..pos];735 const prefix = pkg.name[0..pos];
736 const suffix = pkg.name[pos + lib_name.len ..];736 const suffix = pkg.name[pos + lib_name.len ..];
737 if (prefix.len > 0 and !mem.eql(u8, prefix, "lib")) continue;737 if (prefix.len > 0 and !mem.eql(u8, prefix, "lib")) continue;
...@@ -2129,7 +2129,7 @@ fn matchCompileError(actual: []const u8, expected: []const u8) bool {...@@ -2129,7 +2129,7 @@ fn matchCompileError(actual: []const u8, expected: []const u8) bool {
2129 // We scan for /?/ in expected line and if there is a match, we match everything2129 // We scan for /?/ in expected line and if there is a match, we match everything
2130 // up to and after /?/.2130 // up to and after /?/.
2131 const expected_trim = mem.trim(u8, expected, " ");2131 const expected_trim = mem.trim(u8, expected, " ");
2132 if (mem.indexOf(u8, expected_trim, "/?/")) |index| {2132 if (mem.find(u8, expected_trim, "/?/")) |index| {
2133 const actual_trim = mem.trim(u8, actual, " ");2133 const actual_trim = mem.trim(u8, actual, " ");
2134 const lhs = expected_trim[0..index];2134 const lhs = expected_trim[0..index];
2135 const rhs = expected_trim[index + "/?/".len ..];2135 const rhs = expected_trim[index + "/?/".len ..];
lib/std/Build/Step/ConfigHeader.zig+5-5
...@@ -581,12 +581,12 @@ fn expand_variables_autoconf_at(...@@ -581,12 +581,12 @@ fn expand_variables_autoconf_at(
581 var source_offset: usize = 0;581 var source_offset: usize = 0;
582 while (curr < contents.len) : (curr += 1) {582 while (curr < contents.len) : (curr += 1) {
583 if (contents[curr] != '@') continue;583 if (contents[curr] != '@') continue;
584 if (std.mem.indexOfScalarPos(u8, contents, curr + 1, '@')) |close_pos| {584 if (std.mem.findScalarPos(u8, contents, curr + 1, '@')) |close_pos| {
585 if (close_pos == curr + 1) {585 if (close_pos == curr + 1) {
586 // closed immediately, preserve as a literal586 // closed immediately, preserve as a literal
587 continue;587 continue;
588 }588 }
589 const valid_varname_end = std.mem.indexOfNonePos(u8, contents, curr + 1, valid_varname_chars) orelse 0;589 const valid_varname_end = std.mem.findNonePos(u8, contents, curr + 1, valid_varname_chars) orelse 0;
590 if (valid_varname_end != close_pos) {590 if (valid_varname_end != close_pos) {
591 // contains invalid characters, preserve as a literal591 // contains invalid characters, preserve as a literal
592 continue;592 continue;
...@@ -638,12 +638,12 @@ fn expand_variables_cmake(...@@ -638,12 +638,12 @@ fn expand_variables_cmake(
638 loop: while (curr < contents.len) : (curr += 1) {638 loop: while (curr < contents.len) : (curr += 1) {
639 switch (contents[curr]) {639 switch (contents[curr]) {
640 '@' => blk: {640 '@' => blk: {
641 if (std.mem.indexOfScalarPos(u8, contents, curr + 1, '@')) |close_pos| {641 if (std.mem.findScalarPos(u8, contents, curr + 1, '@')) |close_pos| {
642 if (close_pos == curr + 1) {642 if (close_pos == curr + 1) {
643 // closed immediately, preserve as a literal643 // closed immediately, preserve as a literal
644 break :blk;644 break :blk;
645 }645 }
646 const valid_varname_end = std.mem.indexOfNonePos(u8, contents, curr + 1, valid_varname_chars) orelse 0;646 const valid_varname_end = std.mem.findNonePos(u8, contents, curr + 1, valid_varname_chars) orelse 0;
647 if (valid_varname_end != close_pos) {647 if (valid_varname_end != close_pos) {
648 // contains invalid characters, preserve as a literal648 // contains invalid characters, preserve as a literal
649 break :blk;649 break :blk;
...@@ -734,7 +734,7 @@ fn expand_variables_cmake(...@@ -734,7 +734,7 @@ fn expand_variables_cmake(
734 else => {},734 else => {},
735 }735 }
736736
737 if (var_stack.items.len > 0 and std.mem.indexOfScalar(u8, valid_varname_chars, contents[curr]) == null) {737 if (var_stack.items.len > 0 and std.mem.findScalar(u8, valid_varname_chars, contents[curr]) == null) {
738 return error.InvalidCharacter;738 return error.InvalidCharacter;
739 }739 }
740 }740 }
lib/std/Build/Step/Run.zig+2-2
...@@ -1509,7 +1509,7 @@ fn runCommand(...@@ -1509,7 +1509,7 @@ fn runCommand(
1509 }1509 }
1510 },1510 },
1511 .expect_stderr_match => |match| {1511 .expect_stderr_match => |match| {
1512 if (mem.indexOf(u8, generic_result.stderr.?, match) == null) {1512 if (mem.find(u8, generic_result.stderr.?, match) == null) {
1513 return step.fail(1513 return step.fail(
1514 \\========= expected to find in stderr: =========1514 \\========= expected to find in stderr: =========
1515 \\{s}1515 \\{s}
...@@ -1535,7 +1535,7 @@ fn runCommand(...@@ -1535,7 +1535,7 @@ fn runCommand(
1535 }1535 }
1536 },1536 },
1537 .expect_stdout_match => |match| {1537 .expect_stdout_match => |match| {
1538 if (mem.indexOf(u8, generic_result.stdout.?, match) == null) {1538 if (mem.find(u8, generic_result.stdout.?, match) == null) {
1539 return step.fail(1539 return step.fail(
1540 \\========= expected to find in stdout: =========1540 \\========= expected to find in stdout: =========
1541 \\{s}1541 \\{s}
lib/std/Io/Reader.zig+2-2
...@@ -993,7 +993,7 @@ pub fn streamDelimiterLimit(...@@ -993,7 +993,7 @@ pub fn streamDelimiterLimit(
993 error.ReadFailed => return error.ReadFailed,993 error.ReadFailed => return error.ReadFailed,
994 error.EndOfStream => return @intFromEnum(limit) - remaining,994 error.EndOfStream => return @intFromEnum(limit) - remaining,
995 });995 });
996 if (std.mem.indexOfScalar(u8, available, delimiter)) |delimiter_index| {996 if (std.mem.findScalar(u8, available, delimiter)) |delimiter_index| {
997 try w.writeAll(available[0..delimiter_index]);997 try w.writeAll(available[0..delimiter_index]);
998 r.toss(delimiter_index);998 r.toss(delimiter_index);
999 remaining -= delimiter_index;999 remaining -= delimiter_index;
...@@ -1064,7 +1064,7 @@ pub fn discardDelimiterLimit(r: *Reader, delimiter: u8, limit: Limit) DiscardDel...@@ -1064,7 +1064,7 @@ pub fn discardDelimiterLimit(r: *Reader, delimiter: u8, limit: Limit) DiscardDel
1064 error.ReadFailed => return error.ReadFailed,1064 error.ReadFailed => return error.ReadFailed,
1065 error.EndOfStream => return @intFromEnum(limit) - remaining,1065 error.EndOfStream => return @intFromEnum(limit) - remaining,
1066 });1066 });
1067 if (std.mem.indexOfScalar(u8, available, delimiter)) |delimiter_index| {1067 if (std.mem.findScalar(u8, available, delimiter)) |delimiter_index| {
1068 r.toss(delimiter_index);1068 r.toss(delimiter_index);
1069 remaining -= delimiter_index;1069 remaining -= delimiter_index;
1070 return @intFromEnum(limit) - remaining;1070 return @intFromEnum(limit) - remaining;
lib/std/Progress.zig+2-2
...@@ -257,7 +257,7 @@ pub const Node = struct {...@@ -257,7 +257,7 @@ pub const Node = struct {
257 const index = n.index.unwrap() orelse return;257 const index = n.index.unwrap() orelse return;
258 const storage = storageByIndex(index);258 const storage = storageByIndex(index);
259259
260 const name_len = @min(max_name_len, std.mem.indexOfScalar(u8, new_name, 0) orelse new_name.len);260 const name_len = @min(max_name_len, std.mem.findScalar(u8, new_name, 0) orelse new_name.len);
261261
262 copyAtomicStore(storage.name[0..name_len], new_name[0..name_len]);262 copyAtomicStore(storage.name[0..name_len], new_name[0..name_len]);
263 if (name_len < storage.name.len)263 if (name_len < storage.name.len)
...@@ -1347,7 +1347,7 @@ fn computeNode(...@@ -1347,7 +1347,7 @@ fn computeNode(
1347 const storage = &serialized.storage[@intFromEnum(node_index)];1347 const storage = &serialized.storage[@intFromEnum(node_index)];
1348 const estimated_total = storage.estimated_total_count;1348 const estimated_total = storage.estimated_total_count;
1349 const completed_items = storage.completed_count;1349 const completed_items = storage.completed_count;
1350 const name = if (std.mem.indexOfScalar(u8, &storage.name, 0)) |end| storage.name[0..end] else &storage.name;1350 const name = if (std.mem.findScalar(u8, &storage.name, 0)) |end| storage.name[0..end] else &storage.name;
1351 const parent = serialized.parents[@intFromEnum(node_index)];1351 const parent = serialized.parents[@intFromEnum(node_index)];
13521352
1353 if (parent != .none) p: {1353 if (parent != .none) p: {
lib/std/Random/benchmark.zig+4-4
...@@ -180,7 +180,7 @@ pub fn main() !void {...@@ -180,7 +180,7 @@ pub fn main() !void {
180 if (bench_prngs) {180 if (bench_prngs) {
181 if (bench_long) {181 if (bench_long) {
182 inline for (prngs) |R| {182 inline for (prngs) |R| {
183 if (filter == null or std.mem.indexOf(u8, R.name, filter.?) != null) {183 if (filter == null or std.mem.find(u8, R.name, filter.?) != null) {
184 try stdout.print("{s} (long outputs)\n", .{R.name});184 try stdout.print("{s} (long outputs)\n", .{R.name});
185 try stdout.flush();185 try stdout.flush();
186186
...@@ -191,7 +191,7 @@ pub fn main() !void {...@@ -191,7 +191,7 @@ pub fn main() !void {
191 }191 }
192 if (bench_short) {192 if (bench_short) {
193 inline for (prngs) |R| {193 inline for (prngs) |R| {
194 if (filter == null or std.mem.indexOf(u8, R.name, filter.?) != null) {194 if (filter == null or std.mem.find(u8, R.name, filter.?) != null) {
195 try stdout.print("{s} (short outputs)\n", .{R.name});195 try stdout.print("{s} (short outputs)\n", .{R.name});
196 try stdout.flush();196 try stdout.flush();
197197
...@@ -204,7 +204,7 @@ pub fn main() !void {...@@ -204,7 +204,7 @@ pub fn main() !void {
204 if (bench_csprngs) {204 if (bench_csprngs) {
205 if (bench_long) {205 if (bench_long) {
206 inline for (csprngs) |R| {206 inline for (csprngs) |R| {
207 if (filter == null or std.mem.indexOf(u8, R.name, filter.?) != null) {207 if (filter == null or std.mem.find(u8, R.name, filter.?) != null) {
208 try stdout.print("{s} (cryptographic, long outputs)\n", .{R.name});208 try stdout.print("{s} (cryptographic, long outputs)\n", .{R.name});
209 try stdout.flush();209 try stdout.flush();
210210
...@@ -215,7 +215,7 @@ pub fn main() !void {...@@ -215,7 +215,7 @@ pub fn main() !void {
215 }215 }
216 if (bench_short) {216 if (bench_short) {
217 inline for (csprngs) |R| {217 inline for (csprngs) |R| {
218 if (filter == null or std.mem.indexOf(u8, R.name, filter.?) != null) {218 if (filter == null or std.mem.find(u8, R.name, filter.?) != null) {
219 try stdout.print("{s} (cryptographic, short outputs)\n", .{R.name});219 try stdout.print("{s} (cryptographic, short outputs)\n", .{R.name});
220 try stdout.flush();220 try stdout.flush();
221221
lib/std/SemanticVersion.zig+2-2
...@@ -84,7 +84,7 @@ pub fn order(lhs: Version, rhs: Version) std.math.Order {...@@ -84,7 +84,7 @@ pub fn order(lhs: Version, rhs: Version) std.math.Order {
8484
85pub fn parse(text: []const u8) !Version {85pub fn parse(text: []const u8) !Version {
86 // Parse the required major, minor, and patch numbers.86 // Parse the required major, minor, and patch numbers.
87 const extra_index = std.mem.indexOfAny(u8, text, "-+");87 const extra_index = std.mem.findAny(u8, text, "-+");
88 const required = text[0..(extra_index orelse text.len)];88 const required = text[0..(extra_index orelse text.len)];
89 var it = std.mem.splitScalar(u8, required, '.');89 var it = std.mem.splitScalar(u8, required, '.');
90 var ver = Version{90 var ver = Version{
...@@ -98,7 +98,7 @@ pub fn parse(text: []const u8) !Version {...@@ -98,7 +98,7 @@ pub fn parse(text: []const u8) !Version {
98 // Slice optional pre-release or build metadata components.98 // Slice optional pre-release or build metadata components.
99 const extra: []const u8 = text[extra_index.?..text.len];99 const extra: []const u8 = text[extra_index.?..text.len];
100 if (extra[0] == '-') {100 if (extra[0] == '-') {
101 const build_index = std.mem.indexOfScalar(u8, extra, '+');101 const build_index = std.mem.findScalar(u8, extra, '+');
102 ver.pre = extra[1..(build_index orelse extra.len)];102 ver.pre = extra[1..(build_index orelse extra.len)];
103 if (build_index) |idx| ver.build = extra[(idx + 1)..];103 if (build_index) |idx| ver.build = extra[(idx + 1)..];
104 } else {104 } else {
lib/std/Uri.zig+8-8
...@@ -65,7 +65,7 @@ pub const Component = union(enum) {...@@ -65,7 +65,7 @@ pub const Component = union(enum) {
65 pub fn toRaw(component: Component, buffer: []u8) error{NoSpaceLeft}![]const u8 {65 pub fn toRaw(component: Component, buffer: []u8) error{NoSpaceLeft}![]const u8 {
66 return switch (component) {66 return switch (component) {
67 .raw => |raw| raw,67 .raw => |raw| raw,
68 .percent_encoded => |percent_encoded| if (std.mem.indexOfScalar(u8, percent_encoded, '%')) |_|68 .percent_encoded => |percent_encoded| if (std.mem.findScalar(u8, percent_encoded, '%')) |_|
69 try std.fmt.bufPrint(buffer, "{f}", .{std.fmt.alt(component, .formatRaw)})69 try std.fmt.bufPrint(buffer, "{f}", .{std.fmt.alt(component, .formatRaw)})
70 else70 else
71 percent_encoded,71 percent_encoded,
...@@ -76,7 +76,7 @@ pub const Component = union(enum) {...@@ -76,7 +76,7 @@ pub const Component = union(enum) {
76 pub fn toRawMaybeAlloc(component: Component, arena: Allocator) Allocator.Error![]const u8 {76 pub fn toRawMaybeAlloc(component: Component, arena: Allocator) Allocator.Error![]const u8 {
77 return switch (component) {77 return switch (component) {
78 .raw => |raw| raw,78 .raw => |raw| raw,
79 .percent_encoded => |percent_encoded| if (std.mem.indexOfScalar(u8, percent_encoded, '%')) |_|79 .percent_encoded => |percent_encoded| if (std.mem.findScalar(u8, percent_encoded, '%')) |_|
80 try std.fmt.allocPrint(arena, "{f}", .{std.fmt.alt(component, .formatRaw)})80 try std.fmt.allocPrint(arena, "{f}", .{std.fmt.alt(component, .formatRaw)})
81 else81 else
82 percent_encoded,82 percent_encoded,
...@@ -89,7 +89,7 @@ pub const Component = union(enum) {...@@ -89,7 +89,7 @@ pub const Component = union(enum) {
89 .percent_encoded => |percent_encoded| {89 .percent_encoded => |percent_encoded| {
90 var start: usize = 0;90 var start: usize = 0;
91 var index: usize = 0;91 var index: usize = 0;
92 while (std.mem.indexOfScalarPos(u8, percent_encoded, index, '%')) |percent| {92 while (std.mem.findScalarPos(u8, percent_encoded, index, '%')) |percent| {
93 index = percent + 1;93 index = percent + 1;
94 if (percent_encoded.len - index < 2) continue;94 if (percent_encoded.len - index < 2) continue;
95 const percent_encoded_char =95 const percent_encoded_char =
...@@ -213,7 +213,7 @@ pub fn parseAfterScheme(scheme: []const u8, text: []const u8) ParseError!Uri {...@@ -213,7 +213,7 @@ pub fn parseAfterScheme(scheme: []const u8, text: []const u8) ParseError!Uri {
213 var i: usize = 0;213 var i: usize = 0;
214214
215 if (std.mem.startsWith(u8, text, "//")) a: {215 if (std.mem.startsWith(u8, text, "//")) a: {
216 i = std.mem.indexOfAnyPos(u8, text, 2, &authority_sep) orelse text.len;216 i = std.mem.findAnyPos(u8, text, 2, &authority_sep) orelse text.len;
217 const authority = text[2..i];217 const authority = text[2..i];
218 if (authority.len == 0) {218 if (authority.len == 0) {
219 if (!std.mem.startsWith(u8, text[2..], "/")) return error.InvalidFormat;219 if (!std.mem.startsWith(u8, text[2..], "/")) return error.InvalidFormat;
...@@ -221,11 +221,11 @@ pub fn parseAfterScheme(scheme: []const u8, text: []const u8) ParseError!Uri {...@@ -221,11 +221,11 @@ pub fn parseAfterScheme(scheme: []const u8, text: []const u8) ParseError!Uri {
221 }221 }
222222
223 var start_of_host: usize = 0;223 var start_of_host: usize = 0;
224 if (std.mem.indexOf(u8, authority, "@")) |index| {224 if (std.mem.find(u8, authority, "@")) |index| {
225 start_of_host = index + 1;225 start_of_host = index + 1;
226 const user_info = authority[0..index];226 const user_info = authority[0..index];
227227
228 if (std.mem.indexOf(u8, user_info, ":")) |idx| {228 if (std.mem.find(u8, user_info, ":")) |idx| {
229 uri.user = .{ .percent_encoded = user_info[0..idx] };229 uri.user = .{ .percent_encoded = user_info[0..idx] };
230 if (idx < user_info.len - 1) { // empty password is also "no password"230 if (idx < user_info.len - 1) { // empty password is also "no password"
231 uri.password = .{ .percent_encoded = user_info[idx + 1 ..] };231 uri.password = .{ .percent_encoded = user_info[idx + 1 ..] };
...@@ -268,12 +268,12 @@ pub fn parseAfterScheme(scheme: []const u8, text: []const u8) ParseError!Uri {...@@ -268,12 +268,12 @@ pub fn parseAfterScheme(scheme: []const u8, text: []const u8) ParseError!Uri {
268 }268 }
269269
270 const path_start = i;270 const path_start = i;
271 i = std.mem.indexOfAnyPos(u8, text, path_start, &path_sep) orelse text.len;271 i = std.mem.findAnyPos(u8, text, path_start, &path_sep) orelse text.len;
272 uri.path = .{ .percent_encoded = text[path_start..i] };272 uri.path = .{ .percent_encoded = text[path_start..i] };
273273
274 if (std.mem.startsWith(u8, text[i..], "?")) {274 if (std.mem.startsWith(u8, text[i..], "?")) {
275 const query_start = i + 1;275 const query_start = i + 1;
276 i = std.mem.indexOfScalarPos(u8, text, query_start, '#') orelse text.len;276 i = std.mem.findScalarPos(u8, text, query_start, '#') orelse text.len;
277 uri.query = .{ .percent_encoded = text[query_start..i] };277 uri.query = .{ .percent_encoded = text[query_start..i] };
278 }278 }
279279
lib/std/coff.zig+5-5
...@@ -466,13 +466,13 @@ pub const SectionHeader = extern struct {...@@ -466,13 +466,13 @@ pub const SectionHeader = extern struct {
466466
467 pub fn getName(self: *align(1) const SectionHeader) ?[]const u8 {467 pub fn getName(self: *align(1) const SectionHeader) ?[]const u8 {
468 if (self.name[0] == '/') return null;468 if (self.name[0] == '/') return null;
469 const len = std.mem.indexOfScalar(u8, &self.name, @as(u8, 0)) orelse self.name.len;469 const len = std.mem.findScalar(u8, &self.name, @as(u8, 0)) orelse self.name.len;
470 return self.name[0..len];470 return self.name[0..len];
471 }471 }
472472
473 pub fn getNameOffset(self: SectionHeader) ?u32 {473 pub fn getNameOffset(self: SectionHeader) ?u32 {
474 if (self.name[0] != '/') return null;474 if (self.name[0] != '/') return null;
475 const len = std.mem.indexOfScalar(u8, &self.name, @as(u8, 0)) orelse self.name.len;475 const len = std.mem.findScalar(u8, &self.name, @as(u8, 0)) orelse self.name.len;
476 const offset = std.fmt.parseInt(u32, self.name[1..len], 10) catch unreachable;476 const offset = std.fmt.parseInt(u32, self.name[1..len], 10) catch unreachable;
477 return offset;477 return offset;
478 }478 }
...@@ -628,7 +628,7 @@ pub const Symbol = struct {...@@ -628,7 +628,7 @@ pub const Symbol = struct {
628628
629 pub fn getName(self: *const Symbol) ?[]const u8 {629 pub fn getName(self: *const Symbol) ?[]const u8 {
630 if (std.mem.eql(u8, self.name[0..4], "\x00\x00\x00\x00")) return null;630 if (std.mem.eql(u8, self.name[0..4], "\x00\x00\x00\x00")) return null;
631 const len = std.mem.indexOfScalar(u8, &self.name, @as(u8, 0)) orelse self.name.len;631 const len = std.mem.findScalar(u8, &self.name, @as(u8, 0)) orelse self.name.len;
632 return self.name[0..len];632 return self.name[0..len];
633 }633 }
634634
...@@ -869,7 +869,7 @@ pub const FileDefinition = struct {...@@ -869,7 +869,7 @@ pub const FileDefinition = struct {
869 file_name: [18]u8,869 file_name: [18]u8,
870870
871 pub fn getFileName(self: *const FileDefinition) []const u8 {871 pub fn getFileName(self: *const FileDefinition) []const u8 {
872 const len = std.mem.indexOfScalar(u8, &self.file_name, @as(u8, 0)) orelse self.file_name.len;872 const len = std.mem.findScalar(u8, &self.file_name, @as(u8, 0)) orelse self.file_name.len;
873 return self.file_name[0..len];873 return self.file_name[0..len];
874 }874 }
875};875};
...@@ -1044,7 +1044,7 @@ pub const Coff = struct {...@@ -1044,7 +1044,7 @@ pub const Coff = struct {
10441044
1045 // Finally read the null-terminated string.1045 // Finally read the null-terminated string.
1046 const start = reader.seek;1046 const start = reader.seek;
1047 const len = std.mem.indexOfScalar(u8, self.data[start..], 0) orelse return null;1047 const len = std.mem.findScalar(u8, self.data[start..], 0) orelse return null;
1048 return self.data[start .. start + len];1048 return self.data[start .. start + len];
1049 }1049 }
10501050
lib/std/compress/flate/Compress.zig+1-1
...@@ -598,7 +598,7 @@ fn testFuzzedMatchLen(_: void, input: []const u8) !void {...@@ -598,7 +598,7 @@ fn testFuzzedMatchLen(_: void, input: []const u8) !void {
598 const bytes = w.buffered()[bytes_off..];598 const bytes = w.buffered()[bytes_off..];
599 old = @min(old, bytes.len - 1, token.max_length - 1);599 old = @min(old, bytes.len - 1, token.max_length - 1);
600600
601 const diff_index = mem.indexOfDiff(u8, prev, bytes).?; // unwrap since lengths are not same601 const diff_index = mem.findDiff(u8, prev, bytes).?; // unwrap since lengths are not same
602 const expected_len = @min(diff_index, 258);602 const expected_len = @min(diff_index, 258);
603 errdefer std.debug.print(603 errdefer std.debug.print(
604 \\prev : '{any}'604 \\prev : '{any}'
lib/std/crypto/Certificate.zig+2-2
...@@ -358,10 +358,10 @@ pub const Parsed = struct {...@@ -358,10 +358,10 @@ pub const Parsed = struct {
358 const wildcard_suffix = dns_name[2..];358 const wildcard_suffix = dns_name[2..];
359359
360 // No additional wildcards allowed in the suffix360 // No additional wildcards allowed in the suffix
361 if (mem.indexOf(u8, wildcard_suffix, "*") != null) return false;361 if (mem.find(u8, wildcard_suffix, "*") != null) return false;
362362
363 // Find the first dot in hostname to split first label from rest363 // Find the first dot in hostname to split first label from rest
364 const dot_pos = mem.indexOf(u8, host_name, ".") orelse return false;364 const dot_pos = mem.find(u8, host_name, ".") orelse return false;
365365
366 // Wildcard matches exactly one label, so compare the rest366 // Wildcard matches exactly one label, so compare the rest
367 const host_suffix = host_name[dot_pos + 1 ..];367 const host_suffix = host_name[dot_pos + 1 ..];
lib/std/crypto/Certificate/Bundle.zig+2-2
...@@ -269,9 +269,9 @@ pub fn addCertsFromFile(cb: *Bundle, gpa: Allocator, file_reader: *Io.File.Reade...@@ -269,9 +269,9 @@ pub fn addCertsFromFile(cb: *Bundle, gpa: Allocator, file_reader: *Io.File.Reade
269 const end_marker = "-----END CERTIFICATE-----";269 const end_marker = "-----END CERTIFICATE-----";
270270
271 var start_index: usize = 0;271 var start_index: usize = 0;
272 while (mem.indexOfPos(u8, encoded_bytes, start_index, begin_marker)) |begin_marker_start| {272 while (mem.findPos(u8, encoded_bytes, start_index, begin_marker)) |begin_marker_start| {
273 const cert_start = begin_marker_start + begin_marker.len;273 const cert_start = begin_marker_start + begin_marker.len;
274 const cert_end = mem.indexOfPos(u8, encoded_bytes, cert_start, end_marker) orelse274 const cert_end = mem.findPos(u8, encoded_bytes, cert_start, end_marker) orelse
275 return error.MissingEndCertificateMarker;275 return error.MissingEndCertificateMarker;
276 start_index = cert_end + end_marker.len;276 start_index = cert_end + end_marker.len;
277 const encoded_cert = mem.trim(u8, encoded_bytes[cert_start..cert_end], " \t\r\n");277 const encoded_cert = mem.trim(u8, encoded_bytes[cert_start..cert_end], " \t\r\n");
lib/std/crypto/benchmark.zig+14-14
...@@ -547,7 +547,7 @@ pub fn main() !void {...@@ -547,7 +547,7 @@ pub fn main() !void {
547 }547 }
548548
549 inline for (hashes) |H| {549 inline for (hashes) |H| {
550 if (filter == null or std.mem.indexOf(u8, H.name, filter.?) != null) {550 if (filter == null or std.mem.find(u8, H.name, filter.?) != null) {
551 const throughput = try benchmarkHash(H.ty, mode(128 * MiB));551 const throughput = try benchmarkHash(H.ty, mode(128 * MiB));
552 try stdout.print("{s:>17}: {:10} MiB/s\n", .{ H.name, throughput / (1 * MiB) });552 try stdout.print("{s:>17}: {:10} MiB/s\n", .{ H.name, throughput / (1 * MiB) });
553 try stdout.flush();553 try stdout.flush();
...@@ -559,7 +559,7 @@ pub fn main() !void {...@@ -559,7 +559,7 @@ pub fn main() !void {
559 const io = io_threaded.io();559 const io = io_threaded.io();
560560
561 inline for (parallel_hashes) |H| {561 inline for (parallel_hashes) |H| {
562 if (filter == null or std.mem.indexOf(u8, H.name, filter.?) != null) {562 if (filter == null or std.mem.find(u8, H.name, filter.?) != null) {
563 const throughput = try benchmarkHashParallel(H.ty, mode(128 * MiB), arena_allocator, io);563 const throughput = try benchmarkHashParallel(H.ty, mode(128 * MiB), arena_allocator, io);
564 try stdout.print("{s:>17}: {:10} MiB/s\n", .{ H.name, throughput / (1 * MiB) });564 try stdout.print("{s:>17}: {:10} MiB/s\n", .{ H.name, throughput / (1 * MiB) });
565 try stdout.flush();565 try stdout.flush();
...@@ -567,7 +567,7 @@ pub fn main() !void {...@@ -567,7 +567,7 @@ pub fn main() !void {
567 }567 }
568568
569 inline for (macs) |M| {569 inline for (macs) |M| {
570 if (filter == null or std.mem.indexOf(u8, M.name, filter.?) != null) {570 if (filter == null or std.mem.find(u8, M.name, filter.?) != null) {
571 const throughput = try benchmarkMac(M.ty, mode(128 * MiB));571 const throughput = try benchmarkMac(M.ty, mode(128 * MiB));
572 try stdout.print("{s:>17}: {:10} MiB/s\n", .{ M.name, throughput / (1 * MiB) });572 try stdout.print("{s:>17}: {:10} MiB/s\n", .{ M.name, throughput / (1 * MiB) });
573 try stdout.flush();573 try stdout.flush();
...@@ -575,7 +575,7 @@ pub fn main() !void {...@@ -575,7 +575,7 @@ pub fn main() !void {
575 }575 }
576576
577 inline for (exchanges) |E| {577 inline for (exchanges) |E| {
578 if (filter == null or std.mem.indexOf(u8, E.name, filter.?) != null) {578 if (filter == null or std.mem.find(u8, E.name, filter.?) != null) {
579 const throughput = try benchmarkKeyExchange(E.ty, mode(1000));579 const throughput = try benchmarkKeyExchange(E.ty, mode(1000));
580 try stdout.print("{s:>17}: {:10} exchanges/s\n", .{ E.name, throughput });580 try stdout.print("{s:>17}: {:10} exchanges/s\n", .{ E.name, throughput });
581 try stdout.flush();581 try stdout.flush();
...@@ -583,7 +583,7 @@ pub fn main() !void {...@@ -583,7 +583,7 @@ pub fn main() !void {
583 }583 }
584584
585 inline for (signatures) |E| {585 inline for (signatures) |E| {
586 if (filter == null or std.mem.indexOf(u8, E.name, filter.?) != null) {586 if (filter == null or std.mem.find(u8, E.name, filter.?) != null) {
587 const throughput = try benchmarkSignature(E.ty, mode(1000));587 const throughput = try benchmarkSignature(E.ty, mode(1000));
588 try stdout.print("{s:>17}: {:10} signatures/s\n", .{ E.name, throughput });588 try stdout.print("{s:>17}: {:10} signatures/s\n", .{ E.name, throughput });
589 try stdout.flush();589 try stdout.flush();
...@@ -591,7 +591,7 @@ pub fn main() !void {...@@ -591,7 +591,7 @@ pub fn main() !void {
591 }591 }
592592
593 inline for (signature_verifications) |E| {593 inline for (signature_verifications) |E| {
594 if (filter == null or std.mem.indexOf(u8, E.name, filter.?) != null) {594 if (filter == null or std.mem.find(u8, E.name, filter.?) != null) {
595 const throughput = try benchmarkSignatureVerification(E.ty, mode(1000));595 const throughput = try benchmarkSignatureVerification(E.ty, mode(1000));
596 try stdout.print("{s:>17}: {:10} verifications/s\n", .{ E.name, throughput });596 try stdout.print("{s:>17}: {:10} verifications/s\n", .{ E.name, throughput });
597 try stdout.flush();597 try stdout.flush();
...@@ -599,7 +599,7 @@ pub fn main() !void {...@@ -599,7 +599,7 @@ pub fn main() !void {
599 }599 }
600600
601 inline for (batch_signature_verifications) |E| {601 inline for (batch_signature_verifications) |E| {
602 if (filter == null or std.mem.indexOf(u8, E.name, filter.?) != null) {602 if (filter == null or std.mem.find(u8, E.name, filter.?) != null) {
603 const throughput = try benchmarkBatchSignatureVerification(E.ty, mode(1000));603 const throughput = try benchmarkBatchSignatureVerification(E.ty, mode(1000));
604 try stdout.print("{s:>17}: {:10} verifications/s (batch)\n", .{ E.name, throughput });604 try stdout.print("{s:>17}: {:10} verifications/s (batch)\n", .{ E.name, throughput });
605 try stdout.flush();605 try stdout.flush();
...@@ -607,7 +607,7 @@ pub fn main() !void {...@@ -607,7 +607,7 @@ pub fn main() !void {
607 }607 }
608608
609 inline for (aeads) |E| {609 inline for (aeads) |E| {
610 if (filter == null or std.mem.indexOf(u8, E.name, filter.?) != null) {610 if (filter == null or std.mem.find(u8, E.name, filter.?) != null) {
611 const throughput = try benchmarkAead(E.ty, mode(128 * MiB));611 const throughput = try benchmarkAead(E.ty, mode(128 * MiB));
612 try stdout.print("{s:>17}: {:10} MiB/s\n", .{ E.name, throughput / (1 * MiB) });612 try stdout.print("{s:>17}: {:10} MiB/s\n", .{ E.name, throughput / (1 * MiB) });
613 try stdout.flush();613 try stdout.flush();
...@@ -615,7 +615,7 @@ pub fn main() !void {...@@ -615,7 +615,7 @@ pub fn main() !void {
615 }615 }
616616
617 inline for (aes) |E| {617 inline for (aes) |E| {
618 if (filter == null or std.mem.indexOf(u8, E.name, filter.?) != null) {618 if (filter == null or std.mem.find(u8, E.name, filter.?) != null) {
619 const throughput = try benchmarkAes(E.ty, mode(100000000));619 const throughput = try benchmarkAes(E.ty, mode(100000000));
620 try stdout.print("{s:>17}: {:10} ops/s\n", .{ E.name, throughput });620 try stdout.print("{s:>17}: {:10} ops/s\n", .{ E.name, throughput });
621 try stdout.flush();621 try stdout.flush();
...@@ -623,7 +623,7 @@ pub fn main() !void {...@@ -623,7 +623,7 @@ pub fn main() !void {
623 }623 }
624624
625 inline for (aes8) |E| {625 inline for (aes8) |E| {
626 if (filter == null or std.mem.indexOf(u8, E.name, filter.?) != null) {626 if (filter == null or std.mem.find(u8, E.name, filter.?) != null) {
627 const throughput = try benchmarkAes8(E.ty, mode(10000000));627 const throughput = try benchmarkAes8(E.ty, mode(10000000));
628 try stdout.print("{s:>17}: {:10} ops/s\n", .{ E.name, throughput });628 try stdout.print("{s:>17}: {:10} ops/s\n", .{ E.name, throughput });
629 try stdout.flush();629 try stdout.flush();
...@@ -631,7 +631,7 @@ pub fn main() !void {...@@ -631,7 +631,7 @@ pub fn main() !void {
631 }631 }
632632
633 inline for (pwhashes) |H| {633 inline for (pwhashes) |H| {
634 if (filter == null or std.mem.indexOf(u8, H.name, filter.?) != null) {634 if (filter == null or std.mem.find(u8, H.name, filter.?) != null) {
635 const throughput = try benchmarkPwhash(arena_allocator, H.ty, H.params, mode(64), io);635 const throughput = try benchmarkPwhash(arena_allocator, H.ty, H.params, mode(64), io);
636 try stdout.print("{s:>17}: {d:10.3} s/ops\n", .{ H.name, throughput });636 try stdout.print("{s:>17}: {d:10.3} s/ops\n", .{ H.name, throughput });
637 try stdout.flush();637 try stdout.flush();
...@@ -639,7 +639,7 @@ pub fn main() !void {...@@ -639,7 +639,7 @@ pub fn main() !void {
639 }639 }
640640
641 inline for (kems) |E| {641 inline for (kems) |E| {
642 if (filter == null or std.mem.indexOf(u8, E.name, filter.?) != null) {642 if (filter == null or std.mem.find(u8, E.name, filter.?) != null) {
643 const throughput = try benchmarkKem(E.ty, mode(1000));643 const throughput = try benchmarkKem(E.ty, mode(1000));
644 try stdout.print("{s:>17}: {:10} encaps/s\n", .{ E.name, throughput });644 try stdout.print("{s:>17}: {:10} encaps/s\n", .{ E.name, throughput });
645 try stdout.flush();645 try stdout.flush();
...@@ -647,7 +647,7 @@ pub fn main() !void {...@@ -647,7 +647,7 @@ pub fn main() !void {
647 }647 }
648648
649 inline for (kems) |E| {649 inline for (kems) |E| {
650 if (filter == null or std.mem.indexOf(u8, E.name, filter.?) != null) {650 if (filter == null or std.mem.find(u8, E.name, filter.?) != null) {
651 const throughput = try benchmarkKemDecaps(E.ty, mode(25000));651 const throughput = try benchmarkKemDecaps(E.ty, mode(25000));
652 try stdout.print("{s:>17}: {:10} decaps/s\n", .{ E.name, throughput });652 try stdout.print("{s:>17}: {:10} decaps/s\n", .{ E.name, throughput });
653 try stdout.flush();653 try stdout.flush();
...@@ -655,7 +655,7 @@ pub fn main() !void {...@@ -655,7 +655,7 @@ pub fn main() !void {
655 }655 }
656656
657 inline for (kems) |E| {657 inline for (kems) |E| {
658 if (filter == null or std.mem.indexOf(u8, E.name, filter.?) != null) {658 if (filter == null or std.mem.find(u8, E.name, filter.?) != null) {
659 const throughput = try benchmarkKemKeyGen(E.ty, mode(25000));659 const throughput = try benchmarkKemKeyGen(E.ty, mode(25000));
660 try stdout.print("{s:>17}: {:10} keygen/s\n", .{ E.name, throughput });660 try stdout.print("{s:>17}: {:10} keygen/s\n", .{ E.name, throughput });
661 try stdout.flush();661 try stdout.flush();
lib/std/crypto/scrypt.zig+1-1
...@@ -358,7 +358,7 @@ const crypt_format = struct {...@@ -358,7 +358,7 @@ const crypt_format = struct {
358 fn intDecode(comptime T: type, src: *const [(@bitSizeOf(T) + 5) / 6]u8) !T {358 fn intDecode(comptime T: type, src: *const [(@bitSizeOf(T) + 5) / 6]u8) !T {
359 var v: T = 0;359 var v: T = 0;
360 for (src, 0..) |x, i| {360 for (src, 0..) |x, i| {
361 const vi = mem.indexOfScalar(u8, &map64, x) orelse return EncodingError.InvalidEncoding;361 const vi = mem.findScalar(u8, &map64, x) orelse return EncodingError.InvalidEncoding;
362 v |= @as(T, @intCast(vi)) << @as(math.Log2Int(T), @intCast(i * 6));362 v |= @as(T, @intCast(vi)) << @as(math.Log2Int(T), @intCast(i * 6));
363 }363 }
364 return v;364 return v;
lib/std/debug.zig+3-3
...@@ -1196,7 +1196,7 @@ fn printLineFromFile(writer: *Writer, source_location: SourceLocation) !void {...@@ -1196,7 +1196,7 @@ fn printLineFromFile(writer: *Writer, source_location: SourceLocation) !void {
1196 var next_line: usize = 1;1196 var next_line: usize = 1;
1197 while (next_line != source_location.line) {1197 while (next_line != source_location.line) {
1198 const slice = buf[current_line_start..amt_read];1198 const slice = buf[current_line_start..amt_read];
1199 if (mem.indexOfScalar(u8, slice, '\n')) |pos| {1199 if (mem.findScalar(u8, slice, '\n')) |pos| {
1200 next_line += 1;1200 next_line += 1;
1201 if (pos == slice.len - 1) {1201 if (pos == slice.len - 1) {
1202 amt_read = try f.read(buf[0..]);1202 amt_read = try f.read(buf[0..]);
...@@ -1212,7 +1212,7 @@ fn printLineFromFile(writer: *Writer, source_location: SourceLocation) !void {...@@ -1212,7 +1212,7 @@ fn printLineFromFile(writer: *Writer, source_location: SourceLocation) !void {
1212 break :seek current_line_start;1212 break :seek current_line_start;
1213 };1213 };
1214 const slice = buf[line_start..amt_read];1214 const slice = buf[line_start..amt_read];
1215 if (mem.indexOfScalar(u8, slice, '\n')) |pos| {1215 if (mem.findScalar(u8, slice, '\n')) |pos| {
1216 const line = slice[0 .. pos + 1];1216 const line = slice[0 .. pos + 1];
1217 mem.replaceScalar(u8, line, '\t', ' ');1217 mem.replaceScalar(u8, line, '\t', ' ');
1218 return writer.writeAll(line);1218 return writer.writeAll(line);
...@@ -1221,7 +1221,7 @@ fn printLineFromFile(writer: *Writer, source_location: SourceLocation) !void {...@@ -1221,7 +1221,7 @@ fn printLineFromFile(writer: *Writer, source_location: SourceLocation) !void {
1221 try writer.writeAll(slice);1221 try writer.writeAll(slice);
1222 while (amt_read == buf.len) {1222 while (amt_read == buf.len) {
1223 amt_read = try f.read(buf[0..]);1223 amt_read = try f.read(buf[0..]);
1224 if (mem.indexOfScalar(u8, buf[0..amt_read], '\n')) |pos| {1224 if (mem.findScalar(u8, buf[0..amt_read], '\n')) |pos| {
1225 const line = buf[0 .. pos + 1];1225 const line = buf[0 .. pos + 1];
1226 mem.replaceScalar(u8, line, '\t', ' ');1226 mem.replaceScalar(u8, line, '\t', ' ');
1227 return writer.writeAll(line);1227 return writer.writeAll(line);
lib/std/debug/Dwarf.zig+2-2
...@@ -437,7 +437,7 @@ fn scanAllFunctions(di: *Dwarf, gpa: Allocator, endian: Endian) ScanError!void {...@@ -437,7 +437,7 @@ fn scanAllFunctions(di: *Dwarf, gpa: Allocator, endian: Endian) ScanError!void {
437 };437 };
438438
439 while (true) {439 while (true) {
440 fr.seek = std.mem.indexOfNonePos(u8, fr.buffer, fr.seek, &.{440 fr.seek = std.mem.findNonePos(u8, fr.buffer, fr.seek, &.{
441 zig_padding_abbrev_code, 0,441 zig_padding_abbrev_code, 0,
442 }) orelse fr.buffer.len;442 }) orelse fr.buffer.len;
443 if (fr.seek >= next_unit_pos) break;443 if (fr.seek >= next_unit_pos) break;
...@@ -1539,7 +1539,7 @@ fn getStringGeneric(opt_str: ?[]const u8, offset: u64) ![:0]const u8 {...@@ -1539,7 +1539,7 @@ fn getStringGeneric(opt_str: ?[]const u8, offset: u64) ![:0]const u8 {
1539 if (offset > str.len) return bad();1539 if (offset > str.len) return bad();
1540 const casted_offset = cast(usize, offset) orelse return bad();1540 const casted_offset = cast(usize, offset) orelse return bad();
1541 // Valid strings always have a terminating zero byte1541 // Valid strings always have a terminating zero byte
1542 const last = std.mem.indexOfScalarPos(u8, str, casted_offset, 0) orelse return bad();1542 const last = std.mem.findScalarPos(u8, str, casted_offset, 0) orelse return bad();
1543 return str[casted_offset..last :0];1543 return str[casted_offset..last :0];
1544}1544}
15451545
lib/std/dynamic_library.zig+1-1
...@@ -197,7 +197,7 @@ pub const ElfDynLib = struct {...@@ -197,7 +197,7 @@ pub const ElfDynLib = struct {
197 // - /etc/ld.so.cache is not read197 // - /etc/ld.so.cache is not read
198 fn resolveFromName(path_or_name: []const u8) !posix.fd_t {198 fn resolveFromName(path_or_name: []const u8) !posix.fd_t {
199 // If filename contains a slash ("/"), then it is interpreted as a (relative or absolute) pathname199 // If filename contains a slash ("/"), then it is interpreted as a (relative or absolute) pathname
200 if (std.mem.indexOfScalarPos(u8, path_or_name, 0, '/')) |_| {200 if (std.mem.findScalarPos(u8, path_or_name, 0, '/')) |_| {
201 return posix.open(path_or_name, .{ .ACCMODE = .RDONLY, .CLOEXEC = true }, 0);201 return posix.open(path_or_name, .{ .ACCMODE = .RDONLY, .CLOEXEC = true }, 0);
202 }202 }
203203
lib/std/elf.zig+1-1
...@@ -3039,7 +3039,7 @@ pub const ar_hdr = extern struct {...@@ -3039,7 +3039,7 @@ pub const ar_hdr = extern struct {
3039 pub fn name(self: *const ar_hdr) ?[]const u8 {3039 pub fn name(self: *const ar_hdr) ?[]const u8 {
3040 const value = &self.ar_name;3040 const value = &self.ar_name;
3041 if (value[0] == '/') return null;3041 if (value[0] == '/') return null;
3042 const sentinel = mem.indexOfScalar(u8, value, '/') orelse value.len;3042 const sentinel = mem.findScalar(u8, value, '/') orelse value.len;
3043 return value[0..sentinel];3043 return value[0..sentinel];
3044 }3044 }
30453045
lib/std/fmt.zig+1-1
...@@ -182,7 +182,7 @@ pub const Parser = struct {...@@ -182,7 +182,7 @@ pub const Parser = struct {
182182
183 pub fn until(self: *@This(), delimiter: u8) []const u8 {183 pub fn until(self: *@This(), delimiter: u8) []const u8 {
184 const start = self.i;184 const start = self.i;
185 self.i = std.mem.indexOfScalarPos(u8, self.bytes, self.i, delimiter) orelse self.bytes.len;185 self.i = std.mem.findScalarPos(u8, self.bytes, self.i, delimiter) orelse self.bytes.len;
186 return self.bytes[start..self.i];186 return self.bytes[start..self.i];
187 }187 }
188188
lib/std/fs.zig+1-1
...@@ -469,7 +469,7 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 {...@@ -469,7 +469,7 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 {
469 return error.FileNotFound;469 return error.FileNotFound;
470470
471 const argv0 = mem.span(std.os.argv[0]);471 const argv0 = mem.span(std.os.argv[0]);
472 if (mem.indexOf(u8, argv0, "/") != null) {472 if (mem.find(u8, argv0, "/") != null) {
473 // argv[0] is a path (relative or absolute): use realpath(3) directly473 // argv[0] is a path (relative or absolute): use realpath(3) directly
474 var real_path_buf: [max_path_bytes]u8 = undefined;474 var real_path_buf: [max_path_bytes]u8 = undefined;
475 const real_path = posix.realpathZ(std.os.argv[0], &real_path_buf) catch |err| switch (err) {475 const real_path = posix.realpathZ(std.os.argv[0], &real_path_buf) catch |err| switch (err) {
lib/std/fs/File.zig+1-1
...@@ -179,7 +179,7 @@ pub fn isCygwinPty(file: File) bool {...@@ -179,7 +179,7 @@ pub fn isCygwinPty(file: File) bool {
179 // The name we get from NtQueryInformationFile will be prefixed with a '\', e.g. \msys-1888ae32e00d56aa-pty0-to-master179 // The name we get from NtQueryInformationFile will be prefixed with a '\', e.g. \msys-1888ae32e00d56aa-pty0-to-master
180 return (std.mem.startsWith(u16, name_wide, &[_]u16{ '\\', 'm', 's', 'y', 's', '-' }) or180 return (std.mem.startsWith(u16, name_wide, &[_]u16{ '\\', 'm', 's', 'y', 's', '-' }) or
181 std.mem.startsWith(u16, name_wide, &[_]u16{ '\\', 'c', 'y', 'g', 'w', 'i', 'n', '-' })) and181 std.mem.startsWith(u16, name_wide, &[_]u16{ '\\', 'c', 'y', 'g', 'w', 'i', 'n', '-' })) and
182 std.mem.indexOf(u16, name_wide, &[_]u16{ '-', 'p', 't', 'y' }) != null;182 std.mem.find(u16, name_wide, &[_]u16{ '-', 'p', 't', 'y' }) != null;
183}183}
184184
185/// Returns whether or not ANSI escape codes will be treated as such,185/// Returns whether or not ANSI escape codes will be treated as such,
lib/std/fs/path.zig+3-3
...@@ -402,9 +402,9 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {...@@ -402,9 +402,9 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {
402402
403 if (path.len >= 2 and PathType.windows.isSep(u8, path[0]) and PathType.windows.isSep(u8, path[1])) {403 if (path.len >= 2 and PathType.windows.isSep(u8, path[0]) and PathType.windows.isSep(u8, path[1])) {
404 const root_end = root_end: {404 const root_end = root_end: {
405 var server_end = mem.indexOfAnyPos(u8, path, 2, "/\\") orelse break :root_end path.len;405 var server_end = mem.findAnyPos(u8, path, 2, "/\\") orelse break :root_end path.len;
406 while (server_end < path.len and PathType.windows.isSep(u8, path[server_end])) server_end += 1;406 while (server_end < path.len and PathType.windows.isSep(u8, path[server_end])) server_end += 1;
407 break :root_end mem.indexOfAnyPos(u8, path, server_end, "/\\") orelse path.len;407 break :root_end mem.findAnyPos(u8, path, server_end, "/\\") orelse path.len;
408 };408 };
409 return WindowsPath{409 return WindowsPath{
410 .is_abs = true,410 .is_abs = true,
...@@ -722,7 +722,7 @@ fn parseUNC(comptime T: type, path: []const T) WindowsUNC(T) {...@@ -722,7 +722,7 @@ fn parseUNC(comptime T: type, path: []const T) WindowsUNC(T) {
722 // For the server, the first path separator after the initial two is always722 // For the server, the first path separator after the initial two is always
723 // the terminator of the server name, even if that means the server name is723 // the terminator of the server name, even if that means the server name is
724 // zero-length.724 // zero-length.
725 const server_end = mem.indexOfAnyPos(T, path, 2, any_sep) orelse return .{725 const server_end = mem.findAnyPos(T, path, 2, any_sep) orelse return .{
726 .server = path[2..path.len],726 .server = path[2..path.len],
727 .sep_after_server = false,727 .sep_after_server = false,
728 .share = path[path.len..path.len],728 .share = path[path.len..path.len],
lib/std/hash/benchmark.zig+1-1
...@@ -443,7 +443,7 @@ pub fn main() !void {...@@ -443,7 +443,7 @@ pub fn main() !void {
443 const allocator = gpa.allocator();443 const allocator = gpa.allocator();
444444
445 inline for (hashes) |H| {445 inline for (hashes) |H| {
446 if (filter == null or std.mem.indexOf(u8, H.name, filter.?) != null) hash: {446 if (filter == null or std.mem.find(u8, H.name, filter.?) != null) hash: {
447 if (!test_iterative_only or H.has_iterative_api) {447 if (!test_iterative_only or H.has_iterative_api) {
448 try stdout.print("{s}\n", .{H.name});448 try stdout.print("{s}\n", .{H.name});
449 try stdout.flush();449 try stdout.flush();
lib/std/hash_map.zig+1-1
...@@ -110,7 +110,7 @@ pub const StringIndexAdapter = struct {...@@ -110,7 +110,7 @@ pub const StringIndexAdapter = struct {
110 }110 }
111111
112 pub fn hash(_: @This(), adapted_key: []const u8) u64 {112 pub fn hash(_: @This(), adapted_key: []const u8) u64 {
113 assert(mem.indexOfScalar(u8, adapted_key, 0) == null);113 assert(mem.findScalar(u8, adapted_key, 0) == null);
114 return hashString(adapted_key);114 return hashString(adapted_key);
115 }115 }
116};116};
lib/std/http/Client.zig+5-5
...@@ -1674,14 +1674,14 @@ pub fn request(...@@ -1674,14 +1674,14 @@ pub fn request(
1674 if (std.debug.runtime_safety) {1674 if (std.debug.runtime_safety) {
1675 for (options.extra_headers) |header| {1675 for (options.extra_headers) |header| {
1676 assert(header.name.len != 0);1676 assert(header.name.len != 0);
1677 assert(std.mem.indexOfScalar(u8, header.name, ':') == null);1677 assert(std.mem.findScalar(u8, header.name, ':') == null);
1678 assert(std.mem.indexOfPosLinear(u8, header.name, 0, "\r\n") == null);1678 assert(std.mem.findPosLinear(u8, header.name, 0, "\r\n") == null);
1679 assert(std.mem.indexOfPosLinear(u8, header.value, 0, "\r\n") == null);1679 assert(std.mem.findPosLinear(u8, header.value, 0, "\r\n") == null);
1680 }1680 }
1681 for (options.privileged_headers) |header| {1681 for (options.privileged_headers) |header| {
1682 assert(header.name.len != 0);1682 assert(header.name.len != 0);
1683 assert(std.mem.indexOfPosLinear(u8, header.name, 0, "\r\n") == null);1683 assert(std.mem.findPosLinear(u8, header.name, 0, "\r\n") == null);
1684 assert(std.mem.indexOfPosLinear(u8, header.value, 0, "\r\n") == null);1684 assert(std.mem.findPosLinear(u8, header.value, 0, "\r\n") == null);
1685 }1685 }
1686 }1686 }
16871687
lib/std/http/HeaderIterator.zig+3-3
...@@ -5,17 +5,17 @@ is_trailer: bool,...@@ -5,17 +5,17 @@ is_trailer: bool,
5pub fn init(bytes: []const u8) HeaderIterator {5pub fn init(bytes: []const u8) HeaderIterator {
6 return .{6 return .{
7 .bytes = bytes,7 .bytes = bytes,
8 .index = std.mem.indexOfPosLinear(u8, bytes, 0, "\r\n").? + 2,8 .index = std.mem.findPosLinear(u8, bytes, 0, "\r\n").? + 2,
9 .is_trailer = false,9 .is_trailer = false,
10 };10 };
11}11}
1212
13pub fn next(it: *HeaderIterator) ?std.http.Header {13pub fn next(it: *HeaderIterator) ?std.http.Header {
14 const end = std.mem.indexOfPosLinear(u8, it.bytes, it.index, "\r\n").?;14 const end = std.mem.findPosLinear(u8, it.bytes, it.index, "\r\n").?;
15 if (it.index == end) { // found the trailer boundary (\r\n\r\n)15 if (it.index == end) { // found the trailer boundary (\r\n\r\n)
16 if (it.is_trailer) return null;16 if (it.is_trailer) return null;
1717
18 const next_end = std.mem.indexOfPosLinear(u8, it.bytes, end + 2, "\r\n") orelse18 const next_end = std.mem.findPosLinear(u8, it.bytes, end + 2, "\r\n") orelse
19 return null;19 return null;
2020
21 var kv_it = std.mem.splitScalar(u8, it.bytes[end + 2 .. next_end], ':');21 var kv_it = std.mem.splitScalar(u8, it.bytes[end + 2 .. next_end], ':');
lib/std/http/Server.zig+4-4
...@@ -96,7 +96,7 @@ pub const Request = struct {...@@ -96,7 +96,7 @@ pub const Request = struct {
96 if (first_line.len < 10)96 if (first_line.len < 10)
97 return error.HttpHeadersInvalid;97 return error.HttpHeadersInvalid;
9898
99 const method_end = mem.indexOfScalar(u8, first_line, ' ') orelse99 const method_end = mem.findScalar(u8, first_line, ' ') orelse
100 return error.HttpHeadersInvalid;100 return error.HttpHeadersInvalid;
101101
102 const method = std.meta.stringToEnum(http.Method, first_line[0..method_end]) orelse102 const method = std.meta.stringToEnum(http.Method, first_line[0..method_end]) orelse
...@@ -338,9 +338,9 @@ pub const Request = struct {...@@ -338,9 +338,9 @@ pub const Request = struct {
338 if (std.debug.runtime_safety) {338 if (std.debug.runtime_safety) {
339 for (options.extra_headers) |header| {339 for (options.extra_headers) |header| {
340 assert(header.name.len != 0);340 assert(header.name.len != 0);
341 assert(std.mem.indexOfScalar(u8, header.name, ':') == null);341 assert(std.mem.findScalar(u8, header.name, ':') == null);
342 assert(std.mem.indexOfPosLinear(u8, header.name, 0, "\r\n") == null);342 assert(std.mem.findPosLinear(u8, header.name, 0, "\r\n") == null);
343 assert(std.mem.indexOfPosLinear(u8, header.value, 0, "\r\n") == null);343 assert(std.mem.findPosLinear(u8, header.value, 0, "\r\n") == null);
344 }344 }
345 }345 }
346 try writeExpectContinue(request);346 try writeExpectContinue(request);
lib/std/http/test.zig+1-1
...@@ -435,7 +435,7 @@ test "general client/server API coverage" {...@@ -435,7 +435,7 @@ test "general client/server API coverage" {
435435
436 if (mem.startsWith(u8, target, "/get")) {436 if (mem.startsWith(u8, target, "/get")) {
437 var response = try request.respondStreaming(&.{}, .{437 var response = try request.respondStreaming(&.{}, .{
438 .content_length = if (mem.indexOf(u8, target, "?chunked") == null)438 .content_length = if (mem.find(u8, target, "?chunked") == null)
439 14439 14
440 else440 else
441 null,441 null,
lib/std/json/Scanner.zig+1-1
...@@ -1758,7 +1758,7 @@ fn appendSlice(list: *std.array_list.Managed(u8), buf: []const u8, max_value_len...@@ -1758,7 +1758,7 @@ fn appendSlice(list: *std.array_list.Managed(u8), buf: []const u8, max_value_len
1758/// This function will not give meaningful results on non-numeric input.1758/// This function will not give meaningful results on non-numeric input.
1759pub fn isNumberFormattedLikeAnInteger(value: []const u8) bool {1759pub fn isNumberFormattedLikeAnInteger(value: []const u8) bool {
1760 if (std.mem.eql(u8, value, "-0")) return false;1760 if (std.mem.eql(u8, value, "-0")) return false;
1761 return std.mem.indexOfAny(u8, value, ".eE") == null;1761 return std.mem.findAny(u8, value, ".eE") == null;
1762}1762}
17631763
1764test {1764test {
lib/std/macho.zig+1-1
...@@ -825,7 +825,7 @@ pub const section_64 = extern struct {...@@ -825,7 +825,7 @@ pub const section_64 = extern struct {
825};825};
826826
827fn parseName(name: *const [16]u8) []const u8 {827fn parseName(name: *const [16]u8) []const u8 {
828 const len = mem.indexOfScalar(u8, name, @as(u8, 0)) orelse name.len;828 const len = mem.findScalar(u8, name, @as(u8, 0)) orelse name.len;
829 return name[0..len];829 return name[0..len];
830}830}
831831
lib/std/math/big/int.zig+2-2
...@@ -1658,8 +1658,8 @@ pub const Mutable = struct {...@@ -1658,8 +1658,8 @@ pub const Mutable = struct {
1658 // Handle trailing zero-words of divisor/dividend. These are not handled in the following1658 // Handle trailing zero-words of divisor/dividend. These are not handled in the following
1659 // algorithms.1659 // algorithms.
1660 // Note, there must be a non-zero limb for either.1660 // Note, there must be a non-zero limb for either.
1661 // const x_trailing = std.mem.indexOfScalar(Limb, x.limbs[0..x.len], 0).?;1661 // const x_trailing = std.mem.findScalar(Limb, x.limbs[0..x.len], 0).?;
1662 // const y_trailing = std.mem.indexOfScalar(Limb, y.limbs[0..y.len], 0).?;1662 // const y_trailing = std.mem.findScalar(Limb, y.limbs[0..y.len], 0).?;
16631663
1664 const x_trailing = for (x.limbs[0..x.len], 0..) |xi, i| {1664 const x_trailing = for (x.limbs[0..x.len], 0..) |xi, i| {
1665 if (xi != 0) break i;1665 if (xi != 0) break i;
lib/std/mem.zig+44-44
...@@ -998,7 +998,7 @@ fn lenSliceTo(ptr: anytype, comptime end: std.meta.Elem(@TypeOf(ptr))) usize {...@@ -998,7 +998,7 @@ fn lenSliceTo(ptr: anytype, comptime end: std.meta.Elem(@TypeOf(ptr))) usize {
998 .array => |array_info| {998 .array => |array_info| {
999 if (array_info.sentinel()) |s| {999 if (array_info.sentinel()) |s| {
1000 if (s == end) {1000 if (s == end) {
1001 return indexOfSentinel(array_info.child, end, ptr);1001 return findSentinel(array_info.child, end, ptr);
1002 }1002 }
1003 }1003 }
1004 return findScalar(array_info.child, ptr, end) orelse array_info.len;1004 return findScalar(array_info.child, ptr, end) orelse array_info.len;
...@@ -1007,7 +1007,7 @@ fn lenSliceTo(ptr: anytype, comptime end: std.meta.Elem(@TypeOf(ptr))) usize {...@@ -1007,7 +1007,7 @@ fn lenSliceTo(ptr: anytype, comptime end: std.meta.Elem(@TypeOf(ptr))) usize {
1007 },1007 },
1008 .many => if (ptr_info.sentinel()) |s| {1008 .many => if (ptr_info.sentinel()) |s| {
1009 if (s == end) {1009 if (s == end) {
1010 return indexOfSentinel(ptr_info.child, end, ptr);1010 return findSentinel(ptr_info.child, end, ptr);
1011 }1011 }
1012 // We're looking for something other than the sentinel,1012 // We're looking for something other than the sentinel,
1013 // but iterating past the sentinel would be a bug so we need1013 // but iterating past the sentinel would be a bug so we need
...@@ -1018,12 +1018,12 @@ fn lenSliceTo(ptr: anytype, comptime end: std.meta.Elem(@TypeOf(ptr))) usize {...@@ -1018,12 +1018,12 @@ fn lenSliceTo(ptr: anytype, comptime end: std.meta.Elem(@TypeOf(ptr))) usize {
1018 },1018 },
1019 .c => {1019 .c => {
1020 assert(ptr != null);1020 assert(ptr != null);
1021 return indexOfSentinel(ptr_info.child, end, ptr);1021 return findSentinel(ptr_info.child, end, ptr);
1022 },1022 },
1023 .slice => {1023 .slice => {
1024 if (ptr_info.sentinel()) |s| {1024 if (ptr_info.sentinel()) |s| {
1025 if (s == end) {1025 if (s == end) {
1026 return indexOfSentinel(ptr_info.child, s, ptr);1026 return findSentinel(ptr_info.child, s, ptr);
1027 }1027 }
1028 }1028 }
1029 return findScalar(ptr_info.child, ptr, end) orelse ptr.len;1029 return findScalar(ptr_info.child, ptr, end) orelse ptr.len;
...@@ -1076,11 +1076,11 @@ pub fn len(value: anytype) usize {...@@ -1076,11 +1076,11 @@ pub fn len(value: anytype) usize {
1076 .many => {1076 .many => {
1077 const sentinel = info.sentinel() orelse1077 const sentinel = info.sentinel() orelse
1078 @compileError("invalid type given to std.mem.len: " ++ @typeName(@TypeOf(value)));1078 @compileError("invalid type given to std.mem.len: " ++ @typeName(@TypeOf(value)));
1079 return indexOfSentinel(info.child, sentinel, value);1079 return findSentinel(info.child, sentinel, value);
1080 },1080 },
1081 .c => {1081 .c => {
1082 assert(value != null);1082 assert(value != null);
1083 return indexOfSentinel(info.child, 0, value);1083 return findSentinel(info.child, 0, value);
1084 },1084 },
1085 else => @compileError("invalid type given to std.mem.len: " ++ @typeName(@TypeOf(value))),1085 else => @compileError("invalid type given to std.mem.len: " ++ @typeName(@TypeOf(value))),
1086 },1086 },
...@@ -1166,7 +1166,7 @@ pub fn findSentinel(comptime T: type, comptime sentinel: T, p: [*:sentinel]const...@@ -1166,7 +1166,7 @@ pub fn findSentinel(comptime T: type, comptime sentinel: T, p: [*:sentinel]const
1166 return i;1166 return i;
1167}1167}
11681168
1169test "indexOfSentinel vector paths" {1169test "findSentinel vector paths" {
1170 const Types = [_]type{ u8, u16, u32, u64 };1170 const Types = [_]type{ u8, u16, u32, u64 };
1171 const allocator = std.testing.allocator;1171 const allocator = std.testing.allocator;
1172 const page_size = std.heap.page_size_min;1172 const page_size = std.heap.page_size_min;
...@@ -1189,7 +1189,7 @@ test "indexOfSentinel vector paths" {...@@ -1189,7 +1189,7 @@ test "indexOfSentinel vector paths" {
1189 const search_len = page_size / @sizeOf(T);1189 const search_len = page_size / @sizeOf(T);
1190 memory[start + search_len] = 0;1190 memory[start + search_len] = 0;
1191 for (0..block_len) |offset| {1191 for (0..block_len) |offset| {
1192 try testing.expectEqual(search_len - offset, indexOfSentinel(T, 0, @ptrCast(&memory[start + offset])));1192 try testing.expectEqual(search_len - offset, findSentinel(T, 0, @ptrCast(&memory[start + offset])));
1193 }1193 }
1194 memory[start + search_len] = 0xaa;1194 memory[start + search_len] = 0xaa;
11951195
...@@ -1197,7 +1197,7 @@ test "indexOfSentinel vector paths" {...@@ -1197,7 +1197,7 @@ test "indexOfSentinel vector paths" {
1197 const start_page_boundary = start + (page_size / @sizeOf(T));1197 const start_page_boundary = start + (page_size / @sizeOf(T));
1198 memory[start_page_boundary + block_len] = 0;1198 memory[start_page_boundary + block_len] = 0;
1199 for (0..block_len) |offset| {1199 for (0..block_len) |offset| {
1200 try testing.expectEqual(2 * block_len - offset, indexOfSentinel(T, 0, @ptrCast(&memory[start_page_boundary - block_len + offset])));1200 try testing.expectEqual(2 * block_len - offset, findSentinel(T, 0, @ptrCast(&memory[start_page_boundary - block_len + offset])));
1201 }1201 }
1202 }1202 }
1203}1203}
...@@ -1257,7 +1257,7 @@ pub const indexOfScalar = findScalar;...@@ -1257,7 +1257,7 @@ pub const indexOfScalar = findScalar;
12571257
1258/// Linear search for the index of a scalar value inside a slice.1258/// Linear search for the index of a scalar value inside a slice.
1259pub fn findScalar(comptime T: type, slice: []const T, value: T) ?usize {1259pub fn findScalar(comptime T: type, slice: []const T, value: T) ?usize {
1260 return indexOfScalarPos(T, slice, 0, value);1260 return findScalarPos(T, slice, 0, value);
1261}1261}
12621262
1263/// Deprecated in favor of `findScalarLast`.1263/// Deprecated in favor of `findScalarLast`.
...@@ -1340,7 +1340,7 @@ pub fn findScalarPos(comptime T: type, slice: []const T, start_index: usize, val...@@ -1340,7 +1340,7 @@ pub fn findScalarPos(comptime T: type, slice: []const T, start_index: usize, val
1340 return null;1340 return null;
1341}1341}
13421342
1343test indexOfScalarPos {1343test findScalarPos {
1344 const Types = [_]type{ u8, u16, u32, u64 };1344 const Types = [_]type{ u8, u16, u32, u64 };
13451345
1346 inline for (Types) |T| {1346 inline for (Types) |T| {
...@@ -1349,7 +1349,7 @@ test indexOfScalarPos {...@@ -1349,7 +1349,7 @@ test indexOfScalarPos {
1349 memory[memory.len - 1] = 0;1349 memory[memory.len - 1] = 0;
13501350
1351 for (0..memory.len) |i| {1351 for (0..memory.len) |i| {
1352 try testing.expectEqual(memory.len - i - 1, indexOfScalarPos(T, memory[i..], 0, 0).?);1352 try testing.expectEqual(memory.len - i - 1, findScalarPos(T, memory[i..], 0, 0).?);
1353 }1353 }
1354 }1354 }
1355}1355}
...@@ -1360,7 +1360,7 @@ pub const indexOfAny = findAny;...@@ -1360,7 +1360,7 @@ pub const indexOfAny = findAny;
1360/// Linear search for the index of any value in the provided list inside a slice.1360/// Linear search for the index of any value in the provided list inside a slice.
1361/// Returns null if no values are found.1361/// Returns null if no values are found.
1362pub fn findAny(comptime T: type, slice: []const T, values: []const T) ?usize {1362pub fn findAny(comptime T: type, slice: []const T, values: []const T) ?usize {
1363 return indexOfAnyPos(T, slice, 0, values);1363 return findAnyPos(T, slice, 0, values);
1364}1364}
13651365
1366/// Deprecated in favor of `findLastAny`.1366/// Deprecated in favor of `findLastAny`.
...@@ -1401,7 +1401,7 @@ pub const indexOfNone = findNone;...@@ -1401,7 +1401,7 @@ pub const indexOfNone = findNone;
1401///1401///
1402/// Comparable to `strspn` in the C standard library.1402/// Comparable to `strspn` in the C standard library.
1403pub fn findNone(comptime T: type, slice: []const T, values: []const T) ?usize {1403pub fn findNone(comptime T: type, slice: []const T, values: []const T) ?usize {
1404 return indexOfNonePos(T, slice, 0, values);1404 return findNonePos(T, slice, 0, values);
1405}1405}
14061406
1407test findNone {1407test findNone {
...@@ -1412,7 +1412,7 @@ test findNone {...@@ -1412,7 +1412,7 @@ test findNone {
1412 try testing.expect(findNone(u8, "123123", "123") == null);1412 try testing.expect(findNone(u8, "123123", "123") == null);
1413 try testing.expect(findNone(u8, "333333", "123") == null);1413 try testing.expect(findNone(u8, "333333", "123") == null);
14141414
1415 try testing.expect(indexOfNonePos(u8, "abc123", 3, "321") == null);1415 try testing.expect(findNonePos(u8, "abc123", 3, "321") == null);
1416}1416}
14171417
1418/// Deprecated in favor of `findLastNone`.1418/// Deprecated in favor of `findLastNone`.
...@@ -1457,7 +1457,7 @@ pub const indexOf = find;...@@ -1457,7 +1457,7 @@ pub const indexOf = find;
1457/// Uses Boyer-Moore-Horspool algorithm on large inputs; linear search on small inputs.1457/// Uses Boyer-Moore-Horspool algorithm on large inputs; linear search on small inputs.
1458/// Returns null if needle is not found.1458/// Returns null if needle is not found.
1459pub fn find(comptime T: type, haystack: []const T, needle: []const T) ?usize {1459pub fn find(comptime T: type, haystack: []const T, needle: []const T) ?usize {
1460 return indexOfPos(T, haystack, 0, needle);1460 return findPos(T, haystack, 0, needle);
1461}1461}
14621462
1463/// Deprecated in favor of `findLastLinear`.1463/// Deprecated in favor of `findLastLinear`.
...@@ -1478,7 +1478,7 @@ pub fn findLastLinear(comptime T: type, haystack: []const T, needle: []const T)...@@ -1478,7 +1478,7 @@ pub fn findLastLinear(comptime T: type, haystack: []const T, needle: []const T)
14781478
1479pub const indexOfPosLinear = findPosLinear;1479pub const indexOfPosLinear = findPosLinear;
14801480
1481/// Consider using `indexOfPos` instead of this, which will automatically use a1481/// Consider using `findPos` instead of this, which will automatically use a
1482/// more sophisticated algorithm on larger inputs.1482/// more sophisticated algorithm on larger inputs.
1483pub fn findPosLinear(comptime T: type, haystack: []const T, start_index: usize, needle: []const T) ?usize {1483pub fn findPosLinear(comptime T: type, haystack: []const T, start_index: usize, needle: []const T) ?usize {
1484 if (needle.len > haystack.len) return null;1484 if (needle.len > haystack.len) return null;
...@@ -1572,17 +1572,17 @@ pub fn findLast(comptime T: type, haystack: []const T, needle: []const T) ?usize...@@ -1572,17 +1572,17 @@ pub fn findLast(comptime T: type, haystack: []const T, needle: []const T) ?usize
1572/// Deprecated in favor of `findPos`.1572/// Deprecated in favor of `findPos`.
1573pub const indexOfPos = findPos;1573pub const indexOfPos = findPos;
15741574
1575/// Uses Boyer-Moore-Horspool algorithm on large inputs; `indexOfPosLinear` on small inputs.1575/// Uses Boyer-Moore-Horspool algorithm on large inputs; `findPosLinear` on small inputs.
1576pub fn findPos(comptime T: type, haystack: []const T, start_index: usize, needle: []const T) ?usize {1576pub fn findPos(comptime T: type, haystack: []const T, start_index: usize, needle: []const T) ?usize {
1577 if (needle.len > haystack.len) return null;1577 if (needle.len > haystack.len) return null;
1578 if (needle.len < 2) {1578 if (needle.len < 2) {
1579 if (needle.len == 0) return start_index;1579 if (needle.len == 0) return start_index;
1580 // indexOfScalarPos is significantly faster than indexOfPosLinear1580 // findScalarPos is significantly faster than findPosLinear
1581 return indexOfScalarPos(T, haystack, start_index, needle[0]);1581 return findScalarPos(T, haystack, start_index, needle[0]);
1582 }1582 }
15831583
1584 if (!std.meta.hasUniqueRepresentation(T) or haystack.len < 52 or needle.len <= 4)1584 if (!std.meta.hasUniqueRepresentation(T) or haystack.len < 52 or needle.len <= 4)
1585 return indexOfPosLinear(T, haystack, start_index, needle);1585 return findPosLinear(T, haystack, start_index, needle);
15861586
1587 const haystack_bytes = sliceAsBytes(haystack);1587 const haystack_bytes = sliceAsBytes(haystack);
1588 const needle_bytes = sliceAsBytes(needle);1588 const needle_bytes = sliceAsBytes(needle);
...@@ -1601,43 +1601,43 @@ pub fn findPos(comptime T: type, haystack: []const T, start_index: usize, needle...@@ -1601,43 +1601,43 @@ pub fn findPos(comptime T: type, haystack: []const T, start_index: usize, needle
1601 return null;1601 return null;
1602}1602}
16031603
1604test indexOf {1604test find {
1605 try testing.expect(indexOf(u8, "one two three four five six seven eight nine ten eleven", "three four").? == 8);1605 try testing.expect(find(u8, "one two three four five six seven eight nine ten eleven", "three four").? == 8);
1606 try testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten eleven", "three four").? == 8);1606 try testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten eleven", "three four").? == 8);
1607 try testing.expect(indexOf(u8, "one two three four five six seven eight nine ten eleven", "two two") == null);1607 try testing.expect(find(u8, "one two three four five six seven eight nine ten eleven", "two two") == null);
1608 try testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten eleven", "two two") == null);1608 try testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten eleven", "two two") == null);
16091609
1610 try testing.expect(indexOf(u8, "one two three four five six seven eight nine ten", "").? == 0);1610 try testing.expect(find(u8, "one two three four five six seven eight nine ten", "").? == 0);
1611 try testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten", "").? == 48);1611 try testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten", "").? == 48);
16121612
1613 try testing.expect(indexOf(u8, "one two three four", "four").? == 14);1613 try testing.expect(find(u8, "one two three four", "four").? == 14);
1614 try testing.expect(lastIndexOf(u8, "one two three two four", "two").? == 14);1614 try testing.expect(lastIndexOf(u8, "one two three two four", "two").? == 14);
1615 try testing.expect(indexOf(u8, "one two three four", "gour") == null);1615 try testing.expect(find(u8, "one two three four", "gour") == null);
1616 try testing.expect(lastIndexOf(u8, "one two three four", "gour") == null);1616 try testing.expect(lastIndexOf(u8, "one two three four", "gour") == null);
1617 try testing.expect(indexOf(u8, "foo", "foo").? == 0);1617 try testing.expect(find(u8, "foo", "foo").? == 0);
1618 try testing.expect(lastIndexOf(u8, "foo", "foo").? == 0);1618 try testing.expect(lastIndexOf(u8, "foo", "foo").? == 0);
1619 try testing.expect(indexOf(u8, "foo", "fool") == null);1619 try testing.expect(find(u8, "foo", "fool") == null);
1620 try testing.expect(lastIndexOf(u8, "foo", "lfoo") == null);1620 try testing.expect(lastIndexOf(u8, "foo", "lfoo") == null);
1621 try testing.expect(lastIndexOf(u8, "foo", "fool") == null);1621 try testing.expect(lastIndexOf(u8, "foo", "fool") == null);
16221622
1623 try testing.expect(indexOf(u8, "foo foo", "foo").? == 0);1623 try testing.expect(find(u8, "foo foo", "foo").? == 0);
1624 try testing.expect(lastIndexOf(u8, "foo foo", "foo").? == 4);1624 try testing.expect(lastIndexOf(u8, "foo foo", "foo").? == 4);
1625 try testing.expect(lastIndexOfAny(u8, "boo, cat", "abo").? == 6);1625 try testing.expect(lastIndexOfAny(u8, "boo, cat", "abo").? == 6);
1626 try testing.expect(findScalarLast(u8, "boo", 'o').? == 2);1626 try testing.expect(findScalarLast(u8, "boo", 'o').? == 2);
1627}1627}
16281628
1629test "indexOf multibyte" {1629test "find multibyte" {
1630 {1630 {
1631 // make haystack and needle long enough to trigger Boyer-Moore-Horspool algorithm1631 // make haystack and needle long enough to trigger Boyer-Moore-Horspool algorithm
1632 const haystack = [1]u16{0} ** 100 ++ [_]u16{ 0xbbaa, 0xccbb, 0xddcc, 0xeedd, 0xffee, 0x00ff };1632 const haystack = [1]u16{0} ** 100 ++ [_]u16{ 0xbbaa, 0xccbb, 0xddcc, 0xeedd, 0xffee, 0x00ff };
1633 const needle = [_]u16{ 0xbbaa, 0xccbb, 0xddcc, 0xeedd, 0xffee };1633 const needle = [_]u16{ 0xbbaa, 0xccbb, 0xddcc, 0xeedd, 0xffee };
1634 try testing.expectEqual(indexOfPos(u16, &haystack, 0, &needle), 100);1634 try testing.expectEqual(findPos(u16, &haystack, 0, &needle), 100);
16351635
1636 // check for misaligned false positives (little and big endian)1636 // check for misaligned false positives (little and big endian)
1637 const needleLE = [_]u16{ 0xbbbb, 0xcccc, 0xdddd, 0xeeee, 0xffff };1637 const needleLE = [_]u16{ 0xbbbb, 0xcccc, 0xdddd, 0xeeee, 0xffff };
1638 try testing.expectEqual(indexOfPos(u16, &haystack, 0, &needleLE), null);1638 try testing.expectEqual(findPos(u16, &haystack, 0, &needleLE), null);
1639 const needleBE = [_]u16{ 0xaacc, 0xbbdd, 0xccee, 0xddff, 0xee00 };1639 const needleBE = [_]u16{ 0xaacc, 0xbbdd, 0xccee, 0xddff, 0xee00 };
1640 try testing.expectEqual(indexOfPos(u16, &haystack, 0, &needleBE), null);1640 try testing.expectEqual(findPos(u16, &haystack, 0, &needleBE), null);
1641 }1641 }
16421642
1643 {1643 {
...@@ -1654,8 +1654,8 @@ test "indexOf multibyte" {...@@ -1654,8 +1654,8 @@ test "indexOf multibyte" {
1654 }1654 }
1655}1655}
16561656
1657test "indexOfPos empty needle" {1657test "findPos empty needle" {
1658 try testing.expectEqual(indexOfPos(u8, "abracadabra", 5, ""), 5);1658 try testing.expectEqual(findPos(u8, "abracadabra", 5, ""), 5);
1659}1659}
16601660
1661/// Returns the number of needles inside the haystack1661/// Returns the number of needles inside the haystack
...@@ -1667,7 +1667,7 @@ pub fn count(comptime T: type, haystack: []const T, needle: []const T) usize {...@@ -1667,7 +1667,7 @@ pub fn count(comptime T: type, haystack: []const T, needle: []const T) usize {
1667 var i: usize = 0;1667 var i: usize = 0;
1668 var found: usize = 0;1668 var found: usize = 0;
16691669
1670 while (indexOfPos(T, haystack, i, needle)) |idx| {1670 while (findPos(T, haystack, i, needle)) |idx| {
1671 i = idx + needle.len;1671 i = idx + needle.len;
1672 found += 1;1672 found += 1;
1673 }1673 }
...@@ -1737,7 +1737,7 @@ pub fn containsAtLeast(comptime T: type, haystack: []const T, expected_count: us...@@ -1737,7 +1737,7 @@ pub fn containsAtLeast(comptime T: type, haystack: []const T, expected_count: us
1737 var i: usize = 0;1737 var i: usize = 0;
1738 var found: usize = 0;1738 var found: usize = 0;
17391739
1740 while (indexOfPos(T, haystack, i, needle)) |idx| {1740 while (findPos(T, haystack, i, needle)) |idx| {
1741 i = idx + needle.len;1741 i = idx + needle.len;
1742 found += 1;1742 found += 1;
1743 if (found == expected_count) return true;1743 if (found == expected_count) return true;
...@@ -3362,9 +3362,9 @@ pub fn SplitIterator(comptime T: type, comptime delimiter_type: DelimiterType) t...@@ -3362,9 +3362,9 @@ pub fn SplitIterator(comptime T: type, comptime delimiter_type: DelimiterType) t
3362 pub fn next(self: *Self) ?[]const T {3362 pub fn next(self: *Self) ?[]const T {
3363 const start = self.index orelse return null;3363 const start = self.index orelse return null;
3364 const end = if (switch (delimiter_type) {3364 const end = if (switch (delimiter_type) {
3365 .sequence => indexOfPos(T, self.buffer, start, self.delimiter),3365 .sequence => findPos(T, self.buffer, start, self.delimiter),
3366 .any => indexOfAnyPos(T, self.buffer, start, self.delimiter),3366 .any => findAnyPos(T, self.buffer, start, self.delimiter),
3367 .scalar => indexOfScalarPos(T, self.buffer, start, self.delimiter),3367 .scalar => findScalarPos(T, self.buffer, start, self.delimiter),
3368 }) |delim_start| blk: {3368 }) |delim_start| blk: {
3369 self.index = delim_start + switch (delimiter_type) {3369 self.index = delim_start + switch (delimiter_type) {
3370 .sequence => self.delimiter.len,3370 .sequence => self.delimiter.len,
...@@ -3383,9 +3383,9 @@ pub fn SplitIterator(comptime T: type, comptime delimiter_type: DelimiterType) t...@@ -3383,9 +3383,9 @@ pub fn SplitIterator(comptime T: type, comptime delimiter_type: DelimiterType) t
3383 pub fn peek(self: *Self) ?[]const T {3383 pub fn peek(self: *Self) ?[]const T {
3384 const start = self.index orelse return null;3384 const start = self.index orelse return null;
3385 const end = if (switch (delimiter_type) {3385 const end = if (switch (delimiter_type) {
3386 .sequence => indexOfPos(T, self.buffer, start, self.delimiter),3386 .sequence => findPos(T, self.buffer, start, self.delimiter),
3387 .any => indexOfAnyPos(T, self.buffer, start, self.delimiter),3387 .any => findAnyPos(T, self.buffer, start, self.delimiter),
3388 .scalar => indexOfScalarPos(T, self.buffer, start, self.delimiter),3388 .scalar => findScalarPos(T, self.buffer, start, self.delimiter),
3389 }) |delim_start| delim_start else self.buffer.len;3389 }) |delim_start| delim_start else self.buffer.len;
3390 return self.buffer[start..end];3390 return self.buffer[start..end];
3391 }3391 }
lib/std/os.zig+4-4
...@@ -113,7 +113,7 @@ pub fn getFdPath(fd: std.posix.fd_t, out_buffer: *[max_path_bytes]u8) std.posix....@@ -113,7 +113,7 @@ pub fn getFdPath(fd: std.posix.fd_t, out_buffer: *[max_path_bytes]u8) std.posix.
113 // errno values to expect when command is F.GETPATH...113 // errno values to expect when command is F.GETPATH...
114 else => |err| return posix.unexpectedErrno(err),114 else => |err| return posix.unexpectedErrno(err),
115 }115 }
116 const len = mem.indexOfScalar(u8, out_buffer[0..], 0) orelse max_path_bytes;116 const len = mem.findScalar(u8, out_buffer[0..], 0) orelse max_path_bytes;
117 return out_buffer[0..len];117 return out_buffer[0..len];
118 },118 },
119 .linux, .serenity => {119 .linux, .serenity => {
...@@ -150,7 +150,7 @@ pub fn getFdPath(fd: std.posix.fd_t, out_buffer: *[max_path_bytes]u8) std.posix....@@ -150,7 +150,7 @@ pub fn getFdPath(fd: std.posix.fd_t, out_buffer: *[max_path_bytes]u8) std.posix.
150 .BADF => return error.FileNotFound,150 .BADF => return error.FileNotFound,
151 else => |err| return posix.unexpectedErrno(err),151 else => |err| return posix.unexpectedErrno(err),
152 }152 }
153 const len = mem.indexOfScalar(u8, &kfile.path, 0) orelse max_path_bytes;153 const len = mem.findScalar(u8, &kfile.path, 0) orelse max_path_bytes;
154 if (len == 0) return error.NameTooLong;154 if (len == 0) return error.NameTooLong;
155 const result = out_buffer[0..len];155 const result = out_buffer[0..len];
156 @memcpy(result, kfile.path[0..len]);156 @memcpy(result, kfile.path[0..len]);
...@@ -164,7 +164,7 @@ pub fn getFdPath(fd: std.posix.fd_t, out_buffer: *[max_path_bytes]u8) std.posix....@@ -164,7 +164,7 @@ pub fn getFdPath(fd: std.posix.fd_t, out_buffer: *[max_path_bytes]u8) std.posix.
164 .RANGE => return error.NameTooLong,164 .RANGE => return error.NameTooLong,
165 else => |err| return posix.unexpectedErrno(err),165 else => |err| return posix.unexpectedErrno(err),
166 }166 }
167 const len = mem.indexOfScalar(u8, out_buffer[0..], 0) orelse max_path_bytes;167 const len = mem.findScalar(u8, out_buffer[0..], 0) orelse max_path_bytes;
168 return out_buffer[0..len];168 return out_buffer[0..len];
169 },169 },
170 .netbsd => {170 .netbsd => {
...@@ -178,7 +178,7 @@ pub fn getFdPath(fd: std.posix.fd_t, out_buffer: *[max_path_bytes]u8) std.posix....@@ -178,7 +178,7 @@ pub fn getFdPath(fd: std.posix.fd_t, out_buffer: *[max_path_bytes]u8) std.posix.
178 .RANGE => return error.NameTooLong,178 .RANGE => return error.NameTooLong,
179 else => |err| return posix.unexpectedErrno(err),179 else => |err| return posix.unexpectedErrno(err),
180 }180 }
181 const len = mem.indexOfScalar(u8, out_buffer[0..], 0) orelse max_path_bytes;181 const len = mem.findScalar(u8, out_buffer[0..], 0) orelse max_path_bytes;
182 return out_buffer[0..len];182 return out_buffer[0..len];
183 },183 },
184 else => unreachable, // made unreachable by isGetFdPathSupportedOnTarget above184 else => unreachable, // made unreachable by isGetFdPathSupportedOnTarget above
lib/std/os/linux/IoUring.zig+1-1
...@@ -4092,7 +4092,7 @@ inline fn skipKernelLessThan(required: std.SemanticVersion) !void {...@@ -4092,7 +4092,7 @@ inline fn skipKernelLessThan(required: std.SemanticVersion) !void {
40924092
4093 const release = mem.sliceTo(&uts.release, 0);4093 const release = mem.sliceTo(&uts.release, 0);
4094 // Strips potential extra, as kernel version might not be semver compliant, example "6.8.9-300.fc40.x86_64"4094 // Strips potential extra, as kernel version might not be semver compliant, example "6.8.9-300.fc40.x86_64"
4095 const extra_index = std.mem.indexOfAny(u8, release, "-+");4095 const extra_index = std.mem.findAny(u8, release, "-+");
4096 const stripped = release[0..(extra_index orelse release.len)];4096 const stripped = release[0..(extra_index orelse release.len)];
4097 // Make sure the input don't rely on the extra we just stripped4097 // Make sure the input don't rely on the extra we just stripped
4098 try testing.expect(required.pre == null and required.build == null);4098 try testing.expect(required.pre == null and required.build == null);
lib/std/os/windows.zig+3-3
...@@ -1412,7 +1412,7 @@ pub fn GetFinalPathNameByHandle(...@@ -1412,7 +1412,7 @@ pub fn GetFinalPathNameByHandle(
1412 };1412 };
1413 }1413 }
14141414
1415 const file_path_begin_index = mem.indexOfPos(u16, final_path, device_prefix.len, &[_]u16{'\\'}) orelse unreachable;1415 const file_path_begin_index = mem.findPos(u16, final_path, device_prefix.len, &[_]u16{'\\'}) orelse unreachable;
1416 const volume_name_u16 = final_path[0..file_path_begin_index];1416 const volume_name_u16 = final_path[0..file_path_begin_index];
1417 const device_name_u16 = volume_name_u16[device_prefix.len..];1417 const device_name_u16 = volume_name_u16[device_prefix.len..];
1418 const file_name_u16 = final_path[file_path_begin_index..];1418 const file_name_u16 = final_path[file_path_begin_index..];
...@@ -1494,7 +1494,7 @@ pub fn GetFinalPathNameByHandle(...@@ -1494,7 +1494,7 @@ pub fn GetFinalPathNameByHandle(
1494 const total_len = drive_letter.len + file_name_u16.len;1494 const total_len = drive_letter.len + file_name_u16.len;
14951495
1496 // Validate that DOS does not contain any spurious nul bytes.1496 // Validate that DOS does not contain any spurious nul bytes.
1497 if (mem.indexOfScalar(u16, out_buffer[0..total_len], 0)) |_| {1497 if (mem.findScalar(u16, out_buffer[0..total_len], 0)) |_| {
1498 return error.BadPathName;1498 return error.BadPathName;
1499 }1499 }
15001500
...@@ -1544,7 +1544,7 @@ pub fn GetFinalPathNameByHandle(...@@ -1544,7 +1544,7 @@ pub fn GetFinalPathNameByHandle(
1544 const total_len = volume_path.len + file_name_u16.len;1544 const total_len = volume_path.len + file_name_u16.len;
15451545
1546 // Validate that DOS does not contain any spurious nul bytes.1546 // Validate that DOS does not contain any spurious nul bytes.
1547 if (mem.indexOfScalar(u16, out_buffer[0..total_len], 0)) |_| {1547 if (mem.findScalar(u16, out_buffer[0..total_len], 0)) |_| {
1548 return error.BadPathName;1548 return error.BadPathName;
1549 }1549 }
15501550
lib/std/posix.zig+3-3
...@@ -1773,7 +1773,7 @@ pub fn execvpeZ_expandArg0(...@@ -1773,7 +1773,7 @@ pub fn execvpeZ_expandArg0(
1773 envp: [*:null]const ?[*:0]const u8,1773 envp: [*:null]const ?[*:0]const u8,
1774) ExecveError {1774) ExecveError {
1775 const file_slice = mem.sliceTo(file, 0);1775 const file_slice = mem.sliceTo(file, 0);
1776 if (mem.indexOfScalar(u8, file_slice, '/') != null) return execveZ(file, child_argv, envp);1776 if (mem.findScalar(u8, file_slice, '/') != null) return execveZ(file, child_argv, envp);
17771777
1778 const PATH = getenvZ("PATH") orelse "/usr/local/bin:/bin/:/usr/bin";1778 const PATH = getenvZ("PATH") orelse "/usr/local/bin:/bin/:/usr/bin";
1779 // Use of PATH_MAX here is valid as the path_buf will be passed1779 // Use of PATH_MAX here is valid as the path_buf will be passed
...@@ -1829,7 +1829,7 @@ pub fn getenv(key: []const u8) ?[:0]const u8 {...@@ -1829,7 +1829,7 @@ pub fn getenv(key: []const u8) ?[:0]const u8 {
1829 if (native_os == .windows) {1829 if (native_os == .windows) {
1830 @compileError("std.posix.getenv is unavailable for Windows because environment strings are in WTF-16 format. See std.process.getEnvVarOwned for a cross-platform API or std.process.getenvW for a Windows-specific API.");1830 @compileError("std.posix.getenv is unavailable for Windows because environment strings are in WTF-16 format. See std.process.getEnvVarOwned for a cross-platform API or std.process.getenvW for a Windows-specific API.");
1831 }1831 }
1832 if (mem.indexOfScalar(u8, key, '=') != null) {1832 if (mem.findScalar(u8, key, '=') != null) {
1833 return null;1833 return null;
1834 }1834 }
1835 if (builtin.link_libc) {1835 if (builtin.link_libc) {
...@@ -6663,7 +6663,7 @@ pub fn unexpectedErrno(err: E) UnexpectedError {...@@ -6663,7 +6663,7 @@ pub fn unexpectedErrno(err: E) UnexpectedError {
66636663
6664/// Used to convert a slice to a null terminated slice on the stack.6664/// Used to convert a slice to a null terminated slice on the stack.
6665pub fn toPosixPath(file_path: []const u8) error{NameTooLong}![PATH_MAX - 1:0]u8 {6665pub fn toPosixPath(file_path: []const u8) error{NameTooLong}![PATH_MAX - 1:0]u8 {
6666 if (std.debug.runtime_safety) assert(mem.indexOfScalar(u8, file_path, 0) == null);6666 if (std.debug.runtime_safety) assert(mem.findScalar(u8, file_path, 0) == null);
6667 var path_with_null: [PATH_MAX - 1:0]u8 = undefined;6667 var path_with_null: [PATH_MAX - 1:0]u8 = undefined;
6668 // >= rather than > to make room for the null byte6668 // >= rather than > to make room for the null byte
6669 if (file_path.len >= PATH_MAX) return error.NameTooLong;6669 if (file_path.len >= PATH_MAX) return error.NameTooLong;
lib/std/priority_queue.zig+1-1
...@@ -619,7 +619,7 @@ test "siftUp in remove" {...@@ -619,7 +619,7 @@ test "siftUp in remove" {
619619
620 try queue.addSlice(&.{ 0, 1, 100, 2, 3, 101, 102, 4, 5, 6, 7, 103, 104, 105, 106, 8 });620 try queue.addSlice(&.{ 0, 1, 100, 2, 3, 101, 102, 4, 5, 6, 7, 103, 104, 105, 106, 8 });
621621
622 _ = queue.removeIndex(std.mem.indexOfScalar(u32, queue.items[0..queue.count()], 102).?);622 _ = queue.removeIndex(std.mem.findScalar(u32, queue.items[0..queue.count()], 102).?);
623623
624 const sorted_items = [_]u32{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 100, 101, 103, 104, 105, 106 };624 const sorted_items = [_]u32{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 100, 101, 103, 104, 105, 106 };
625 for (sorted_items) |e| {625 for (sorted_items) |e| {
lib/std/process.zig+2-2
...@@ -546,7 +546,7 @@ pub fn getenvW(key: [*:0]const u16) ?[:0]const u16 {...@@ -546,7 +546,7 @@ pub fn getenvW(key: [*:0]const u16) ?[:0]const u16 {
546 }546 }
547 const key_slice = mem.sliceTo(key, 0);547 const key_slice = mem.sliceTo(key, 0);
548 // '=' anywhere but the start makes this an invalid environment variable name548 // '=' anywhere but the start makes this an invalid environment variable name
549 if (key_slice.len > 0 and std.mem.indexOfScalar(u16, key_slice[1..], '=') != null) {549 if (key_slice.len > 0 and std.mem.findScalar(u16, key_slice[1..], '=') != null) {
550 return null;550 return null;
551 }551 }
552 const ptr = windows.peb().ProcessParameters.Environment;552 const ptr = windows.peb().ProcessParameters.Environment;
...@@ -559,7 +559,7 @@ pub fn getenvW(key: [*:0]const u16) ?[:0]const u16 {...@@ -559,7 +559,7 @@ pub fn getenvW(key: [*:0]const u16) ?[:0]const u16 {
559 // if it's the first character.559 // if it's the first character.
560 // https://devblogs.microsoft.com/oldnewthing/20100506-00/?p=14133560 // https://devblogs.microsoft.com/oldnewthing/20100506-00/?p=14133
561 const equal_search_start: usize = if (key_value[0] == '=') 1 else 0;561 const equal_search_start: usize = if (key_value[0] == '=') 1 else 0;
562 const equal_index = std.mem.indexOfScalarPos(u16, key_value, equal_search_start, '=') orelse {562 const equal_index = std.mem.findScalarPos(u16, key_value, equal_search_start, '=') orelse {
563 // This is enforced by CreateProcess.563 // This is enforced by CreateProcess.
564 // If violated, CreateProcess will fail with INVALID_PARAMETER.564 // If violated, CreateProcess will fail with INVALID_PARAMETER.
565 unreachable; // must contain a =565 unreachable; // must contain a =
lib/std/process/Child.zig+2-2
...@@ -1810,7 +1810,7 @@ fn argvToScriptCommandLineWindows(...@@ -1810,7 +1810,7 @@ fn argvToScriptCommandLineWindows(
1810 //1810 //
1811 // If the script path does not have a path separator, then we know its relative to CWD and1811 // If the script path does not have a path separator, then we know its relative to CWD and
1812 // we can just put `.\` in the front.1812 // we can just put `.\` in the front.
1813 if (mem.indexOfAny(u16, script_path, &[_]u16{ mem.nativeToLittle(u16, '\\'), mem.nativeToLittle(u16, '/') }) == null) {1813 if (mem.findAny(u16, script_path, &[_]u16{ mem.nativeToLittle(u16, '\\'), mem.nativeToLittle(u16, '/') }) == null) {
1814 try buf.appendSlice(".\\");1814 try buf.appendSlice(".\\");
1815 }1815 }
1816 // Note that we don't do any escaping/mitigations for this argument, since the relevant1816 // Note that we don't do any escaping/mitigations for this argument, since the relevant
...@@ -1825,7 +1825,7 @@ fn argvToScriptCommandLineWindows(...@@ -1825,7 +1825,7 @@ fn argvToScriptCommandLineWindows(
1825 // always a mistake to include these characters in argv, so it's1825 // always a mistake to include these characters in argv, so it's
1826 // an error condition in order to ensure that the return of this1826 // an error condition in order to ensure that the return of this
1827 // function can always roundtrip through cmd.exe.1827 // function can always roundtrip through cmd.exe.
1828 if (std.mem.indexOfAny(u8, arg, "\x00\r\n") != null) {1828 if (std.mem.findAny(u8, arg, "\x00\r\n") != null) {
1829 return error.InvalidBatchScriptArg;1829 return error.InvalidBatchScriptArg;
1830 }1830 }
18311831
lib/std/tar.zig+3-3
...@@ -71,7 +71,7 @@ pub const Diagnostics = struct {...@@ -71,7 +71,7 @@ pub const Diagnostics = struct {
71 const start_index: usize = if (path[0] == '/') 1 else 0;71 const start_index: usize = if (path[0] == '/') 1 else 0;
72 const end_index: usize = if (path[path.len - 1] == '/') path.len - 1 else path.len;72 const end_index: usize = if (path[path.len - 1] == '/') path.len - 1 else path.len;
73 const buf = path[start_index..end_index];73 const buf = path[start_index..end_index];
74 if (std.mem.indexOfScalarPos(u8, buf, 0, '/')) |idx| {74 if (std.mem.findScalarPos(u8, buf, 0, '/')) |idx| {
75 return buf[0..idx];75 return buf[0..idx];
76 }76 }
7777
...@@ -569,7 +569,7 @@ pub const PaxIterator = struct {...@@ -569,7 +569,7 @@ pub const PaxIterator = struct {
569 }569 }
570570
571 fn hasNull(str: []const u8) bool {571 fn hasNull(str: []const u8) bool {
572 return (std.mem.indexOfScalar(u8, str, 0)) != null;572 return (std.mem.findScalar(u8, str, 0)) != null;
573 }573 }
574574
575 // Checks that each record ends with new line.575 // Checks that each record ends with new line.
...@@ -667,7 +667,7 @@ fn stripComponents(path: []const u8, count: u32) []const u8 {...@@ -667,7 +667,7 @@ fn stripComponents(path: []const u8, count: u32) []const u8 {
667 var i: usize = 0;667 var i: usize = 0;
668 var c = count;668 var c = count;
669 while (c > 0) : (c -= 1) {669 while (c > 0) : (c -= 1) {
670 if (std.mem.indexOfScalarPos(u8, path, i, '/')) |pos| {670 if (std.mem.findScalarPos(u8, path, i, '/')) |pos| {
671 i = pos + 1;671 i = pos + 1;
672 } else {672 } else {
673 i = path.len;673 i = path.len;
lib/std/testing.zig+3-3
...@@ -643,7 +643,7 @@ pub fn tmpDir(opts: std.fs.Dir.OpenOptions) TmpDir {...@@ -643,7 +643,7 @@ pub fn tmpDir(opts: std.fs.Dir.OpenOptions) TmpDir {
643}643}
644644
645pub fn expectEqualStrings(expected: []const u8, actual: []const u8) !void {645pub fn expectEqualStrings(expected: []const u8, actual: []const u8) !void {
646 if (std.mem.indexOfDiff(u8, actual, expected)) |diff_index| {646 if (std.mem.findDiff(u8, actual, expected)) |diff_index| {
647 if (@inComptime()) {647 if (@inComptime()) {
648 @compileError(std.fmt.comptimePrint("\nexpected:\n{s}\nfound:\n{s}\ndifference starts at index {d}", .{648 @compileError(std.fmt.comptimePrint("\nexpected:\n{s}\nfound:\n{s}\ndifference starts at index {d}", .{
649 expected, actual, diff_index,649 expected, actual, diff_index,
...@@ -992,7 +992,7 @@ fn printIndicatorLine(source: []const u8, indicator_index: usize) void {...@@ -992,7 +992,7 @@ fn printIndicatorLine(source: []const u8, indicator_index: usize) void {
992 line_begin + 1992 line_begin + 1
993 else993 else
994 0;994 0;
995 const line_end_index = if (std.mem.indexOfScalar(u8, source[indicator_index..], '\n')) |line_end|995 const line_end_index = if (std.mem.findScalar(u8, source[indicator_index..], '\n')) |line_end|
996 (indicator_index + line_end)996 (indicator_index + line_end)
997 else997 else
998 source.len;998 source.len;
...@@ -1008,7 +1008,7 @@ fn printIndicatorLine(source: []const u8, indicator_index: usize) void {...@@ -1008,7 +1008,7 @@ fn printIndicatorLine(source: []const u8, indicator_index: usize) void {
10081008
1009fn printWithVisibleNewlines(source: []const u8) void {1009fn printWithVisibleNewlines(source: []const u8) void {
1010 var i: usize = 0;1010 var i: usize = 0;
1011 while (std.mem.indexOfScalar(u8, source[i..], '\n')) |nl| : (i += nl + 1) {1011 while (std.mem.findScalar(u8, source[i..], '\n')) |nl| : (i += nl + 1) {
1012 printLine(source[i..][0..nl]);1012 printLine(source[i..][0..nl]);
1013 }1013 }
1014 print("{s}␃\n", .{source[i..]}); // End of Text symbol (ETX)1014 print("{s}␃\n", .{source[i..]}); // End of Text symbol (ETX)
lib/std/zig/Ast.zig+2-2
...@@ -234,7 +234,7 @@ pub fn tokenLocation(self: Ast, start_offset: ByteOffset, token_index: TokenInde...@@ -234,7 +234,7 @@ pub fn tokenLocation(self: Ast, start_offset: ByteOffset, token_index: TokenInde
234 const token_start = self.tokenStart(token_index);234 const token_start = self.tokenStart(token_index);
235235
236 // Scan to by line until we go past the token start236 // Scan to by line until we go past the token start
237 while (std.mem.indexOfScalarPos(u8, self.source, loc.line_start, '\n')) |i| {237 while (std.mem.findScalarPos(u8, self.source, loc.line_start, '\n')) |i| {
238 if (i >= token_start) {238 if (i >= token_start) {
239 break; // Went past239 break; // Went past
240 }240 }
...@@ -1315,7 +1315,7 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex {...@@ -1315,7 +1315,7 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex {
13151315
1316pub fn tokensOnSameLine(tree: Ast, token1: TokenIndex, token2: TokenIndex) bool {1316pub fn tokensOnSameLine(tree: Ast, token1: TokenIndex, token2: TokenIndex) bool {
1317 const source = tree.source[tree.tokenStart(token1)..tree.tokenStart(token2)];1317 const source = tree.source[tree.tokenStart(token1)..tree.tokenStart(token2)];
1318 return mem.indexOfScalar(u8, source, '\n') == null;1318 return mem.findScalar(u8, source, '\n') == null;
1319}1319}
13201320
1321pub fn getNodeSource(tree: Ast, node: Node.Index) []const u8 {1321pub fn getNodeSource(tree: Ast, node: Node.Index) []const u8 {
lib/std/zig/Ast/Render.zig+9-9
...@@ -1420,7 +1420,7 @@ fn renderFor(r: *Render, for_node: Ast.full.For, space: Space) Error!void {...@@ -1420,7 +1420,7 @@ fn renderFor(r: *Render, for_node: Ast.full.For, space: Space) Error!void {
1420 try renderParamList(r, lparen, for_node.ast.inputs, .space);1420 try renderParamList(r, lparen, for_node.ast.inputs, .space);
14211421
1422 var cur = for_node.payload_token;1422 var cur = for_node.payload_token;
1423 const pipe = std.mem.indexOfScalarPos(std.zig.Token.Tag, token_tags, cur, .pipe).?;1423 const pipe = std.mem.findScalarPos(std.zig.Token.Tag, token_tags, cur, .pipe).?;
1424 if (tree.tokenTag(@intCast(pipe - 1)) == .comma) {1424 if (tree.tokenTag(@intCast(pipe - 1)) == .comma) {
1425 try ais.pushIndent(.normal);1425 try ais.pushIndent(.normal);
1426 try renderToken(r, cur - 1, .newline); // |1426 try renderToken(r, cur - 1, .newline); // |
...@@ -2197,7 +2197,7 @@ fn renderArrayInit(...@@ -2197,7 +2197,7 @@ fn renderArrayInit(
2197 try renderExpression(&sub_render, expr, .none);2197 try renderExpression(&sub_render, expr, .none);
2198 const written = sub_expr_buffer.written();2198 const written = sub_expr_buffer.written();
2199 const width = written.len - start;2199 const width = written.len - start;
2200 const this_contains_newline = mem.indexOfScalar(u8, written[start..], '\n') != null;2200 const this_contains_newline = mem.findScalar(u8, written[start..], '\n') != null;
2201 contains_newline = contains_newline or this_contains_newline;2201 contains_newline = contains_newline or this_contains_newline;
2202 expr_widths[i] = width;2202 expr_widths[i] = width;
2203 expr_newlines[i] = this_contains_newline;2203 expr_newlines[i] = this_contains_newline;
...@@ -2221,7 +2221,7 @@ fn renderArrayInit(...@@ -2221,7 +2221,7 @@ fn renderArrayInit(
22212221
2222 const written = sub_expr_buffer.written();2222 const written = sub_expr_buffer.written();
2223 const width = written.len - start - 2;2223 const width = written.len - start - 2;
2224 const this_contains_newline = mem.indexOfScalar(u8, written[start .. written.len - 1], '\n') != null;2224 const this_contains_newline = mem.findScalar(u8, written[start .. written.len - 1], '\n') != null;
2225 contains_newline = contains_newline or this_contains_newline;2225 contains_newline = contains_newline or this_contains_newline;
2226 expr_widths[i] = width;2226 expr_widths[i] = width;
2227 expr_newlines[i] = contains_newline;2227 expr_newlines[i] = contains_newline;
...@@ -3092,7 +3092,7 @@ fn hasComment(tree: Ast, start_token: Ast.TokenIndex, end_token: Ast.TokenIndex)...@@ -3092,7 +3092,7 @@ fn hasComment(tree: Ast, start_token: Ast.TokenIndex, end_token: Ast.TokenIndex)
3092 const token: Ast.TokenIndex = @intCast(i);3092 const token: Ast.TokenIndex = @intCast(i);
3093 const start = tree.tokenStart(token) + tree.tokenSlice(token).len;3093 const start = tree.tokenStart(token) + tree.tokenSlice(token).len;
3094 const end = tree.tokenStart(token + 1);3094 const end = tree.tokenStart(token + 1);
3095 if (mem.indexOf(u8, tree.source[start..end], "//") != null) return true;3095 if (mem.find(u8, tree.source[start..end], "//") != null) return true;
3096 }3096 }
30973097
3098 return false;3098 return false;
...@@ -3101,7 +3101,7 @@ fn hasComment(tree: Ast, start_token: Ast.TokenIndex, end_token: Ast.TokenIndex)...@@ -3101,7 +3101,7 @@ fn hasComment(tree: Ast, start_token: Ast.TokenIndex, end_token: Ast.TokenIndex)
3101/// Returns true if there exists a multiline string literal between the start3101/// Returns true if there exists a multiline string literal between the start
3102/// of token `start_token` and the start of token `end_token`.3102/// of token `start_token` and the start of token `end_token`.
3103fn hasMultilineString(tree: Ast, start_token: Ast.TokenIndex, end_token: Ast.TokenIndex) bool {3103fn hasMultilineString(tree: Ast, start_token: Ast.TokenIndex, end_token: Ast.TokenIndex) bool {
3104 return std.mem.indexOfScalar(3104 return std.mem.findScalar(
3105 Token.Tag,3105 Token.Tag,
3106 tree.tokens.items(.tag)[start_token..end_token],3106 tree.tokens.items(.tag)[start_token..end_token],
3107 .multiline_string_literal_line,3107 .multiline_string_literal_line,
...@@ -3115,11 +3115,11 @@ fn renderComments(r: *Render, start: usize, end: usize) Error!bool {...@@ -3115,11 +3115,11 @@ fn renderComments(r: *Render, start: usize, end: usize) Error!bool {
3115 const ais = r.ais;3115 const ais = r.ais;
31163116
3117 var index: usize = start;3117 var index: usize = start;
3118 while (mem.indexOf(u8, tree.source[index..end], "//")) |offset| {3118 while (mem.find(u8, tree.source[index..end], "//")) |offset| {
3119 const comment_start = index + offset;3119 const comment_start = index + offset;
31203120
3121 // If there is no newline, the comment ends with EOF3121 // If there is no newline, the comment ends with EOF
3122 const newline_index = mem.indexOfScalar(u8, tree.source[comment_start..end], '\n');3122 const newline_index = mem.findScalar(u8, tree.source[comment_start..end], '\n');
3123 const newline = if (newline_index) |i| comment_start + i else null;3123 const newline = if (newline_index) |i| comment_start + i else null;
31243124
3125 const untrimmed_comment = tree.source[comment_start .. newline orelse tree.source.len];3125 const untrimmed_comment = tree.source[comment_start .. newline orelse tree.source.len];
...@@ -3131,7 +3131,7 @@ fn renderComments(r: *Render, start: usize, end: usize) Error!bool {...@@ -3131,7 +3131,7 @@ fn renderComments(r: *Render, start: usize, end: usize) Error!bool {
3131 // Leave up to one empty line before the first comment3131 // Leave up to one empty line before the first comment
3132 try ais.insertNewline();3132 try ais.insertNewline();
3133 try ais.insertNewline();3133 try ais.insertNewline();
3134 } else if (mem.indexOfScalar(u8, tree.source[index..comment_start], '\n') != null) {3134 } else if (mem.findScalar(u8, tree.source[index..comment_start], '\n') != null) {
3135 // Respect the newline directly before the comment.3135 // Respect the newline directly before the comment.
3136 // Note: This allows an empty line between comments3136 // Note: This allows an empty line between comments
3137 try ais.insertNewline();3137 try ais.insertNewline();
...@@ -3190,7 +3190,7 @@ fn renderExtraNewlineToken(r: *Render, token_index: Ast.TokenIndex) Error!void {...@@ -3190,7 +3190,7 @@ fn renderExtraNewlineToken(r: *Render, token_index: Ast.TokenIndex) Error!void {
31903190
3191 // If there is a immediately preceding comment or doc_comment,3191 // If there is a immediately preceding comment or doc_comment,
3192 // skip it because required extra newline has already been rendered.3192 // skip it because required extra newline has already been rendered.
3193 if (mem.indexOf(u8, tree.source[prev_token_end..token_start], "//") != null) return;3193 if (mem.find(u8, tree.source[prev_token_end..token_start], "//") != null) return;
3194 if (tree.isTokenPrecededByTags(token_index, &.{.doc_comment})) return;3194 if (tree.isTokenPrecededByTags(token_index, &.{.doc_comment})) return;
31953195
3196 // Iterate backwards to the end of the previous token, stopping if a3196 // Iterate backwards to the end of the previous token, stopping if a
lib/std/zig/AstGen.zig+8-8
...@@ -4131,7 +4131,7 @@ fn fnDecl(...@@ -4131,7 +4131,7 @@ fn fnDecl(
4131 const lib_name = if (fn_proto.lib_name) |lib_name_token| blk: {4131 const lib_name = if (fn_proto.lib_name) |lib_name_token| blk: {
4132 const lib_name_str = try astgen.strLitAsString(lib_name_token);4132 const lib_name_str = try astgen.strLitAsString(lib_name_token);
4133 const lib_name_slice = astgen.string_bytes.items[@intFromEnum(lib_name_str.index)..][0..lib_name_str.len];4133 const lib_name_slice = astgen.string_bytes.items[@intFromEnum(lib_name_str.index)..][0..lib_name_str.len];
4134 if (mem.indexOfScalar(u8, lib_name_slice, 0) != null) {4134 if (mem.findScalar(u8, lib_name_slice, 0) != null) {
4135 return astgen.failTok(lib_name_token, "library name cannot contain null bytes", .{});4135 return astgen.failTok(lib_name_token, "library name cannot contain null bytes", .{});
4136 } else if (lib_name_str.len == 0) {4136 } else if (lib_name_str.len == 0) {
4137 return astgen.failTok(lib_name_token, "library name cannot be empty", .{});4137 return astgen.failTok(lib_name_token, "library name cannot be empty", .{});
...@@ -4547,7 +4547,7 @@ fn globalVarDecl(...@@ -4547,7 +4547,7 @@ fn globalVarDecl(
4547 const lib_name = if (var_decl.lib_name) |lib_name_token| blk: {4547 const lib_name = if (var_decl.lib_name) |lib_name_token| blk: {
4548 const lib_name_str = try astgen.strLitAsString(lib_name_token);4548 const lib_name_str = try astgen.strLitAsString(lib_name_token);
4549 const lib_name_slice = astgen.string_bytes.items[@intFromEnum(lib_name_str.index)..][0..lib_name_str.len];4549 const lib_name_slice = astgen.string_bytes.items[@intFromEnum(lib_name_str.index)..][0..lib_name_str.len];
4550 if (mem.indexOfScalar(u8, lib_name_slice, 0) != null) {4550 if (mem.findScalar(u8, lib_name_slice, 0) != null) {
4551 return astgen.failTok(lib_name_token, "library name cannot contain null bytes", .{});4551 return astgen.failTok(lib_name_token, "library name cannot contain null bytes", .{});
4552 } else if (lib_name_str.len == 0) {4552 } else if (lib_name_str.len == 0) {
4553 return astgen.failTok(lib_name_token, "library name cannot be empty", .{});4553 return astgen.failTok(lib_name_token, "library name cannot be empty", .{});
...@@ -4769,7 +4769,7 @@ fn testDecl(...@@ -4769,7 +4769,7 @@ fn testDecl(
4769 .string_literal => name: {4769 .string_literal => name: {
4770 const name = try astgen.strLitAsString(test_name_token);4770 const name = try astgen.strLitAsString(test_name_token);
4771 const slice = astgen.string_bytes.items[@intFromEnum(name.index)..][0..name.len];4771 const slice = astgen.string_bytes.items[@intFromEnum(name.index)..][0..name.len];
4772 if (mem.indexOfScalar(u8, slice, 0) != null) {4772 if (mem.findScalar(u8, slice, 0) != null) {
4773 return astgen.failTok(test_name_token, "test name cannot contain null bytes", .{});4773 return astgen.failTok(test_name_token, "test name cannot contain null bytes", .{});
4774 } else if (slice.len == 0) {4774 } else if (slice.len == 0) {
4775 return astgen.failTok(test_name_token, "empty test name must be omitted", .{});4775 return astgen.failTok(test_name_token, "empty test name must be omitted", .{});
...@@ -8779,7 +8779,7 @@ fn numberLiteral(gz: *GenZir, ri: ResultInfo, node: Ast.Node.Index, source_node:...@@ -8779,7 +8779,7 @@ fn numberLiteral(gz: *GenZir, ri: ResultInfo, node: Ast.Node.Index, source_node:
8779}8779}
87808780
8781fn failWithNumberError(astgen: *AstGen, err: std.zig.number_literal.Error, token: Ast.TokenIndex, bytes: []const u8) InnerError {8781fn failWithNumberError(astgen: *AstGen, err: std.zig.number_literal.Error, token: Ast.TokenIndex, bytes: []const u8) InnerError {
8782 const is_float = std.mem.indexOfScalar(u8, bytes, '.') != null;8782 const is_float = std.mem.findScalar(u8, bytes, '.') != null;
8783 switch (err) {8783 switch (err) {
8784 .leading_zero => if (is_float) {8784 .leading_zero => if (is_float) {
8785 return astgen.failTok(token, "number '{s}' has leading zero", .{bytes});8785 return astgen.failTok(token, "number '{s}' has leading zero", .{bytes});
...@@ -9272,7 +9272,7 @@ fn builtinCall(...@@ -9272,7 +9272,7 @@ fn builtinCall(
9272 const str_lit_token = tree.nodeMainToken(operand_node);9272 const str_lit_token = tree.nodeMainToken(operand_node);
9273 const str = try astgen.strLitAsString(str_lit_token);9273 const str = try astgen.strLitAsString(str_lit_token);
9274 const str_slice = astgen.string_bytes.items[@intFromEnum(str.index)..][0..str.len];9274 const str_slice = astgen.string_bytes.items[@intFromEnum(str.index)..][0..str.len];
9275 if (mem.indexOfScalar(u8, str_slice, 0) != null) {9275 if (mem.findScalar(u8, str_slice, 0) != null) {
9276 return astgen.failTok(str_lit_token, "import path cannot contain null bytes", .{});9276 return astgen.failTok(str_lit_token, "import path cannot contain null bytes", .{});
9277 } else if (str.len == 0) {9277 } else if (str.len == 0) {
9278 return astgen.failTok(str_lit_token, "import path cannot be empty", .{});9278 return astgen.failTok(str_lit_token, "import path cannot be empty", .{});
...@@ -11418,7 +11418,7 @@ fn identifierTokenString(astgen: *AstGen, token: Ast.TokenIndex) InnerError![]co...@@ -11418,7 +11418,7 @@ fn identifierTokenString(astgen: *AstGen, token: Ast.TokenIndex) InnerError![]co
11418 var buf: ArrayList(u8) = .empty;11418 var buf: ArrayList(u8) = .empty;
11419 defer buf.deinit(astgen.gpa);11419 defer buf.deinit(astgen.gpa);
11420 try astgen.parseStrLit(token, &buf, ident_name, 1);11420 try astgen.parseStrLit(token, &buf, ident_name, 1);
11421 if (mem.indexOfScalar(u8, buf.items, 0) != null) {11421 if (mem.findScalar(u8, buf.items, 0) != null) {
11422 return astgen.failTok(token, "identifier cannot contain null bytes", .{});11422 return astgen.failTok(token, "identifier cannot contain null bytes", .{});
11423 } else if (buf.items.len == 0) {11423 } else if (buf.items.len == 0) {
11424 return astgen.failTok(token, "identifier cannot be empty", .{});11424 return astgen.failTok(token, "identifier cannot be empty", .{});
...@@ -11444,7 +11444,7 @@ fn appendIdentStr(...@@ -11444,7 +11444,7 @@ fn appendIdentStr(
11444 const start = buf.items.len;11444 const start = buf.items.len;
11445 try astgen.parseStrLit(token, buf, ident_name, 1);11445 try astgen.parseStrLit(token, buf, ident_name, 1);
11446 const slice = buf.items[start..];11446 const slice = buf.items[start..];
11447 if (mem.indexOfScalar(u8, slice, 0) != null) {11447 if (mem.findScalar(u8, slice, 0) != null) {
11448 return astgen.failTok(token, "identifier cannot contain null bytes", .{});11448 return astgen.failTok(token, "identifier cannot contain null bytes", .{});
11449 } else if (slice.len == 0) {11449 } else if (slice.len == 0) {
11450 return astgen.failTok(token, "identifier cannot be empty", .{});11450 return astgen.failTok(token, "identifier cannot be empty", .{});
...@@ -11701,7 +11701,7 @@ fn strLitAsString(astgen: *AstGen, str_lit_token: Ast.TokenIndex) !IndexSlice {...@@ -11701,7 +11701,7 @@ fn strLitAsString(astgen: *AstGen, str_lit_token: Ast.TokenIndex) !IndexSlice {
11701 const token_bytes = astgen.tree.tokenSlice(str_lit_token);11701 const token_bytes = astgen.tree.tokenSlice(str_lit_token);
11702 try astgen.parseStrLit(str_lit_token, string_bytes, token_bytes, 0);11702 try astgen.parseStrLit(str_lit_token, string_bytes, token_bytes, 0);
11703 const key: []const u8 = string_bytes.items[str_index..];11703 const key: []const u8 = string_bytes.items[str_index..];
11704 if (std.mem.indexOfScalar(u8, key, 0)) |_| return .{11704 if (std.mem.findScalar(u8, key, 0)) |_| return .{
11705 .index = @enumFromInt(str_index),11705 .index = @enumFromInt(str_index),
11706 .len = @intCast(key.len),11706 .len = @intCast(key.len),
11707 };11707 };
lib/std/zig/Parse.zig+1-1
...@@ -3686,7 +3686,7 @@ fn eatDocComments(p: *Parse) Allocator.Error!?TokenIndex {...@@ -3686,7 +3686,7 @@ fn eatDocComments(p: *Parse) Allocator.Error!?TokenIndex {
3686}3686}
36873687
3688fn tokensOnSameLine(p: *Parse, token1: TokenIndex, token2: TokenIndex) bool {3688fn tokensOnSameLine(p: *Parse, token1: TokenIndex, token2: TokenIndex) bool {
3689 return std.mem.indexOfScalar(u8, p.source[p.tokenStart(token1)..p.tokenStart(token2)], '\n') == null;3689 return std.mem.findScalar(u8, p.source[p.tokenStart(token1)..p.tokenStart(token2)], '\n') == null;
3690}3690}
36913691
3692fn eatToken(p: *Parse, tag: Token.Tag) ?TokenIndex {3692fn eatToken(p: *Parse, tag: Token.Tag) ?TokenIndex {
lib/std/zig/WindowsSdk.zig+1-1
...@@ -109,7 +109,7 @@ fn iterateAndFilterByVersion(...@@ -109,7 +109,7 @@ fn iterateAndFilterByVersion(
109 .build = "",109 .build = "",
110 };110 };
111 const suffix = entry.name[prefix.len..];111 const suffix = entry.name[prefix.len..];
112 const underscore = std.mem.indexOfScalar(u8, entry.name, '_');112 const underscore = std.mem.findScalar(u8, entry.name, '_');
113 var num_it = std.mem.splitScalar(u8, suffix[0 .. underscore orelse suffix.len], '.');113 var num_it = std.mem.splitScalar(u8, suffix[0 .. underscore orelse suffix.len], '.');
114 version.nums[0] = Version.parseNum(num_it.first()) orelse continue;114 version.nums[0] = Version.parseNum(num_it.first()) orelse continue;
115 for (version.nums[1..]) |*num|115 for (version.nums[1..]) |*num|
lib/std/zig/Zir.zig+1-1
...@@ -120,7 +120,7 @@ pub const NullTerminatedString = enum(u32) {...@@ -120,7 +120,7 @@ pub const NullTerminatedString = enum(u32) {
120/// Given an index into `string_bytes` returns the null-terminated string found there.120/// Given an index into `string_bytes` returns the null-terminated string found there.
121pub fn nullTerminatedString(code: Zir, index: NullTerminatedString) [:0]const u8 {121pub fn nullTerminatedString(code: Zir, index: NullTerminatedString) [:0]const u8 {
122 const slice = code.string_bytes[@intFromEnum(index)..];122 const slice = code.string_bytes[@intFromEnum(index)..];
123 return slice[0..std.mem.indexOfScalar(u8, slice, 0).? :0];123 return slice[0..std.mem.findScalar(u8, slice, 0).? :0];
124}124}
125125
126pub fn refSlice(code: Zir, start: usize, len: usize) []Inst.Ref {126pub fn refSlice(code: Zir, start: usize, len: usize) []Inst.Ref {
lib/std/zig/Zoir.zig+1-1
...@@ -221,7 +221,7 @@ pub const Node = union(enum) {...@@ -221,7 +221,7 @@ pub const Node = union(enum) {
221pub const NullTerminatedString = enum(u32) {221pub const NullTerminatedString = enum(u32) {
222 _,222 _,
223 pub fn get(nts: NullTerminatedString, zoir: Zoir) [:0]const u8 {223 pub fn get(nts: NullTerminatedString, zoir: Zoir) [:0]const u8 {
224 const idx = std.mem.indexOfScalar(u8, zoir.string_bytes[@intFromEnum(nts)..], 0).?;224 const idx = std.mem.findScalar(u8, zoir.string_bytes[@intFromEnum(nts)..], 0).?;
225 return zoir.string_bytes[@intFromEnum(nts)..][0..idx :0];225 return zoir.string_bytes[@intFromEnum(nts)..][0..idx :0];
226 }226 }
227};227};
lib/std/zig/ZonGen.zig+3-3
...@@ -487,7 +487,7 @@ fn appendIdentStr(zg: *ZonGen, ident_token: Ast.TokenIndex) error{ OutOfMemory,...@@ -487,7 +487,7 @@ fn appendIdentStr(zg: *ZonGen, ident_token: Ast.TokenIndex) error{ OutOfMemory,
487 }487 }
488488
489 const slice = zg.string_bytes.items[start..];489 const slice = zg.string_bytes.items[start..];
490 if (mem.indexOfScalar(u8, slice, 0) != null) {490 if (mem.findScalar(u8, slice, 0) != null) {
491 try zg.addErrorTok(ident_token, "identifier cannot contain null bytes", .{});491 try zg.addErrorTok(ident_token, "identifier cannot contain null bytes", .{});
492 return error.BadString;492 return error.BadString;
493 } else if (slice.len == 0) {493 } else if (slice.len == 0) {
...@@ -586,7 +586,7 @@ fn strLitAsString(zg: *ZonGen, str_node: Ast.Node.Index) error{ OutOfMemory, Bad...@@ -586,7 +586,7 @@ fn strLitAsString(zg: *ZonGen, str_node: Ast.Node.Index) error{ OutOfMemory, Bad
586 },586 },
587 }587 }
588 const key: []const u8 = string_bytes.items[str_index..];588 const key: []const u8 = string_bytes.items[str_index..];
589 if (std.mem.indexOfScalar(u8, key, 0) != null) return .{ .slice = .{589 if (std.mem.findScalar(u8, key, 0) != null) return .{ .slice = .{
590 .start = str_index,590 .start = str_index,
591 .len = @intCast(key.len),591 .len = @intCast(key.len),
592 } };592 } };
...@@ -785,7 +785,7 @@ fn lowerStrLitError(...@@ -785,7 +785,7 @@ fn lowerStrLitError(
785}785}
786786
787fn lowerNumberError(zg: *ZonGen, err: std.zig.number_literal.Error, token: Ast.TokenIndex, bytes: []const u8) Allocator.Error!void {787fn lowerNumberError(zg: *ZonGen, err: std.zig.number_literal.Error, token: Ast.TokenIndex, bytes: []const u8) Allocator.Error!void {
788 const is_float = std.mem.indexOfScalar(u8, bytes, '.') != null;788 const is_float = std.mem.findScalar(u8, bytes, '.') != null;
789 switch (err) {789 switch (err) {
790 .leading_zero => if (is_float) {790 .leading_zero => if (is_float) {
791 try zg.addErrorTok(token, "number '{s}' has leading zero", .{bytes});791 try zg.addErrorTok(token, "number '{s}' has leading zero", .{bytes});
lib/std/zig/c_translation/helpers.zig+1-1
...@@ -115,7 +115,7 @@ fn PromoteIntLiteralReturnType(comptime SuffixType: type, comptime number: compt...@@ -115,7 +115,7 @@ fn PromoteIntLiteralReturnType(comptime SuffixType: type, comptime number: compt
115 else115 else
116 &signed_oct_hex;116 &signed_oct_hex;
117117
118 var pos = std.mem.indexOfScalar(type, list, SuffixType).?;118 var pos = std.mem.findScalar(type, list, SuffixType).?;
119 while (pos < list.len) : (pos += 1) {119 while (pos < list.len) : (pos += 1) {
120 if (number >= std.math.minInt(list[pos]) and number <= std.math.maxInt(list[pos])) {120 if (number >= std.math.minInt(list[pos]) and number <= std.math.maxInt(list[pos])) {
121 return list[pos];121 return list[pos];
lib/std/zig/llvm/bitcode_writer.zig+1-1
...@@ -26,7 +26,7 @@ pub fn BitcodeWriter(comptime types: []const type) type {...@@ -26,7 +26,7 @@ pub fn BitcodeWriter(comptime types: []const type) type {
26 widths: [types.len]u16,26 widths: [types.len]u16,
2727
28 pub fn getTypeWidth(self: BcWriter, comptime Type: type) u16 {28 pub fn getTypeWidth(self: BcWriter, comptime Type: type) u16 {
29 return self.widths[comptime std.mem.indexOfScalar(type, types, Type).?];29 return self.widths[comptime std.mem.findScalar(type, types, Type).?];
30 }30 }
3131
32 pub fn init(allocator: std.mem.Allocator, widths: [types.len]u16) BcWriter {32 pub fn init(allocator: std.mem.Allocator, widths: [types.len]u16) BcWriter {
lib/std/zig/system.zig+1-1
...@@ -1076,7 +1076,7 @@ fn detectAbiAndDynamicLinker(io: Io, cpu: Target.Cpu, os: Target.Os, query: Targ...@@ -1076,7 +1076,7 @@ fn detectAbiAndDynamicLinker(io: Io, cpu: Target.Cpu, os: Target.Os, query: Targ
1076 const path_maybe_args = mem.trimEnd(u8, trimmed_line, "\n");1076 const path_maybe_args = mem.trimEnd(u8, trimmed_line, "\n");
10771077
1078 // Separate path and args.1078 // Separate path and args.
1079 const path_end = mem.indexOfAny(u8, path_maybe_args, &.{ ' ', '\t', 0 }) orelse path_maybe_args.len;1079 const path_end = mem.findAny(u8, path_maybe_args, &.{ ' ', '\t', 0 }) orelse path_maybe_args.len;
1080 const unvalidated_path = path_maybe_args[0..path_end];1080 const unvalidated_path = path_maybe_args[0..path_end];
1081 file_name = if (fs.path.isAbsolute(unvalidated_path)) unvalidated_path else return error.RelativeShebang;1081 file_name = if (fs.path.isAbsolute(unvalidated_path)) unvalidated_path else return error.RelativeShebang;
1082 continue;1082 continue;
lib/std/zig/system/linux.zig+4-4
...@@ -35,7 +35,7 @@ const SparcCpuinfoImpl = struct {...@@ -35,7 +35,7 @@ const SparcCpuinfoImpl = struct {
35 fn line_hook(self: *SparcCpuinfoImpl, key: []const u8, value: []const u8) !bool {35 fn line_hook(self: *SparcCpuinfoImpl, key: []const u8, value: []const u8) !bool {
36 if (mem.eql(u8, key, "cpu")) {36 if (mem.eql(u8, key, "cpu")) {
37 inline for (cpu_names) |pair| {37 inline for (cpu_names) |pair| {
38 if (mem.indexOfPos(u8, value, 0, pair[0]) != null) {38 if (mem.findPos(u8, value, 0, pair[0]) != null) {
39 self.model = pair[1];39 self.model = pair[1];
40 break;40 break;
41 }41 }
...@@ -147,7 +147,7 @@ const PowerpcCpuinfoImpl = struct {...@@ -147,7 +147,7 @@ const PowerpcCpuinfoImpl = struct {
147 // The model name is often followed by a comma or space and extra147 // The model name is often followed by a comma or space and extra
148 // info.148 // info.
149 inline for (cpu_names) |pair| {149 inline for (cpu_names) |pair| {
150 const end_index = mem.indexOfAny(u8, value, ", ") orelse value.len;150 const end_index = mem.findAny(u8, value, ", ") orelse value.len;
151 if (mem.eql(u8, value[0..end_index], pair[0])) {151 if (mem.eql(u8, value[0..end_index], pair[0])) {
152 self.model = pair[1];152 self.model = pair[1];
153 break;153 break;
...@@ -318,7 +318,7 @@ const ArmCpuinfoImpl = struct {...@@ -318,7 +318,7 @@ const ArmCpuinfoImpl = struct {
318 self.have_fields += 1;318 self.have_fields += 1;
319 } else if (mem.eql(u8, key, "model name")) {319 } else if (mem.eql(u8, key, "model name")) {
320 // ARMv6 cores report "CPU architecture" equal to 7.320 // ARMv6 cores report "CPU architecture" equal to 7.
321 if (mem.indexOf(u8, value, "(v6l)")) |_| {321 if (mem.find(u8, value, "(v6l)")) |_| {
322 info.is_really_v6 = true;322 info.is_really_v6 = true;
323 }323 }
324 } else if (mem.eql(u8, key, "CPU revision")) {324 } else if (mem.eql(u8, key, "CPU revision")) {
...@@ -427,7 +427,7 @@ fn CpuinfoParser(comptime impl: anytype) type {...@@ -427,7 +427,7 @@ fn CpuinfoParser(comptime impl: anytype) type {
427 fn parse(arch: Target.Cpu.Arch, reader: *Io.Reader) !?Target.Cpu {427 fn parse(arch: Target.Cpu.Arch, reader: *Io.Reader) !?Target.Cpu {
428 var obj: impl = .{};428 var obj: impl = .{};
429 while (try reader.takeDelimiter('\n')) |line| {429 while (try reader.takeDelimiter('\n')) |line| {
430 const colon_pos = mem.indexOfScalar(u8, line, ':') orelse continue;430 const colon_pos = mem.findScalar(u8, line, ':') orelse continue;
431 const key = mem.trimEnd(u8, line[0..colon_pos], " \t");431 const key = mem.trimEnd(u8, line[0..colon_pos], " \t");
432 const value = mem.trimStart(u8, line[colon_pos + 1 ..], " \t");432 const value = mem.trimStart(u8, line[colon_pos + 1 ..], " \t");
433 if (!try obj.line_hook(key, value)) break;433 if (!try obj.line_hook(key, value)) break;
lib/std/zip.zig+2-2
...@@ -539,7 +539,7 @@ pub const Iterator = struct {...@@ -539,7 +539,7 @@ pub const Iterator = struct {
539 if (options.allow_backslashes) {539 if (options.allow_backslashes) {
540 std.mem.replaceScalar(u8, filename, '\\', '/');540 std.mem.replaceScalar(u8, filename, '\\', '/');
541 } else {541 } else {
542 if (std.mem.indexOfScalar(u8, filename, '\\')) |_|542 if (std.mem.findScalar(u8, filename, '\\')) |_|
543 return error.ZipFilenameHasBackslash;543 return error.ZipFilenameHasBackslash;
544 }544 }
545545
...@@ -626,7 +626,7 @@ pub const Diagnostics = struct {...@@ -626,7 +626,7 @@ pub const Diagnostics = struct {
626 if (!self.saw_first_file) {626 if (!self.saw_first_file) {
627 self.saw_first_file = true;627 self.saw_first_file = true;
628 std.debug.assert(self.root_dir.len == 0);628 std.debug.assert(self.root_dir.len == 0);
629 const root_len = std.mem.indexOfScalar(u8, name, '/') orelse return;629 const root_len = std.mem.findScalar(u8, name, '/') orelse return;
630 std.debug.assert(root_len > 0);630 std.debug.assert(root_len > 0);
631 self.root_dir = try self.allocator.dupe(u8, name[0..root_len]);631 self.root_dir = try self.allocator.dupe(u8, name[0..root_len]);
632 } else if (self.root_dir.len > 0) {632 } else if (self.root_dir.len > 0) {