authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-12-22 12:50:46+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-12-22 12:50:46+01:00
logaa0249d74e573742db3567f589fc6e4a00e1fff8
treecce61cb7f02072d205a12ae451922f0bf09c13ce
parent6b9125cbe662d530160e0732c856aa0da86894c0
parent02c5f05e2f0e8e786f0530014e35c1520efd0084

Merge pull request 'std.ascii: rename indexOf functions to find' (#30101) from adria/zig:indexof-find into master

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30101 Reviewed-by: Andrew Kelley <andrewrk@noreply.codeberg.org> Reviewed-by: mlugg <mlugg@noreply.codeberg.org>

57 files changed, 215 insertions(+), 206 deletions(-)

lib/std/Build/Step/CheckFile.zig+1-1
......@@ -60,7 +60,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
6060 };
6161
6262 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) {
6464 return step.fail(
6565 \\
6666 \\========= expected to find: ===================
lib/std/Build/Step/CheckObject.zig+3-3
......@@ -88,7 +88,7 @@ const Action = struct {
8888 while (needle_it.next()) |needle_tok| {
8989 const hay_tok = hay_it.next() orelse break;
9090 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;
9292 if (closing_brace != needle_tok.len - 1) return error.ClosingBraceNotLast;
9393
9494 const name = needle_tok[1..closing_brace];
......@@ -133,7 +133,7 @@ const Action = struct {
133133 assert(act.tag == .contains);
134134 const hay = mem.trim(u8, haystack, " ");
135135 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;
137137 }
138138
139139 /// Returns true if the `phrase` does not exist within the haystack.
......@@ -1662,7 +1662,7 @@ const MachODumper = struct {
16621662
16631663 .dump_section => {
16641664 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, ',') orelse
1665 const sep_index = mem.findScalar(u8, name, ',') orelse
16661666 return step.fail("invalid section name: {s}", .{name});
16671667 const segname = name[0..sep_index];
16681668 const sectname = name[sep_index + 1 ..];
lib/std/Build/Step/Compile.zig+3-3
......@@ -369,7 +369,7 @@ pub const TestRunner = struct {
369369
370370pub fn create(owner: *std.Build, options: Options) *Compile {
371371 const name = owner.dupe(options.name);
372 if (mem.indexOf(u8, name, "/") != null or mem.indexOf(u8, name, "\\") != null) {
372 if (mem.find(u8, name, "/") != null or mem.find(u8, name, "\\") != null) {
373373 panic("invalid name: '{s}'. It looks like a file path, but it is supposed to be the library or application name.", .{name});
374374 }
375375
......@@ -716,7 +716,7 @@ fn runPkgConfig(compile: *Compile, lib_name: []const u8) !PkgConfigResult {
716716
717717 // Prefixed "lib" or suffixed ".0".
718718 for (pkgs) |pkg| {
719 if (std.ascii.indexOfIgnoreCase(pkg.name, lib_name)) |pos| {
719 if (std.ascii.findIgnoreCase(pkg.name, lib_name)) |pos| {
720720 const prefix = pkg.name[0..pos];
721721 const suffix = pkg.name[pos + lib_name.len ..];
722722 if (prefix.len > 0 and !mem.eql(u8, prefix, "lib")) continue;
......@@ -1996,7 +1996,7 @@ fn matchCompileError(actual: []const u8, expected: []const u8) bool {
19961996 // We scan for /?/ in expected line and if there is a match, we match everything
19971997 // up to and after /?/.
19981998 const expected_trim = mem.trim(u8, expected, " ");
1999 if (mem.indexOf(u8, expected_trim, "/?/")) |index| {
1999 if (mem.find(u8, expected_trim, "/?/")) |index| {
20002000 const actual_trim = mem.trim(u8, actual, " ");
20012001 const lhs = expected_trim[0..index];
20022002 const rhs = expected_trim[index + "/?/".len ..];
lib/std/Build/Step/ConfigHeader.zig+5-5
......@@ -578,12 +578,12 @@ fn expand_variables_autoconf_at(
578578 var source_offset: usize = 0;
579579 while (curr < contents.len) : (curr += 1) {
580580 if (contents[curr] != '@') continue;
581 if (std.mem.indexOfScalarPos(u8, contents, curr + 1, '@')) |close_pos| {
581 if (std.mem.findScalarPos(u8, contents, curr + 1, '@')) |close_pos| {
582582 if (close_pos == curr + 1) {
583583 // closed immediately, preserve as a literal
584584 continue;
585585 }
586 const valid_varname_end = std.mem.indexOfNonePos(u8, contents, curr + 1, valid_varname_chars) orelse 0;
586 const valid_varname_end = std.mem.findNonePos(u8, contents, curr + 1, valid_varname_chars) orelse 0;
587587 if (valid_varname_end != close_pos) {
588588 // contains invalid characters, preserve as a literal
589589 continue;
......@@ -635,12 +635,12 @@ fn expand_variables_cmake(
635635 loop: while (curr < contents.len) : (curr += 1) {
636636 switch (contents[curr]) {
637637 '@' => blk: {
638 if (std.mem.indexOfScalarPos(u8, contents, curr + 1, '@')) |close_pos| {
638 if (std.mem.findScalarPos(u8, contents, curr + 1, '@')) |close_pos| {
639639 if (close_pos == curr + 1) {
640640 // closed immediately, preserve as a literal
641641 break :blk;
642642 }
643 const valid_varname_end = std.mem.indexOfNonePos(u8, contents, curr + 1, valid_varname_chars) orelse 0;
643 const valid_varname_end = std.mem.findNonePos(u8, contents, curr + 1, valid_varname_chars) orelse 0;
644644 if (valid_varname_end != close_pos) {
645645 // contains invalid characters, preserve as a literal
646646 break :blk;
......@@ -731,7 +731,7 @@ fn expand_variables_cmake(
731731 else => {},
732732 }
733733
734 if (var_stack.items.len > 0 and std.mem.indexOfScalar(u8, valid_varname_chars, contents[curr]) == null) {
734 if (var_stack.items.len > 0 and std.mem.findScalar(u8, valid_varname_chars, contents[curr]) == null) {
735735 return error.InvalidCharacter;
736736 }
737737 }
lib/std/Build/Step/Run.zig+2-2
......@@ -1505,7 +1505,7 @@ fn runCommand(
15051505 }
15061506 },
15071507 .expect_stderr_match => |match| {
1508 if (mem.indexOf(u8, generic_result.stderr.?, match) == null) {
1508 if (mem.find(u8, generic_result.stderr.?, match) == null) {
15091509 return step.fail(
15101510 \\========= expected to find in stderr: =========
15111511 \\{s}
......@@ -1531,7 +1531,7 @@ fn runCommand(
15311531 }
15321532 },
15331533 .expect_stdout_match => |match| {
1534 if (mem.indexOf(u8, generic_result.stdout.?, match) == null) {
1534 if (mem.find(u8, generic_result.stdout.?, match) == null) {
15351535 return step.fail(
15361536 \\========= expected to find in stdout: =========
15371537 \\{s}
lib/std/Io/Reader.zig+2-2
......@@ -993,7 +993,7 @@ pub fn streamDelimiterLimit(
993993 error.ReadFailed => return error.ReadFailed,
994994 error.EndOfStream => return @intFromEnum(limit) - remaining,
995995 });
996 if (std.mem.indexOfScalar(u8, available, delimiter)) |delimiter_index| {
996 if (std.mem.findScalar(u8, available, delimiter)) |delimiter_index| {
997997 try w.writeAll(available[0..delimiter_index]);
998998 r.toss(delimiter_index);
999999 remaining -= delimiter_index;
......@@ -1064,7 +1064,7 @@ pub fn discardDelimiterLimit(r: *Reader, delimiter: u8, limit: Limit) DiscardDel
10641064 error.ReadFailed => return error.ReadFailed,
10651065 error.EndOfStream => return @intFromEnum(limit) - remaining,
10661066 });
1067 if (std.mem.indexOfScalar(u8, available, delimiter)) |delimiter_index| {
1067 if (std.mem.findScalar(u8, available, delimiter)) |delimiter_index| {
10681068 r.toss(delimiter_index);
10691069 remaining -= delimiter_index;
10701070 return @intFromEnum(limit) - remaining;
lib/std/Progress.zig+2-2
......@@ -257,7 +257,7 @@ pub const Node = struct {
257257 const index = n.index.unwrap() orelse return;
258258 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
262262 copyAtomicStore(storage.name[0..name_len], new_name[0..name_len]);
263263 if (name_len < storage.name.len)
......@@ -1347,7 +1347,7 @@ fn computeNode(
13471347 const storage = &serialized.storage[@intFromEnum(node_index)];
13481348 const estimated_total = storage.estimated_total_count;
13491349 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;
13511351 const parent = serialized.parents[@intFromEnum(node_index)];
13521352
13531353 if (parent != .none) p: {
lib/std/Random/benchmark.zig+4-4
......@@ -180,7 +180,7 @@ pub fn main() !void {
180180 if (bench_prngs) {
181181 if (bench_long) {
182182 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) {
184184 try stdout.print("{s} (long outputs)\n", .{R.name});
185185 try stdout.flush();
186186
......@@ -191,7 +191,7 @@ pub fn main() !void {
191191 }
192192 if (bench_short) {
193193 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) {
195195 try stdout.print("{s} (short outputs)\n", .{R.name});
196196 try stdout.flush();
197197
......@@ -204,7 +204,7 @@ pub fn main() !void {
204204 if (bench_csprngs) {
205205 if (bench_long) {
206206 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) {
208208 try stdout.print("{s} (cryptographic, long outputs)\n", .{R.name});
209209 try stdout.flush();
210210
......@@ -215,7 +215,7 @@ pub fn main() !void {
215215 }
216216 if (bench_short) {
217217 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) {
219219 try stdout.print("{s} (cryptographic, short outputs)\n", .{R.name});
220220 try stdout.flush();
221221
lib/std/SemanticVersion.zig+2-2
......@@ -84,7 +84,7 @@ pub fn order(lhs: Version, rhs: Version) std.math.Order {
8484
8585pub fn parse(text: []const u8) !Version {
8686 // 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, "-+");
8888 const required = text[0..(extra_index orelse text.len)];
8989 var it = std.mem.splitScalar(u8, required, '.');
9090 var ver = Version{
......@@ -98,7 +98,7 @@ pub fn parse(text: []const u8) !Version {
9898 // Slice optional pre-release or build metadata components.
9999 const extra: []const u8 = text[extra_index.?..text.len];
100100 if (extra[0] == '-') {
101 const build_index = std.mem.indexOfScalar(u8, extra, '+');
101 const build_index = std.mem.findScalar(u8, extra, '+');
102102 ver.pre = extra[1..(build_index orelse extra.len)];
103103 if (build_index) |idx| ver.build = extra[(idx + 1)..];
104104 } else {
lib/std/Uri.zig+8-8
......@@ -65,7 +65,7 @@ pub const Component = union(enum) {
6565 pub fn toRaw(component: Component, buffer: []u8) error{NoSpaceLeft}![]const u8 {
6666 return switch (component) {
6767 .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, '%')) |_|
6969 try std.fmt.bufPrint(buffer, "{f}", .{std.fmt.alt(component, .formatRaw)})
7070 else
7171 percent_encoded,
......@@ -76,7 +76,7 @@ pub const Component = union(enum) {
7676 pub fn toRawMaybeAlloc(component: Component, arena: Allocator) Allocator.Error![]const u8 {
7777 return switch (component) {
7878 .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, '%')) |_|
8080 try std.fmt.allocPrint(arena, "{f}", .{std.fmt.alt(component, .formatRaw)})
8181 else
8282 percent_encoded,
......@@ -89,7 +89,7 @@ pub const Component = union(enum) {
8989 .percent_encoded => |percent_encoded| {
9090 var start: usize = 0;
9191 var index: usize = 0;
92 while (std.mem.indexOfScalarPos(u8, percent_encoded, index, '%')) |percent| {
92 while (std.mem.findScalarPos(u8, percent_encoded, index, '%')) |percent| {
9393 index = percent + 1;
9494 if (percent_encoded.len - index < 2) continue;
9595 const percent_encoded_char =
......@@ -213,7 +213,7 @@ pub fn parseAfterScheme(scheme: []const u8, text: []const u8) ParseError!Uri {
213213 var i: usize = 0;
214214
215215 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;
217217 const authority = text[2..i];
218218 if (authority.len == 0) {
219219 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 {
221221 }
222222
223223 var start_of_host: usize = 0;
224 if (std.mem.indexOf(u8, authority, "@")) |index| {
224 if (std.mem.find(u8, authority, "@")) |index| {
225225 start_of_host = index + 1;
226226 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| {
229229 uri.user = .{ .percent_encoded = user_info[0..idx] };
230230 if (idx < user_info.len - 1) { // empty password is also "no password"
231231 uri.password = .{ .percent_encoded = user_info[idx + 1 ..] };
......@@ -268,12 +268,12 @@ pub fn parseAfterScheme(scheme: []const u8, text: []const u8) ParseError!Uri {
268268 }
269269
270270 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;
272272 uri.path = .{ .percent_encoded = text[path_start..i] };
273273
274274 if (std.mem.startsWith(u8, text[i..], "?")) {
275275 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;
277277 uri.query = .{ .percent_encoded = text[query_start..i] };
278278 }
279279
lib/std/ascii.zig+25-16
......@@ -156,7 +156,7 @@ test whitespace {
156156
157157 var i: u8 = 0;
158158 while (isAscii(i)) : (i += 1) {
159 if (isWhitespace(i)) try std.testing.expect(std.mem.indexOfScalar(u8, &whitespace, i) != null);
159 if (isWhitespace(i)) try std.testing.expect(std.mem.findScalar(u8, &whitespace, i) != null);
160160 }
161161}
162162
......@@ -357,19 +357,25 @@ test endsWithIgnoreCase {
357357 try std.testing.expect(!endsWithIgnoreCase("BoB", "Bo"));
358358}
359359
360/// Deprecated in favor of `findIgnoreCase`.
361pub const indexOfIgnoreCase = findIgnoreCase;
362
360363/// Finds `needle` in `haystack`, ignoring case, starting at index 0.
361pub fn indexOfIgnoreCase(haystack: []const u8, needle: []const u8) ?usize {
362 return indexOfIgnoreCasePos(haystack, 0, needle);
364pub fn findIgnoreCase(haystack: []const u8, needle: []const u8) ?usize {
365 return findIgnoreCasePos(haystack, 0, needle);
363366}
364367
368/// Deprecated in favor of `findIgnoreCasePos`.
369pub const indexOfIgnoreCasePos = findIgnoreCasePos;
370
365371/// Finds `needle` in `haystack`, ignoring case, starting at `start_index`.
366/// Uses Boyer-Moore-Horspool algorithm on large inputs; `indexOfIgnoreCasePosLinear` on small inputs.
367pub fn indexOfIgnoreCasePos(haystack: []const u8, start_index: usize, needle: []const u8) ?usize {
372/// Uses Boyer-Moore-Horspool algorithm on large inputs; `findIgnoreCasePosLinear` on small inputs.
373pub fn findIgnoreCasePos(haystack: []const u8, start_index: usize, needle: []const u8) ?usize {
368374 if (needle.len > haystack.len) return null;
369375 if (needle.len == 0) return start_index;
370376
371377 if (haystack.len < 52 or needle.len <= 4)
372 return indexOfIgnoreCasePosLinear(haystack, start_index, needle);
378 return findIgnoreCasePosLinear(haystack, start_index, needle);
373379
374380 var skip_table: [256]usize = undefined;
375381 boyerMooreHorspoolPreprocessIgnoreCase(needle, skip_table[0..]);
......@@ -383,9 +389,12 @@ pub fn indexOfIgnoreCasePos(haystack: []const u8, start_index: usize, needle: []
383389 return null;
384390}
385391
386/// Consider using `indexOfIgnoreCasePos` instead of this, which will automatically use a
392/// Deprecated in favor of `findIgnoreCaseLinear`.
393pub const indexOfIgnoreCasePosLinear = findIgnoreCasePosLinear;
394
395/// Consider using `findIgnoreCasePos` instead of this, which will automatically use a
387396/// more sophisticated algorithm on larger inputs.
388pub fn indexOfIgnoreCasePosLinear(haystack: []const u8, start_index: usize, needle: []const u8) ?usize {
397pub fn findIgnoreCasePosLinear(haystack: []const u8, start_index: usize, needle: []const u8) ?usize {
389398 var i: usize = start_index;
390399 const end = haystack.len - needle.len;
391400 while (i <= end) : (i += 1) {
......@@ -407,15 +416,15 @@ fn boyerMooreHorspoolPreprocessIgnoreCase(pattern: []const u8, table: *[256]usiz
407416 }
408417}
409418
410test indexOfIgnoreCase {
411 try std.testing.expect(indexOfIgnoreCase("one Two Three Four", "foUr").? == 14);
412 try std.testing.expect(indexOfIgnoreCase("one two three FouR", "gOur") == null);
413 try std.testing.expect(indexOfIgnoreCase("foO", "Foo").? == 0);
414 try std.testing.expect(indexOfIgnoreCase("foo", "fool") == null);
415 try std.testing.expect(indexOfIgnoreCase("FOO foo", "fOo").? == 0);
419test findIgnoreCase {
420 try std.testing.expect(findIgnoreCase("one Two Three Four", "foUr").? == 14);
421 try std.testing.expect(findIgnoreCase("one two three FouR", "gOur") == null);
422 try std.testing.expect(findIgnoreCase("foO", "Foo").? == 0);
423 try std.testing.expect(findIgnoreCase("foo", "fool") == null);
424 try std.testing.expect(findIgnoreCase("FOO foo", "fOo").? == 0);
416425
417 try std.testing.expect(indexOfIgnoreCase("one two three four five six seven eight nine ten eleven", "ThReE fOUr").? == 8);
418 try std.testing.expect(indexOfIgnoreCase("one two three four five six seven eight nine ten eleven", "Two tWo") == null);
426 try std.testing.expect(findIgnoreCase("one two three four five six seven eight nine ten eleven", "ThReE fOUr").? == 8);
427 try std.testing.expect(findIgnoreCase("one two three four five six seven eight nine ten eleven", "Two tWo") == null);
419428}
420429
421430/// Returns the lexicographical order of two slices. O(n).
lib/std/coff.zig+5-5
......@@ -466,13 +466,13 @@ pub const SectionHeader = extern struct {
466466
467467 pub fn getName(self: *align(1) const SectionHeader) ?[]const u8 {
468468 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;
470470 return self.name[0..len];
471471 }
472472
473473 pub fn getNameOffset(self: SectionHeader) ?u32 {
474474 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;
476476 const offset = std.fmt.parseInt(u32, self.name[1..len], 10) catch unreachable;
477477 return offset;
478478 }
......@@ -628,7 +628,7 @@ pub const Symbol = struct {
628628
629629 pub fn getName(self: *const Symbol) ?[]const u8 {
630630 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;
632632 return self.name[0..len];
633633 }
634634
......@@ -869,7 +869,7 @@ pub const FileDefinition = struct {
869869 file_name: [18]u8,
870870
871871 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;
873873 return self.file_name[0..len];
874874 }
875875};
......@@ -1044,7 +1044,7 @@ pub const Coff = struct {
10441044
10451045 // Finally read the null-terminated string.
10461046 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;
10481048 return self.data[start .. start + len];
10491049 }
10501050
lib/std/compress/flate/Compress.zig+1-1
......@@ -598,7 +598,7 @@ fn testFuzzedMatchLen(_: void, input: []const u8) !void {
598598 const bytes = w.buffered()[bytes_off..];
599599 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 same
601 const diff_index = mem.findDiff(u8, prev, bytes).?; // unwrap since lengths are not same
602602 const expected_len = @min(diff_index, 258);
603603 errdefer std.debug.print(
604604 \\prev : '{any}'
lib/std/crypto/Certificate.zig+2-2
......@@ -358,10 +358,10 @@ pub const Parsed = struct {
358358 const wildcard_suffix = dns_name[2..];
359359
360360 // 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
363363 // 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
366366 // Wildcard matches exactly one label, so compare the rest
367367 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
269269 const end_marker = "-----END CERTIFICATE-----";
270270
271271 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| {
273273 const cert_start = begin_marker_start + begin_marker.len;
274 const cert_end = mem.indexOfPos(u8, encoded_bytes, cert_start, end_marker) orelse
274 const cert_end = mem.findPos(u8, encoded_bytes, cert_start, end_marker) orelse
275275 return error.MissingEndCertificateMarker;
276276 start_index = cert_end + end_marker.len;
277277 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 {
547547 }
548548
549549 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) {
551551 const throughput = try benchmarkHash(H.ty, mode(128 * MiB));
552552 try stdout.print("{s:>17}: {:10} MiB/s\n", .{ H.name, throughput / (1 * MiB) });
553553 try stdout.flush();
......@@ -559,7 +559,7 @@ pub fn main() !void {
559559 const io = io_threaded.io();
560560
561561 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) {
563563 const throughput = try benchmarkHashParallel(H.ty, mode(128 * MiB), arena_allocator, io);
564564 try stdout.print("{s:>17}: {:10} MiB/s\n", .{ H.name, throughput / (1 * MiB) });
565565 try stdout.flush();
......@@ -567,7 +567,7 @@ pub fn main() !void {
567567 }
568568
569569 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) {
571571 const throughput = try benchmarkMac(M.ty, mode(128 * MiB));
572572 try stdout.print("{s:>17}: {:10} MiB/s\n", .{ M.name, throughput / (1 * MiB) });
573573 try stdout.flush();
......@@ -575,7 +575,7 @@ pub fn main() !void {
575575 }
576576
577577 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) {
579579 const throughput = try benchmarkKeyExchange(E.ty, mode(1000));
580580 try stdout.print("{s:>17}: {:10} exchanges/s\n", .{ E.name, throughput });
581581 try stdout.flush();
......@@ -583,7 +583,7 @@ pub fn main() !void {
583583 }
584584
585585 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) {
587587 const throughput = try benchmarkSignature(E.ty, mode(1000));
588588 try stdout.print("{s:>17}: {:10} signatures/s\n", .{ E.name, throughput });
589589 try stdout.flush();
......@@ -591,7 +591,7 @@ pub fn main() !void {
591591 }
592592
593593 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) {
595595 const throughput = try benchmarkSignatureVerification(E.ty, mode(1000));
596596 try stdout.print("{s:>17}: {:10} verifications/s\n", .{ E.name, throughput });
597597 try stdout.flush();
......@@ -599,7 +599,7 @@ pub fn main() !void {
599599 }
600600
601601 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) {
603603 const throughput = try benchmarkBatchSignatureVerification(E.ty, mode(1000));
604604 try stdout.print("{s:>17}: {:10} verifications/s (batch)\n", .{ E.name, throughput });
605605 try stdout.flush();
......@@ -607,7 +607,7 @@ pub fn main() !void {
607607 }
608608
609609 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) {
611611 const throughput = try benchmarkAead(E.ty, mode(128 * MiB));
612612 try stdout.print("{s:>17}: {:10} MiB/s\n", .{ E.name, throughput / (1 * MiB) });
613613 try stdout.flush();
......@@ -615,7 +615,7 @@ pub fn main() !void {
615615 }
616616
617617 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) {
619619 const throughput = try benchmarkAes(E.ty, mode(100000000));
620620 try stdout.print("{s:>17}: {:10} ops/s\n", .{ E.name, throughput });
621621 try stdout.flush();
......@@ -623,7 +623,7 @@ pub fn main() !void {
623623 }
624624
625625 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) {
627627 const throughput = try benchmarkAes8(E.ty, mode(10000000));
628628 try stdout.print("{s:>17}: {:10} ops/s\n", .{ E.name, throughput });
629629 try stdout.flush();
......@@ -631,7 +631,7 @@ pub fn main() !void {
631631 }
632632
633633 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) {
635635 const throughput = try benchmarkPwhash(arena_allocator, H.ty, H.params, mode(64), io);
636636 try stdout.print("{s:>17}: {d:10.3} s/ops\n", .{ H.name, throughput });
637637 try stdout.flush();
......@@ -639,7 +639,7 @@ pub fn main() !void {
639639 }
640640
641641 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) {
643643 const throughput = try benchmarkKem(E.ty, mode(1000));
644644 try stdout.print("{s:>17}: {:10} encaps/s\n", .{ E.name, throughput });
645645 try stdout.flush();
......@@ -647,7 +647,7 @@ pub fn main() !void {
647647 }
648648
649649 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) {
651651 const throughput = try benchmarkKemDecaps(E.ty, mode(25000));
652652 try stdout.print("{s:>17}: {:10} decaps/s\n", .{ E.name, throughput });
653653 try stdout.flush();
......@@ -655,7 +655,7 @@ pub fn main() !void {
655655 }
656656
657657 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) {
659659 const throughput = try benchmarkKemKeyGen(E.ty, mode(25000));
660660 try stdout.print("{s:>17}: {:10} keygen/s\n", .{ E.name, throughput });
661661 try stdout.flush();
lib/std/crypto/scrypt.zig+1-1
......@@ -358,7 +358,7 @@ const crypt_format = struct {
358358 fn intDecode(comptime T: type, src: *const [(@bitSizeOf(T) + 5) / 6]u8) !T {
359359 var v: T = 0;
360360 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;
362362 v |= @as(T, @intCast(vi)) << @as(math.Log2Int(T), @intCast(i * 6));
363363 }
364364 return v;
lib/std/debug.zig+3-3
......@@ -1196,7 +1196,7 @@ fn printLineFromFile(writer: *Writer, source_location: SourceLocation) !void {
11961196 var next_line: usize = 1;
11971197 while (next_line != source_location.line) {
11981198 const slice = buf[current_line_start..amt_read];
1199 if (mem.indexOfScalar(u8, slice, '\n')) |pos| {
1199 if (mem.findScalar(u8, slice, '\n')) |pos| {
12001200 next_line += 1;
12011201 if (pos == slice.len - 1) {
12021202 amt_read = try f.read(buf[0..]);
......@@ -1212,7 +1212,7 @@ fn printLineFromFile(writer: *Writer, source_location: SourceLocation) !void {
12121212 break :seek current_line_start;
12131213 };
12141214 const slice = buf[line_start..amt_read];
1215 if (mem.indexOfScalar(u8, slice, '\n')) |pos| {
1215 if (mem.findScalar(u8, slice, '\n')) |pos| {
12161216 const line = slice[0 .. pos + 1];
12171217 mem.replaceScalar(u8, line, '\t', ' ');
12181218 return writer.writeAll(line);
......@@ -1221,7 +1221,7 @@ fn printLineFromFile(writer: *Writer, source_location: SourceLocation) !void {
12211221 try writer.writeAll(slice);
12221222 while (amt_read == buf.len) {
12231223 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| {
12251225 const line = buf[0 .. pos + 1];
12261226 mem.replaceScalar(u8, line, '\t', ' ');
12271227 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 {
437437 };
438438
439439 while (true) {
440 fr.seek = std.mem.indexOfNonePos(u8, fr.buffer, fr.seek, &.{
440 fr.seek = std.mem.findNonePos(u8, fr.buffer, fr.seek, &.{
441441 zig_padding_abbrev_code, 0,
442442 }) orelse fr.buffer.len;
443443 if (fr.seek >= next_unit_pos) break;
......@@ -1539,7 +1539,7 @@ fn getStringGeneric(opt_str: ?[]const u8, offset: u64) ![:0]const u8 {
15391539 if (offset > str.len) return bad();
15401540 const casted_offset = cast(usize, offset) orelse return bad();
15411541 // 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();
15431543 return str[casted_offset..last :0];
15441544}
15451545
lib/std/dynamic_library.zig+1-1
......@@ -197,7 +197,7 @@ pub const ElfDynLib = struct {
197197 // - /etc/ld.so.cache is not read
198198 fn resolveFromName(path_or_name: []const u8) !posix.fd_t {
199199 // 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, '/')) |_| {
201201 return posix.open(path_or_name, .{ .ACCMODE = .RDONLY, .CLOEXEC = true }, 0);
202202 }
203203
lib/std/elf.zig+1-1
......@@ -3039,7 +3039,7 @@ pub const ar_hdr = extern struct {
30393039 pub fn name(self: *const ar_hdr) ?[]const u8 {
30403040 const value = &self.ar_name;
30413041 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;
30433043 return value[0..sentinel];
30443044 }
30453045
lib/std/fmt.zig+1-1
......@@ -182,7 +182,7 @@ pub const Parser = struct {
182182
183183 pub fn until(self: *@This(), delimiter: u8) []const u8 {
184184 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;
186186 return self.bytes[start..self.i];
187187 }
188188
lib/std/fs.zig+1-1
......@@ -469,7 +469,7 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 {
469469 return error.FileNotFound;
470470
471471 const argv0 = mem.span(std.os.argv[0]);
472 if (mem.indexOf(u8, argv0, "/") != null) {
472 if (mem.find(u8, argv0, "/") != null) {
473473 // argv[0] is a path (relative or absolute): use realpath(3) directly
474474 var real_path_buf: [max_path_bytes]u8 = undefined;
475475 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 {
179179 // The name we get from NtQueryInformationFile will be prefixed with a '\', e.g. \msys-1888ae32e00d56aa-pty0-to-master
180180 return (std.mem.startsWith(u16, name_wide, &[_]u16{ '\\', 'm', 's', 'y', 's', '-' }) or
181181 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;
183183}
184184
185185/// 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 {
402402
403403 if (path.len >= 2 and PathType.windows.isSep(u8, path[0]) and PathType.windows.isSep(u8, path[1])) {
404404 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;
406406 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;
408408 };
409409 return WindowsPath{
410410 .is_abs = true,
......@@ -722,7 +722,7 @@ fn parseUNC(comptime T: type, path: []const T) WindowsUNC(T) {
722722 // For the server, the first path separator after the initial two is always
723723 // the terminator of the server name, even if that means the server name is
724724 // 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 .{
726726 .server = path[2..path.len],
727727 .sep_after_server = false,
728728 .share = path[path.len..path.len],
lib/std/hash/benchmark.zig+1-1
......@@ -443,7 +443,7 @@ pub fn main() !void {
443443 const allocator = gpa.allocator();
444444
445445 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: {
447447 if (!test_iterative_only or H.has_iterative_api) {
448448 try stdout.print("{s}\n", .{H.name});
449449 try stdout.flush();
lib/std/hash_map.zig+1-1
......@@ -110,7 +110,7 @@ pub const StringIndexAdapter = struct {
110110 }
111111
112112 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);
114114 return hashString(adapted_key);
115115 }
116116};
lib/std/http/Client.zig+5-5
......@@ -1674,14 +1674,14 @@ pub fn request(
16741674 if (std.debug.runtime_safety) {
16751675 for (options.extra_headers) |header| {
16761676 assert(header.name.len != 0);
1677 assert(std.mem.indexOfScalar(u8, header.name, ':') == null);
1678 assert(std.mem.indexOfPosLinear(u8, header.name, 0, "\r\n") == null);
1679 assert(std.mem.indexOfPosLinear(u8, header.value, 0, "\r\n") == null);
1677 assert(std.mem.findScalar(u8, header.name, ':') == null);
1678 assert(std.mem.findPosLinear(u8, header.name, 0, "\r\n") == null);
1679 assert(std.mem.findPosLinear(u8, header.value, 0, "\r\n") == null);
16801680 }
16811681 for (options.privileged_headers) |header| {
16821682 assert(header.name.len != 0);
1683 assert(std.mem.indexOfPosLinear(u8, header.name, 0, "\r\n") == null);
1684 assert(std.mem.indexOfPosLinear(u8, header.value, 0, "\r\n") == null);
1683 assert(std.mem.findPosLinear(u8, header.name, 0, "\r\n") == null);
1684 assert(std.mem.findPosLinear(u8, header.value, 0, "\r\n") == null);
16851685 }
16861686 }
16871687
lib/std/http/HeaderIterator.zig+3-3
......@@ -5,17 +5,17 @@ is_trailer: bool,
55pub fn init(bytes: []const u8) HeaderIterator {
66 return .{
77 .bytes = bytes,
8 .index = std.mem.indexOfPosLinear(u8, bytes, 0, "\r\n").? + 2,
8 .index = std.mem.findPosLinear(u8, bytes, 0, "\r\n").? + 2,
99 .is_trailer = false,
1010 };
1111}
1212
1313pub 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").?;
1515 if (it.index == end) { // found the trailer boundary (\r\n\r\n)
1616 if (it.is_trailer) return null;
1717
18 const next_end = std.mem.indexOfPosLinear(u8, it.bytes, end + 2, "\r\n") orelse
18 const next_end = std.mem.findPosLinear(u8, it.bytes, end + 2, "\r\n") orelse
1919 return null;
2020
2121 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 {
9696 if (first_line.len < 10)
9797 return error.HttpHeadersInvalid;
9898
99 const method_end = mem.indexOfScalar(u8, first_line, ' ') orelse
99 const method_end = mem.findScalar(u8, first_line, ' ') orelse
100100 return error.HttpHeadersInvalid;
101101
102102 const method = std.meta.stringToEnum(http.Method, first_line[0..method_end]) orelse
......@@ -338,9 +338,9 @@ pub const Request = struct {
338338 if (std.debug.runtime_safety) {
339339 for (options.extra_headers) |header| {
340340 assert(header.name.len != 0);
341 assert(std.mem.indexOfScalar(u8, header.name, ':') == null);
342 assert(std.mem.indexOfPosLinear(u8, header.name, 0, "\r\n") == null);
343 assert(std.mem.indexOfPosLinear(u8, header.value, 0, "\r\n") == null);
341 assert(std.mem.findScalar(u8, header.name, ':') == null);
342 assert(std.mem.findPosLinear(u8, header.name, 0, "\r\n") == null);
343 assert(std.mem.findPosLinear(u8, header.value, 0, "\r\n") == null);
344344 }
345345 }
346346 try writeExpectContinue(request);
lib/std/http/test.zig+1-1
......@@ -447,7 +447,7 @@ test "general client/server API coverage" {
447447
448448 if (mem.startsWith(u8, target, "/get")) {
449449 var response = try request.respondStreaming(&.{}, .{
450 .content_length = if (mem.indexOf(u8, target, "?chunked") == null)
450 .content_length = if (mem.find(u8, target, "?chunked") == null)
451451 14
452452 else
453453 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
17581758/// This function will not give meaningful results on non-numeric input.
17591759pub fn isNumberFormattedLikeAnInteger(value: []const u8) bool {
17601760 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;
17621762}
17631763
17641764test {
lib/std/macho.zig+1-1
......@@ -825,7 +825,7 @@ pub const section_64 = extern struct {
825825};
826826
827827fn 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;
829829 return name[0..len];
830830}
831831
lib/std/math/big/int.zig+2-2
......@@ -1694,8 +1694,8 @@ pub const Mutable = struct {
16941694 // Handle trailing zero-words of divisor/dividend. These are not handled in the following
16951695 // algorithms.
16961696 // Note, there must be a non-zero limb for either.
1697 // const x_trailing = std.mem.indexOfScalar(Limb, x.limbs[0..x.len], 0).?;
1698 // const y_trailing = std.mem.indexOfScalar(Limb, y.limbs[0..y.len], 0).?;
1697 // const x_trailing = std.mem.findScalar(Limb, x.limbs[0..x.len], 0).?;
1698 // const y_trailing = std.mem.findScalar(Limb, y.limbs[0..y.len], 0).?;
16991699
17001700 const x_trailing = for (x.limbs[0..x.len], 0..) |xi, i| {
17011701 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 {
998998 .array => |array_info| {
999999 if (array_info.sentinel()) |s| {
10001000 if (s == end) {
1001 return indexOfSentinel(array_info.child, end, ptr);
1001 return findSentinel(array_info.child, end, ptr);
10021002 }
10031003 }
10041004 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 {
10071007 },
10081008 .many => if (ptr_info.sentinel()) |s| {
10091009 if (s == end) {
1010 return indexOfSentinel(ptr_info.child, end, ptr);
1010 return findSentinel(ptr_info.child, end, ptr);
10111011 }
10121012 // We're looking for something other than the sentinel,
10131013 // 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 {
10181018 },
10191019 .c => {
10201020 assert(ptr != null);
1021 return indexOfSentinel(ptr_info.child, end, ptr);
1021 return findSentinel(ptr_info.child, end, ptr);
10221022 },
10231023 .slice => {
10241024 if (ptr_info.sentinel()) |s| {
10251025 if (s == end) {
1026 return indexOfSentinel(ptr_info.child, s, ptr);
1026 return findSentinel(ptr_info.child, s, ptr);
10271027 }
10281028 }
10291029 return findScalar(ptr_info.child, ptr, end) orelse ptr.len;
......@@ -1076,11 +1076,11 @@ pub fn len(value: anytype) usize {
10761076 .many => {
10771077 const sentinel = info.sentinel() orelse
10781078 @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);
10801080 },
10811081 .c => {
10821082 assert(value != null);
1083 return indexOfSentinel(info.child, 0, value);
1083 return findSentinel(info.child, 0, value);
10841084 },
10851085 else => @compileError("invalid type given to std.mem.len: " ++ @typeName(@TypeOf(value))),
10861086 },
......@@ -1166,7 +1166,7 @@ pub fn findSentinel(comptime T: type, comptime sentinel: T, p: [*:sentinel]const
11661166 return i;
11671167}
11681168
1169test "indexOfSentinel vector paths" {
1169test "findSentinel vector paths" {
11701170 const Types = [_]type{ u8, u16, u32, u64 };
11711171 const allocator = std.testing.allocator;
11721172 const page_size = std.heap.page_size_min;
......@@ -1189,7 +1189,7 @@ test "indexOfSentinel vector paths" {
11891189 const search_len = page_size / @sizeOf(T);
11901190 memory[start + search_len] = 0;
11911191 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])));
11931193 }
11941194 memory[start + search_len] = 0xaa;
11951195
......@@ -1197,7 +1197,7 @@ test "indexOfSentinel vector paths" {
11971197 const start_page_boundary = start + (page_size / @sizeOf(T));
11981198 memory[start_page_boundary + block_len] = 0;
11991199 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])));
12011201 }
12021202 }
12031203}
......@@ -1251,7 +1251,7 @@ pub const indexOfScalar = findScalar;
12511251
12521252/// Linear search for the index of a scalar value inside a slice.
12531253pub fn findScalar(comptime T: type, slice: []const T, value: T) ?usize {
1254 return indexOfScalarPos(T, slice, 0, value);
1254 return findScalarPos(T, slice, 0, value);
12551255}
12561256
12571257/// Deprecated in favor of `findScalarLast`.
......@@ -1334,7 +1334,7 @@ pub fn findScalarPos(comptime T: type, slice: []const T, start_index: usize, val
13341334 return null;
13351335}
13361336
1337test indexOfScalarPos {
1337test findScalarPos {
13381338 const Types = [_]type{ u8, u16, u32, u64 };
13391339
13401340 inline for (Types) |T| {
......@@ -1343,7 +1343,7 @@ test indexOfScalarPos {
13431343 memory[memory.len - 1] = 0;
13441344
13451345 for (0..memory.len) |i| {
1346 try testing.expectEqual(memory.len - i - 1, indexOfScalarPos(T, memory[i..], 0, 0).?);
1346 try testing.expectEqual(memory.len - i - 1, findScalarPos(T, memory[i..], 0, 0).?);
13471347 }
13481348 }
13491349}
......@@ -1354,7 +1354,7 @@ pub const indexOfAny = findAny;
13541354/// Linear search for the index of any value in the provided list inside a slice.
13551355/// Returns null if no values are found.
13561356pub fn findAny(comptime T: type, slice: []const T, values: []const T) ?usize {
1357 return indexOfAnyPos(T, slice, 0, values);
1357 return findAnyPos(T, slice, 0, values);
13581358}
13591359
13601360/// Deprecated in favor of `findLastAny`.
......@@ -1395,7 +1395,7 @@ pub const indexOfNone = findNone;
13951395///
13961396/// Comparable to `strspn` in the C standard library.
13971397pub fn findNone(comptime T: type, slice: []const T, values: []const T) ?usize {
1398 return indexOfNonePos(T, slice, 0, values);
1398 return findNonePos(T, slice, 0, values);
13991399}
14001400
14011401test findNone {
......@@ -1406,7 +1406,7 @@ test findNone {
14061406 try testing.expect(findNone(u8, "123123", "123") == null);
14071407 try testing.expect(findNone(u8, "333333", "123") == null);
14081408
1409 try testing.expect(indexOfNonePos(u8, "abc123", 3, "321") == null);
1409 try testing.expect(findNonePos(u8, "abc123", 3, "321") == null);
14101410}
14111411
14121412/// Deprecated in favor of `findLastNone`.
......@@ -1451,7 +1451,7 @@ pub const indexOf = find;
14511451/// Uses Boyer-Moore-Horspool algorithm on large inputs; linear search on small inputs.
14521452/// Returns null if needle is not found.
14531453pub fn find(comptime T: type, haystack: []const T, needle: []const T) ?usize {
1454 return indexOfPos(T, haystack, 0, needle);
1454 return findPos(T, haystack, 0, needle);
14551455}
14561456
14571457/// Deprecated in favor of `findLastLinear`.
......@@ -1472,7 +1472,7 @@ pub fn findLastLinear(comptime T: type, haystack: []const T, needle: []const T)
14721472
14731473pub const indexOfPosLinear = findPosLinear;
14741474
1475/// Consider using `indexOfPos` instead of this, which will automatically use a
1475/// Consider using `findPos` instead of this, which will automatically use a
14761476/// more sophisticated algorithm on larger inputs.
14771477pub fn findPosLinear(comptime T: type, haystack: []const T, start_index: usize, needle: []const T) ?usize {
14781478 if (needle.len > haystack.len) return null;
......@@ -1566,17 +1566,17 @@ pub fn findLast(comptime T: type, haystack: []const T, needle: []const T) ?usize
15661566/// Deprecated in favor of `findPos`.
15671567pub const indexOfPos = findPos;
15681568
1569/// Uses Boyer-Moore-Horspool algorithm on large inputs; `indexOfPosLinear` on small inputs.
1569/// Uses Boyer-Moore-Horspool algorithm on large inputs; `findPosLinear` on small inputs.
15701570pub fn findPos(comptime T: type, haystack: []const T, start_index: usize, needle: []const T) ?usize {
15711571 if (needle.len > haystack.len) return null;
15721572 if (needle.len < 2) {
15731573 if (needle.len == 0) return start_index;
1574 // indexOfScalarPos is significantly faster than indexOfPosLinear
1575 return indexOfScalarPos(T, haystack, start_index, needle[0]);
1574 // findScalarPos is significantly faster than findPosLinear
1575 return findScalarPos(T, haystack, start_index, needle[0]);
15761576 }
15771577
15781578 if (!std.meta.hasUniqueRepresentation(T) or haystack.len < 52 or needle.len <= 4)
1579 return indexOfPosLinear(T, haystack, start_index, needle);
1579 return findPosLinear(T, haystack, start_index, needle);
15801580
15811581 const haystack_bytes = sliceAsBytes(haystack);
15821582 const needle_bytes = sliceAsBytes(needle);
......@@ -1595,43 +1595,43 @@ pub fn findPos(comptime T: type, haystack: []const T, start_index: usize, needle
15951595 return null;
15961596}
15971597
1598test indexOf {
1599 try testing.expect(indexOf(u8, "one two three four five six seven eight nine ten eleven", "three four").? == 8);
1598test find {
1599 try testing.expect(find(u8, "one two three four five six seven eight nine ten eleven", "three four").? == 8);
16001600 try testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten eleven", "three four").? == 8);
1601 try testing.expect(indexOf(u8, "one two three four five six seven eight nine ten eleven", "two two") == null);
1601 try testing.expect(find(u8, "one two three four five six seven eight nine ten eleven", "two two") == null);
16021602 try testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten eleven", "two two") == null);
16031603
1604 try testing.expect(indexOf(u8, "one two three four five six seven eight nine ten", "").? == 0);
1604 try testing.expect(find(u8, "one two three four five six seven eight nine ten", "").? == 0);
16051605 try testing.expect(lastIndexOf(u8, "one two three four five six seven eight nine ten", "").? == 48);
16061606
1607 try testing.expect(indexOf(u8, "one two three four", "four").? == 14);
1607 try testing.expect(find(u8, "one two three four", "four").? == 14);
16081608 try testing.expect(lastIndexOf(u8, "one two three two four", "two").? == 14);
1609 try testing.expect(indexOf(u8, "one two three four", "gour") == null);
1609 try testing.expect(find(u8, "one two three four", "gour") == null);
16101610 try testing.expect(lastIndexOf(u8, "one two three four", "gour") == null);
1611 try testing.expect(indexOf(u8, "foo", "foo").? == 0);
1611 try testing.expect(find(u8, "foo", "foo").? == 0);
16121612 try testing.expect(lastIndexOf(u8, "foo", "foo").? == 0);
1613 try testing.expect(indexOf(u8, "foo", "fool") == null);
1613 try testing.expect(find(u8, "foo", "fool") == null);
16141614 try testing.expect(lastIndexOf(u8, "foo", "lfoo") == null);
16151615 try testing.expect(lastIndexOf(u8, "foo", "fool") == null);
16161616
1617 try testing.expect(indexOf(u8, "foo foo", "foo").? == 0);
1617 try testing.expect(find(u8, "foo foo", "foo").? == 0);
16181618 try testing.expect(lastIndexOf(u8, "foo foo", "foo").? == 4);
16191619 try testing.expect(lastIndexOfAny(u8, "boo, cat", "abo").? == 6);
16201620 try testing.expect(findScalarLast(u8, "boo", 'o').? == 2);
16211621}
16221622
1623test "indexOf multibyte" {
1623test "find multibyte" {
16241624 {
16251625 // make haystack and needle long enough to trigger Boyer-Moore-Horspool algorithm
16261626 const haystack = [1]u16{0} ** 100 ++ [_]u16{ 0xbbaa, 0xccbb, 0xddcc, 0xeedd, 0xffee, 0x00ff };
16271627 const needle = [_]u16{ 0xbbaa, 0xccbb, 0xddcc, 0xeedd, 0xffee };
1628 try testing.expectEqual(indexOfPos(u16, &haystack, 0, &needle), 100);
1628 try testing.expectEqual(findPos(u16, &haystack, 0, &needle), 100);
16291629
16301630 // check for misaligned false positives (little and big endian)
16311631 const needleLE = [_]u16{ 0xbbbb, 0xcccc, 0xdddd, 0xeeee, 0xffff };
1632 try testing.expectEqual(indexOfPos(u16, &haystack, 0, &needleLE), null);
1632 try testing.expectEqual(findPos(u16, &haystack, 0, &needleLE), null);
16331633 const needleBE = [_]u16{ 0xaacc, 0xbbdd, 0xccee, 0xddff, 0xee00 };
1634 try testing.expectEqual(indexOfPos(u16, &haystack, 0, &needleBE), null);
1634 try testing.expectEqual(findPos(u16, &haystack, 0, &needleBE), null);
16351635 }
16361636
16371637 {
......@@ -1648,8 +1648,8 @@ test "indexOf multibyte" {
16481648 }
16491649}
16501650
1651test "indexOfPos empty needle" {
1652 try testing.expectEqual(indexOfPos(u8, "abracadabra", 5, ""), 5);
1651test "findPos empty needle" {
1652 try testing.expectEqual(findPos(u8, "abracadabra", 5, ""), 5);
16531653}
16541654
16551655/// Returns the number of needles inside the haystack
......@@ -1661,7 +1661,7 @@ pub fn count(comptime T: type, haystack: []const T, needle: []const T) usize {
16611661 var i: usize = 0;
16621662 var found: usize = 0;
16631663
1664 while (indexOfPos(T, haystack, i, needle)) |idx| {
1664 while (findPos(T, haystack, i, needle)) |idx| {
16651665 i = idx + needle.len;
16661666 found += 1;
16671667 }
......@@ -1731,7 +1731,7 @@ pub fn containsAtLeast(comptime T: type, haystack: []const T, expected_count: us
17311731 var i: usize = 0;
17321732 var found: usize = 0;
17331733
1734 while (indexOfPos(T, haystack, i, needle)) |idx| {
1734 while (findPos(T, haystack, i, needle)) |idx| {
17351735 i = idx + needle.len;
17361736 found += 1;
17371737 if (found == expected_count) return true;
......@@ -3356,9 +3356,9 @@ pub fn SplitIterator(comptime T: type, comptime delimiter_type: DelimiterType) t
33563356 pub fn next(self: *Self) ?[]const T {
33573357 const start = self.index orelse return null;
33583358 const end = if (switch (delimiter_type) {
3359 .sequence => indexOfPos(T, self.buffer, start, self.delimiter),
3360 .any => indexOfAnyPos(T, self.buffer, start, self.delimiter),
3361 .scalar => indexOfScalarPos(T, self.buffer, start, self.delimiter),
3359 .sequence => findPos(T, self.buffer, start, self.delimiter),
3360 .any => findAnyPos(T, self.buffer, start, self.delimiter),
3361 .scalar => findScalarPos(T, self.buffer, start, self.delimiter),
33623362 }) |delim_start| blk: {
33633363 self.index = delim_start + switch (delimiter_type) {
33643364 .sequence => self.delimiter.len,
......@@ -3377,9 +3377,9 @@ pub fn SplitIterator(comptime T: type, comptime delimiter_type: DelimiterType) t
33773377 pub fn peek(self: *Self) ?[]const T {
33783378 const start = self.index orelse return null;
33793379 const end = if (switch (delimiter_type) {
3380 .sequence => indexOfPos(T, self.buffer, start, self.delimiter),
3381 .any => indexOfAnyPos(T, self.buffer, start, self.delimiter),
3382 .scalar => indexOfScalarPos(T, self.buffer, start, self.delimiter),
3380 .sequence => findPos(T, self.buffer, start, self.delimiter),
3381 .any => findAnyPos(T, self.buffer, start, self.delimiter),
3382 .scalar => findScalarPos(T, self.buffer, start, self.delimiter),
33833383 }) |delim_start| delim_start else self.buffer.len;
33843384 return self.buffer[start..end];
33853385 }
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.
113113 // errno values to expect when command is F.GETPATH...
114114 else => |err| return posix.unexpectedErrno(err),
115115 }
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;
117117 return out_buffer[0..len];
118118 },
119119 .linux, .serenity => {
......@@ -150,7 +150,7 @@ pub fn getFdPath(fd: std.posix.fd_t, out_buffer: *[max_path_bytes]u8) std.posix.
150150 .BADF => return error.FileNotFound,
151151 else => |err| return posix.unexpectedErrno(err),
152152 }
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;
154154 if (len == 0) return error.NameTooLong;
155155 const result = out_buffer[0..len];
156156 @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.
164164 .RANGE => return error.NameTooLong,
165165 else => |err| return posix.unexpectedErrno(err),
166166 }
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;
168168 return out_buffer[0..len];
169169 },
170170 .netbsd => {
......@@ -178,7 +178,7 @@ pub fn getFdPath(fd: std.posix.fd_t, out_buffer: *[max_path_bytes]u8) std.posix.
178178 .RANGE => return error.NameTooLong,
179179 else => |err| return posix.unexpectedErrno(err),
180180 }
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;
182182 return out_buffer[0..len];
183183 },
184184 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 {
40924092
40934093 const release = mem.sliceTo(&uts.release, 0);
40944094 // 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, "-+");
40964096 const stripped = release[0..(extra_index orelse release.len)];
40974097 // Make sure the input don't rely on the extra we just stripped
40984098 try testing.expect(required.pre == null and required.build == null);
lib/std/os/windows.zig+3-3
......@@ -3661,7 +3661,7 @@ pub fn GetFinalPathNameByHandle(
36613661 };
36623662 }
36633663
3664 const file_path_begin_index = mem.indexOfPos(u16, final_path, device_prefix.len, &[_]u16{'\\'}) orelse unreachable;
3664 const file_path_begin_index = mem.findPos(u16, final_path, device_prefix.len, &[_]u16{'\\'}) orelse unreachable;
36653665 const volume_name_u16 = final_path[0..file_path_begin_index];
36663666 const device_name_u16 = volume_name_u16[device_prefix.len..];
36673667 const file_name_u16 = final_path[file_path_begin_index..];
......@@ -3746,7 +3746,7 @@ pub fn GetFinalPathNameByHandle(
37463746 const total_len = drive_letter.len + file_name_u16.len;
37473747
37483748 // Validate that DOS does not contain any spurious nul bytes.
3749 if (mem.indexOfScalar(u16, out_buffer[0..total_len], 0)) |_| {
3749 if (mem.findScalar(u16, out_buffer[0..total_len], 0)) |_| {
37503750 return error.BadPathName;
37513751 }
37523752
......@@ -3798,7 +3798,7 @@ pub fn GetFinalPathNameByHandle(
37983798 const total_len = volume_path.len + file_name_u16.len;
37993799
38003800 // Validate that DOS does not contain any spurious nul bytes.
3801 if (mem.indexOfScalar(u16, out_buffer[0..total_len], 0)) |_| {
3801 if (mem.findScalar(u16, out_buffer[0..total_len], 0)) |_| {
38023802 return error.BadPathName;
38033803 }
38043804
lib/std/posix.zig+3-3
......@@ -1788,7 +1788,7 @@ pub fn execvpeZ_expandArg0(
17881788 envp: [*:null]const ?[*:0]const u8,
17891789) ExecveError {
17901790 const file_slice = mem.sliceTo(file, 0);
1791 if (mem.indexOfScalar(u8, file_slice, '/') != null) return execveZ(file, child_argv, envp);
1791 if (mem.findScalar(u8, file_slice, '/') != null) return execveZ(file, child_argv, envp);
17921792
17931793 const PATH = getenvZ("PATH") orelse "/usr/local/bin:/bin/:/usr/bin";
17941794 // Use of PATH_MAX here is valid as the path_buf will be passed
......@@ -1844,7 +1844,7 @@ pub fn getenv(key: []const u8) ?[:0]const u8 {
18441844 if (native_os == .windows) {
18451845 @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.");
18461846 }
1847 if (mem.indexOfScalar(u8, key, '=') != null) {
1847 if (mem.findScalar(u8, key, '=') != null) {
18481848 return null;
18491849 }
18501850 if (builtin.link_libc) {
......@@ -6676,7 +6676,7 @@ pub fn unexpectedErrno(err: E) UnexpectedError {
66766676
66776677/// Used to convert a slice to a null terminated slice on the stack.
66786678pub fn toPosixPath(file_path: []const u8) error{NameTooLong}![PATH_MAX - 1:0]u8 {
6679 if (std.debug.runtime_safety) assert(mem.indexOfScalar(u8, file_path, 0) == null);
6679 if (std.debug.runtime_safety) assert(mem.findScalar(u8, file_path, 0) == null);
66806680 var path_with_null: [PATH_MAX - 1:0]u8 = undefined;
66816681 // >= rather than > to make room for the null byte
66826682 if (file_path.len >= PATH_MAX) return error.NameTooLong;
lib/std/priority_queue.zig+1-1
......@@ -619,7 +619,7 @@ test "siftUp in remove" {
619619
620620 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
624624 const sorted_items = [_]u32{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 100, 101, 103, 104, 105, 106 };
625625 for (sorted_items) |e| {
lib/std/process.zig+2-2
......@@ -546,7 +546,7 @@ pub fn getenvW(key: [*:0]const u16) ?[:0]const u16 {
546546 }
547547 const key_slice = mem.sliceTo(key, 0);
548548 // '=' 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) {
550550 return null;
551551 }
552552 const ptr = windows.peb().ProcessParameters.Environment;
......@@ -559,7 +559,7 @@ pub fn getenvW(key: [*:0]const u16) ?[:0]const u16 {
559559 // if it's the first character.
560560 // https://devblogs.microsoft.com/oldnewthing/20100506-00/?p=14133
561561 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 {
563563 // This is enforced by CreateProcess.
564564 // If violated, CreateProcess will fail with INVALID_PARAMETER.
565565 unreachable; // must contain a =
lib/std/process/Child.zig+2-2
......@@ -1812,7 +1812,7 @@ fn argvToScriptCommandLineWindows(
18121812 //
18131813 // If the script path does not have a path separator, then we know its relative to CWD and
18141814 // we can just put `.\` in the front.
1815 if (mem.indexOfAny(u16, script_path, &[_]u16{ mem.nativeToLittle(u16, '\\'), mem.nativeToLittle(u16, '/') }) == null) {
1815 if (mem.findAny(u16, script_path, &[_]u16{ mem.nativeToLittle(u16, '\\'), mem.nativeToLittle(u16, '/') }) == null) {
18161816 try buf.appendSlice(".\\");
18171817 }
18181818 // Note that we don't do any escaping/mitigations for this argument, since the relevant
......@@ -1827,7 +1827,7 @@ fn argvToScriptCommandLineWindows(
18271827 // always a mistake to include these characters in argv, so it's
18281828 // an error condition in order to ensure that the return of this
18291829 // function can always roundtrip through cmd.exe.
1830 if (std.mem.indexOfAny(u8, arg, "\x00\r\n") != null) {
1830 if (std.mem.findAny(u8, arg, "\x00\r\n") != null) {
18311831 return error.InvalidBatchScriptArg;
18321832 }
18331833
lib/std/tar.zig+3-3
......@@ -71,7 +71,7 @@ pub const Diagnostics = struct {
7171 const start_index: usize = if (path[0] == '/') 1 else 0;
7272 const end_index: usize = if (path[path.len - 1] == '/') path.len - 1 else path.len;
7373 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| {
7575 return buf[0..idx];
7676 }
7777
......@@ -569,7 +569,7 @@ pub const PaxIterator = struct {
569569 }
570570
571571 fn hasNull(str: []const u8) bool {
572 return (std.mem.indexOfScalar(u8, str, 0)) != null;
572 return (std.mem.findScalar(u8, str, 0)) != null;
573573 }
574574
575575 // Checks that each record ends with new line.
......@@ -667,7 +667,7 @@ fn stripComponents(path: []const u8, count: u32) []const u8 {
667667 var i: usize = 0;
668668 var c = count;
669669 while (c > 0) : (c -= 1) {
670 if (std.mem.indexOfScalarPos(u8, path, i, '/')) |pos| {
670 if (std.mem.findScalarPos(u8, path, i, '/')) |pos| {
671671 i = pos + 1;
672672 } else {
673673 i = path.len;
lib/std/testing.zig+3-3
......@@ -643,7 +643,7 @@ pub fn tmpDir(opts: std.fs.Dir.OpenOptions) TmpDir {
643643}
644644
645645pub 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| {
647647 if (@inComptime()) {
648648 @compileError(std.fmt.comptimePrint("\nexpected:\n{s}\nfound:\n{s}\ndifference starts at index {d}", .{
649649 expected, actual, diff_index,
......@@ -992,7 +992,7 @@ fn printIndicatorLine(source: []const u8, indicator_index: usize) void {
992992 line_begin + 1
993993 else
994994 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|
996996 (indicator_index + line_end)
997997 else
998998 source.len;
......@@ -1008,7 +1008,7 @@ fn printIndicatorLine(source: []const u8, indicator_index: usize) void {
10081008
10091009fn printWithVisibleNewlines(source: []const u8) void {
10101010 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) {
10121012 printLine(source[i..][0..nl]);
10131013 }
10141014 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
234234 const token_start = self.tokenStart(token_index);
235235
236236 // 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| {
238238 if (i >= token_start) {
239239 break; // Went past
240240 }
......@@ -1309,7 +1309,7 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex {
13091309
13101310pub fn tokensOnSameLine(tree: Ast, token1: TokenIndex, token2: TokenIndex) bool {
13111311 const source = tree.source[tree.tokenStart(token1)..tree.tokenStart(token2)];
1312 return mem.indexOfScalar(u8, source, '\n') == null;
1312 return mem.findScalar(u8, source, '\n') == null;
13131313}
13141314
13151315pub fn getNodeSource(tree: Ast, node: Node.Index) []const u8 {
lib/std/zig/Ast/Render.zig+9-9
......@@ -1417,7 +1417,7 @@ fn renderFor(r: *Render, for_node: Ast.full.For, space: Space) Error!void {
14171417 try renderParamList(r, lparen, for_node.ast.inputs, .space);
14181418
14191419 var cur = for_node.payload_token;
1420 const pipe = std.mem.indexOfScalarPos(std.zig.Token.Tag, token_tags, cur, .pipe).?;
1420 const pipe = std.mem.findScalarPos(std.zig.Token.Tag, token_tags, cur, .pipe).?;
14211421 if (tree.tokenTag(@intCast(pipe - 1)) == .comma) {
14221422 try ais.pushIndent(.normal);
14231423 try renderToken(r, cur - 1, .newline); // |
......@@ -2194,7 +2194,7 @@ fn renderArrayInit(
21942194 try renderExpression(&sub_render, expr, .none);
21952195 const written = sub_expr_buffer.written();
21962196 const width = written.len - start;
2197 const this_contains_newline = mem.indexOfScalar(u8, written[start..], '\n') != null;
2197 const this_contains_newline = mem.findScalar(u8, written[start..], '\n') != null;
21982198 contains_newline = contains_newline or this_contains_newline;
21992199 expr_widths[i] = width;
22002200 expr_newlines[i] = this_contains_newline;
......@@ -2218,7 +2218,7 @@ fn renderArrayInit(
22182218
22192219 const written = sub_expr_buffer.written();
22202220 const width = written.len - start - 2;
2221 const this_contains_newline = mem.indexOfScalar(u8, written[start .. written.len - 1], '\n') != null;
2221 const this_contains_newline = mem.findScalar(u8, written[start .. written.len - 1], '\n') != null;
22222222 contains_newline = contains_newline or this_contains_newline;
22232223 expr_widths[i] = width;
22242224 expr_newlines[i] = contains_newline;
......@@ -2910,7 +2910,7 @@ fn hasComment(tree: Ast, start_token: Ast.TokenIndex, end_token: Ast.TokenIndex)
29102910 const token: Ast.TokenIndex = @intCast(i);
29112911 const start = tree.tokenStart(token) + tree.tokenSlice(token).len;
29122912 const end = tree.tokenStart(token + 1);
2913 if (mem.indexOf(u8, tree.source[start..end], "//") != null) return true;
2913 if (mem.find(u8, tree.source[start..end], "//") != null) return true;
29142914 }
29152915
29162916 return false;
......@@ -2919,7 +2919,7 @@ fn hasComment(tree: Ast, start_token: Ast.TokenIndex, end_token: Ast.TokenIndex)
29192919/// Returns true if there exists a multiline string literal between the start
29202920/// of token `start_token` and the start of token `end_token`.
29212921fn hasMultilineString(tree: Ast, start_token: Ast.TokenIndex, end_token: Ast.TokenIndex) bool {
2922 return std.mem.indexOfScalar(
2922 return std.mem.findScalar(
29232923 Token.Tag,
29242924 tree.tokens.items(.tag)[start_token..end_token],
29252925 .multiline_string_literal_line,
......@@ -2933,11 +2933,11 @@ fn renderComments(r: *Render, start: usize, end: usize) Error!bool {
29332933 const ais = r.ais;
29342934
29352935 var index: usize = start;
2936 while (mem.indexOf(u8, tree.source[index..end], "//")) |offset| {
2936 while (mem.find(u8, tree.source[index..end], "//")) |offset| {
29372937 const comment_start = index + offset;
29382938
29392939 // If there is no newline, the comment ends with EOF
2940 const newline_index = mem.indexOfScalar(u8, tree.source[comment_start..end], '\n');
2940 const newline_index = mem.findScalar(u8, tree.source[comment_start..end], '\n');
29412941 const newline = if (newline_index) |i| comment_start + i else null;
29422942
29432943 const untrimmed_comment = tree.source[comment_start .. newline orelse tree.source.len];
......@@ -2949,7 +2949,7 @@ fn renderComments(r: *Render, start: usize, end: usize) Error!bool {
29492949 // Leave up to one empty line before the first comment
29502950 try ais.insertNewline();
29512951 try ais.insertNewline();
2952 } else if (mem.indexOfScalar(u8, tree.source[index..comment_start], '\n') != null) {
2952 } else if (mem.findScalar(u8, tree.source[index..comment_start], '\n') != null) {
29532953 // Respect the newline directly before the comment.
29542954 // Note: This allows an empty line between comments
29552955 try ais.insertNewline();
......@@ -3008,7 +3008,7 @@ fn renderExtraNewlineToken(r: *Render, token_index: Ast.TokenIndex) Error!void {
30083008
30093009 // If there is a immediately preceding comment or doc_comment,
30103010 // skip it because required extra newline has already been rendered.
3011 if (mem.indexOf(u8, tree.source[prev_token_end..token_start], "//") != null) return;
3011 if (mem.find(u8, tree.source[prev_token_end..token_start], "//") != null) return;
30123012 if (tree.isTokenPrecededByTags(token_index, &.{.doc_comment})) return;
30133013
30143014 // Iterate backwards to the end of the previous token, stopping if a
lib/std/zig/AstGen.zig+8-8
......@@ -4124,7 +4124,7 @@ fn fnDecl(
41244124 const lib_name = if (fn_proto.lib_name) |lib_name_token| blk: {
41254125 const lib_name_str = try astgen.strLitAsString(lib_name_token);
41264126 const lib_name_slice = astgen.string_bytes.items[@intFromEnum(lib_name_str.index)..][0..lib_name_str.len];
4127 if (mem.indexOfScalar(u8, lib_name_slice, 0) != null) {
4127 if (mem.findScalar(u8, lib_name_slice, 0) != null) {
41284128 return astgen.failTok(lib_name_token, "library name cannot contain null bytes", .{});
41294129 } else if (lib_name_str.len == 0) {
41304130 return astgen.failTok(lib_name_token, "library name cannot be empty", .{});
......@@ -4540,7 +4540,7 @@ fn globalVarDecl(
45404540 const lib_name = if (var_decl.lib_name) |lib_name_token| blk: {
45414541 const lib_name_str = try astgen.strLitAsString(lib_name_token);
45424542 const lib_name_slice = astgen.string_bytes.items[@intFromEnum(lib_name_str.index)..][0..lib_name_str.len];
4543 if (mem.indexOfScalar(u8, lib_name_slice, 0) != null) {
4543 if (mem.findScalar(u8, lib_name_slice, 0) != null) {
45444544 return astgen.failTok(lib_name_token, "library name cannot contain null bytes", .{});
45454545 } else if (lib_name_str.len == 0) {
45464546 return astgen.failTok(lib_name_token, "library name cannot be empty", .{});
......@@ -4762,7 +4762,7 @@ fn testDecl(
47624762 .string_literal => name: {
47634763 const name = try astgen.strLitAsString(test_name_token);
47644764 const slice = astgen.string_bytes.items[@intFromEnum(name.index)..][0..name.len];
4765 if (mem.indexOfScalar(u8, slice, 0) != null) {
4765 if (mem.findScalar(u8, slice, 0) != null) {
47664766 return astgen.failTok(test_name_token, "test name cannot contain null bytes", .{});
47674767 } else if (slice.len == 0) {
47684768 return astgen.failTok(test_name_token, "empty test name must be omitted", .{});
......@@ -8772,7 +8772,7 @@ fn numberLiteral(gz: *GenZir, ri: ResultInfo, node: Ast.Node.Index, source_node:
87728772}
87738773
87748774fn failWithNumberError(astgen: *AstGen, err: std.zig.number_literal.Error, token: Ast.TokenIndex, bytes: []const u8) InnerError {
8775 const is_float = std.mem.indexOfScalar(u8, bytes, '.') != null;
8775 const is_float = std.mem.findScalar(u8, bytes, '.') != null;
87768776 switch (err) {
87778777 .leading_zero => if (is_float) {
87788778 return astgen.failTok(token, "number '{s}' has leading zero", .{bytes});
......@@ -9265,7 +9265,7 @@ fn builtinCall(
92659265 const str_lit_token = tree.nodeMainToken(operand_node);
92669266 const str = try astgen.strLitAsString(str_lit_token);
92679267 const str_slice = astgen.string_bytes.items[@intFromEnum(str.index)..][0..str.len];
9268 if (mem.indexOfScalar(u8, str_slice, 0) != null) {
9268 if (mem.findScalar(u8, str_slice, 0) != null) {
92699269 return astgen.failTok(str_lit_token, "import path cannot contain null bytes", .{});
92709270 } else if (str.len == 0) {
92719271 return astgen.failTok(str_lit_token, "import path cannot be empty", .{});
......@@ -11408,7 +11408,7 @@ fn identifierTokenString(astgen: *AstGen, token: Ast.TokenIndex) InnerError![]co
1140811408 var buf: ArrayList(u8) = .empty;
1140911409 defer buf.deinit(astgen.gpa);
1141011410 try astgen.parseStrLit(token, &buf, ident_name, 1);
11411 if (mem.indexOfScalar(u8, buf.items, 0) != null) {
11411 if (mem.findScalar(u8, buf.items, 0) != null) {
1141211412 return astgen.failTok(token, "identifier cannot contain null bytes", .{});
1141311413 } else if (buf.items.len == 0) {
1141411414 return astgen.failTok(token, "identifier cannot be empty", .{});
......@@ -11434,7 +11434,7 @@ fn appendIdentStr(
1143411434 const start = buf.items.len;
1143511435 try astgen.parseStrLit(token, buf, ident_name, 1);
1143611436 const slice = buf.items[start..];
11437 if (mem.indexOfScalar(u8, slice, 0) != null) {
11437 if (mem.findScalar(u8, slice, 0) != null) {
1143811438 return astgen.failTok(token, "identifier cannot contain null bytes", .{});
1143911439 } else if (slice.len == 0) {
1144011440 return astgen.failTok(token, "identifier cannot be empty", .{});
......@@ -11691,7 +11691,7 @@ fn strLitAsString(astgen: *AstGen, str_lit_token: Ast.TokenIndex) !IndexSlice {
1169111691 const token_bytes = astgen.tree.tokenSlice(str_lit_token);
1169211692 try astgen.parseStrLit(str_lit_token, string_bytes, token_bytes, 0);
1169311693 const key: []const u8 = string_bytes.items[str_index..];
11694 if (std.mem.indexOfScalar(u8, key, 0)) |_| return .{
11694 if (std.mem.findScalar(u8, key, 0)) |_| return .{
1169511695 .index = @enumFromInt(str_index),
1169611696 .len = @intCast(key.len),
1169711697 };
lib/std/zig/Parse.zig+1-1
......@@ -3660,7 +3660,7 @@ fn eatDocComments(p: *Parse) Allocator.Error!?TokenIndex {
36603660}
36613661
36623662fn tokensOnSameLine(p: *Parse, token1: TokenIndex, token2: TokenIndex) bool {
3663 return std.mem.indexOfScalar(u8, p.source[p.tokenStart(token1)..p.tokenStart(token2)], '\n') == null;
3663 return std.mem.findScalar(u8, p.source[p.tokenStart(token1)..p.tokenStart(token2)], '\n') == null;
36643664}
36653665
36663666fn eatToken(p: *Parse, tag: Token.Tag) ?TokenIndex {
lib/std/zig/WindowsSdk.zig+1-1
......@@ -109,7 +109,7 @@ fn iterateAndFilterByVersion(
109109 .build = "",
110110 };
111111 const suffix = entry.name[prefix.len..];
112 const underscore = std.mem.indexOfScalar(u8, entry.name, '_');
112 const underscore = std.mem.findScalar(u8, entry.name, '_');
113113 var num_it = std.mem.splitScalar(u8, suffix[0 .. underscore orelse suffix.len], '.');
114114 version.nums[0] = Version.parseNum(num_it.first()) orelse continue;
115115 for (version.nums[1..]) |*num|
lib/std/zig/Zir.zig+1-1
......@@ -120,7 +120,7 @@ pub const NullTerminatedString = enum(u32) {
120120/// Given an index into `string_bytes` returns the null-terminated string found there.
121121pub fn nullTerminatedString(code: Zir, index: NullTerminatedString) [:0]const u8 {
122122 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];
124124}
125125
126126pub 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) {
221221pub const NullTerminatedString = enum(u32) {
222222 _,
223223 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).?;
225225 return zoir.string_bytes[@intFromEnum(nts)..][0..idx :0];
226226 }
227227};
lib/std/zig/ZonGen.zig+3-3
......@@ -487,7 +487,7 @@ fn appendIdentStr(zg: *ZonGen, ident_token: Ast.TokenIndex) error{ OutOfMemory,
487487 }
488488
489489 const slice = zg.string_bytes.items[start..];
490 if (mem.indexOfScalar(u8, slice, 0) != null) {
490 if (mem.findScalar(u8, slice, 0) != null) {
491491 try zg.addErrorTok(ident_token, "identifier cannot contain null bytes", .{});
492492 return error.BadString;
493493 } else if (slice.len == 0) {
......@@ -586,7 +586,7 @@ fn strLitAsString(zg: *ZonGen, str_node: Ast.Node.Index) error{ OutOfMemory, Bad
586586 },
587587 }
588588 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 = .{
590590 .start = str_index,
591591 .len = @intCast(key.len),
592592 } };
......@@ -785,7 +785,7 @@ fn lowerStrLitError(
785785}
786786
787787fn 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;
789789 switch (err) {
790790 .leading_zero => if (is_float) {
791791 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
115115 else
116116 &signed_oct_hex;
117117
118 var pos = std.mem.indexOfScalar(type, list, SuffixType).?;
118 var pos = std.mem.findScalar(type, list, SuffixType).?;
119119 while (pos < list.len) : (pos += 1) {
120120 if (number >= std.math.minInt(list[pos]) and number <= std.math.maxInt(list[pos])) {
121121 return list[pos];
lib/std/zig/llvm/bitcode_writer.zig+1-1
......@@ -26,7 +26,7 @@ pub fn BitcodeWriter(comptime types: []const type) type {
2626 widths: [types.len]u16,
2727
2828 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).?];
3030 }
3131
3232 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
10761076 const path_maybe_args = mem.trimEnd(u8, trimmed_line, "\n");
10771077
10781078 // 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;
10801080 const unvalidated_path = path_maybe_args[0..path_end];
10811081 file_name = if (fs.path.isAbsolute(unvalidated_path)) unvalidated_path else return error.RelativeShebang;
10821082 continue;
lib/std/zig/system/linux.zig+4-4
......@@ -35,7 +35,7 @@ const SparcCpuinfoImpl = struct {
3535 fn line_hook(self: *SparcCpuinfoImpl, key: []const u8, value: []const u8) !bool {
3636 if (mem.eql(u8, key, "cpu")) {
3737 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) {
3939 self.model = pair[1];
4040 break;
4141 }
......@@ -147,7 +147,7 @@ const PowerpcCpuinfoImpl = struct {
147147 // The model name is often followed by a comma or space and extra
148148 // info.
149149 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;
151151 if (mem.eql(u8, value[0..end_index], pair[0])) {
152152 self.model = pair[1];
153153 break;
......@@ -318,7 +318,7 @@ const ArmCpuinfoImpl = struct {
318318 self.have_fields += 1;
319319 } else if (mem.eql(u8, key, "model name")) {
320320 // ARMv6 cores report "CPU architecture" equal to 7.
321 if (mem.indexOf(u8, value, "(v6l)")) |_| {
321 if (mem.find(u8, value, "(v6l)")) |_| {
322322 info.is_really_v6 = true;
323323 }
324324 } else if (mem.eql(u8, key, "CPU revision")) {
......@@ -427,7 +427,7 @@ fn CpuinfoParser(comptime impl: anytype) type {
427427 fn parse(arch: Target.Cpu.Arch, reader: *Io.Reader) !?Target.Cpu {
428428 var obj: impl = .{};
429429 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;
431431 const key = mem.trimEnd(u8, line[0..colon_pos], " \t");
432432 const value = mem.trimStart(u8, line[colon_pos + 1 ..], " \t");
433433 if (!try obj.line_hook(key, value)) break;
lib/std/zip.zig+2-2
......@@ -539,7 +539,7 @@ pub const Iterator = struct {
539539 if (options.allow_backslashes) {
540540 std.mem.replaceScalar(u8, filename, '\\', '/');
541541 } else {
542 if (std.mem.indexOfScalar(u8, filename, '\\')) |_|
542 if (std.mem.findScalar(u8, filename, '\\')) |_|
543543 return error.ZipFilenameHasBackslash;
544544 }
545545
......@@ -626,7 +626,7 @@ pub const Diagnostics = struct {
626626 if (!self.saw_first_file) {
627627 self.saw_first_file = true;
628628 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;
630630 std.debug.assert(root_len > 0);
631631 self.root_dir = try self.allocator.dupe(u8, name[0..root_len]);
632632 } else if (self.root_dir.len > 0) {