authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2025-04-13 17:49:16 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2025-04-13 17:54:28 -07:00
loga15274495b0ad14423bff47b9caa7d2a5ab04eef
treed13cefbb45a2379ceea86022673e835ba05cc6e4
parent5a04adea0d459efc2ea2f15e4ceac0d5277d86fd

use splitScalar where possible


4 files changed, 15 insertions(+), 15 deletions(-)

src/common.zig+5-5
......@@ -127,10 +127,10 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !
127127 },
128128 .git => {
129129 if (d.version.len > 0) {
130 const vers = u.parse_split(zigmod.Dep.Type.Version.Git, "-").do(d.version) catch |e| switch (e) {
130 const vers = u.parse_split(zigmod.Dep.Type.Version.Git, '-').do(d.version) catch |e| switch (e) {
131131 error.IterEmpty => unreachable,
132132 error.NoMemberFound => {
133 const vtype = d.version[0..std.mem.indexOf(u8, d.version, "-").?];
133 const vtype = d.version[0..std.mem.indexOfScalar(u8, d.version, '-').?];
134134 u.fail("fetch: git: version type '{s}' is invalid.", .{vtype});
135135 },
136136 };
......@@ -179,7 +179,7 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !
179179 if (try extras.doesFolderExist(null, pv)) {
180180 return pv;
181181 }
182 const file_name = u.last(try u.split(options.alloc, d.path, "/")).?;
182 const file_name = u.last(try u.split(options.alloc, d.path, '/')).?;
183183 if (d.version.len > 0) {
184184 if (try extras.doesFolderExist(null, pv)) {
185185 return pv;
......@@ -338,7 +338,7 @@ pub fn parse_lockfile(alloc: std.mem.Allocator, dir: std.fs.Dir) ![]const [4]str
338338 }
339339 switch (v) {
340340 1 => {
341 var iter = std.mem.split(u8, line, " ");
341 var iter = std.mem.splitScalar(u8, line, ' ');
342342 try list.append([4]string{
343343 iter.next().?,
344344 iter.next().?,
......@@ -347,7 +347,7 @@ pub fn parse_lockfile(alloc: std.mem.Allocator, dir: std.fs.Dir) ![]const [4]str
347347 });
348348 },
349349 2 => {
350 var iter = std.mem.split(u8, line, " ");
350 var iter = std.mem.splitScalar(u8, line, ' ');
351351 const asdep = zigmod.Dep{
352352 .type = std.meta.stringToEnum(zigmod.Dep.Type, iter.next().?).?,
353353 .path = iter.next().?,
src/util/dep.zig+1-1
......@@ -71,7 +71,7 @@ pub const Dep = struct {
7171 }
7272 return switch (self.type) {
7373 .git => blk: {
74 const vers = try u.parse_split(zigmod.Dep.Type.Version.Git, "-").do(self.version);
74 const vers = try u.parse_split(zigmod.Dep.Type.Version.Git, '-').do(self.version);
7575 if (vers.id.frozen()) break :blk self.version;
7676 break :blk try self.type.exact_version(alloc, dpath);
7777 },
src/util/funcs.zig+6-6
......@@ -36,11 +36,11 @@ pub fn try_index(comptime T: type, array: []T, n: usize, def: T) T {
3636 return array[n];
3737}
3838
39pub fn split(alloc: std.mem.Allocator, in: string, delim: string) ![]string {
39pub fn split(alloc: std.mem.Allocator, in: string, delim: u8) ![]string {
4040 var list = std.ArrayList(string).init(alloc);
4141 errdefer list.deinit();
4242
43 var iter = std.mem.split(u8, in, delim);
43 var iter = std.mem.splitScalar(u8, in, delim);
4444 while (iter.next()) |str| {
4545 try list.append(str);
4646 }
......@@ -99,7 +99,7 @@ pub fn random_string(comptime len: usize) [len]u8 {
9999 return buf;
100100}
101101
102pub fn parse_split(comptime T: type, comptime delim: string) type {
102pub fn parse_split(comptime T: type, comptime delim: u8) type {
103103 return struct {
104104 const Self = @This();
105105
......@@ -107,7 +107,7 @@ pub fn parse_split(comptime T: type, comptime delim: string) type {
107107 string: string,
108108
109109 pub fn do(input: string) !Self {
110 var iter = std.mem.split(u8, input, delim);
110 var iter = std.mem.splitScalar(u8, input, delim);
111111 const start = iter.next() orelse return error.IterEmpty;
112112 const id = std.meta.stringToEnum(T, start) orelse return error.NoMemberFound;
113113 return Self{
......@@ -125,7 +125,7 @@ pub const HashFn = enum {
125125};
126126
127127pub fn validate_hash(alloc: std.mem.Allocator, input: string, file_path: string) !bool {
128 const hash = parse_split(HashFn, "-").do(input) catch return false;
128 const hash = parse_split(HashFn, '-').do(input) catch return false;
129129 const file = try std.fs.cwd().openFile(file_path, .{});
130130 defer file.close();
131131 const data = try file.reader().readAllAlloc(alloc, gb);
......@@ -169,7 +169,7 @@ pub fn detect_pkgname(alloc: std.mem.Allocator, override: string, dir: string) !
169169 return error.NoBuildZig;
170170 }
171171 const dpath = try std.fs.realpathAlloc(alloc, try std.fs.path.join(alloc, &.{ dir, "build.zig" }));
172 const splitP = try split(alloc, dpath, std.fs.path.sep_str);
172 const splitP = try split(alloc, dpath, std.fs.path.sep);
173173 var name = splitP[splitP.len - 2];
174174 name = extras.trimPrefix(name, "zig-");
175175 assert(name.len > 0, "package name must not be an empty string", .{});
src/util/modfile.zig+3-3
......@@ -93,7 +93,7 @@ pub const ModFile = struct {
9393 var main = item.mapping.get_string("main") orelse "";
9494
9595 if (item.mapping.get("src")) |val| {
96 var src_iter = std.mem.tokenize(u8, val.string, " ");
96 var src_iter = std.mem.tokenizeScalar(u8, val.string, ' ');
9797 dtype = src_iter.next().?;
9898 path = src_iter.next().?;
9999 if (src_iter.next()) |dver| {
......@@ -130,8 +130,8 @@ pub const ModFile = struct {
130130 .c_include_dirs = try item.mapping.get_string_array(alloc, "c_include_dirs"),
131131 .c_source_flags = try item.mapping.get_string_array(alloc, "c_source_flags"),
132132 .c_source_files = try item.mapping.get_string_array(alloc, "c_source_files"),
133 .only_os = try u.list_remove(alloc, try u.split(alloc, item.mapping.get_string("only_os") orelse "", ","), ""),
134 .except_os = try u.list_remove(alloc, try u.split(alloc, item.mapping.get_string("except_os") orelse "", ","), ""),
133 .only_os = try u.list_remove(alloc, try u.split(alloc, item.mapping.get_string("only_os") orelse "", ','), ""),
134 .except_os = try u.list_remove(alloc, try u.split(alloc, item.mapping.get_string("except_os") orelse "", ','), ""),
135135 .yaml = item.mapping,
136136 .deps = try dep_list_by_name(alloc, item.mapping, &.{"dependencies"}, for_build),
137137 .keep = std.mem.eql(u8, "true", item.mapping.get_string("keep") orelse ""),