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 {
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
......@@ -372,7 +372,7 @@ pub const TestRunner = struct {
372372
373373pub fn create(owner: *std.Build, options: Options) *Compile {
374374 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) {
376376 panic("invalid name: '{s}'. It looks like a file path, but it is supposed to be the library or application name.", .{name});
377377 }
378378
......@@ -731,7 +731,7 @@ fn runPkgConfig(compile: *Compile, lib_name: []const u8) !PkgConfigResult {
731731
732732 // Prefixed "lib" or suffixed ".0".
733733 for (pkgs) |pkg| {
734 if (std.ascii.indexOfIgnoreCase(pkg.name, lib_name)) |pos| {
734 if (std.ascii.findIgnoreCase(pkg.name, lib_name)) |pos| {
735735 const prefix = pkg.name[0..pos];
736736 const suffix = pkg.name[pos + lib_name.len ..];
737737 if (prefix.len > 0 and !mem.eql(u8, prefix, "lib")) continue;
......@@ -2129,7 +2129,7 @@ fn matchCompileError(actual: []const u8, expected: []const u8) bool {
21292129 // We scan for /?/ in expected line and if there is a match, we match everything
21302130 // up to and after /?/.
21312131 const expected_trim = mem.trim(u8, expected, " ");
2132 if (mem.indexOf(u8, expected_trim, "/?/")) |index| {
2132 if (mem.find(u8, expected_trim, "/?/")) |index| {
21332133 const actual_trim = mem.trim(u8, actual, " ");
21342134 const lhs = expected_trim[0..index];
21352135 const rhs = expected_trim[index + "/?/".len ..];
lib/std/Build/Step/ConfigHeader.zig+5-5
......@@ -581,12 +581,12 @@ fn expand_variables_autoconf_at(
581581 var source_offset: usize = 0;
582582 while (curr < contents.len) : (curr += 1) {
583583 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| {
585585 if (close_pos == curr + 1) {
586586 // closed immediately, preserve as a literal
587587 continue;
588588 }
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;
590590 if (valid_varname_end != close_pos) {
591591 // contains invalid characters, preserve as a literal
592592 continue;
......@@ -638,12 +638,12 @@ fn expand_variables_cmake(
638638 loop: while (curr < contents.len) : (curr += 1) {
639639 switch (contents[curr]) {
640640 '@' => blk: {
641 if (std.mem.indexOfScalarPos(u8, contents, curr + 1, '@')) |close_pos| {
641 if (std.mem.findScalarPos(u8, contents, curr + 1, '@')) |close_pos| {
642642 if (close_pos == curr + 1) {
643643 // closed immediately, preserve as a literal
644644 break :blk;
645645 }
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;
647647 if (valid_varname_end != close_pos) {
648648 // contains invalid characters, preserve as a literal
649649 break :blk;
......@@ -734,7 +734,7 @@ fn expand_variables_cmake(
734734 else => {},
735735 }
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) {
738738 return error.InvalidCharacter;
739739 }
740740 }
lib/std/Build/Step/Run.zig+2-2
......@@ -1509,7 +1509,7 @@ fn runCommand(
15091509 }
15101510 },
15111511 .expect_stderr_match => |match| {
1512 if (mem.indexOf(u8, generic_result.stderr.?, match) == null) {
1512 if (mem.find(u8, generic_result.stderr.?, match) == null) {
15131513 return step.fail(
15141514 \\========= expected to find in stderr: =========
15151515 \\{s}
......@@ -1535,7 +1535,7 @@ fn runCommand(
15351535 }
15361536 },
15371537 .expect_stdout_match => |match| {
1538 if (mem.indexOf(u8, generic_result.stdout.?, match) == null) {
1538 if (mem.find(u8, generic_result.stdout.?, match) == null) {
15391539 return step.fail(
15401540 \\========= expected to find in stdout: =========
15411541 \\{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/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
......@@ -435,7 +435,7 @@ test "general client/server API coverage" {
435435
436436 if (mem.startsWith(u8, target, "/get")) {
437437 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)
439439 14
440440 else
441441 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
......@@ -1658,8 +1658,8 @@ pub const Mutable = struct {
16581658 // Handle trailing zero-words of divisor/dividend. These are not handled in the following
16591659 // algorithms.
16601660 // Note, there must be a non-zero limb for either.
1661 // const x_trailing = std.mem.indexOfScalar(Limb, x.limbs[0..x.len], 0).?;
1662 // const y_trailing = std.mem.indexOfScalar(Limb, y.limbs[0..y.len], 0).?;
1661 // const x_trailing = std.mem.findScalar(Limb, x.limbs[0..x.len], 0).?;
1662 // const y_trailing = std.mem.findScalar(Limb, y.limbs[0..y.len], 0).?;
16631663
16641664 const x_trailing = for (x.limbs[0..x.len], 0..) |xi, i| {
16651665 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}
......@@ -1257,7 +1257,7 @@ pub const indexOfScalar = findScalar;
12571257
12581258/// Linear search for the index of a scalar value inside a slice.
12591259pub 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);
12611261}
12621262
12631263/// Deprecated in favor of `findScalarLast`.
......@@ -1340,7 +1340,7 @@ pub fn findScalarPos(comptime T: type, slice: []const T, start_index: usize, val
13401340 return null;
13411341}
13421342
1343test indexOfScalarPos {
1343test findScalarPos {
13441344 const Types = [_]type{ u8, u16, u32, u64 };
13451345
13461346 inline for (Types) |T| {
......@@ -1349,7 +1349,7 @@ test indexOfScalarPos {
13491349 memory[memory.len - 1] = 0;
13501350
13511351 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).?);
13531353 }
13541354 }
13551355}
......@@ -1360,7 +1360,7 @@ pub const indexOfAny = findAny;
13601360/// Linear search for the index of any value in the provided list inside a slice.
13611361/// Returns null if no values are found.
13621362pub 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);
13641364}
13651365
13661366/// Deprecated in favor of `findLastAny`.
......@@ -1401,7 +1401,7 @@ pub const indexOfNone = findNone;
14011401///
14021402/// Comparable to `strspn` in the C standard library.
14031403pub 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);
14051405}
14061406
14071407test findNone {
......@@ -1412,7 +1412,7 @@ test findNone {
14121412 try testing.expect(findNone(u8, "123123", "123") == null);
14131413 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);
14161416}
14171417
14181418/// Deprecated in favor of `findLastNone`.
......@@ -1457,7 +1457,7 @@ pub const indexOf = find;
14571457/// Uses Boyer-Moore-Horspool algorithm on large inputs; linear search on small inputs.
14581458/// Returns null if needle is not found.
14591459pub 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);
14611461}
14621462
14631463/// Deprecated in favor of `findLastLinear`.
......@@ -1478,7 +1478,7 @@ pub fn findLastLinear(comptime T: type, haystack: []const T, needle: []const T)
14781478
14791479pub const indexOfPosLinear = findPosLinear;
14801480
1481/// Consider using `indexOfPos` instead of this, which will automatically use a
1481/// Consider using `findPos` instead of this, which will automatically use a
14821482/// more sophisticated algorithm on larger inputs.
14831483pub fn findPosLinear(comptime T: type, haystack: []const T, start_index: usize, needle: []const T) ?usize {
14841484 if (needle.len > haystack.len) return null;
......@@ -1572,17 +1572,17 @@ pub fn findLast(comptime T: type, haystack: []const T, needle: []const T) ?usize
15721572/// Deprecated in favor of `findPos`.
15731573pub 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.
15761576pub fn findPos(comptime T: type, haystack: []const T, start_index: usize, needle: []const T) ?usize {
15771577 if (needle.len > haystack.len) return null;
15781578 if (needle.len < 2) {
15791579 if (needle.len == 0) return start_index;
1580 // indexOfScalarPos is significantly faster than indexOfPosLinear
1581 return indexOfScalarPos(T, haystack, start_index, needle[0]);
1580 // findScalarPos is significantly faster than findPosLinear
1581 return findScalarPos(T, haystack, start_index, needle[0]);
15821582 }
15831583
15841584 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
15871587 const haystack_bytes = sliceAsBytes(haystack);
15881588 const needle_bytes = sliceAsBytes(needle);
......@@ -1601,43 +1601,43 @@ pub fn findPos(comptime T: type, haystack: []const T, start_index: usize, needle
16011601 return null;
16021602}
16031603
1604test indexOf {
1605 try testing.expect(indexOf(u8, "one two three four five six seven eight nine ten eleven", "three four").? == 8);
1604test find {
1605 try testing.expect(find(u8, "one two three four five six seven eight nine ten eleven", "three four").? == 8);
16061606 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);
16081608 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);
16111611 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);
16141614 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);
16161616 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);
16181618 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);
16201620 try testing.expect(lastIndexOf(u8, "foo", "lfoo") == null);
16211621 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);
16241624 try testing.expect(lastIndexOf(u8, "foo foo", "foo").? == 4);
16251625 try testing.expect(lastIndexOfAny(u8, "boo, cat", "abo").? == 6);
16261626 try testing.expect(findScalarLast(u8, "boo", 'o').? == 2);
16271627}
16281628
1629test "indexOf multibyte" {
1629test "find multibyte" {
16301630 {
16311631 // make haystack and needle long enough to trigger Boyer-Moore-Horspool algorithm
16321632 const haystack = [1]u16{0} ** 100 ++ [_]u16{ 0xbbaa, 0xccbb, 0xddcc, 0xeedd, 0xffee, 0x00ff };
16331633 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
16361636 // check for misaligned false positives (little and big endian)
16371637 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);
16391639 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);
16411641 }
16421642
16431643 {
......@@ -1654,8 +1654,8 @@ test "indexOf multibyte" {
16541654 }
16551655}
16561656
1657test "indexOfPos empty needle" {
1658 try testing.expectEqual(indexOfPos(u8, "abracadabra", 5, ""), 5);
1657test "findPos empty needle" {
1658 try testing.expectEqual(findPos(u8, "abracadabra", 5, ""), 5);
16591659}
16601660
16611661/// 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 {
16671667 var i: usize = 0;
16681668 var found: usize = 0;
16691669
1670 while (indexOfPos(T, haystack, i, needle)) |idx| {
1670 while (findPos(T, haystack, i, needle)) |idx| {
16711671 i = idx + needle.len;
16721672 found += 1;
16731673 }
......@@ -1737,7 +1737,7 @@ pub fn containsAtLeast(comptime T: type, haystack: []const T, expected_count: us
17371737 var i: usize = 0;
17381738 var found: usize = 0;
17391739
1740 while (indexOfPos(T, haystack, i, needle)) |idx| {
1740 while (findPos(T, haystack, i, needle)) |idx| {
17411741 i = idx + needle.len;
17421742 found += 1;
17431743 if (found == expected_count) return true;
......@@ -3362,9 +3362,9 @@ pub fn SplitIterator(comptime T: type, comptime delimiter_type: DelimiterType) t
33623362 pub fn next(self: *Self) ?[]const T {
33633363 const start = self.index orelse return null;
33643364 const end = if (switch (delimiter_type) {
3365 .sequence => indexOfPos(T, self.buffer, start, self.delimiter),
3366 .any => indexOfAnyPos(T, self.buffer, start, self.delimiter),
3367 .scalar => indexOfScalarPos(T, self.buffer, start, self.delimiter),
3365 .sequence => findPos(T, self.buffer, start, self.delimiter),
3366 .any => findAnyPos(T, self.buffer, start, self.delimiter),
3367 .scalar => findScalarPos(T, self.buffer, start, self.delimiter),
33683368 }) |delim_start| blk: {
33693369 self.index = delim_start + switch (delimiter_type) {
33703370 .sequence => self.delimiter.len,
......@@ -3383,9 +3383,9 @@ pub fn SplitIterator(comptime T: type, comptime delimiter_type: DelimiterType) t
33833383 pub fn peek(self: *Self) ?[]const T {
33843384 const start = self.index orelse return null;
33853385 const end = if (switch (delimiter_type) {
3386 .sequence => indexOfPos(T, self.buffer, start, self.delimiter),
3387 .any => indexOfAnyPos(T, self.buffer, start, self.delimiter),
3388 .scalar => indexOfScalarPos(T, self.buffer, start, self.delimiter),
3386 .sequence => findPos(T, self.buffer, start, self.delimiter),
3387 .any => findAnyPos(T, self.buffer, start, self.delimiter),
3388 .scalar => findScalarPos(T, self.buffer, start, self.delimiter),
33893389 }) |delim_start| delim_start else self.buffer.len;
33903390 return self.buffer[start..end];
33913391 }
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
......@@ -1412,7 +1412,7 @@ pub fn GetFinalPathNameByHandle(
14121412 };
14131413 }
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;
14161416 const volume_name_u16 = final_path[0..file_path_begin_index];
14171417 const device_name_u16 = volume_name_u16[device_prefix.len..];
14181418 const file_name_u16 = final_path[file_path_begin_index..];
......@@ -1494,7 +1494,7 @@ pub fn GetFinalPathNameByHandle(
14941494 const total_len = drive_letter.len + file_name_u16.len;
14951495
14961496 // 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)) |_| {
14981498 return error.BadPathName;
14991499 }
15001500
......@@ -1544,7 +1544,7 @@ pub fn GetFinalPathNameByHandle(
15441544 const total_len = volume_path.len + file_name_u16.len;
15451545
15461546 // 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)) |_| {
15481548 return error.BadPathName;
15491549 }
15501550
lib/std/posix.zig+3-3
......@@ -1773,7 +1773,7 @@ pub fn execvpeZ_expandArg0(
17731773 envp: [*:null]const ?[*:0]const u8,
17741774) ExecveError {
17751775 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
17781778 const PATH = getenvZ("PATH") orelse "/usr/local/bin:/bin/:/usr/bin";
17791779 // 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 {
18291829 if (native_os == .windows) {
18301830 @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.");
18311831 }
1832 if (mem.indexOfScalar(u8, key, '=') != null) {
1832 if (mem.findScalar(u8, key, '=') != null) {
18331833 return null;
18341834 }
18351835 if (builtin.link_libc) {
......@@ -6663,7 +6663,7 @@ pub fn unexpectedErrno(err: E) UnexpectedError {
66636663
66646664/// Used to convert a slice to a null terminated slice on the stack.
66656665pub 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);
66676667 var path_with_null: [PATH_MAX - 1:0]u8 = undefined;
66686668 // >= rather than > to make room for the null byte
66696669 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
......@@ -1810,7 +1810,7 @@ fn argvToScriptCommandLineWindows(
18101810 //
18111811 // If the script path does not have a path separator, then we know its relative to CWD and
18121812 // 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) {
18141814 try buf.appendSlice(".\\");
18151815 }
18161816 // Note that we don't do any escaping/mitigations for this argument, since the relevant
......@@ -1825,7 +1825,7 @@ fn argvToScriptCommandLineWindows(
18251825 // always a mistake to include these characters in argv, so it's
18261826 // an error condition in order to ensure that the return of this
18271827 // 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) {
18291829 return error.InvalidBatchScriptArg;
18301830 }
18311831
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 }
......@@ -1315,7 +1315,7 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex {
13151315
13161316pub fn tokensOnSameLine(tree: Ast, token1: TokenIndex, token2: TokenIndex) bool {
13171317 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;
13191319}
13201320
13211321pub 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 {
14201420 try renderParamList(r, lparen, for_node.ast.inputs, .space);
14211421
14221422 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).?;
14241424 if (tree.tokenTag(@intCast(pipe - 1)) == .comma) {
14251425 try ais.pushIndent(.normal);
14261426 try renderToken(r, cur - 1, .newline); // |
......@@ -2197,7 +2197,7 @@ fn renderArrayInit(
21972197 try renderExpression(&sub_render, expr, .none);
21982198 const written = sub_expr_buffer.written();
21992199 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;
22012201 contains_newline = contains_newline or this_contains_newline;
22022202 expr_widths[i] = width;
22032203 expr_newlines[i] = this_contains_newline;
......@@ -2221,7 +2221,7 @@ fn renderArrayInit(
22212221
22222222 const written = sub_expr_buffer.written();
22232223 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;
22252225 contains_newline = contains_newline or this_contains_newline;
22262226 expr_widths[i] = width;
22272227 expr_newlines[i] = contains_newline;
......@@ -3092,7 +3092,7 @@ fn hasComment(tree: Ast, start_token: Ast.TokenIndex, end_token: Ast.TokenIndex)
30923092 const token: Ast.TokenIndex = @intCast(i);
30933093 const start = tree.tokenStart(token) + tree.tokenSlice(token).len;
30943094 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;
30963096 }
30973097
30983098 return false;
......@@ -3101,7 +3101,7 @@ fn hasComment(tree: Ast, start_token: Ast.TokenIndex, end_token: Ast.TokenIndex)
31013101/// Returns true if there exists a multiline string literal between the start
31023102/// of token `start_token` and the start of token `end_token`.
31033103fn hasMultilineString(tree: Ast, start_token: Ast.TokenIndex, end_token: Ast.TokenIndex) bool {
3104 return std.mem.indexOfScalar(
3104 return std.mem.findScalar(
31053105 Token.Tag,
31063106 tree.tokens.items(.tag)[start_token..end_token],
31073107 .multiline_string_literal_line,
......@@ -3115,11 +3115,11 @@ fn renderComments(r: *Render, start: usize, end: usize) Error!bool {
31153115 const ais = r.ais;
31163116
31173117 var index: usize = start;
3118 while (mem.indexOf(u8, tree.source[index..end], "//")) |offset| {
3118 while (mem.find(u8, tree.source[index..end], "//")) |offset| {
31193119 const comment_start = index + offset;
31203120
31213121 // 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');
31233123 const newline = if (newline_index) |i| comment_start + i else null;
31243124
31253125 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 {
31313131 // Leave up to one empty line before the first comment
31323132 try ais.insertNewline();
31333133 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) {
31353135 // Respect the newline directly before the comment.
31363136 // Note: This allows an empty line between comments
31373137 try ais.insertNewline();
......@@ -3190,7 +3190,7 @@ fn renderExtraNewlineToken(r: *Render, token_index: Ast.TokenIndex) Error!void {
31903190
31913191 // If there is a immediately preceding comment or doc_comment,
31923192 // 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;
31943194 if (tree.isTokenPrecededByTags(token_index, &.{.doc_comment})) return;
31953195
31963196 // 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(
41314131 const lib_name = if (fn_proto.lib_name) |lib_name_token| blk: {
41324132 const lib_name_str = try astgen.strLitAsString(lib_name_token);
41334133 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) {
41354135 return astgen.failTok(lib_name_token, "library name cannot contain null bytes", .{});
41364136 } else if (lib_name_str.len == 0) {
41374137 return astgen.failTok(lib_name_token, "library name cannot be empty", .{});
......@@ -4547,7 +4547,7 @@ fn globalVarDecl(
45474547 const lib_name = if (var_decl.lib_name) |lib_name_token| blk: {
45484548 const lib_name_str = try astgen.strLitAsString(lib_name_token);
45494549 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) {
45514551 return astgen.failTok(lib_name_token, "library name cannot contain null bytes", .{});
45524552 } else if (lib_name_str.len == 0) {
45534553 return astgen.failTok(lib_name_token, "library name cannot be empty", .{});
......@@ -4769,7 +4769,7 @@ fn testDecl(
47694769 .string_literal => name: {
47704770 const name = try astgen.strLitAsString(test_name_token);
47714771 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) {
47734773 return astgen.failTok(test_name_token, "test name cannot contain null bytes", .{});
47744774 } else if (slice.len == 0) {
47754775 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:
87798779}
87808780
87818781fn 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;
87838783 switch (err) {
87848784 .leading_zero => if (is_float) {
87858785 return astgen.failTok(token, "number '{s}' has leading zero", .{bytes});
......@@ -9272,7 +9272,7 @@ fn builtinCall(
92729272 const str_lit_token = tree.nodeMainToken(operand_node);
92739273 const str = try astgen.strLitAsString(str_lit_token);
92749274 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) {
92769276 return astgen.failTok(str_lit_token, "import path cannot contain null bytes", .{});
92779277 } else if (str.len == 0) {
92789278 return astgen.failTok(str_lit_token, "import path cannot be empty", .{});
......@@ -11418,7 +11418,7 @@ fn identifierTokenString(astgen: *AstGen, token: Ast.TokenIndex) InnerError![]co
1141811418 var buf: ArrayList(u8) = .empty;
1141911419 defer buf.deinit(astgen.gpa);
1142011420 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) {
1142211422 return astgen.failTok(token, "identifier cannot contain null bytes", .{});
1142311423 } else if (buf.items.len == 0) {
1142411424 return astgen.failTok(token, "identifier cannot be empty", .{});
......@@ -11444,7 +11444,7 @@ fn appendIdentStr(
1144411444 const start = buf.items.len;
1144511445 try astgen.parseStrLit(token, buf, ident_name, 1);
1144611446 const slice = buf.items[start..];
11447 if (mem.indexOfScalar(u8, slice, 0) != null) {
11447 if (mem.findScalar(u8, slice, 0) != null) {
1144811448 return astgen.failTok(token, "identifier cannot contain null bytes", .{});
1144911449 } else if (slice.len == 0) {
1145011450 return astgen.failTok(token, "identifier cannot be empty", .{});
......@@ -11701,7 +11701,7 @@ fn strLitAsString(astgen: *AstGen, str_lit_token: Ast.TokenIndex) !IndexSlice {
1170111701 const token_bytes = astgen.tree.tokenSlice(str_lit_token);
1170211702 try astgen.parseStrLit(str_lit_token, string_bytes, token_bytes, 0);
1170311703 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 .{
1170511705 .index = @enumFromInt(str_index),
1170611706 .len = @intCast(key.len),
1170711707 };
lib/std/zig/Parse.zig+1-1
......@@ -3686,7 +3686,7 @@ fn eatDocComments(p: *Parse) Allocator.Error!?TokenIndex {
36863686}
36873687
36883688fn 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;
36903690}
36913691
36923692fn 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) {