mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
rename mem.separate to mem.split
This commit is contained in:
parent
e5d479b06e
commit
cd20e0cc67
@ -412,7 +412,7 @@ fn findAndParseConfigH(b: *Builder) !Context {
|
|||||||
while (lines_it.next()) |line| {
|
while (lines_it.next()) |line| {
|
||||||
inline for (mappings) |mapping| {
|
inline for (mappings) |mapping| {
|
||||||
if (mem.startsWith(u8, line, mapping.prefix)) {
|
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
|
_ = it.next().?; // skip the stuff before the quote
|
||||||
@field(ctx, mapping.field) = it.next().?; // the stuff inside the quote
|
@field(ctx, mapping.field) = it.next().?; // the stuff inside the quote
|
||||||
}
|
}
|
||||||
|
|||||||
@ -424,7 +424,7 @@ pub const Version = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse(text: []const u8) !Version {
|
pub fn parse(text: []const u8) !Version {
|
||||||
var it = std.mem.separate(text, ".");
|
var it = std.mem.split(text, ".");
|
||||||
return Version{
|
return Version{
|
||||||
.major = try std.fmt.parseInt(u32, it.next() orelse return error.InvalidVersion, 10),
|
.major = try std.fmt.parseInt(u32, it.next() orelse return error.InvalidVersion, 10),
|
||||||
.minor = try std.fmt.parseInt(u32, it.next() orelse "0", 10),
|
.minor = try std.fmt.parseInt(u32, it.next() orelse "0", 10),
|
||||||
|
|||||||
@ -1141,7 +1141,7 @@ test "writeIntBig and writeIntLittle" {
|
|||||||
/// If `buffer` is empty, the iterator will return null.
|
/// If `buffer` is empty, the iterator will return null.
|
||||||
/// If `delimiter_bytes` does not exist in buffer,
|
/// If `delimiter_bytes` does not exist in buffer,
|
||||||
/// the iterator will return `buffer`, null, in that order.
|
/// 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 {
|
pub fn tokenize(buffer: []const u8, delimiter_bytes: []const u8) TokenIterator {
|
||||||
return TokenIterator{
|
return TokenIterator{
|
||||||
.index = 0,
|
.index = 0,
|
||||||
@ -1196,15 +1196,13 @@ test "mem.tokenize (multibyte)" {
|
|||||||
|
|
||||||
/// Returns an iterator that iterates over the slices of `buffer` that
|
/// Returns an iterator that iterates over the slices of `buffer` that
|
||||||
/// are separated by bytes in `delimiter`.
|
/// 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.
|
/// will return slices for "abc", "def", "", "ghi", null, in that order.
|
||||||
/// If `delimiter` does not exist in buffer,
|
/// If `delimiter` does not exist in buffer,
|
||||||
/// the iterator will return `buffer`, null, in that order.
|
/// the iterator will return `buffer`, null, in that order.
|
||||||
/// The delimiter length must not be zero.
|
/// The delimiter length must not be zero.
|
||||||
/// See also the related function `tokenize`.
|
/// 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 split(buffer: []const u8, delimiter: []const u8) SplitIterator {
|
|
||||||
pub fn separate(buffer: []const u8, delimiter: []const u8) SplitIterator {
|
|
||||||
assert(delimiter.len != 0);
|
assert(delimiter.len != 0);
|
||||||
return SplitIterator{
|
return SplitIterator{
|
||||||
.index = 0,
|
.index = 0,
|
||||||
@ -1213,30 +1211,32 @@ pub fn separate(buffer: []const u8, delimiter: []const u8) SplitIterator {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
test "mem.separate" {
|
pub const separate = @compileError("deprecated: renamed to split (behavior remains unchanged)");
|
||||||
var it = separate("abc|def||ghi", "|");
|
|
||||||
|
test "mem.split" {
|
||||||
|
var it = split("abc|def||ghi", "|");
|
||||||
testing.expect(eql(u8, it.next().?, "abc"));
|
testing.expect(eql(u8, it.next().?, "abc"));
|
||||||
testing.expect(eql(u8, it.next().?, "def"));
|
testing.expect(eql(u8, it.next().?, "def"));
|
||||||
testing.expect(eql(u8, it.next().?, ""));
|
testing.expect(eql(u8, it.next().?, ""));
|
||||||
testing.expect(eql(u8, it.next().?, "ghi"));
|
testing.expect(eql(u8, it.next().?, "ghi"));
|
||||||
testing.expect(it.next() == null);
|
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);
|
testing.expect(it.next() == null);
|
||||||
|
|
||||||
it = separate("|", "|");
|
it = split("|", "|");
|
||||||
testing.expect(eql(u8, it.next().?, ""));
|
testing.expect(eql(u8, it.next().?, ""));
|
||||||
testing.expect(eql(u8, it.next().?, ""));
|
testing.expect(eql(u8, it.next().?, ""));
|
||||||
testing.expect(it.next() == null);
|
testing.expect(it.next() == null);
|
||||||
|
|
||||||
it = separate("hello", " ");
|
it = split("hello", " ");
|
||||||
testing.expect(eql(u8, it.next().?, "hello"));
|
testing.expect(eql(u8, it.next().?, "hello"));
|
||||||
testing.expect(it.next() == null);
|
testing.expect(it.next() == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "mem.separate (multibyte)" {
|
test "mem.split (multibyte)" {
|
||||||
var it = separate("a, b ,, c, d, e", ", ");
|
var it = split("a, b ,, c, d, e", ", ");
|
||||||
testing.expect(eql(u8, it.next().?, "a"));
|
testing.expect(eql(u8, it.next().?, "a"));
|
||||||
testing.expect(eql(u8, it.next().?, "b ,"));
|
testing.expect(eql(u8, it.next().?, "b ,"));
|
||||||
testing.expect(eql(u8, it.next().?, "c"));
|
testing.expect(eql(u8, it.next().?, "c"));
|
||||||
|
|||||||
@ -823,7 +823,7 @@ fn linuxLookupNameFromHosts(
|
|||||||
},
|
},
|
||||||
else => |e| return e,
|
else => |e| return e,
|
||||||
}) |line| {
|
}) |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");
|
var line_it = mem.tokenize(no_comment_line, " \t");
|
||||||
const ip_text = line_it.next() orelse continue;
|
const ip_text = line_it.next() orelse continue;
|
||||||
@ -1020,13 +1020,13 @@ fn getResolvConf(allocator: *mem.Allocator, rc: *ResolvConf) !void {
|
|||||||
},
|
},
|
||||||
else => |e| return e,
|
else => |e| return e,
|
||||||
}) |line| {
|
}) |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");
|
var line_it = mem.tokenize(no_comment_line, " \t");
|
||||||
|
|
||||||
const token = line_it.next() orelse continue;
|
const token = line_it.next() orelse continue;
|
||||||
if (mem.eql(u8, token, "options")) {
|
if (mem.eql(u8, token, "options")) {
|
||||||
while (line_it.next()) |sub_tok| {
|
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 name = colon_it.next().?;
|
||||||
const value_txt = colon_it.next() orelse continue;
|
const value_txt = colon_it.next() orelse continue;
|
||||||
const value = std.fmt.parseInt(u8, value_txt, 10) catch |err| switch (err) {
|
const value = std.fmt.parseInt(u8, value_txt, 10) catch |err| switch (err) {
|
||||||
|
|||||||
@ -84,7 +84,7 @@ pub fn getEnvMap(allocator: *Allocator) !BufMap {
|
|||||||
for (environ) |env| {
|
for (environ) |env| {
|
||||||
if (env) |ptr| {
|
if (env) |ptr| {
|
||||||
const pair = mem.spanZ(ptr);
|
const pair = mem.spanZ(ptr);
|
||||||
var parts = mem.separate(pair, "=");
|
var parts = mem.split(pair, "=");
|
||||||
const key = parts.next().?;
|
const key = parts.next().?;
|
||||||
const value = parts.next().?;
|
const value = parts.next().?;
|
||||||
try result.set(key, value);
|
try result.set(key, value);
|
||||||
|
|||||||
@ -224,7 +224,7 @@ pub const CrossTarget = struct {
|
|||||||
.dynamic_linker = DynamicLinker.init(args.dynamic_linker),
|
.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_name = it.next().?;
|
||||||
const arch_is_native = mem.eql(u8, arch_name, "native");
|
const arch_is_native = mem.eql(u8, arch_name, "native");
|
||||||
if (!arch_is_native) {
|
if (!arch_is_native) {
|
||||||
@ -242,7 +242,7 @@ pub const CrossTarget = struct {
|
|||||||
|
|
||||||
const opt_abi_text = it.next();
|
const opt_abi_text = it.next();
|
||||||
if (opt_abi_text) |abi_text| {
|
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
|
const abi = std.meta.stringToEnum(Target.Abi, abi_it.next().?) orelse
|
||||||
return error.UnknownApplicationBinaryInterface;
|
return error.UnknownApplicationBinaryInterface;
|
||||||
result.abi = abi;
|
result.abi = abi;
|
||||||
@ -668,7 +668,7 @@ pub const CrossTarget = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn parseOs(result: *CrossTarget, diags: *ParseOptions.Diagnostics, text: []const u8) !void {
|
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().?;
|
const os_name = it.next().?;
|
||||||
diags.os_name = os_name;
|
diags.os_name = os_name;
|
||||||
const os_is_native = mem.eql(u8, os_name, "native");
|
const os_is_native = mem.eql(u8, os_name, "native");
|
||||||
@ -722,7 +722,7 @@ pub const CrossTarget = struct {
|
|||||||
.linux,
|
.linux,
|
||||||
.dragonfly,
|
.dragonfly,
|
||||||
=> {
|
=> {
|
||||||
var range_it = mem.separate(version_text, "...");
|
var range_it = mem.split(version_text, "...");
|
||||||
|
|
||||||
const min_text = range_it.next().?;
|
const min_text = range_it.next().?;
|
||||||
const min_ver = SemVer.parse(min_text) catch |err| switch (err) {
|
const min_ver = SemVer.parse(min_text) catch |err| switch (err) {
|
||||||
@ -742,7 +742,7 @@ pub const CrossTarget = struct {
|
|||||||
},
|
},
|
||||||
|
|
||||||
.windows => {
|
.windows => {
|
||||||
var range_it = mem.separate(version_text, "...");
|
var range_it = mem.split(version_text, "...");
|
||||||
|
|
||||||
const min_text = range_it.next().?;
|
const min_text = range_it.next().?;
|
||||||
const min_ver = std.meta.stringToEnum(Target.Os.WindowsVersion, min_text) orelse
|
const min_ver = std.meta.stringToEnum(Target.Os.WindowsVersion, min_text) orelse
|
||||||
|
|||||||
@ -61,7 +61,7 @@ pub const LibCInstallation = struct {
|
|||||||
var it = std.mem.tokenize(contents, "\n");
|
var it = std.mem.tokenize(contents, "\n");
|
||||||
while (it.next()) |line| {
|
while (it.next()) |line| {
|
||||||
if (line.len == 0 or line[0] == '#') continue;
|
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 {
|
const name = line_it.next() orelse {
|
||||||
try stderr.print("missing equal sign after field name\n", .{});
|
try stderr.print("missing equal sign after field name\n", .{});
|
||||||
return error.ParseError;
|
return error.ParseError;
|
||||||
|
|||||||
@ -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: {
|
const root_name = if (provided_name) |n| n else blk: {
|
||||||
if (root_src_file) |file| {
|
if (root_src_file) |file| {
|
||||||
const basename = fs.path.basename(file);
|
const basename = fs.path.basename(file);
|
||||||
var it = mem.separate(basename, ".");
|
var it = mem.split(basename, ".");
|
||||||
break :blk it.next() orelse basename;
|
break :blk it.next() orelse basename;
|
||||||
} else {
|
} else {
|
||||||
try stderr.writeAll("--name [name] not provided and unable to infer\n");
|
try stderr.writeAll("--name [name] not provided and unable to infer\n");
|
||||||
|
|||||||
@ -657,7 +657,7 @@ pub const StackTracesContext = struct {
|
|||||||
var buf = ArrayList(u8).init(b.allocator);
|
var buf = ArrayList(u8).init(b.allocator);
|
||||||
defer buf.deinit();
|
defer buf.deinit();
|
||||||
if (stderr.len != 0 and stderr[stderr.len - 1] == '\n') stderr = stderr[0 .. stderr.len - 1];
|
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| {
|
process_lines: while (it.next()) |line| {
|
||||||
if (line.len == 0) continue;
|
if (line.len == 0) continue;
|
||||||
const delims = [_][]const u8{ ":", ":", ":", " in " };
|
const delims = [_][]const u8{ ":", ":", ":", " in " };
|
||||||
@ -750,7 +750,7 @@ pub const CompileErrorContext = struct {
|
|||||||
const source_file = "tmp.zig";
|
const source_file = "tmp.zig";
|
||||||
|
|
||||||
fn init(input: []const u8) ErrLineIter {
|
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 {
|
fn next(self: *ErrLineIter) ?[]const u8 {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user