authorgravatar for 14938807+xackus@users.noreply.github.comxackus <14938807+xackus@users.noreply.github.com> 2020-04-04 19:15:08+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-04-04 17:37:51-04:00
logcd20e0cc672249555709e1b58a415ddd50b03ad9
tree38f017bc3a4f7adbf7c3a1463ba66d3a1ab9569f
parente5d479b06e74e04b3ef3108e6098424b2130cbe5

rename mem.separate to mem.split


9 files changed, 27 insertions(+), 27 deletions(-)

build.zig+1-1
......@@ -412,7 +412,7 @@ fn findAndParseConfigH(b: *Builder) !Context {
412412 while (lines_it.next()) |line| {
413413 inline for (mappings) |mapping| {
414414 if (mem.startsWith(u8, line, mapping.prefix)) {
415 var it = mem.separate(line, "\"");
415 var it = mem.split(line, "\"");
416416 _ = it.next().?; // skip the stuff before the quote
417417 @field(ctx, mapping.field) = it.next().?; // the stuff inside the quote
418418 }
lib/std/builtin.zig+1-1
......@@ -424,7 +424,7 @@ pub const Version = struct {
424424 }
425425
426426 pub fn parse(text: []const u8) !Version {
427 var it = std.mem.separate(text, ".");
427 var it = std.mem.split(text, ".");
428428 return Version{
429429 .major = try std.fmt.parseInt(u32, it.next() orelse return error.InvalidVersion, 10),
430430 .minor = try std.fmt.parseInt(u32, it.next() orelse "0", 10),
lib/std/mem.zig+12-12
......@@ -1141,7 +1141,7 @@ test "writeIntBig and writeIntLittle" {
11411141/// If `buffer` is empty, the iterator will return null.
11421142/// If `delimiter_bytes` does not exist in buffer,
11431143/// the iterator will return `buffer`, null, in that order.
1144/// See also the related function `separate`.
1144/// See also the related function `split`.
11451145pub fn tokenize(buffer: []const u8, delimiter_bytes: []const u8) TokenIterator {
11461146 return TokenIterator{
11471147 .index = 0,
......@@ -1196,15 +1196,13 @@ test "mem.tokenize (multibyte)" {
11961196
11971197/// Returns an iterator that iterates over the slices of `buffer` that
11981198/// are separated by bytes in `delimiter`.
1199/// separate("abc|def||ghi", "|")
1199/// split("abc|def||ghi", "|")
12001200/// will return slices for "abc", "def", "", "ghi", null, in that order.
12011201/// If `delimiter` does not exist in buffer,
12021202/// the iterator will return `buffer`, null, in that order.
12031203/// The delimiter length must not be zero.
12041204/// See also the related function `tokenize`.
1205/// It is planned to rename this function to `split` before 1.0.0, like this:
1206/// pub fn split(buffer: []const u8, delimiter: []const u8) SplitIterator {
1207pub fn separate(buffer: []const u8, delimiter: []const u8) SplitIterator {
1205pub fn split(buffer: []const u8, delimiter: []const u8) SplitIterator {
12081206 assert(delimiter.len != 0);
12091207 return SplitIterator{
12101208 .index = 0,
......@@ -1213,30 +1211,32 @@ pub fn separate(buffer: []const u8, delimiter: []const u8) SplitIterator {
12131211 };
12141212}
12151213
1216test "mem.separate" {
1217 var it = separate("abc|def||ghi", "|");
1214pub const separate = @compileError("deprecated: renamed to split (behavior remains unchanged)");
1215
1216test "mem.split" {
1217 var it = split("abc|def||ghi", "|");
12181218 testing.expect(eql(u8, it.next().?, "abc"));
12191219 testing.expect(eql(u8, it.next().?, "def"));
12201220 testing.expect(eql(u8, it.next().?, ""));
12211221 testing.expect(eql(u8, it.next().?, "ghi"));
12221222 testing.expect(it.next() == null);
12231223
1224 it = separate("", "|");
1224 it = split("", "|");
12251225 testing.expect(eql(u8, it.next().?, ""));
12261226 testing.expect(it.next() == null);
12271227
1228 it = separate("|", "|");
1228 it = split("|", "|");
12291229 testing.expect(eql(u8, it.next().?, ""));
12301230 testing.expect(eql(u8, it.next().?, ""));
12311231 testing.expect(it.next() == null);
12321232
1233 it = separate("hello", " ");
1233 it = split("hello", " ");
12341234 testing.expect(eql(u8, it.next().?, "hello"));
12351235 testing.expect(it.next() == null);
12361236}
12371237
1238test "mem.separate (multibyte)" {
1239 var it = separate("a, b ,, c, d, e", ", ");
1238test "mem.split (multibyte)" {
1239 var it = split("a, b ,, c, d, e", ", ");
12401240 testing.expect(eql(u8, it.next().?, "a"));
12411241 testing.expect(eql(u8, it.next().?, "b ,"));
12421242 testing.expect(eql(u8, it.next().?, "c"));
lib/std/net.zig+3-3
......@@ -823,7 +823,7 @@ fn linuxLookupNameFromHosts(
823823 },
824824 else => |e| return e,
825825 }) |line| {
826 const no_comment_line = mem.separate(line, "#").next().?;
826 const no_comment_line = mem.split(line, "#").next().?;
827827
828828 var line_it = mem.tokenize(no_comment_line, " \t");
829829 const ip_text = line_it.next() orelse continue;
......@@ -1020,13 +1020,13 @@ fn getResolvConf(allocator: *mem.Allocator, rc: *ResolvConf) !void {
10201020 },
10211021 else => |e| return e,
10221022 }) |line| {
1023 const no_comment_line = mem.separate(line, "#").next().?;
1023 const no_comment_line = mem.split(line, "#").next().?;
10241024 var line_it = mem.tokenize(no_comment_line, " \t");
10251025
10261026 const token = line_it.next() orelse continue;
10271027 if (mem.eql(u8, token, "options")) {
10281028 while (line_it.next()) |sub_tok| {
1029 var colon_it = mem.separate(sub_tok, ":");
1029 var colon_it = mem.split(sub_tok, ":");
10301030 const name = colon_it.next().?;
10311031 const value_txt = colon_it.next() orelse continue;
10321032 const value = std.fmt.parseInt(u8, value_txt, 10) catch |err| switch (err) {
lib/std/process.zig+1-1
......@@ -84,7 +84,7 @@ pub fn getEnvMap(allocator: *Allocator) !BufMap {
8484 for (environ) |env| {
8585 if (env) |ptr| {
8686 const pair = mem.spanZ(ptr);
87 var parts = mem.separate(pair, "=");
87 var parts = mem.split(pair, "=");
8888 const key = parts.next().?;
8989 const value = parts.next().?;
9090 try result.set(key, value);
lib/std/zig/cross_target.zig+5-5
......@@ -224,7 +224,7 @@ pub const CrossTarget = struct {
224224 .dynamic_linker = DynamicLinker.init(args.dynamic_linker),
225225 };
226226
227 var it = mem.separate(args.arch_os_abi, "-");
227 var it = mem.split(args.arch_os_abi, "-");
228228 const arch_name = it.next().?;
229229 const arch_is_native = mem.eql(u8, arch_name, "native");
230230 if (!arch_is_native) {
......@@ -242,7 +242,7 @@ pub const CrossTarget = struct {
242242
243243 const opt_abi_text = it.next();
244244 if (opt_abi_text) |abi_text| {
245 var abi_it = mem.separate(abi_text, ".");
245 var abi_it = mem.split(abi_text, ".");
246246 const abi = std.meta.stringToEnum(Target.Abi, abi_it.next().?) orelse
247247 return error.UnknownApplicationBinaryInterface;
248248 result.abi = abi;
......@@ -668,7 +668,7 @@ pub const CrossTarget = struct {
668668 }
669669
670670 fn parseOs(result: *CrossTarget, diags: *ParseOptions.Diagnostics, text: []const u8) !void {
671 var it = mem.separate(text, ".");
671 var it = mem.split(text, ".");
672672 const os_name = it.next().?;
673673 diags.os_name = os_name;
674674 const os_is_native = mem.eql(u8, os_name, "native");
......@@ -722,7 +722,7 @@ pub const CrossTarget = struct {
722722 .linux,
723723 .dragonfly,
724724 => {
725 var range_it = mem.separate(version_text, "...");
725 var range_it = mem.split(version_text, "...");
726726
727727 const min_text = range_it.next().?;
728728 const min_ver = SemVer.parse(min_text) catch |err| switch (err) {
......@@ -742,7 +742,7 @@ pub const CrossTarget = struct {
742742 },
743743
744744 .windows => {
745 var range_it = mem.separate(version_text, "...");
745 var range_it = mem.split(version_text, "...");
746746
747747 const min_text = range_it.next().?;
748748 const min_ver = std.meta.stringToEnum(Target.Os.WindowsVersion, min_text) orelse
src-self-hosted/libc_installation.zig+1-1
......@@ -61,7 +61,7 @@ pub const LibCInstallation = struct {
6161 var it = std.mem.tokenize(contents, "\n");
6262 while (it.next()) |line| {
6363 if (line.len == 0 or line[0] == '#') continue;
64 var line_it = std.mem.separate(line, "=");
64 var line_it = std.mem.split(line, "=");
6565 const name = line_it.next() orelse {
6666 try stderr.print("missing equal sign after field name\n", .{});
6767 return error.ParseError;
src-self-hosted/main.zig+1-1
......@@ -403,7 +403,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co
403403 const root_name = if (provided_name) |n| n else blk: {
404404 if (root_src_file) |file| {
405405 const basename = fs.path.basename(file);
406 var it = mem.separate(basename, ".");
406 var it = mem.split(basename, ".");
407407 break :blk it.next() orelse basename;
408408 } else {
409409 try stderr.writeAll("--name [name] not provided and unable to infer\n");
test/tests.zig+2-2
......@@ -657,7 +657,7 @@ pub const StackTracesContext = struct {
657657 var buf = ArrayList(u8).init(b.allocator);
658658 defer buf.deinit();
659659 if (stderr.len != 0 and stderr[stderr.len - 1] == '\n') stderr = stderr[0 .. stderr.len - 1];
660 var it = mem.separate(stderr, "\n");
660 var it = mem.split(stderr, "\n");
661661 process_lines: while (it.next()) |line| {
662662 if (line.len == 0) continue;
663663 const delims = [_][]const u8{ ":", ":", ":", " in " };
......@@ -750,7 +750,7 @@ pub const CompileErrorContext = struct {
750750 const source_file = "tmp.zig";
751751
752752 fn init(input: []const u8) ErrLineIter {
753 return ErrLineIter{ .lines = mem.separate(input, "\n") };
753 return ErrLineIter{ .lines = mem.split(input, "\n") };
754754 }
755755
756756 fn next(self: *ErrLineIter) ?[]const u8 {