diff --git a/build.zig b/build.zig index 65175256a8..3abe5ff92b 100644 --- a/build.zig +++ b/build.zig @@ -412,7 +412,7 @@ fn findAndParseConfigH(b: *Builder) !Context { while (lines_it.next()) |line| { inline for (mappings) |mapping| { if (mem.startsWith(u8, line, mapping.prefix)) { - var it = mem.separate(line, "\""); + var it = mem.split(line, "\""); _ = it.next().?; // skip the stuff before the quote @field(ctx, mapping.field) = it.next().?; // the stuff inside the quote } diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig index 3dbd82b2b5..af8033ae91 100644 --- a/lib/std/builtin.zig +++ b/lib/std/builtin.zig @@ -424,7 +424,7 @@ pub const Version = struct { } pub fn parse(text: []const u8) !Version { - var it = std.mem.separate(text, "."); + var it = std.mem.split(text, "."); return Version{ .major = try std.fmt.parseInt(u32, it.next() orelse return error.InvalidVersion, 10), .minor = try std.fmt.parseInt(u32, it.next() orelse "0", 10), diff --git a/lib/std/mem.zig b/lib/std/mem.zig index f54eb03d65..f3220ba9fe 100644 --- a/lib/std/mem.zig +++ b/lib/std/mem.zig @@ -1141,7 +1141,7 @@ test "writeIntBig and writeIntLittle" { /// If `buffer` is empty, the iterator will return null. /// If `delimiter_bytes` does not exist in buffer, /// the iterator will return `buffer`, null, in that order. -/// See also the related function `separate`. +/// See also the related function `split`. pub fn tokenize(buffer: []const u8, delimiter_bytes: []const u8) TokenIterator { return TokenIterator{ .index = 0, @@ -1196,15 +1196,13 @@ test "mem.tokenize (multibyte)" { /// Returns an iterator that iterates over the slices of `buffer` that /// are separated by bytes in `delimiter`. -/// separate("abc|def||ghi", "|") +/// split("abc|def||ghi", "|") /// will return slices for "abc", "def", "", "ghi", null, in that order. /// If `delimiter` does not exist in buffer, /// the iterator will return `buffer`, null, in that order. /// The delimiter length must not be zero. /// See also the related function `tokenize`. -/// It is planned to rename this function to `split` before 1.0.0, like this: -/// pub fn split(buffer: []const u8, delimiter: []const u8) SplitIterator { -pub fn separate(buffer: []const u8, delimiter: []const u8) SplitIterator { +pub fn split(buffer: []const u8, delimiter: []const u8) SplitIterator { assert(delimiter.len != 0); return SplitIterator{ .index = 0, @@ -1213,30 +1211,32 @@ pub fn separate(buffer: []const u8, delimiter: []const u8) SplitIterator { }; } -test "mem.separate" { - var it = separate("abc|def||ghi", "|"); +pub const separate = @compileError("deprecated: renamed to split (behavior remains unchanged)"); + +test "mem.split" { + var it = split("abc|def||ghi", "|"); testing.expect(eql(u8, it.next().?, "abc")); testing.expect(eql(u8, it.next().?, "def")); testing.expect(eql(u8, it.next().?, "")); testing.expect(eql(u8, it.next().?, "ghi")); testing.expect(it.next() == null); - it = separate("", "|"); + it = split("", "|"); testing.expect(eql(u8, it.next().?, "")); testing.expect(it.next() == null); - it = separate("|", "|"); + it = split("|", "|"); testing.expect(eql(u8, it.next().?, "")); testing.expect(eql(u8, it.next().?, "")); testing.expect(it.next() == null); - it = separate("hello", " "); + it = split("hello", " "); testing.expect(eql(u8, it.next().?, "hello")); testing.expect(it.next() == null); } -test "mem.separate (multibyte)" { - var it = separate("a, b ,, c, d, e", ", "); +test "mem.split (multibyte)" { + var it = split("a, b ,, c, d, e", ", "); testing.expect(eql(u8, it.next().?, "a")); testing.expect(eql(u8, it.next().?, "b ,")); testing.expect(eql(u8, it.next().?, "c")); diff --git a/lib/std/net.zig b/lib/std/net.zig index f91b2b86aa..9e57aa500b 100644 --- a/lib/std/net.zig +++ b/lib/std/net.zig @@ -823,7 +823,7 @@ fn linuxLookupNameFromHosts( }, else => |e| return e, }) |line| { - const no_comment_line = mem.separate(line, "#").next().?; + const no_comment_line = mem.split(line, "#").next().?; var line_it = mem.tokenize(no_comment_line, " \t"); const ip_text = line_it.next() orelse continue; @@ -1020,13 +1020,13 @@ fn getResolvConf(allocator: *mem.Allocator, rc: *ResolvConf) !void { }, else => |e| return e, }) |line| { - const no_comment_line = mem.separate(line, "#").next().?; + const no_comment_line = mem.split(line, "#").next().?; var line_it = mem.tokenize(no_comment_line, " \t"); const token = line_it.next() orelse continue; if (mem.eql(u8, token, "options")) { while (line_it.next()) |sub_tok| { - var colon_it = mem.separate(sub_tok, ":"); + var colon_it = mem.split(sub_tok, ":"); const name = colon_it.next().?; const value_txt = colon_it.next() orelse continue; const value = std.fmt.parseInt(u8, value_txt, 10) catch |err| switch (err) { diff --git a/lib/std/process.zig b/lib/std/process.zig index 89e9cea8d6..b4baf49cf2 100644 --- a/lib/std/process.zig +++ b/lib/std/process.zig @@ -84,7 +84,7 @@ pub fn getEnvMap(allocator: *Allocator) !BufMap { for (environ) |env| { if (env) |ptr| { const pair = mem.spanZ(ptr); - var parts = mem.separate(pair, "="); + var parts = mem.split(pair, "="); const key = parts.next().?; const value = parts.next().?; try result.set(key, value); diff --git a/lib/std/zig/cross_target.zig b/lib/std/zig/cross_target.zig index 76aff2ae51..8783ddcb6d 100644 --- a/lib/std/zig/cross_target.zig +++ b/lib/std/zig/cross_target.zig @@ -224,7 +224,7 @@ pub const CrossTarget = struct { .dynamic_linker = DynamicLinker.init(args.dynamic_linker), }; - var it = mem.separate(args.arch_os_abi, "-"); + var it = mem.split(args.arch_os_abi, "-"); const arch_name = it.next().?; const arch_is_native = mem.eql(u8, arch_name, "native"); if (!arch_is_native) { @@ -242,7 +242,7 @@ pub const CrossTarget = struct { const opt_abi_text = it.next(); if (opt_abi_text) |abi_text| { - var abi_it = mem.separate(abi_text, "."); + var abi_it = mem.split(abi_text, "."); const abi = std.meta.stringToEnum(Target.Abi, abi_it.next().?) orelse return error.UnknownApplicationBinaryInterface; result.abi = abi; @@ -668,7 +668,7 @@ pub const CrossTarget = struct { } fn parseOs(result: *CrossTarget, diags: *ParseOptions.Diagnostics, text: []const u8) !void { - var it = mem.separate(text, "."); + var it = mem.split(text, "."); const os_name = it.next().?; diags.os_name = os_name; const os_is_native = mem.eql(u8, os_name, "native"); @@ -722,7 +722,7 @@ pub const CrossTarget = struct { .linux, .dragonfly, => { - var range_it = mem.separate(version_text, "..."); + var range_it = mem.split(version_text, "..."); const min_text = range_it.next().?; const min_ver = SemVer.parse(min_text) catch |err| switch (err) { @@ -742,7 +742,7 @@ pub const CrossTarget = struct { }, .windows => { - var range_it = mem.separate(version_text, "..."); + var range_it = mem.split(version_text, "..."); const min_text = range_it.next().?; const min_ver = std.meta.stringToEnum(Target.Os.WindowsVersion, min_text) orelse diff --git a/src-self-hosted/libc_installation.zig b/src-self-hosted/libc_installation.zig index db9db64a67..943405310c 100644 --- a/src-self-hosted/libc_installation.zig +++ b/src-self-hosted/libc_installation.zig @@ -61,7 +61,7 @@ pub const LibCInstallation = struct { var it = std.mem.tokenize(contents, "\n"); while (it.next()) |line| { if (line.len == 0 or line[0] == '#') continue; - var line_it = std.mem.separate(line, "="); + var line_it = std.mem.split(line, "="); const name = line_it.next() orelse { try stderr.print("missing equal sign after field name\n", .{}); return error.ParseError; diff --git a/src-self-hosted/main.zig b/src-self-hosted/main.zig index fb96e0260a..b7535fca6f 100644 --- a/src-self-hosted/main.zig +++ b/src-self-hosted/main.zig @@ -403,7 +403,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co const root_name = if (provided_name) |n| n else blk: { if (root_src_file) |file| { const basename = fs.path.basename(file); - var it = mem.separate(basename, "."); + var it = mem.split(basename, "."); break :blk it.next() orelse basename; } else { try stderr.writeAll("--name [name] not provided and unable to infer\n"); diff --git a/test/tests.zig b/test/tests.zig index e66ae7296a..d88c84502d 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -657,7 +657,7 @@ pub const StackTracesContext = struct { var buf = ArrayList(u8).init(b.allocator); defer buf.deinit(); if (stderr.len != 0 and stderr[stderr.len - 1] == '\n') stderr = stderr[0 .. stderr.len - 1]; - var it = mem.separate(stderr, "\n"); + var it = mem.split(stderr, "\n"); process_lines: while (it.next()) |line| { if (line.len == 0) continue; const delims = [_][]const u8{ ":", ":", ":", " in " }; @@ -750,7 +750,7 @@ pub const CompileErrorContext = struct { const source_file = "tmp.zig"; fn init(input: []const u8) ErrLineIter { - return ErrLineIter{ .lines = mem.separate(input, "\n") }; + return ErrLineIter{ .lines = mem.split(input, "\n") }; } fn next(self: *ErrLineIter) ?[]const u8 {