authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-03 13:51:02-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-06-03 13:51:02-07:00
log629f0d23b5c0768b5957688591f6fa6216ae4dd3
tree8952bf92a1069fa9dfee49d3fcf8f3c2abafbd4b
parent3add9d8257d9414421acf91823917d9d49b28c6f
parent104f4053a2c3c6a1a2bf801ca5bf88ce4fee7a2a
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #15579 from squeek502/mem-delimiters

Split `std.mem.split` and `tokenize` into `sequence`, `any`, and `scalar` versions

42 files changed, 587 insertions(+), 235 deletions(-)

build.zig+7-7
......@@ -235,7 +235,7 @@ pub fn build(b: *std.Build) !void {
235235 },
236236 2 => {
237237 // Untagged development build (e.g. 0.10.0-dev.2025+ecf0050a9).
238 var it = mem.split(u8, git_describe, "-");
238 var it = mem.splitScalar(u8, git_describe, '-');
239239 const tagged_ancestor = it.first();
240240 const commit_height = it.next().?;
241241 const commit_id = it.next().?;
......@@ -280,7 +280,7 @@ pub fn build(b: *std.Build) !void {
280280 // That means we also have to rely on stage1 compiled c++ files. We parse config.h to find
281281 // the information passed on to us from cmake.
282282 if (cfg.cmake_prefix_path.len > 0) {
283 var it = mem.tokenize(u8, cfg.cmake_prefix_path, ";");
283 var it = mem.tokenizeScalar(u8, cfg.cmake_prefix_path, ';');
284284 while (it.next()) |path| {
285285 b.addSearchPrefix(path);
286286 }
......@@ -682,7 +682,7 @@ fn addCxxKnownPath(
682682 if (!std.process.can_spawn)
683683 return error.RequiredLibraryNotFound;
684684 const path_padded = b.exec(&.{ ctx.cxx_compiler, b.fmt("-print-file-name={s}", .{objname}) });
685 var tokenizer = mem.tokenize(u8, path_padded, "\r\n");
685 var tokenizer = mem.tokenizeAny(u8, path_padded, "\r\n");
686686 const path_unpadded = tokenizer.next().?;
687687 if (mem.eql(u8, path_unpadded, objname)) {
688688 if (errtxt) |msg| {
......@@ -705,7 +705,7 @@ fn addCxxKnownPath(
705705}
706706
707707fn addCMakeLibraryList(exe: *std.Build.Step.Compile, list: []const u8) void {
708 var it = mem.tokenize(u8, list, ";");
708 var it = mem.tokenizeScalar(u8, list, ';');
709709 while (it.next()) |lib| {
710710 if (mem.startsWith(u8, lib, "-l")) {
711711 exe.linkSystemLibrary(lib["-l".len..]);
......@@ -850,18 +850,18 @@ fn parseConfigH(b: *std.Build, config_h_text: []const u8) ?CMakeConfig {
850850 // .prefix = ZIG_LLVM_LINK_MODE parsed manually below
851851 };
852852
853 var lines_it = mem.tokenize(u8, config_h_text, "\r\n");
853 var lines_it = mem.tokenizeAny(u8, config_h_text, "\r\n");
854854 while (lines_it.next()) |line| {
855855 inline for (mappings) |mapping| {
856856 if (mem.startsWith(u8, line, mapping.prefix)) {
857 var it = mem.split(u8, line, "\"");
857 var it = mem.splitScalar(u8, line, '"');
858858 _ = it.first(); // skip the stuff before the quote
859859 const quoted = it.next().?; // the stuff inside the quote
860860 @field(ctx, mapping.field) = toNativePathSep(b, quoted);
861861 }
862862 }
863863 if (mem.startsWith(u8, line, "#define ZIG_LLVM_LINK_MODE ")) {
864 var it = mem.split(u8, line, "\"");
864 var it = mem.splitScalar(u8, line, '"');
865865 _ = it.next().?; // skip the stuff before the quote
866866 const quoted = it.next().?; // the stuff inside the quote
867867 ctx.llvm_linkage = if (mem.eql(u8, quoted, "shared")) .dynamic else .static;
doc/docgen.zig+1-1
......@@ -1223,7 +1223,7 @@ fn printShell(out: anytype, shell_content: []const u8, escape: bool) !void {
12231223 const trimmed_shell_content = mem.trim(u8, shell_content, " \n");
12241224 try out.writeAll("<figure><figcaption class=\"shell-cap\">Shell</figcaption><pre><samp>");
12251225 var cmd_cont: bool = false;
1226 var iter = std.mem.split(u8, trimmed_shell_content, "\n");
1226 var iter = std.mem.splitScalar(u8, trimmed_shell_content, '\n');
12271227 while (iter.next()) |orig_line| {
12281228 const line = mem.trimRight(u8, orig_line, " ");
12291229 if (!cmd_cont and line.len > 1 and mem.eql(u8, line[0..2], "$ ") and line[line.len - 1] != '\\') {
lib/std/Build.zig+1-1
......@@ -1388,7 +1388,7 @@ pub fn findProgram(self: *Build, names: []const []const u8, paths: []const []con
13881388 if (fs.path.isAbsolute(name)) {
13891389 return name;
13901390 }
1391 var it = mem.tokenize(u8, PATH, &[_]u8{fs.path.delimiter});
1391 var it = mem.tokenizeScalar(u8, PATH, fs.path.delimiter);
13921392 while (it.next()) |path| {
13931393 const full_path = self.pathJoin(&.{
13941394 path,
lib/std/Build/Cache.zig+2-2
......@@ -438,7 +438,7 @@ pub const Manifest = struct {
438438
439439 const input_file_count = self.files.items.len;
440440 var any_file_changed = false;
441 var line_iter = mem.tokenize(u8, file_contents, "\n");
441 var line_iter = mem.tokenizeScalar(u8, file_contents, '\n');
442442 var idx: usize = 0;
443443 if (if (line_iter.next()) |line| !std.mem.eql(u8, line, manifest_header) else true) {
444444 if (try self.upgradeToExclusiveLock()) continue;
......@@ -467,7 +467,7 @@ pub const Manifest = struct {
467467 break :blk new;
468468 };
469469
470 var iter = mem.tokenize(u8, line, " ");
470 var iter = mem.tokenizeScalar(u8, line, ' ');
471471 const size = iter.next() orelse return error.InvalidFormat;
472472 const inode = iter.next() orelse return error.InvalidFormat;
473473 const mtime_nsec_str = iter.next() orelse return error.InvalidFormat;
lib/std/Build/Step/CheckObject.zig+4-4
......@@ -103,8 +103,8 @@ const Action = struct {
103103 assert(act.tag == .match or act.tag == .not_present);
104104 const phrase = act.phrase.resolve(b, step);
105105 var candidate_var: ?struct { name: []const u8, value: u64 } = null;
106 var hay_it = mem.tokenize(u8, mem.trim(u8, haystack, " "), " ");
107 var needle_it = mem.tokenize(u8, mem.trim(u8, phrase, " "), " ");
106 var hay_it = mem.tokenizeScalar(u8, mem.trim(u8, haystack, " "), ' ');
107 var needle_it = mem.tokenizeScalar(u8, mem.trim(u8, phrase, " "), ' ');
108108
109109 while (needle_it.next()) |needle_tok| {
110110 const hay_tok = hay_it.next() orelse return false;
......@@ -155,7 +155,7 @@ const Action = struct {
155155 var op_stack = std.ArrayList(enum { add, sub, mod, mul }).init(gpa);
156156 var values = std.ArrayList(u64).init(gpa);
157157
158 var it = mem.tokenize(u8, phrase, " ");
158 var it = mem.tokenizeScalar(u8, phrase, ' ');
159159 while (it.next()) |next| {
160160 if (mem.eql(u8, next, "+")) {
161161 try op_stack.append(.add);
......@@ -365,7 +365,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
365365 var vars = std.StringHashMap(u64).init(gpa);
366366
367367 for (self.checks.items) |chk| {
368 var it = mem.tokenize(u8, output, "\r\n");
368 var it = mem.tokenizeAny(u8, output, "\r\n");
369369 for (chk.actions.items) |act| {
370370 switch (act.tag) {
371371 .match => {
lib/std/Build/Step/Compile.zig+4-4
......@@ -853,7 +853,7 @@ fn runPkgConfig(self: *Compile, lib_name: []const u8) ![]const []const u8 {
853853 var zig_args = ArrayList([]const u8).init(b.allocator);
854854 defer zig_args.deinit();
855855
856 var it = mem.tokenize(u8, stdout, " \r\n\t");
856 var it = mem.tokenizeAny(u8, stdout, " \r\n\t");
857857 while (it.next()) |tok| {
858858 if (mem.eql(u8, tok, "-I")) {
859859 const dir = it.next() orelse return error.PkgConfigInvalidOutput;
......@@ -2101,10 +2101,10 @@ fn execPkgConfigList(self: *std.Build, out_code: *u8) (PkgConfigError || ExecErr
21012101 const stdout = try self.execAllowFail(&[_][]const u8{ "pkg-config", "--list-all" }, out_code, .Ignore);
21022102 var list = ArrayList(PkgConfigPkg).init(self.allocator);
21032103 errdefer list.deinit();
2104 var line_it = mem.tokenize(u8, stdout, "\r\n");
2104 var line_it = mem.tokenizeAny(u8, stdout, "\r\n");
21052105 while (line_it.next()) |line| {
21062106 if (mem.trim(u8, line, " \t").len == 0) continue;
2107 var tok_it = mem.tokenize(u8, line, " \t");
2107 var tok_it = mem.tokenizeAny(u8, line, " \t");
21082108 try list.append(PkgConfigPkg{
21092109 .name = tok_it.next() orelse return error.PkgConfigInvalidOutput,
21102110 .desc = tok_it.rest(),
......@@ -2224,7 +2224,7 @@ fn checkCompileErrors(self: *Compile) !void {
22242224 // Render the expected lines into a string that we can compare verbatim.
22252225 var expected_generated = std.ArrayList(u8).init(arena);
22262226
2227 var actual_line_it = mem.split(u8, actual_stderr, "\n");
2227 var actual_line_it = mem.splitScalar(u8, actual_stderr, '\n');
22282228 for (self.expect_errors) |expect_line| {
22292229 const actual_line = actual_line_it.next() orelse {
22302230 try expected_generated.appendSlice(expect_line);
lib/std/Build/Step/ConfigHeader.zig+4-4
......@@ -250,14 +250,14 @@ fn render_autoconf(
250250
251251 var any_errors = false;
252252 var line_index: u32 = 0;
253 var line_it = std.mem.split(u8, contents, "\n");
253 var line_it = std.mem.splitScalar(u8, contents, '\n');
254254 while (line_it.next()) |line| : (line_index += 1) {
255255 if (!std.mem.startsWith(u8, line, "#")) {
256256 try output.appendSlice(line);
257257 try output.appendSlice("\n");
258258 continue;
259259 }
260 var it = std.mem.tokenize(u8, line[1..], " \t\r");
260 var it = std.mem.tokenizeAny(u8, line[1..], " \t\r");
261261 const undef = it.next().?;
262262 if (!std.mem.eql(u8, undef, "undef")) {
263263 try output.appendSlice(line);
......@@ -297,14 +297,14 @@ fn render_cmake(
297297
298298 var any_errors = false;
299299 var line_index: u32 = 0;
300 var line_it = std.mem.split(u8, contents, "\n");
300 var line_it = std.mem.splitScalar(u8, contents, '\n');
301301 while (line_it.next()) |line| : (line_index += 1) {
302302 if (!std.mem.startsWith(u8, line, "#")) {
303303 try output.appendSlice(line);
304304 try output.appendSlice("\n");
305305 continue;
306306 }
307 var it = std.mem.tokenize(u8, line[1..], " \t\r");
307 var it = std.mem.tokenizeAny(u8, line[1..], " \t\r");
308308 const cmakedefine = it.next().?;
309309 if (!std.mem.eql(u8, cmakedefine, "cmakedefine") and
310310 !std.mem.eql(u8, cmakedefine, "cmakedefine01"))
lib/std/SemanticVersion.zig+5-5
......@@ -42,8 +42,8 @@ pub fn order(lhs: Version, rhs: Version) std.math.Order {
4242 if (lhs.pre == null and rhs.pre != null) return .gt;
4343
4444 // Iterate over pre-release identifiers until a difference is found.
45 var lhs_pre_it = std.mem.split(u8, lhs.pre.?, ".");
46 var rhs_pre_it = std.mem.split(u8, rhs.pre.?, ".");
45 var lhs_pre_it = std.mem.splitScalar(u8, lhs.pre.?, '.');
46 var rhs_pre_it = std.mem.splitScalar(u8, rhs.pre.?, '.');
4747 while (true) {
4848 const next_lid = lhs_pre_it.next();
4949 const next_rid = rhs_pre_it.next();
......@@ -86,7 +86,7 @@ pub fn parse(text: []const u8) !Version {
8686 // Parse the required major, minor, and patch numbers.
8787 const extra_index = std.mem.indexOfAny(u8, text, "-+");
8888 const required = text[0..(extra_index orelse text.len)];
89 var it = std.mem.split(u8, required, ".");
89 var it = std.mem.splitScalar(u8, required, '.');
9090 var ver = Version{
9191 .major = try parseNum(it.first()),
9292 .minor = try parseNum(it.next() orelse return error.InvalidVersion),
......@@ -108,7 +108,7 @@ pub fn parse(text: []const u8) !Version {
108108 // Check validity of optional pre-release identifiers.
109109 // See: https://semver.org/#spec-item-9
110110 if (ver.pre) |pre| {
111 it = std.mem.split(u8, pre, ".");
111 it = std.mem.splitScalar(u8, pre, '.');
112112 while (it.next()) |id| {
113113 // Identifiers MUST NOT be empty.
114114 if (id.len == 0) return error.InvalidVersion;
......@@ -127,7 +127,7 @@ pub fn parse(text: []const u8) !Version {
127127 // Check validity of optional build metadata identifiers.
128128 // See: https://semver.org/#spec-item-10
129129 if (ver.build) |build| {
130 it = std.mem.split(u8, build, ".");
130 it = std.mem.splitScalar(u8, build, '.');
131131 while (it.next()) |id| {
132132 // Identifiers MUST NOT be empty.
133133 if (id.len == 0) return error.InvalidVersion;
lib/std/builtin.zig+1-1
......@@ -531,7 +531,7 @@ pub const Version = struct {
531531 // found no digits or '.' before unexpected character
532532 if (end == 0) return error.InvalidVersion;
533533
534 var it = std.mem.split(u8, text[0..end], ".");
534 var it = std.mem.splitScalar(u8, text[0..end], '.');
535535 // substring is not empty, first call will succeed
536536 const major = it.first();
537537 if (major.len == 0) return error.InvalidVersion;
lib/std/child_process.zig+2-2
......@@ -850,7 +850,7 @@ pub const ChildProcess = struct {
850850 return original_err;
851851 }
852852
853 var it = mem.tokenize(u16, PATH, &[_]u16{';'});
853 var it = mem.tokenizeScalar(u16, PATH, ';');
854854 while (it.next()) |search_path| {
855855 dir_buf.clearRetainingCapacity();
856856 try dir_buf.appendSlice(self.allocator, search_path);
......@@ -1064,7 +1064,7 @@ fn windowsCreateProcessPathExt(
10641064 // Now we know that at least *a* file matching the wildcard exists, we can loop
10651065 // through PATHEXT in order and exec any that exist
10661066
1067 var ext_it = mem.tokenize(u16, pathext, &[_]u16{';'});
1067 var ext_it = mem.tokenizeScalar(u16, pathext, ';');
10681068 while (ext_it.next()) |ext| {
10691069 if (!windowsCreateProcessSupportsExtension(ext)) continue;
10701070
lib/std/crypto/Certificate.zig+2-2
......@@ -337,8 +337,8 @@ pub const Parsed = struct {
337337 return true; // exact match
338338 }
339339
340 var it_host = std.mem.split(u8, host_name, ".");
341 var it_dns = std.mem.split(u8, dns_name, ".");
340 var it_host = std.mem.splitScalar(u8, host_name, '.');
341 var it_dns = std.mem.splitScalar(u8, dns_name, '.');
342342
343343 const len_match = while (true) {
344344 const host = it_host.next();
lib/std/crypto/phc_encoding.zig+6-3
......@@ -7,9 +7,12 @@ const mem = std.mem;
77const meta = std.meta;
88
99const fields_delimiter = "$";
10const fields_delimiter_scalar = '$';
1011const version_param_name = "v";
1112const params_delimiter = ",";
13const params_delimiter_scalar = ',';
1214const kv_delimiter = "=";
15const kv_delimiter_scalar = '=';
1316
1417pub const Error = std.crypto.errors.EncodingError || error{NoSpaceLeft};
1518
......@@ -73,7 +76,7 @@ pub fn BinValue(comptime max_len: usize) type {
7376/// Other fields will also be deserialized from the function parameters section.
7477pub fn deserialize(comptime HashResult: type, str: []const u8) Error!HashResult {
7578 var out = mem.zeroes(HashResult);
76 var it = mem.split(u8, str, fields_delimiter);
79 var it = mem.splitScalar(u8, str, fields_delimiter_scalar);
7780 var set_fields: usize = 0;
7881
7982 while (true) {
......@@ -104,7 +107,7 @@ pub fn deserialize(comptime HashResult: type, str: []const u8) Error!HashResult
104107
105108 // Read optional parameters
106109 var has_params = false;
107 var it_params = mem.split(u8, field, params_delimiter);
110 var it_params = mem.splitScalar(u8, field, params_delimiter_scalar);
108111 while (it_params.next()) |params| {
109112 const param = kvSplit(params) catch break;
110113 var found = false;
......@@ -252,7 +255,7 @@ fn serializeTo(params: anytype, out: anytype) !void {
252255
253256// Split a `key=value` string into `key` and `value`
254257fn kvSplit(str: []const u8) !struct { key: []const u8, value: []const u8 } {
255 var it = mem.split(u8, str, kv_delimiter);
258 var it = mem.splitScalar(u8, str, kv_delimiter_scalar);
256259 const key = it.first();
257260 const value = it.next() orelse return Error.InvalidEncoding;
258261 const ret = .{ .key = key, .value = value };
lib/std/crypto/scrypt.zig+1-1
......@@ -287,7 +287,7 @@ const crypt_format = struct {
287287 out.r = try Codec.intDecode(u30, str[4..9]);
288288 out.p = try Codec.intDecode(u30, str[9..14]);
289289
290 var it = mem.split(u8, str[14..], "$");
290 var it = mem.splitScalar(u8, str[14..], '$');
291291
292292 const salt = it.first();
293293 if (@hasField(T, "salt")) out.salt = salt;
lib/std/fs.zig+1-1
......@@ -3021,7 +3021,7 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 {
30213021 } else if (argv0.len != 0) {
30223022 // argv[0] is not empty (and not a path): search it inside PATH
30233023 const PATH = std.os.getenvZ("PATH") orelse return error.FileNotFound;
3024 var path_it = mem.tokenize(u8, PATH, &[_]u8{path.delimiter});
3024 var path_it = mem.tokenizeScalar(u8, PATH, path.delimiter);
30253025 while (path_it.next()) |a_path| {
30263026 var resolved_path_buf: [MAX_PATH_BYTES - 1:0]u8 = undefined;
30273027 const resolved_path = std.fmt.bufPrintZ(&resolved_path_buf, "{s}/{s}", .{
lib/std/fs/path.zig+13-13
......@@ -358,7 +358,7 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {
358358 return relative_path;
359359 }
360360
361 var it = mem.tokenize(u8, path, &[_]u8{this_sep});
361 var it = mem.tokenizeScalar(u8, path, this_sep);
362362 _ = (it.next() orelse return relative_path);
363363 _ = (it.next() orelse return relative_path);
364364 return WindowsPath{
......@@ -420,8 +420,8 @@ fn networkShareServersEql(ns1: []const u8, ns2: []const u8) bool {
420420 const sep1 = ns1[0];
421421 const sep2 = ns2[0];
422422
423 var it1 = mem.tokenize(u8, ns1, &[_]u8{sep1});
424 var it2 = mem.tokenize(u8, ns2, &[_]u8{sep2});
423 var it1 = mem.tokenizeScalar(u8, ns1, sep1);
424 var it2 = mem.tokenizeScalar(u8, ns2, sep2);
425425
426426 // TODO ASCII is wrong, we actually need full unicode support to compare paths.
427427 return ascii.eqlIgnoreCase(it1.next().?, it2.next().?);
......@@ -441,8 +441,8 @@ fn compareDiskDesignators(kind: WindowsPath.Kind, p1: []const u8, p2: []const u8
441441 const sep1 = p1[0];
442442 const sep2 = p2[0];
443443
444 var it1 = mem.tokenize(u8, p1, &[_]u8{sep1});
445 var it2 = mem.tokenize(u8, p2, &[_]u8{sep2});
444 var it1 = mem.tokenizeScalar(u8, p1, sep1);
445 var it2 = mem.tokenizeScalar(u8, p2, sep2);
446446
447447 // TODO ASCII is wrong, we actually need full unicode support to compare paths.
448448 return ascii.eqlIgnoreCase(it1.next().?, it2.next().?) and ascii.eqlIgnoreCase(it1.next().?, it2.next().?);
......@@ -535,7 +535,7 @@ pub fn resolveWindows(allocator: Allocator, paths: []const []const u8) ![]u8 {
535535 break :l disk_designator.len;
536536 },
537537 .NetworkShare => {
538 var it = mem.tokenize(u8, paths[first_index], "/\\");
538 var it = mem.tokenizeAny(u8, paths[first_index], "/\\");
539539 const server_name = it.next().?;
540540 const other_name = it.next().?;
541541
......@@ -570,7 +570,7 @@ pub fn resolveWindows(allocator: Allocator, paths: []const []const u8) ![]u8 {
570570 if (!correct_disk_designator) {
571571 continue;
572572 }
573 var it = mem.tokenize(u8, p[parsed.disk_designator.len..], "/\\");
573 var it = mem.tokenizeAny(u8, p[parsed.disk_designator.len..], "/\\");
574574 while (it.next()) |component| {
575575 if (mem.eql(u8, component, ".")) {
576576 continue;
......@@ -657,7 +657,7 @@ pub fn resolvePosix(allocator: Allocator, paths: []const []const u8) Allocator.E
657657 negative_count = 0;
658658 result.clearRetainingCapacity();
659659 }
660 var it = mem.tokenize(u8, p, "/");
660 var it = mem.tokenizeScalar(u8, p, '/');
661661 while (it.next()) |component| {
662662 if (mem.eql(u8, component, ".")) {
663663 continue;
......@@ -1078,8 +1078,8 @@ pub fn relativeWindows(allocator: Allocator, from: []const u8, to: []const u8) !
10781078 return resolved_to;
10791079 }
10801080
1081 var from_it = mem.tokenize(u8, resolved_from, "/\\");
1082 var to_it = mem.tokenize(u8, resolved_to, "/\\");
1081 var from_it = mem.tokenizeAny(u8, resolved_from, "/\\");
1082 var to_it = mem.tokenizeAny(u8, resolved_to, "/\\");
10831083 while (true) {
10841084 const from_component = from_it.next() orelse return allocator.dupe(u8, to_it.rest());
10851085 const to_rest = to_it.rest();
......@@ -1102,7 +1102,7 @@ pub fn relativeWindows(allocator: Allocator, from: []const u8, to: []const u8) !
11021102 result_index += 3;
11031103 }
11041104
1105 var rest_it = mem.tokenize(u8, to_rest, "/\\");
1105 var rest_it = mem.tokenizeAny(u8, to_rest, "/\\");
11061106 while (rest_it.next()) |to_component| {
11071107 result[result_index] = '\\';
11081108 result_index += 1;
......@@ -1124,8 +1124,8 @@ pub fn relativePosix(allocator: Allocator, from: []const u8, to: []const u8) ![]
11241124 const resolved_to = try resolvePosix(allocator, &[_][]const u8{ cwd, to });
11251125 defer allocator.free(resolved_to);
11261126
1127 var from_it = mem.tokenize(u8, resolved_from, "/");
1128 var to_it = mem.tokenize(u8, resolved_to, "/");
1127 var from_it = mem.tokenizeScalar(u8, resolved_from, '/');
1128 var to_it = mem.tokenizeScalar(u8, resolved_to, '/');
11291129 while (true) {
11301130 const from_component = from_it.next() orelse return allocator.dupe(u8, to_it.rest());
11311131 const to_rest = to_it.rest();
lib/std/http/Client.zig+3-3
......@@ -331,7 +331,7 @@ pub const Response = struct {
331331 };
332332
333333 pub fn parse(res: *Response, bytes: []const u8, trailing: bool) ParseError!void {
334 var it = mem.tokenize(u8, bytes[0 .. bytes.len - 4], "\r\n");
334 var it = mem.tokenizeAny(u8, bytes[0 .. bytes.len - 4], "\r\n");
335335
336336 const first_line = it.next() orelse return error.HttpHeadersInvalid;
337337 if (first_line.len < 12)
......@@ -357,7 +357,7 @@ pub const Response = struct {
357357 else => {},
358358 }
359359
360 var line_it = mem.tokenize(u8, line, ": ");
360 var line_it = mem.tokenizeAny(u8, line, ": ");
361361 const header_name = line_it.next() orelse return error.HttpHeadersInvalid;
362362 const header_value = line_it.rest();
363363
......@@ -371,7 +371,7 @@ pub const Response = struct {
371371 } else if (std.ascii.eqlIgnoreCase(header_name, "transfer-encoding")) {
372372 // Transfer-Encoding: second, first
373373 // Transfer-Encoding: deflate, chunked
374 var iter = mem.splitBackwards(u8, header_value, ",");
374 var iter = mem.splitBackwardsScalar(u8, header_value, ',');
375375
376376 if (iter.next()) |first| {
377377 const trimmed = mem.trim(u8, first, " ");
lib/std/http/Server.zig+3-3
......@@ -178,7 +178,7 @@ pub const Request = struct {
178178 };
179179
180180 pub fn parse(req: *Request, bytes: []const u8) ParseError!void {
181 var it = mem.tokenize(u8, bytes[0 .. bytes.len - 4], "\r\n");
181 var it = mem.tokenizeAny(u8, bytes[0 .. bytes.len - 4], "\r\n");
182182
183183 const first_line = it.next() orelse return error.HttpHeadersInvalid;
184184 if (first_line.len < 10)
......@@ -212,7 +212,7 @@ pub const Request = struct {
212212 else => {},
213213 }
214214
215 var line_it = mem.tokenize(u8, line, ": ");
215 var line_it = mem.tokenizeAny(u8, line, ": ");
216216 const header_name = line_it.next() orelse return error.HttpHeadersInvalid;
217217 const header_value = line_it.rest();
218218
......@@ -224,7 +224,7 @@ pub const Request = struct {
224224 } else if (std.ascii.eqlIgnoreCase(header_name, "transfer-encoding")) {
225225 // Transfer-Encoding: second, first
226226 // Transfer-Encoding: deflate, chunked
227 var iter = mem.splitBackwards(u8, header_value, ",");
227 var iter = mem.splitBackwardsScalar(u8, header_value, ',');
228228
229229 if (iter.next()) |first| {
230230 const trimmed = mem.trim(u8, first, " ");
lib/std/mem.zig+447-98
......@@ -1958,72 +1958,117 @@ test "byteSwapAllFields" {
19581958 }, k);
19591959}
19601960
1961/// Deprecated: use `tokenizeAny`, `tokenizeSequence`, or `tokenizeScalar`
1962pub const tokenize = tokenizeAny;
1963
19611964/// Returns an iterator that iterates over the slices of `buffer` that are not
1962/// any of the bytes in `delimiter_bytes`.
1965/// any of the items in `delimiters`.
19631966///
1964/// `tokenize(u8, " abc def ghi ", " ")` will return slices
1967/// `tokenizeAny(u8, " abc|def || ghi ", " |")` will return slices
19651968/// for "abc", "def", "ghi", null, in that order.
19661969///
19671970/// If `buffer` is empty, the iterator will return null.
1968/// If `delimiter_bytes` does not exist in buffer,
1971/// If none of `delimiters` exist in buffer,
19691972/// the iterator will return `buffer`, null, in that order.
19701973///
1971/// See also: `split` and `splitBackwards`.
1972pub fn tokenize(comptime T: type, buffer: []const T, delimiter_bytes: []const T) TokenIterator(T) {
1974/// See also: `tokenizeSequence`, `tokenizeScalar`,
1975/// `splitSequence`,`splitAny`, `splitScalar`,
1976/// `splitBackwardsSequence`, `splitBackwardsAny`, and `splitBackwardsScalar`
1977pub fn tokenizeAny(comptime T: type, buffer: []const T, delimiters: []const T) TokenIterator(T, .any) {
19731978 return .{
19741979 .index = 0,
19751980 .buffer = buffer,
1976 .delimiter_bytes = delimiter_bytes,
1981 .delimiter = delimiters,
19771982 };
19781983}
19791984
1980test "tokenize" {
1981 var it = tokenize(u8, " abc def ghi ", " ");
1985/// Returns an iterator that iterates over the slices of `buffer` that are not
1986/// the sequence in `delimiter`.
1987///
1988/// `tokenizeSequence(u8, "<>abc><def<><>ghi", "<>")` will return slices
1989/// for "abc><def", "ghi", null, in that order.
1990///
1991/// If `buffer` is empty, the iterator will return null.
1992/// If `delimiter` does not exist in buffer,
1993/// the iterator will return `buffer`, null, in that order.
1994/// The delimiter length must not be zero.
1995///
1996/// See also: `tokenizeAny`, `tokenizeScalar`,
1997/// `splitSequence`,`splitAny`, and `splitScalar`
1998/// `splitBackwardsSequence`, `splitBackwardsAny`, and `splitBackwardsScalar`
1999pub fn tokenizeSequence(comptime T: type, buffer: []const T, delimiter: []const T) TokenIterator(T, .sequence) {
2000 assert(delimiter.len != 0);
2001 return .{
2002 .index = 0,
2003 .buffer = buffer,
2004 .delimiter = delimiter,
2005 };
2006}
2007
2008/// Returns an iterator that iterates over the slices of `buffer` that are not
2009/// `delimiter`.
2010///
2011/// `tokenizeScalar(u8, " abc def ghi ", ' ')` will return slices
2012/// for "abc", "def", "ghi", null, in that order.
2013///
2014/// If `buffer` is empty, the iterator will return null.
2015/// If `delimiter` does not exist in buffer,
2016/// the iterator will return `buffer`, null, in that order.
2017///
2018/// See also: `tokenizeAny`, `tokenizeSequence`,
2019/// `splitSequence`,`splitAny`, and `splitScalar`
2020/// `splitBackwardsSequence`, `splitBackwardsAny`, and `splitBackwardsScalar`
2021pub fn tokenizeScalar(comptime T: type, buffer: []const T, delimiter: T) TokenIterator(T, .scalar) {
2022 return .{
2023 .index = 0,
2024 .buffer = buffer,
2025 .delimiter = delimiter,
2026 };
2027}
2028
2029test "tokenizeScalar" {
2030 var it = tokenizeScalar(u8, " abc def ghi ", ' ');
19822031 try testing.expect(eql(u8, it.next().?, "abc"));
19832032 try testing.expect(eql(u8, it.peek().?, "def"));
19842033 try testing.expect(eql(u8, it.next().?, "def"));
19852034 try testing.expect(eql(u8, it.next().?, "ghi"));
19862035 try testing.expect(it.next() == null);
19872036
1988 it = tokenize(u8, "..\\bob", "\\");
2037 it = tokenizeScalar(u8, "..\\bob", '\\');
19892038 try testing.expect(eql(u8, it.next().?, ".."));
19902039 try testing.expect(eql(u8, "..", "..\\bob"[0..it.index]));
19912040 try testing.expect(eql(u8, it.next().?, "bob"));
19922041 try testing.expect(it.next() == null);
19932042
1994 it = tokenize(u8, "//a/b", "/");
2043 it = tokenizeScalar(u8, "//a/b", '/');
19952044 try testing.expect(eql(u8, it.next().?, "a"));
19962045 try testing.expect(eql(u8, it.next().?, "b"));
19972046 try testing.expect(eql(u8, "//a/b", "//a/b"[0..it.index]));
19982047 try testing.expect(it.next() == null);
19992048
2000 it = tokenize(u8, "|", "|");
2049 it = tokenizeScalar(u8, "|", '|');
20012050 try testing.expect(it.next() == null);
20022051 try testing.expect(it.peek() == null);
20032052
2004 it = tokenize(u8, "", "|");
2053 it = tokenizeScalar(u8, "", '|');
20052054 try testing.expect(it.next() == null);
20062055 try testing.expect(it.peek() == null);
20072056
2008 it = tokenize(u8, "hello", "");
2057 it = tokenizeScalar(u8, "hello", ' ');
20092058 try testing.expect(eql(u8, it.next().?, "hello"));
20102059 try testing.expect(it.next() == null);
20112060
2012 it = tokenize(u8, "hello", " ");
2013 try testing.expect(eql(u8, it.next().?, "hello"));
2014 try testing.expect(it.next() == null);
2015
2016 var it16 = tokenize(
2061 var it16 = tokenizeScalar(
20172062 u16,
20182063 std.unicode.utf8ToUtf16LeStringLiteral("hello"),
2019 std.unicode.utf8ToUtf16LeStringLiteral(" "),
2064 ' ',
20202065 );
20212066 try testing.expect(eql(u16, it16.next().?, std.unicode.utf8ToUtf16LeStringLiteral("hello")));
20222067 try testing.expect(it16.next() == null);
20232068}
20242069
2025test "tokenize (multibyte)" {
2026 var it = tokenize(u8, "a|b,c/d e", " /,|");
2070test "tokenizeAny" {
2071 var it = tokenizeAny(u8, "a|b,c/d e", " /,|");
20272072 try testing.expect(eql(u8, it.next().?, "a"));
20282073 try testing.expect(eql(u8, it.peek().?, "b"));
20292074 try testing.expect(eql(u8, it.next().?, "b"));
......@@ -2033,7 +2078,11 @@ test "tokenize (multibyte)" {
20332078 try testing.expect(it.next() == null);
20342079 try testing.expect(it.peek() == null);
20352080
2036 var it16 = tokenize(
2081 it = tokenizeAny(u8, "hello", "");
2082 try testing.expect(eql(u8, it.next().?, "hello"));
2083 try testing.expect(it.next() == null);
2084
2085 var it16 = tokenizeAny(
20372086 u16,
20382087 std.unicode.utf8ToUtf16LeStringLiteral("a|b,c/d e"),
20392088 std.unicode.utf8ToUtf16LeStringLiteral(" /,|"),
......@@ -2046,32 +2095,87 @@ test "tokenize (multibyte)" {
20462095 try testing.expect(it16.next() == null);
20472096}
20482097
2098test "tokenizeSequence" {
2099 var it = tokenizeSequence(u8, "a<>b<><>c><>d><", "<>");
2100 try testing.expectEqualStrings("a", it.next().?);
2101 try testing.expectEqualStrings("b", it.peek().?);
2102 try testing.expectEqualStrings("b", it.next().?);
2103 try testing.expectEqualStrings("c>", it.next().?);
2104 try testing.expectEqualStrings("d><", it.next().?);
2105 try testing.expect(it.next() == null);
2106 try testing.expect(it.peek() == null);
2107
2108 var it16 = tokenizeSequence(
2109 u16,
2110 std.unicode.utf8ToUtf16LeStringLiteral("a<>b<><>c><>d><"),
2111 std.unicode.utf8ToUtf16LeStringLiteral("<>"),
2112 );
2113 try testing.expect(eql(u16, it16.next().?, std.unicode.utf8ToUtf16LeStringLiteral("a")));
2114 try testing.expect(eql(u16, it16.next().?, std.unicode.utf8ToUtf16LeStringLiteral("b")));
2115 try testing.expect(eql(u16, it16.next().?, std.unicode.utf8ToUtf16LeStringLiteral("c>")));
2116 try testing.expect(eql(u16, it16.next().?, std.unicode.utf8ToUtf16LeStringLiteral("d><")));
2117 try testing.expect(it16.next() == null);
2118}
2119
20492120test "tokenize (reset)" {
2050 var it = tokenize(u8, " abc def ghi ", " ");
2051 try testing.expect(eql(u8, it.next().?, "abc"));
2052 try testing.expect(eql(u8, it.next().?, "def"));
2053 try testing.expect(eql(u8, it.next().?, "ghi"));
2121 {
2122 var it = tokenizeAny(u8, " abc def ghi ", " ");
2123 try testing.expect(eql(u8, it.next().?, "abc"));
2124 try testing.expect(eql(u8, it.next().?, "def"));
2125 try testing.expect(eql(u8, it.next().?, "ghi"));
2126
2127 it.reset();
20542128
2055 it.reset();
2129 try testing.expect(eql(u8, it.next().?, "abc"));
2130 try testing.expect(eql(u8, it.next().?, "def"));
2131 try testing.expect(eql(u8, it.next().?, "ghi"));
2132 try testing.expect(it.next() == null);
2133 }
2134 {
2135 var it = tokenizeSequence(u8, "<><>abc<>def<><>ghi<>", "<>");
2136 try testing.expect(eql(u8, it.next().?, "abc"));
2137 try testing.expect(eql(u8, it.next().?, "def"));
2138 try testing.expect(eql(u8, it.next().?, "ghi"));
20562139
2057 try testing.expect(eql(u8, it.next().?, "abc"));
2058 try testing.expect(eql(u8, it.next().?, "def"));
2059 try testing.expect(eql(u8, it.next().?, "ghi"));
2060 try testing.expect(it.next() == null);
2140 it.reset();
2141
2142 try testing.expect(eql(u8, it.next().?, "abc"));
2143 try testing.expect(eql(u8, it.next().?, "def"));
2144 try testing.expect(eql(u8, it.next().?, "ghi"));
2145 try testing.expect(it.next() == null);
2146 }
2147 {
2148 var it = tokenizeScalar(u8, " abc def ghi ", ' ');
2149 try testing.expect(eql(u8, it.next().?, "abc"));
2150 try testing.expect(eql(u8, it.next().?, "def"));
2151 try testing.expect(eql(u8, it.next().?, "ghi"));
2152
2153 it.reset();
2154
2155 try testing.expect(eql(u8, it.next().?, "abc"));
2156 try testing.expect(eql(u8, it.next().?, "def"));
2157 try testing.expect(eql(u8, it.next().?, "ghi"));
2158 try testing.expect(it.next() == null);
2159 }
20612160}
20622161
2162/// Deprecated: use `splitSequence`, `splitAny`, or `splitScalar`
2163pub const split = splitSequence;
2164
20632165/// Returns an iterator that iterates over the slices of `buffer` that
2064/// are separated by bytes in `delimiter`.
2166/// are separated by the byte sequence in `delimiter`.
20652167///
2066/// `split(u8, "abc|def||ghi", "|")` will return slices
2168/// `splitSequence(u8, "abc||def||||ghi", "||")` will return slices
20672169/// for "abc", "def", "", "ghi", null, in that order.
20682170///
20692171/// If `delimiter` does not exist in buffer,
20702172/// the iterator will return `buffer`, null, in that order.
20712173/// The delimiter length must not be zero.
20722174///
2073/// See also: `tokenize` and `splitBackwards`.
2074pub fn split(comptime T: type, buffer: []const T, delimiter: []const T) SplitIterator(T) {
2175/// See also: `splitAny`, `splitScalar`, `splitBackwardsSequence`,
2176/// `splitBackwardsAny`,`splitBackwardsScalar`,
2177/// `tokenizeAny`, `tokenizeSequence`, and `tokenizeScalar`.
2178pub fn splitSequence(comptime T: type, buffer: []const T, delimiter: []const T) SplitIterator(T, .sequence) {
20752179 assert(delimiter.len != 0);
20762180 return .{
20772181 .index = 0,
......@@ -2080,8 +2184,48 @@ pub fn split(comptime T: type, buffer: []const T, delimiter: []const T) SplitIte
20802184 };
20812185}
20822186
2083test "split" {
2084 var it = split(u8, "abc|def||ghi", "|");
2187/// Returns an iterator that iterates over the slices of `buffer` that
2188/// are separated by any item in `delimiters`.
2189///
2190/// `splitAny(u8, "abc,def||ghi", "|,")` will return slices
2191/// for "abc", "def", "", "ghi", null, in that order.
2192///
2193/// If none of `delimiters` exist in buffer,
2194/// the iterator will return `buffer`, null, in that order.
2195///
2196/// See also: `splitSequence`, `splitScalar`, `splitBackwardsSequence`,
2197/// `splitBackwardsAny`,`splitBackwardsScalar`,
2198/// `tokenizeAny`, `tokenizeSequence`, and `tokenizeScalar`.
2199pub fn splitAny(comptime T: type, buffer: []const T, delimiters: []const T) SplitIterator(T, .any) {
2200 return .{
2201 .index = 0,
2202 .buffer = buffer,
2203 .delimiter = delimiters,
2204 };
2205}
2206
2207/// Returns an iterator that iterates over the slices of `buffer` that
2208/// are separated by `delimiter`.
2209///
2210/// `splitScalar(u8, "abc|def||ghi", '|')` will return slices
2211/// for "abc", "def", "", "ghi", null, in that order.
2212///
2213/// If `delimiter` does not exist in buffer,
2214/// the iterator will return `buffer`, null, in that order.
2215///
2216/// See also: `splitSequence`, `splitAny`, `splitBackwardsSequence`,
2217/// `splitBackwardsAny`,`splitBackwardsScalar`,
2218/// `tokenizeAny`, `tokenizeSequence`, and `tokenizeScalar`.
2219pub fn splitScalar(comptime T: type, buffer: []const T, delimiter: T) SplitIterator(T, .scalar) {
2220 return .{
2221 .index = 0,
2222 .buffer = buffer,
2223 .delimiter = delimiter,
2224 };
2225}
2226
2227test "splitScalar" {
2228 var it = splitScalar(u8, "abc|def||ghi", '|');
20852229 try testing.expectEqualSlices(u8, it.rest(), "abc|def||ghi");
20862230 try testing.expectEqualSlices(u8, it.first(), "abc");
20872231
......@@ -2097,30 +2241,30 @@ test "split" {
20972241 try testing.expectEqualSlices(u8, it.rest(), "");
20982242 try testing.expect(it.next() == null);
20992243
2100 it = split(u8, "", "|");
2244 it = splitScalar(u8, "", '|');
21012245 try testing.expectEqualSlices(u8, it.first(), "");
21022246 try testing.expect(it.next() == null);
21032247
2104 it = split(u8, "|", "|");
2248 it = splitScalar(u8, "|", '|');
21052249 try testing.expectEqualSlices(u8, it.first(), "");
21062250 try testing.expectEqualSlices(u8, it.next().?, "");
21072251 try testing.expect(it.next() == null);
21082252
2109 it = split(u8, "hello", " ");
2253 it = splitScalar(u8, "hello", ' ');
21102254 try testing.expectEqualSlices(u8, it.first(), "hello");
21112255 try testing.expect(it.next() == null);
21122256
2113 var it16 = split(
2257 var it16 = splitScalar(
21142258 u16,
21152259 std.unicode.utf8ToUtf16LeStringLiteral("hello"),
2116 std.unicode.utf8ToUtf16LeStringLiteral(" "),
2260 ' ',
21172261 );
21182262 try testing.expectEqualSlices(u16, it16.first(), std.unicode.utf8ToUtf16LeStringLiteral("hello"));
21192263 try testing.expect(it16.next() == null);
21202264}
21212265
2122test "split (multibyte)" {
2123 var it = split(u8, "a, b ,, c, d, e", ", ");
2266test "splitSequence" {
2267 var it = splitSequence(u8, "a, b ,, c, d, e", ", ");
21242268 try testing.expectEqualSlices(u8, it.first(), "a");
21252269 try testing.expectEqualSlices(u8, it.rest(), "b ,, c, d, e");
21262270 try testing.expectEqualSlices(u8, it.next().?, "b ,");
......@@ -2129,7 +2273,7 @@ test "split (multibyte)" {
21292273 try testing.expectEqualSlices(u8, it.next().?, "e");
21302274 try testing.expect(it.next() == null);
21312275
2132 var it16 = split(
2276 var it16 = splitSequence(
21332277 u16,
21342278 std.unicode.utf8ToUtf16LeStringLiteral("a, b ,, c, d, e"),
21352279 std.unicode.utf8ToUtf16LeStringLiteral(", "),
......@@ -2142,42 +2286,144 @@ test "split (multibyte)" {
21422286 try testing.expect(it16.next() == null);
21432287}
21442288
2289test "splitAny" {
2290 var it = splitAny(u8, "a,b, c d e", ", ");
2291 try testing.expectEqualSlices(u8, it.first(), "a");
2292 try testing.expectEqualSlices(u8, it.rest(), "b, c d e");
2293 try testing.expectEqualSlices(u8, it.next().?, "b");
2294 try testing.expectEqualSlices(u8, it.next().?, "");
2295 try testing.expectEqualSlices(u8, it.next().?, "c");
2296 try testing.expectEqualSlices(u8, it.next().?, "d");
2297 try testing.expectEqualSlices(u8, it.next().?, "e");
2298 try testing.expect(it.next() == null);
2299
2300 it = splitAny(u8, "hello", "");
2301 try testing.expect(eql(u8, it.next().?, "hello"));
2302 try testing.expect(it.next() == null);
2303
2304 var it16 = splitAny(
2305 u16,
2306 std.unicode.utf8ToUtf16LeStringLiteral("a,b, c d e"),
2307 std.unicode.utf8ToUtf16LeStringLiteral(", "),
2308 );
2309 try testing.expectEqualSlices(u16, it16.first(), std.unicode.utf8ToUtf16LeStringLiteral("a"));
2310 try testing.expectEqualSlices(u16, it16.next().?, std.unicode.utf8ToUtf16LeStringLiteral("b"));
2311 try testing.expectEqualSlices(u16, it16.next().?, std.unicode.utf8ToUtf16LeStringLiteral(""));
2312 try testing.expectEqualSlices(u16, it16.next().?, std.unicode.utf8ToUtf16LeStringLiteral("c"));
2313 try testing.expectEqualSlices(u16, it16.next().?, std.unicode.utf8ToUtf16LeStringLiteral("d"));
2314 try testing.expectEqualSlices(u16, it16.next().?, std.unicode.utf8ToUtf16LeStringLiteral("e"));
2315 try testing.expect(it16.next() == null);
2316}
2317
21452318test "split (reset)" {
2146 var it = split(u8, "abc def ghi", " ");
2147 try testing.expect(eql(u8, it.first(), "abc"));
2148 try testing.expect(eql(u8, it.next().?, "def"));
2149 try testing.expect(eql(u8, it.next().?, "ghi"));
2319 {
2320 var it = splitSequence(u8, "abc def ghi", " ");
2321 try testing.expect(eql(u8, it.first(), "abc"));
2322 try testing.expect(eql(u8, it.next().?, "def"));
2323 try testing.expect(eql(u8, it.next().?, "ghi"));
21502324
2151 it.reset();
2325 it.reset();
21522326
2153 try testing.expect(eql(u8, it.first(), "abc"));
2154 try testing.expect(eql(u8, it.next().?, "def"));
2155 try testing.expect(eql(u8, it.next().?, "ghi"));
2156 try testing.expect(it.next() == null);
2327 try testing.expect(eql(u8, it.first(), "abc"));
2328 try testing.expect(eql(u8, it.next().?, "def"));
2329 try testing.expect(eql(u8, it.next().?, "ghi"));
2330 try testing.expect(it.next() == null);
2331 }
2332 {
2333 var it = splitAny(u8, "abc def,ghi", " ,");
2334 try testing.expect(eql(u8, it.first(), "abc"));
2335 try testing.expect(eql(u8, it.next().?, "def"));
2336 try testing.expect(eql(u8, it.next().?, "ghi"));
2337
2338 it.reset();
2339
2340 try testing.expect(eql(u8, it.first(), "abc"));
2341 try testing.expect(eql(u8, it.next().?, "def"));
2342 try testing.expect(eql(u8, it.next().?, "ghi"));
2343 try testing.expect(it.next() == null);
2344 }
2345 {
2346 var it = splitScalar(u8, "abc def ghi", ' ');
2347 try testing.expect(eql(u8, it.first(), "abc"));
2348 try testing.expect(eql(u8, it.next().?, "def"));
2349 try testing.expect(eql(u8, it.next().?, "ghi"));
2350
2351 it.reset();
2352
2353 try testing.expect(eql(u8, it.first(), "abc"));
2354 try testing.expect(eql(u8, it.next().?, "def"));
2355 try testing.expect(eql(u8, it.next().?, "ghi"));
2356 try testing.expect(it.next() == null);
2357 }
21572358}
21582359
2159/// Returns an iterator that iterates backwards over the slices of `buffer`
2160/// that are separated by bytes in `delimiter`.
2360/// Deprecated: use `splitBackwardsSequence`, `splitBackwardsAny`, or `splitBackwardsScalar`
2361pub const splitBackwards = splitBackwardsSequence;
2362
2363/// Returns an iterator that iterates backwards over the slices of `buffer` that
2364/// are separated by the sequence in `delimiter`.
21612365///
2162/// `splitBackwards(u8, "abc|def||ghi", "|")` will return slices
2366/// `splitBackwardsSequence(u8, "abc||def||||ghi", "||")` will return slices
21632367/// for "ghi", "", "def", "abc", null, in that order.
21642368///
21652369/// If `delimiter` does not exist in buffer,
21662370/// the iterator will return `buffer`, null, in that order.
21672371/// The delimiter length must not be zero.
21682372///
2169/// See also: `tokenize` and `split`.
2170pub fn splitBackwards(comptime T: type, buffer: []const T, delimiter: []const T) SplitBackwardsIterator(T) {
2373/// See also: `splitBackwardsAny`, `splitBackwardsScalar`,
2374/// `splitSequence`, `splitAny`,`splitScalar`,
2375/// `tokenizeAny`, `tokenizeSequence`, and `tokenizeScalar`.
2376pub fn splitBackwardsSequence(comptime T: type, buffer: []const T, delimiter: []const T) SplitBackwardsIterator(T, .sequence) {
21712377 assert(delimiter.len != 0);
2172 return SplitBackwardsIterator(T){
2378 return .{
2379 .index = buffer.len,
2380 .buffer = buffer,
2381 .delimiter = delimiter,
2382 };
2383}
2384
2385/// Returns an iterator that iterates backwards over the slices of `buffer` that
2386/// are separated by any item in `delimiters`.
2387///
2388/// `splitBackwardsAny(u8, "abc,def||ghi", "|,")` will return slices
2389/// for "ghi", "", "def", "abc", null, in that order.
2390///
2391/// If none of `delimiters` exist in buffer,
2392/// the iterator will return `buffer`, null, in that order.
2393///
2394/// See also: `splitBackwardsSequence`, `splitBackwardsScalar`,
2395/// `splitSequence`, `splitAny`,`splitScalar`,
2396/// `tokenizeAny`, `tokenizeSequence`, and `tokenizeScalar`.
2397pub fn splitBackwardsAny(comptime T: type, buffer: []const T, delimiters: []const T) SplitBackwardsIterator(T, .any) {
2398 return .{
2399 .index = buffer.len,
2400 .buffer = buffer,
2401 .delimiter = delimiters,
2402 };
2403}
2404
2405/// Returns an iterator that iterates backwards over the slices of `buffer` that
2406/// are separated by `delimiter`.
2407///
2408/// `splitBackwardsScalar(u8, "abc|def||ghi", '|')` will return slices
2409/// for "ghi", "", "def", "abc", null, in that order.
2410///
2411/// If `delimiter` does not exist in buffer,
2412/// the iterator will return `buffer`, null, in that order.
2413///
2414/// See also: `splitBackwardsSequence`, `splitBackwardsAny`,
2415/// `splitSequence`, `splitAny`,`splitScalar`,
2416/// `tokenizeAny`, `tokenizeSequence`, and `tokenizeScalar`.
2417pub fn splitBackwardsScalar(comptime T: type, buffer: []const T, delimiter: T) SplitBackwardsIterator(T, .scalar) {
2418 return .{
21732419 .index = buffer.len,
21742420 .buffer = buffer,
21752421 .delimiter = delimiter,
21762422 };
21772423}
21782424
2179test "splitBackwards" {
2180 var it = splitBackwards(u8, "abc|def||ghi", "|");
2425test "splitBackwardsScalar" {
2426 var it = splitBackwardsScalar(u8, "abc|def||ghi", '|');
21812427 try testing.expectEqualSlices(u8, it.rest(), "abc|def||ghi");
21822428 try testing.expectEqualSlices(u8, it.first(), "ghi");
21832429
......@@ -2193,30 +2439,30 @@ test "splitBackwards" {
21932439 try testing.expectEqualSlices(u8, it.rest(), "");
21942440 try testing.expect(it.next() == null);
21952441
2196 it = splitBackwards(u8, "", "|");
2442 it = splitBackwardsScalar(u8, "", '|');
21972443 try testing.expectEqualSlices(u8, it.first(), "");
21982444 try testing.expect(it.next() == null);
21992445
2200 it = splitBackwards(u8, "|", "|");
2446 it = splitBackwardsScalar(u8, "|", '|');
22012447 try testing.expectEqualSlices(u8, it.first(), "");
22022448 try testing.expectEqualSlices(u8, it.next().?, "");
22032449 try testing.expect(it.next() == null);
22042450
2205 it = splitBackwards(u8, "hello", " ");
2451 it = splitBackwardsScalar(u8, "hello", ' ');
22062452 try testing.expectEqualSlices(u8, it.first(), "hello");
22072453 try testing.expect(it.next() == null);
22082454
2209 var it16 = splitBackwards(
2455 var it16 = splitBackwardsScalar(
22102456 u16,
22112457 std.unicode.utf8ToUtf16LeStringLiteral("hello"),
2212 std.unicode.utf8ToUtf16LeStringLiteral(" "),
2458 ' ',
22132459 );
22142460 try testing.expectEqualSlices(u16, it16.first(), std.unicode.utf8ToUtf16LeStringLiteral("hello"));
22152461 try testing.expect(it16.next() == null);
22162462}
22172463
2218test "splitBackwards (multibyte)" {
2219 var it = splitBackwards(u8, "a, b ,, c, d, e", ", ");
2464test "splitBackwardsSequence" {
2465 var it = splitBackwardsSequence(u8, "a, b ,, c, d, e", ", ");
22202466 try testing.expectEqualSlices(u8, it.rest(), "a, b ,, c, d, e");
22212467 try testing.expectEqualSlices(u8, it.first(), "e");
22222468
......@@ -2235,7 +2481,7 @@ test "splitBackwards (multibyte)" {
22352481 try testing.expectEqualSlices(u8, it.rest(), "");
22362482 try testing.expect(it.next() == null);
22372483
2238 var it16 = splitBackwards(
2484 var it16 = splitBackwardsSequence(
22392485 u16,
22402486 std.unicode.utf8ToUtf16LeStringLiteral("a, b ,, c, d, e"),
22412487 std.unicode.utf8ToUtf16LeStringLiteral(", "),
......@@ -2248,18 +2494,83 @@ test "splitBackwards (multibyte)" {
22482494 try testing.expect(it16.next() == null);
22492495}
22502496
2251test "splitBackwards (reset)" {
2252 var it = splitBackwards(u8, "abc def ghi", " ");
2253 try testing.expect(eql(u8, it.first(), "ghi"));
2254 try testing.expect(eql(u8, it.next().?, "def"));
2255 try testing.expect(eql(u8, it.next().?, "abc"));
2497test "splitBackwardsAny" {
2498 var it = splitBackwardsAny(u8, "a,b, c d e", ", ");
2499 try testing.expectEqualSlices(u8, it.rest(), "a,b, c d e");
2500 try testing.expectEqualSlices(u8, it.first(), "e");
22562501
2257 it.reset();
2502 try testing.expectEqualSlices(u8, it.rest(), "a,b, c d");
2503 try testing.expectEqualSlices(u8, it.next().?, "d");
22582504
2259 try testing.expect(eql(u8, it.first(), "ghi"));
2260 try testing.expect(eql(u8, it.next().?, "def"));
2261 try testing.expect(eql(u8, it.next().?, "abc"));
2505 try testing.expectEqualSlices(u8, it.rest(), "a,b, c");
2506 try testing.expectEqualSlices(u8, it.next().?, "c");
2507
2508 try testing.expectEqualSlices(u8, it.rest(), "a,b,");
2509 try testing.expectEqualSlices(u8, it.next().?, "");
2510
2511 try testing.expectEqualSlices(u8, it.rest(), "a,b");
2512 try testing.expectEqualSlices(u8, it.next().?, "b");
2513
2514 try testing.expectEqualSlices(u8, it.rest(), "a");
2515 try testing.expectEqualSlices(u8, it.next().?, "a");
2516
2517 try testing.expectEqualSlices(u8, it.rest(), "");
22622518 try testing.expect(it.next() == null);
2519
2520 var it16 = splitBackwardsAny(
2521 u16,
2522 std.unicode.utf8ToUtf16LeStringLiteral("a,b, c d e"),
2523 std.unicode.utf8ToUtf16LeStringLiteral(", "),
2524 );
2525 try testing.expectEqualSlices(u16, it16.first(), std.unicode.utf8ToUtf16LeStringLiteral("e"));
2526 try testing.expectEqualSlices(u16, it16.next().?, std.unicode.utf8ToUtf16LeStringLiteral("d"));
2527 try testing.expectEqualSlices(u16, it16.next().?, std.unicode.utf8ToUtf16LeStringLiteral("c"));
2528 try testing.expectEqualSlices(u16, it16.next().?, std.unicode.utf8ToUtf16LeStringLiteral(""));
2529 try testing.expectEqualSlices(u16, it16.next().?, std.unicode.utf8ToUtf16LeStringLiteral("b"));
2530 try testing.expectEqualSlices(u16, it16.next().?, std.unicode.utf8ToUtf16LeStringLiteral("a"));
2531 try testing.expect(it16.next() == null);
2532}
2533
2534test "splitBackwards (reset)" {
2535 {
2536 var it = splitBackwardsSequence(u8, "abc def ghi", " ");
2537 try testing.expect(eql(u8, it.first(), "ghi"));
2538 try testing.expect(eql(u8, it.next().?, "def"));
2539 try testing.expect(eql(u8, it.next().?, "abc"));
2540
2541 it.reset();
2542
2543 try testing.expect(eql(u8, it.first(), "ghi"));
2544 try testing.expect(eql(u8, it.next().?, "def"));
2545 try testing.expect(eql(u8, it.next().?, "abc"));
2546 try testing.expect(it.next() == null);
2547 }
2548 {
2549 var it = splitBackwardsAny(u8, "abc def,ghi", " ,");
2550 try testing.expect(eql(u8, it.first(), "ghi"));
2551 try testing.expect(eql(u8, it.next().?, "def"));
2552 try testing.expect(eql(u8, it.next().?, "abc"));
2553
2554 it.reset();
2555
2556 try testing.expect(eql(u8, it.first(), "ghi"));
2557 try testing.expect(eql(u8, it.next().?, "def"));
2558 try testing.expect(eql(u8, it.next().?, "abc"));
2559 try testing.expect(it.next() == null);
2560 }
2561 {
2562 var it = splitBackwardsScalar(u8, "abc def ghi", ' ');
2563 try testing.expect(eql(u8, it.first(), "ghi"));
2564 try testing.expect(eql(u8, it.next().?, "def"));
2565 try testing.expect(eql(u8, it.next().?, "abc"));
2566
2567 it.reset();
2568
2569 try testing.expect(eql(u8, it.first(), "ghi"));
2570 try testing.expect(eql(u8, it.next().?, "def"));
2571 try testing.expect(eql(u8, it.next().?, "abc"));
2572 try testing.expect(it.next() == null);
2573 }
22632574}
22642575
22652576/// Returns an iterator with a sliding window of slices for `buffer`.
......@@ -2430,10 +2741,15 @@ test "endsWith" {
24302741 try testing.expect(!endsWith(u8, "Bob", "Bo"));
24312742}
24322743
2433pub fn TokenIterator(comptime T: type) type {
2744pub const DelimiterType = enum { sequence, any, scalar };
2745
2746pub fn TokenIterator(comptime T: type, comptime delimiter_type: DelimiterType) type {
24342747 return struct {
24352748 buffer: []const T,
2436 delimiter_bytes: []const T,
2749 delimiter: switch (delimiter_type) {
2750 .sequence, .any => []const T,
2751 .scalar => T,
2752 },
24372753 index: usize,
24382754
24392755 const Self = @This();
......@@ -2450,7 +2766,10 @@ pub fn TokenIterator(comptime T: type) type {
24502766 /// complete. Does not advance to the next token.
24512767 pub fn peek(self: *Self) ?[]const T {
24522768 // move to beginning of token
2453 while (self.index < self.buffer.len and self.isSplitByte(self.buffer[self.index])) : (self.index += 1) {}
2769 while (self.index < self.buffer.len and self.isDelimiter(self.index)) : (self.index += switch (delimiter_type) {
2770 .sequence => self.delimiter.len,
2771 .any, .scalar => 1,
2772 }) {}
24542773 const start = self.index;
24552774 if (start == self.buffer.len) {
24562775 return null;
......@@ -2458,7 +2777,7 @@ pub fn TokenIterator(comptime T: type) type {
24582777
24592778 // move to end of token
24602779 var end = start;
2461 while (end < self.buffer.len and !self.isSplitByte(self.buffer[end])) : (end += 1) {}
2780 while (end < self.buffer.len and !self.isDelimiter(end)) : (end += 1) {}
24622781
24632782 return self.buffer[start..end];
24642783 }
......@@ -2467,7 +2786,10 @@ pub fn TokenIterator(comptime T: type) type {
24672786 pub fn rest(self: Self) []const T {
24682787 // move to beginning of token
24692788 var index: usize = self.index;
2470 while (index < self.buffer.len and self.isSplitByte(self.buffer[index])) : (index += 1) {}
2789 while (index < self.buffer.len and self.isDelimiter(index)) : (index += switch (delimiter_type) {
2790 .sequence => self.delimiter.len,
2791 .any, .scalar => 1,
2792 }) {}
24712793 return self.buffer[index..];
24722794 }
24732795
......@@ -2476,22 +2798,32 @@ pub fn TokenIterator(comptime T: type) type {
24762798 self.index = 0;
24772799 }
24782800
2479 fn isSplitByte(self: Self, byte: T) bool {
2480 for (self.delimiter_bytes) |delimiter_byte| {
2481 if (byte == delimiter_byte) {
2482 return true;
2483 }
2801 fn isDelimiter(self: Self, index: usize) bool {
2802 switch (delimiter_type) {
2803 .sequence => return startsWith(T, self.buffer[index..], self.delimiter),
2804 .any => {
2805 const item = self.buffer[index];
2806 for (self.delimiter) |delimiter_item| {
2807 if (item == delimiter_item) {
2808 return true;
2809 }
2810 }
2811 return false;
2812 },
2813 .scalar => return self.buffer[index] == self.delimiter,
24842814 }
2485 return false;
24862815 }
24872816 };
24882817}
24892818
2490pub fn SplitIterator(comptime T: type) type {
2819pub fn SplitIterator(comptime T: type, comptime delimiter_type: DelimiterType) type {
24912820 return struct {
24922821 buffer: []const T,
24932822 index: ?usize,
2494 delimiter: []const T,
2823 delimiter: switch (delimiter_type) {
2824 .sequence, .any => []const T,
2825 .scalar => T,
2826 },
24952827
24962828 const Self = @This();
24972829
......@@ -2505,8 +2837,15 @@ pub fn SplitIterator(comptime T: type) type {
25052837 /// Returns a slice of the next field, or null if splitting is complete.
25062838 pub fn next(self: *Self) ?[]const T {
25072839 const start = self.index orelse return null;
2508 const end = if (indexOfPos(T, self.buffer, start, self.delimiter)) |delim_start| blk: {
2509 self.index = delim_start + self.delimiter.len;
2840 const end = if (switch (delimiter_type) {
2841 .sequence => indexOfPos(T, self.buffer, start, self.delimiter),
2842 .any => indexOfAnyPos(T, self.buffer, start, self.delimiter),
2843 .scalar => indexOfScalarPos(T, self.buffer, start, self.delimiter),
2844 }) |delim_start| blk: {
2845 self.index = delim_start + switch (delimiter_type) {
2846 .sequence => self.delimiter.len,
2847 .any, .scalar => 1,
2848 };
25102849 break :blk delim_start;
25112850 } else blk: {
25122851 self.index = null;
......@@ -2529,11 +2868,14 @@ pub fn SplitIterator(comptime T: type) type {
25292868 };
25302869}
25312870
2532pub fn SplitBackwardsIterator(comptime T: type) type {
2871pub fn SplitBackwardsIterator(comptime T: type, comptime delimiter_type: DelimiterType) type {
25332872 return struct {
25342873 buffer: []const T,
25352874 index: ?usize,
2536 delimiter: []const T,
2875 delimiter: switch (delimiter_type) {
2876 .sequence, .any => []const T,
2877 .scalar => T,
2878 },
25372879
25382880 const Self = @This();
25392881
......@@ -2547,9 +2889,16 @@ pub fn SplitBackwardsIterator(comptime T: type) type {
25472889 /// Returns a slice of the next field, or null if splitting is complete.
25482890 pub fn next(self: *Self) ?[]const T {
25492891 const end = self.index orelse return null;
2550 const start = if (lastIndexOf(T, self.buffer[0..end], self.delimiter)) |delim_start| blk: {
2892 const start = if (switch (delimiter_type) {
2893 .sequence => lastIndexOf(T, self.buffer[0..end], self.delimiter),
2894 .any => lastIndexOfAny(T, self.buffer[0..end], self.delimiter),
2895 .scalar => lastIndexOfScalar(T, self.buffer[0..end], self.delimiter),
2896 }) |delim_start| blk: {
25512897 self.index = delim_start;
2552 break :blk delim_start + self.delimiter.len;
2898 break :blk delim_start + switch (delimiter_type) {
2899 .sequence => self.delimiter.len,
2900 .any, .scalar => 1,
2901 };
25532902 } else blk: {
25542903 self.index = null;
25552904 break :blk 0;
lib/std/net.zig+6-6
......@@ -1263,10 +1263,10 @@ fn linuxLookupNameFromHosts(
12631263 },
12641264 else => |e| return e,
12651265 }) |line| {
1266 var split_it = mem.split(u8, line, "#");
1266 var split_it = mem.splitScalar(u8, line, '#');
12671267 const no_comment_line = split_it.first();
12681268
1269 var line_it = mem.tokenize(u8, no_comment_line, " \t");
1269 var line_it = mem.tokenizeAny(u8, no_comment_line, " \t");
12701270 const ip_text = line_it.next() orelse continue;
12711271 var first_name_text: ?[]const u8 = null;
12721272 while (line_it.next()) |name_text| {
......@@ -1346,7 +1346,7 @@ fn linuxLookupNameFromDnsSearch(
13461346 @memcpy(canon.items, canon_name);
13471347 try canon.append('.');
13481348
1349 var tok_it = mem.tokenize(u8, search, " \t");
1349 var tok_it = mem.tokenizeAny(u8, search, " \t");
13501350 while (tok_it.next()) |tok| {
13511351 canon.shrinkRetainingCapacity(canon_name.len + 1);
13521352 try canon.appendSlice(tok);
......@@ -1465,15 +1465,15 @@ fn getResolvConf(allocator: mem.Allocator, rc: *ResolvConf) !void {
14651465 else => |e| return e,
14661466 }) |line| {
14671467 const no_comment_line = no_comment_line: {
1468 var split = mem.split(u8, line, "#");
1468 var split = mem.splitScalar(u8, line, '#');
14691469 break :no_comment_line split.first();
14701470 };
1471 var line_it = mem.tokenize(u8, no_comment_line, " \t");
1471 var line_it = mem.tokenizeAny(u8, no_comment_line, " \t");
14721472
14731473 const token = line_it.next() orelse continue;
14741474 if (mem.eql(u8, token, "options")) {
14751475 while (line_it.next()) |sub_tok| {
1476 var colon_it = mem.split(u8, sub_tok, ":");
1476 var colon_it = mem.splitScalar(u8, sub_tok, ':');
14771477 const name = colon_it.first();
14781478 const value_txt = colon_it.next() orelse continue;
14791479 const value = std.fmt.parseInt(u8, value_txt, 10) catch |err| switch (err) {
lib/std/os.zig+1-1
......@@ -1878,7 +1878,7 @@ pub fn execvpeZ_expandArg0(
18781878 // Use of MAX_PATH_BYTES here is valid as the path_buf will be passed
18791879 // directly to the operating system in execveZ.
18801880 var path_buf: [MAX_PATH_BYTES]u8 = undefined;
1881 var it = mem.tokenize(u8, PATH, ":");
1881 var it = mem.tokenizeScalar(u8, PATH, ':');
18821882 var seen_eacces = false;
18831883 var err: ExecveError = error.FileNotFound;
18841884
lib/std/process.zig+2-2
......@@ -310,7 +310,7 @@ pub fn getEnvMap(allocator: Allocator) !EnvMap {
310310
311311 for (environ) |env| {
312312 const pair = mem.sliceTo(env, 0);
313 var parts = mem.split(u8, pair, "=");
313 var parts = mem.splitScalar(u8, pair, '=');
314314 const key = parts.first();
315315 const value = parts.rest();
316316 try result.put(key, value);
......@@ -1200,7 +1200,7 @@ fn totalSystemMemoryLinux() !usize {
12001200 var buf: [50]u8 = undefined;
12011201 const amt = try file.read(&buf);
12021202 if (amt != 50) return error.Unexpected;
1203 var it = std.mem.tokenize(u8, buf[0..amt], " \n");
1203 var it = std.mem.tokenizeAny(u8, buf[0..amt], " \n");
12041204 const label = it.next().?;
12051205 if (!std.mem.eql(u8, label, "MemTotal:")) return error.Unexpected;
12061206 const int_text = it.next() orelse return error.Unexpected;
lib/std/zig/CrossTarget.zig+6-6
......@@ -239,7 +239,7 @@ pub fn parse(args: ParseOptions) !CrossTarget {
239239 .dynamic_linker = DynamicLinker.init(args.dynamic_linker),
240240 };
241241
242 var it = mem.split(u8, args.arch_os_abi, "-");
242 var it = mem.splitScalar(u8, args.arch_os_abi, '-');
243243 const arch_name = it.first();
244244 const arch_is_native = mem.eql(u8, arch_name, "native");
245245 if (!arch_is_native) {
......@@ -257,7 +257,7 @@ pub fn parse(args: ParseOptions) !CrossTarget {
257257
258258 const opt_abi_text = it.next();
259259 if (opt_abi_text) |abi_text| {
260 var abi_it = mem.split(u8, abi_text, ".");
260 var abi_it = mem.splitScalar(u8, abi_text, '.');
261261 const abi = std.meta.stringToEnum(Target.Abi, abi_it.first()) orelse
262262 return error.UnknownApplicationBinaryInterface;
263263 result.abi = abi;
......@@ -343,7 +343,7 @@ pub fn parse(args: ParseOptions) !CrossTarget {
343343/// This is intended to be used if the API user of CrossTarget needs to learn the
344344/// target CPU architecture in order to fully populate `ParseOptions`.
345345pub fn parseCpuArch(args: ParseOptions) ?Target.Cpu.Arch {
346 var it = mem.split(u8, args.arch_os_abi, "-");
346 var it = mem.splitScalar(u8, args.arch_os_abi, '-');
347347 const arch_name = it.first();
348348 const arch_is_native = mem.eql(u8, arch_name, "native");
349349 if (arch_is_native) {
......@@ -645,7 +645,7 @@ pub fn updateCpuFeatures(self: CrossTarget, set: *Target.Cpu.Feature.Set) void {
645645}
646646
647647fn parseOs(result: *CrossTarget, diags: *ParseOptions.Diagnostics, text: []const u8) !void {
648 var it = mem.split(u8, text, ".");
648 var it = mem.splitScalar(u8, text, '.');
649649 const os_name = it.first();
650650 diags.os_name = os_name;
651651 const os_is_native = mem.eql(u8, os_name, "native");
......@@ -706,7 +706,7 @@ fn parseOs(result: *CrossTarget, diags: *ParseOptions.Diagnostics, text: []const
706706 .linux,
707707 .dragonfly,
708708 => {
709 var range_it = mem.split(u8, version_text, "...");
709 var range_it = mem.splitSequence(u8, version_text, "...");
710710
711711 const min_text = range_it.next().?;
712712 const min_ver = SemVer.parse(min_text) catch |err| switch (err) {
......@@ -726,7 +726,7 @@ fn parseOs(result: *CrossTarget, diags: *ParseOptions.Diagnostics, text: []const
726726 },
727727
728728 .windows => {
729 var range_it = mem.split(u8, version_text, "...");
729 var range_it = mem.splitSequence(u8, version_text, "...");
730730
731731 const min_text = range_it.first();
732732 const min_ver = std.meta.stringToEnum(Target.Os.WindowsVersion, min_text) orelse
lib/std/zig/ErrorBundle.zig+1-1
......@@ -294,7 +294,7 @@ fn renderErrorMessageToWriter(
294294///
295295/// This is used to split the message in `@compileError("hello\nworld")` for example.
296296fn writeMsg(eb: ErrorBundle, err_msg: ErrorMessage, stderr: anytype, indent: usize) !void {
297 var lines = std.mem.split(u8, eb.nullTerminatedString(err_msg.msg), "\n");
297 var lines = std.mem.splitScalar(u8, eb.nullTerminatedString(err_msg.msg), '\n');
298298 while (lines.next()) |line| {
299299 try stderr.writeAll(line);
300300 if (lines.index == null) break;
lib/std/zig/render.zig+1-1
......@@ -1995,7 +1995,7 @@ fn renderArrayInit(
19951995 if (!expr_newlines[i]) {
19961996 try ais.writer().writeAll(expr_text);
19971997 } else {
1998 var by_line = std.mem.split(u8, expr_text, "\n");
1998 var by_line = std.mem.splitScalar(u8, expr_text, '\n');
19991999 var last_line_was_empty = false;
20002000 try ais.writer().writeAll(by_line.first());
20012001 while (by_line.next()) |line| {
lib/std/zig/system/NativePaths.zig+5-5
......@@ -31,7 +31,7 @@ pub fn detect(allocator: Allocator, native_info: NativeTargetInfo) !NativePaths
3131 defer allocator.free(nix_cflags_compile);
3232
3333 is_nix = true;
34 var it = mem.tokenize(u8, nix_cflags_compile, " ");
34 var it = mem.tokenizeScalar(u8, nix_cflags_compile, ' ');
3535 while (true) {
3636 const word = it.next() orelse break;
3737 if (mem.eql(u8, word, "-isystem")) {
......@@ -62,7 +62,7 @@ pub fn detect(allocator: Allocator, native_info: NativeTargetInfo) !NativePaths
6262 defer allocator.free(nix_ldflags);
6363
6464 is_nix = true;
65 var it = mem.tokenize(u8, nix_ldflags, " ");
65 var it = mem.tokenizeScalar(u8, nix_ldflags, ' ');
6666 while (true) {
6767 const word = it.next() orelse break;
6868 if (mem.eql(u8, word, "-rpath")) {
......@@ -147,21 +147,21 @@ pub fn detect(allocator: Allocator, native_info: NativeTargetInfo) !NativePaths
147147 // We use os.getenv here since this part won't be executed on
148148 // windows, to get rid of unnecessary error handling.
149149 if (std.os.getenv("C_INCLUDE_PATH")) |c_include_path| {
150 var it = mem.tokenize(u8, c_include_path, ":");
150 var it = mem.tokenizeScalar(u8, c_include_path, ':');
151151 while (it.next()) |dir| {
152152 try self.addIncludeDir(dir);
153153 }
154154 }
155155
156156 if (std.os.getenv("CPLUS_INCLUDE_PATH")) |cplus_include_path| {
157 var it = mem.tokenize(u8, cplus_include_path, ":");
157 var it = mem.tokenizeScalar(u8, cplus_include_path, ':');
158158 while (it.next()) |dir| {
159159 try self.addIncludeDir(dir);
160160 }
161161 }
162162
163163 if (std.os.getenv("LIBRARY_PATH")) |library_path| {
164 var it = mem.tokenize(u8, library_path, ":");
164 var it = mem.tokenizeScalar(u8, library_path, ':');
165165 while (it.next()) |dir| {
166166 try self.addLibDir(dir);
167167 }
lib/std/zig/system/NativeTargetInfo.zig+3-3
......@@ -354,7 +354,7 @@ fn detectAbiAndDynamicLinker(
354354 const newline = mem.indexOfScalar(u8, buffer[0..len], '\n') orelse break :blk file;
355355 const line = buffer[0..newline];
356356 if (!mem.startsWith(u8, line, "#!")) break :blk file;
357 var it = mem.tokenize(u8, line[2..], " ");
357 var it = mem.tokenizeScalar(u8, line[2..], ' ');
358358 file_name = it.next() orelse return defaultAbiAndDynamicLinker(cpu, os, cross_target);
359359 file.close();
360360 }
......@@ -556,7 +556,7 @@ fn glibcVerFromSoFile(file: fs.File) !std.builtin.Version {
556556 const dynstr_size = @intCast(usize, dynstr.size);
557557 const dynstr_bytes = buf[0..dynstr_size];
558558 _ = try preadMin(file, dynstr_bytes, dynstr.offset, dynstr_bytes.len);
559 var it = mem.split(u8, dynstr_bytes, &.{0});
559 var it = mem.splitScalar(u8, dynstr_bytes, 0);
560560 var max_ver: std.builtin.Version = .{ .major = 2, .minor = 2, .patch = 5 };
561561 while (it.next()) |s| {
562562 if (mem.startsWith(u8, s, "GLIBC_2.")) {
......@@ -811,7 +811,7 @@ pub fn abiAndDynamicLinkerFromFile(
811811 const strtab = strtab_buf[0..strtab_read_len];
812812
813813 const rpath_list = mem.sliceTo(strtab, 0);
814 var it = mem.tokenize(u8, rpath_list, ":");
814 var it = mem.tokenizeScalar(u8, rpath_list, ':');
815815 while (it.next()) |rpath| {
816816 if (glibcVerFromRPath(rpath)) |ver| {
817817 result.target.os.version_range.linux.glibc = ver;
src/Autodoc.zig+1-1
......@@ -4950,7 +4950,7 @@ fn findGuidePaths(self: *Autodoc, file: *File, str: []const u8) ![]const u8 {
49504950
49514951 // TODO: this algo is kinda inefficient
49524952
4953 var it = std.mem.split(u8, str, "\n");
4953 var it = std.mem.splitScalar(u8, str, '\n');
49544954 while (it.next()) |line| {
49554955 const trimmed_line = std.mem.trim(u8, line, " ");
49564956 if (std.mem.startsWith(u8, trimmed_line, guide_prefix)) {
src/Compilation.zig+3-3
......@@ -4671,7 +4671,7 @@ pub fn hasSharedLibraryExt(filename: []const u8) bool {
46714671 return true;
46724672 }
46734673 // Look for .so.X, .so.X.Y, .so.X.Y.Z
4674 var it = mem.split(u8, filename, ".");
4674 var it = mem.splitScalar(u8, filename, '.');
46754675 _ = it.first();
46764676 var so_txt = it.next() orelse return false;
46774677 while (!mem.eql(u8, so_txt, "so")) {
......@@ -5051,14 +5051,14 @@ fn parseLldStderr(comp: *Compilation, comptime prefix: []const u8, stderr: []con
50515051 defer context_lines.deinit();
50525052
50535053 var current_err: ?*LldError = null;
5054 var lines = mem.split(u8, stderr, std.cstr.line_sep);
5054 var lines = mem.splitSequence(u8, stderr, std.cstr.line_sep);
50555055 while (lines.next()) |line| {
50565056 if (mem.startsWith(u8, line, prefix ++ ":")) {
50575057 if (current_err) |err| {
50585058 err.context_lines = try context_lines.toOwnedSlice();
50595059 }
50605060
5061 var split = std.mem.split(u8, line, "error: ");
5061 var split = std.mem.splitSequence(u8, line, "error: ");
50625062 _ = split.first();
50635063
50645064 const duped_msg = try std.fmt.allocPrint(comp.gpa, "{s}: {s}", .{ prefix, split.rest() });
src/arch/x86_64/CodeGen.zig+3-3
......@@ -9232,9 +9232,9 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
92329232 }
92339233
92349234 const asm_source = mem.sliceAsBytes(self.air.extra[extra_i..])[0..extra.data.source_len];
9235 var line_it = mem.tokenize(u8, asm_source, "\n\r;");
9235 var line_it = mem.tokenizeAny(u8, asm_source, "\n\r;");
92369236 while (line_it.next()) |line| {
9237 var mnem_it = mem.tokenize(u8, line, " \t");
9237 var mnem_it = mem.tokenizeAny(u8, line, " \t");
92389238 const mnem_str = mnem_it.next() orelse continue;
92399239 if (mem.startsWith(u8, mnem_str, "#")) continue;
92409240
......@@ -9258,7 +9258,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void {
92589258 return self.fail("Invalid mnemonic: '{s}'", .{mnem_str});
92599259 } };
92609260
9261 var op_it = mem.tokenize(u8, mnem_it.rest(), ",");
9261 var op_it = mem.tokenizeScalar(u8, mnem_it.rest(), ',');
92629262 var ops = [1]encoder.Instruction.Operand{.none} ** 4;
92639263 for (&ops) |*op| {
92649264 const op_str = mem.trim(u8, op_it.next() orelse break, " \t");
src/glibc.zig+1-1
......@@ -109,7 +109,7 @@ pub fn loadMetaData(gpa: Allocator, contents: []const u8) LoadMetaDataError!*ABI
109109 const target_name = mem.sliceTo(contents[index..], 0);
110110 index += target_name.len + 1;
111111
112 var component_it = mem.tokenize(u8, target_name, "-");
112 var component_it = mem.tokenizeScalar(u8, target_name, '-');
113113 const arch_name = component_it.next() orelse {
114114 log.err("abilists: expected arch name", .{});
115115 return error.ZigInstallationCorrupt;
src/libc_installation.zig+5-5
......@@ -60,10 +60,10 @@ pub const LibCInstallation = struct {
6060 const contents = try std.fs.cwd().readFileAlloc(allocator, libc_file, std.math.maxInt(usize));
6161 defer allocator.free(contents);
6262
63 var it = std.mem.tokenize(u8, contents, "\n");
63 var it = std.mem.tokenizeScalar(u8, contents, '\n');
6464 while (it.next()) |line| {
6565 if (line.len == 0 or line[0] == '#') continue;
66 var line_it = std.mem.split(u8, line, "=");
66 var line_it = std.mem.splitScalar(u8, line, '=');
6767 const name = line_it.first();
6868 const value = line_it.rest();
6969 inline for (fields, 0..) |field, i| {
......@@ -293,7 +293,7 @@ pub const LibCInstallation = struct {
293293 },
294294 }
295295
296 var it = std.mem.tokenize(u8, exec_res.stderr, "\n\r");
296 var it = std.mem.tokenizeAny(u8, exec_res.stderr, "\n\r");
297297 var search_paths = std.ArrayList([]const u8).init(allocator);
298298 defer search_paths.deinit();
299299 while (it.next()) |line| {
......@@ -613,7 +613,7 @@ fn ccPrintFileName(args: CCPrintFileNameOptions) ![:0]u8 {
613613 },
614614 }
615615
616 var it = std.mem.tokenize(u8, exec_res.stdout, "\n\r");
616 var it = std.mem.tokenizeAny(u8, exec_res.stdout, "\n\r");
617617 const line = it.next() orelse return error.LibCRuntimeNotFound;
618618 // When this command fails, it returns exit code 0 and duplicates the input file name.
619619 // So we detect failure by checking if the output matches exactly the input.
......@@ -692,7 +692,7 @@ fn appendCcExe(args: *std.ArrayList([]const u8), skip_cc_env_var: bool) !void {
692692 return;
693693 };
694694 // Respect space-separated flags to the C compiler.
695 var it = std.mem.tokenize(u8, cc_env_var, " ");
695 var it = std.mem.tokenizeScalar(u8, cc_env_var, ' ');
696696 while (it.next()) |arg| {
697697 try args.append(arg);
698698 }
src/link/MachO/Dylib.zig+1-1
......@@ -91,7 +91,7 @@ pub const Id = struct {
9191 var out: u32 = 0;
9292 var values: [3][]const u8 = undefined;
9393
94 var split = mem.split(u8, string, ".");
94 var split = mem.splitScalar(u8, string, '.');
9595 var count: u4 = 0;
9696 while (split.next()) |value| {
9797 if (count > 2) {
src/link/Plan9.zig+1-1
......@@ -264,7 +264,7 @@ fn putFn(self: *Plan9, decl_index: Module.Decl.Index, out: FnDeclOutput) !void {
264264
265265fn addPathComponents(self: *Plan9, path: []const u8, a: *std.ArrayList(u8)) !void {
266266 const sep = std.fs.path.sep;
267 var it = std.mem.tokenize(u8, path, &.{sep});
267 var it = std.mem.tokenizeScalar(u8, path, sep);
268268 while (it.next()) |component| {
269269 if (self.file_segments.get(component)) |num| {
270270 try a.writer().writeIntBig(u16, num);
src/main.zig+9-9
......@@ -973,7 +973,7 @@ fn buildOutputType(
973973 }
974974 } else if (mem.eql(u8, arg, "--mod")) {
975975 const info = args_iter.nextOrFatal();
976 var info_it = mem.split(u8, info, ":");
976 var info_it = mem.splitScalar(u8, info, ':');
977977 const mod_name = info_it.next() orelse fatal("expected non-empty argument after {s}", .{arg});
978978 const deps_str = info_it.next() orelse fatal("expected 'name:deps:path' after {s}", .{arg});
979979 const root_src_orig = info_it.rest();
......@@ -1173,7 +1173,7 @@ fn buildOutputType(
11731173 } else {
11741174 if (build_options.only_core_functionality) unreachable;
11751175 // example: --listen 127.0.0.1:9000
1176 var it = std.mem.split(u8, next_arg, ":");
1176 var it = std.mem.splitScalar(u8, next_arg, ':');
11771177 const host = it.next().?;
11781178 const port_text = it.next() orelse "14735";
11791179 const port = std.fmt.parseInt(u16, port_text, 10) catch |err|
......@@ -1676,7 +1676,7 @@ fn buildOutputType(
16761676 },
16771677 .rdynamic => rdynamic = true,
16781678 .wl => {
1679 var split_it = mem.split(u8, it.only_arg, ",");
1679 var split_it = mem.splitScalar(u8, it.only_arg, ',');
16801680 while (split_it.next()) |linker_arg| {
16811681 // Handle nested-joined args like `-Wl,-rpath=foo`.
16821682 // Must be prefixed with 1 or 2 dashes.
......@@ -2191,17 +2191,17 @@ fn buildOutputType(
21912191 const next_arg = linker_args_it.nextOrFatal();
21922192 try symbol_wrap_set.put(arena, next_arg, {});
21932193 } else if (mem.startsWith(u8, arg, "/subsystem:")) {
2194 var split_it = mem.splitBackwards(u8, arg, ":");
2194 var split_it = mem.splitBackwardsScalar(u8, arg, ':');
21952195 subsystem = try parseSubSystem(split_it.first());
21962196 } else if (mem.startsWith(u8, arg, "/implib:")) {
2197 var split_it = mem.splitBackwards(u8, arg, ":");
2197 var split_it = mem.splitBackwardsScalar(u8, arg, ':');
21982198 emit_implib = .{ .yes = split_it.first() };
21992199 emit_implib_arg_provided = true;
22002200 } else if (mem.startsWith(u8, arg, "/pdb:")) {
2201 var split_it = mem.splitBackwards(u8, arg, ":");
2201 var split_it = mem.splitBackwardsScalar(u8, arg, ':');
22022202 pdb_out_path = split_it.first();
22032203 } else if (mem.startsWith(u8, arg, "/version:")) {
2204 var split_it = mem.splitBackwards(u8, arg, ":");
2204 var split_it = mem.splitBackwardsScalar(u8, arg, ':');
22052205 const version_arg = split_it.first();
22062206 version = std.builtin.Version.parse(version_arg) catch |err| {
22072207 fatal("unable to parse /version '{s}': {s}", .{ arg, @errorName(err) });
......@@ -3541,10 +3541,10 @@ fn serveUpdateResults(s: *Server, comp: *Compilation) !void {
35413541}
35423542
35433543const ModuleDepIterator = struct {
3544 split: mem.SplitIterator(u8),
3544 split: mem.SplitIterator(u8, .scalar),
35453545
35463546 fn init(deps_str: []const u8) ModuleDepIterator {
3547 return .{ .split = mem.split(u8, deps_str, ",") };
3547 return .{ .split = mem.splitScalar(u8, deps_str, ',') };
35483548 }
35493549
35503550 const Dependency = struct {
src/print_zir.zig+1-1
......@@ -2588,7 +2588,7 @@ const Writer = struct {
25882588 fn writeDocComment(self: *Writer, stream: anytype, doc_comment_index: u32) !void {
25892589 if (doc_comment_index != 0) {
25902590 const doc_comment = self.code.nullTerminatedString(doc_comment_index);
2591 var it = std.mem.tokenize(u8, doc_comment, "\n");
2591 var it = std.mem.tokenizeScalar(u8, doc_comment, '\n');
25922592 while (it.next()) |doc_line| {
25932593 try stream.writeByteNTimes(' ', self.indent);
25942594 try stream.print("///{s}\n", .{doc_line});
test/behavior/bugs/6456.zig+1-1
......@@ -18,7 +18,7 @@ test "issue 6456" {
1818 comptime {
1919 var fields: []const StructField = &[0]StructField{};
2020
21 var it = std.mem.tokenize(u8, text, "\n");
21 var it = std.mem.tokenizeScalar(u8, text, '\n');
2222 while (it.next()) |name| {
2323 fields = fields ++ &[_]StructField{StructField{
2424 .alignment = 0,
test/src/Cases.zig+7-7
......@@ -804,7 +804,7 @@ const TestManifest = struct {
804804 };
805805
806806 const TrailingIterator = struct {
807 inner: std.mem.TokenIterator(u8),
807 inner: std.mem.TokenIterator(u8, .any),
808808
809809 fn next(self: *TrailingIterator) ?[]const u8 {
810810 const next_inner = self.inner.next() orelse return null;
......@@ -814,7 +814,7 @@ const TestManifest = struct {
814814
815815 fn ConfigValueIterator(comptime T: type) type {
816816 return struct {
817 inner: std.mem.SplitIterator(u8),
817 inner: std.mem.SplitIterator(u8, .scalar),
818818
819819 fn next(self: *@This()) !?T {
820820 const next_raw = self.inner.next() orelse return null;
......@@ -855,7 +855,7 @@ const TestManifest = struct {
855855 const actual_start = start orelse return error.MissingTestManifest;
856856 const manifest_bytes = bytes[actual_start..end];
857857
858 var it = std.mem.tokenize(u8, manifest_bytes, "\r\n");
858 var it = std.mem.tokenizeAny(u8, manifest_bytes, "\r\n");
859859
860860 // First line is the test type
861861 const tt: Type = blk: {
......@@ -886,7 +886,7 @@ const TestManifest = struct {
886886 if (trimmed.len == 0) break;
887887
888888 // Parse key=value(s)
889 var kv_it = std.mem.split(u8, trimmed, "=");
889 var kv_it = std.mem.splitScalar(u8, trimmed, '=');
890890 const key = kv_it.first();
891891 try manifest.config_map.putNoClobber(key, kv_it.next() orelse return error.MissingValuesForConfig);
892892 }
......@@ -904,7 +904,7 @@ const TestManifest = struct {
904904 ) ConfigValueIterator(T) {
905905 const bytes = self.config_map.get(key) orelse TestManifestConfigDefaults.get(self.type, key);
906906 return ConfigValueIterator(T){
907 .inner = std.mem.split(u8, bytes, ","),
907 .inner = std.mem.splitScalar(u8, bytes, ','),
908908 };
909909 }
910910
......@@ -932,7 +932,7 @@ const TestManifest = struct {
932932
933933 fn trailing(self: TestManifest) TrailingIterator {
934934 return .{
935 .inner = std.mem.tokenize(u8, self.trailing_bytes, "\r\n"),
935 .inner = std.mem.tokenizeAny(u8, self.trailing_bytes, "\r\n"),
936936 };
937937 }
938938
......@@ -1408,7 +1408,7 @@ fn runOneCase(
14081408 // Render the expected lines into a string that we can compare verbatim.
14091409 var expected_generated = std.ArrayList(u8).init(arena);
14101410
1411 var actual_line_it = std.mem.split(u8, actual_stderr.items, "\n");
1411 var actual_line_it = std.mem.splitScalar(u8, actual_stderr.items, '\n');
14121412 for (expected_errors) |expect_line| {
14131413 const actual_line = actual_line_it.next() orelse {
14141414 try expected_generated.appendSlice(expect_line);
test/src/check-stack-trace.zig+1-1
......@@ -27,7 +27,7 @@ pub fn main() !void {
2727 var buf = std.ArrayList(u8).init(arena);
2828 defer buf.deinit();
2929 if (stderr.len != 0 and stderr[stderr.len - 1] == '\n') stderr = stderr[0 .. stderr.len - 1];
30 var it = mem.split(u8, stderr, "\n");
30 var it = mem.splitScalar(u8, stderr, '\n');
3131 process_lines: while (it.next()) |line| {
3232 if (line.len == 0) continue;
3333
tools/gen_outline_atomics.zig+1-1
......@@ -88,7 +88,7 @@ fn writeFunction(
8888 \\ asm volatile (
8989 \\
9090 );
91 var iter = std.mem.split(u8, body, "\n");
91 var iter = std.mem.splitScalar(u8, body, '\n');
9292 while (iter.next()) |line| {
9393 try w.writeAll(" \\\\");
9494 try w.writeAll(line);
tools/generate_linux_syscalls.zig+18-18
......@@ -51,11 +51,11 @@ pub fn main() !void {
5151 try writer.writeAll("pub const X86 = enum(usize) {\n");
5252
5353 const table = try linux_dir.readFile("arch/x86/entry/syscalls/syscall_32.tbl", buf);
54 var lines = mem.tokenize(u8, table, "\n");
54 var lines = mem.tokenizeScalar(u8, table, '\n');
5555 while (lines.next()) |line| {
5656 if (line[0] == '#') continue;
5757
58 var fields = mem.tokenize(u8, line, " \t");
58 var fields = mem.tokenizeAny(u8, line, " \t");
5959 const number = fields.next() orelse return error.Incomplete;
6060 // abi is always i386
6161 _ = fields.next() orelse return error.Incomplete;
......@@ -70,11 +70,11 @@ pub fn main() !void {
7070 try writer.writeAll("pub const X64 = enum(usize) {\n");
7171
7272 const table = try linux_dir.readFile("arch/x86/entry/syscalls/syscall_64.tbl", buf);
73 var lines = mem.tokenize(u8, table, "\n");
73 var lines = mem.tokenizeScalar(u8, table, '\n');
7474 while (lines.next()) |line| {
7575 if (line[0] == '#') continue;
7676
77 var fields = mem.tokenize(u8, line, " \t");
77 var fields = mem.tokenizeAny(u8, line, " \t");
7878 const number = fields.next() orelse return error.Incomplete;
7979 const abi = fields.next() orelse return error.Incomplete;
8080 // The x32 abi syscalls are always at the end.
......@@ -96,11 +96,11 @@ pub fn main() !void {
9696 );
9797
9898 const table = try linux_dir.readFile("arch/arm/tools/syscall.tbl", buf);
99 var lines = mem.tokenize(u8, table, "\n");
99 var lines = mem.tokenizeScalar(u8, table, '\n');
100100 while (lines.next()) |line| {
101101 if (line[0] == '#') continue;
102102
103 var fields = mem.tokenize(u8, line, " \t");
103 var fields = mem.tokenizeAny(u8, line, " \t");
104104 const number = fields.next() orelse return error.Incomplete;
105105 const abi = fields.next() orelse return error.Incomplete;
106106 if (mem.eql(u8, abi, "oabi")) continue;
......@@ -127,11 +127,11 @@ pub fn main() !void {
127127 {
128128 try writer.writeAll("pub const Sparc64 = enum(usize) {\n");
129129 const table = try linux_dir.readFile("arch/sparc/kernel/syscalls/syscall.tbl", buf);
130 var lines = mem.tokenize(u8, table, "\n");
130 var lines = mem.tokenizeScalar(u8, table, '\n');
131131 while (lines.next()) |line| {
132132 if (line[0] == '#') continue;
133133
134 var fields = mem.tokenize(u8, line, " \t");
134 var fields = mem.tokenizeAny(u8, line, " \t");
135135 const number = fields.next() orelse return error.Incomplete;
136136 const abi = fields.next() orelse return error.Incomplete;
137137 if (mem.eql(u8, abi, "32")) continue;
......@@ -151,11 +151,11 @@ pub fn main() !void {
151151 );
152152
153153 const table = try linux_dir.readFile("arch/mips/kernel/syscalls/syscall_o32.tbl", buf);
154 var lines = mem.tokenize(u8, table, "\n");
154 var lines = mem.tokenizeScalar(u8, table, '\n');
155155 while (lines.next()) |line| {
156156 if (line[0] == '#') continue;
157157
158 var fields = mem.tokenize(u8, line, " \t");
158 var fields = mem.tokenizeAny(u8, line, " \t");
159159 const number = fields.next() orelse return error.Incomplete;
160160 // abi is always o32
161161 _ = fields.next() orelse return error.Incomplete;
......@@ -176,11 +176,11 @@ pub fn main() !void {
176176 );
177177
178178 const table = try linux_dir.readFile("arch/mips/kernel/syscalls/syscall_n64.tbl", buf);
179 var lines = mem.tokenize(u8, table, "\n");
179 var lines = mem.tokenizeScalar(u8, table, '\n');
180180 while (lines.next()) |line| {
181181 if (line[0] == '#') continue;
182182
183 var fields = mem.tokenize(u8, line, " \t");
183 var fields = mem.tokenizeAny(u8, line, " \t");
184184 const number = fields.next() orelse return error.Incomplete;
185185 // abi is always n64
186186 _ = fields.next() orelse return error.Incomplete;
......@@ -197,11 +197,11 @@ pub fn main() !void {
197197
198198 const table = try linux_dir.readFile("arch/powerpc/kernel/syscalls/syscall.tbl", buf);
199199 var list_64 = std.ArrayList(u8).init(allocator);
200 var lines = mem.tokenize(u8, table, "\n");
200 var lines = mem.tokenizeScalar(u8, table, '\n');
201201 while (lines.next()) |line| {
202202 if (line[0] == '#') continue;
203203
204 var fields = mem.tokenize(u8, line, " \t");
204 var fields = mem.tokenizeAny(u8, line, " \t");
205205 const number = fields.next() orelse return error.Incomplete;
206206 const abi = fields.next() orelse return error.Incomplete;
207207 const name = fields.next() orelse return error.Incomplete;
......@@ -277,9 +277,9 @@ pub fn main() !void {
277277 },
278278 };
279279
280 var lines = mem.tokenize(u8, defines, "\n");
280 var lines = mem.tokenizeScalar(u8, defines, '\n');
281281 loop: while (lines.next()) |line| {
282 var fields = mem.tokenize(u8, line, " \t");
282 var fields = mem.tokenizeAny(u8, line, " \t");
283283 const cmd = fields.next() orelse return error.Incomplete;
284284 if (!mem.eql(u8, cmd, "#define")) continue;
285285 const define = fields.next() orelse return error.Incomplete;
......@@ -339,9 +339,9 @@ pub fn main() !void {
339339 },
340340 };
341341
342 var lines = mem.tokenize(u8, defines, "\n");
342 var lines = mem.tokenizeScalar(u8, defines, '\n');
343343 loop: while (lines.next()) |line| {
344 var fields = mem.tokenize(u8, line, " \t");
344 var fields = mem.tokenizeAny(u8, line, " \t");
345345 const cmd = fields.next() orelse return error.Incomplete;
346346 if (!mem.eql(u8, cmd, "#define")) continue;
347347 const define = fields.next() orelse return error.Incomplete;
tools/update_crc_catalog.zig+1-1
......@@ -78,7 +78,7 @@ pub fn main() anyerror!void {
7878 var residue: []const u8 = undefined;
7979 var name: []const u8 = undefined;
8080
81 var it = mem.split(u8, line, " ");
81 var it = mem.splitSequence(u8, line, " ");
8282 while (it.next()) |property| {
8383 const i = mem.indexOf(u8, property, "=").?;
8484 const key = property[0..i];
tools/update_spirv_features.zig+1-1
......@@ -19,7 +19,7 @@ const Version = struct {
1919 minor: u32,
2020
2121 fn parse(str: []const u8) !Version {
22 var it = std.mem.split(u8, str, ".");
22 var it = std.mem.splitScalar(u8, str, '.');
2323
2424 const major = it.first();
2525 const minor = it.next() orelse return error.InvalidVersion;