diff --git a/src/util/funcs.zig b/src/util/funcs.zig index a0b27bc5482f187556325a58f4f97bda865c1a79..96def941d4b7c6e4fd1405c769e57c4bfe927dcf 100644 --- a/src/util/funcs.zig +++ b/src/util/funcs.zig @@ -79,7 +79,7 @@ pub fn does_folder_exist(fpath: string) !bool { return true; } -pub fn _join(comptime delim: string, comptime xs: []string) string { +pub fn _join(comptime delim: string, comptime xs: []const string) string { var buf: string = ""; for (xs) |x, i| { buf = buf ++ x; @@ -96,12 +96,13 @@ pub fn trim_suffix(in: string, suffix: string) string { } pub fn repeat(s: string, times: i32) !string { - var list = std.ArrayList(string).init(gpa); + var list = std.ArrayList(u8).init(gpa); + defer list.deinit(); var i: i32 = 0; while (i < times) : (i += 1) { - try list.append(s); + try list.appendSlice(s); } - return try std.mem.join(gpa, "", list.items); + return list.toOwnedSlice(); } pub fn list_contains(haystack: []const string, needle: string) bool { @@ -122,7 +123,10 @@ pub fn list_contains_gen(comptime T: type, haystack: []const T, needle: T) bool return false; } -pub fn file_list(dpath: string, list: *std.ArrayList(string)) !void { +pub fn file_list(dpath: string) ![]const string { + var list = std.ArrayList(string).init(gpa); + defer list.deinit(); + const dir = try std.fs.cwd().openDir(dpath, .{ .iterate = true }); var walk = try dir.walk(gpa); defer walk.deinit(); @@ -136,6 +140,7 @@ pub fn file_list(dpath: string, list: *std.ArrayList(string)) !void { break; } } + return list.toOwnedSlice(); } pub fn run_cmd_raw(dir: ?string, args: []const string) !std.ChildProcess.ExecResult { @@ -186,7 +191,7 @@ pub fn random_string(len: usize) !string { return buf; } -pub fn parse_split(comptime T: type, delim: string) type { +pub fn parse_split(comptime T: type, comptime delim: string) type { return struct { const Self = @This(); @@ -195,8 +200,10 @@ pub fn parse_split(comptime T: type, delim: string) type { pub fn do(input: string) !Self { var iter = std.mem.split(u8, input, delim); + const start = iter.next() orelse return error.IterEmpty; + const id = std.meta.stringToEnum(T, start) orelse return error.NoMemberFound; return Self{ - .id = std.meta.stringToEnum(T, iter.next() orelse return error.IterEmpty) orelse return error.NoMemberFound, + .id = id, .string = iter.rest(), }; } diff --git a/src/util/module.zig b/src/util/module.zig index dd2b528ee41181ec258a1f655d0a92aa4647ae55..8a48892bfaade01aa4a44cefca5d5875fd1f4926 100644 --- a/src/util/module.zig +++ b/src/util/module.zig @@ -55,13 +55,11 @@ pub const Module = struct { } pub fn get_hash(self: Module, cdpath: string) !string { - var file_list_1 = std.ArrayList(string).init(gpa); - defer file_list_1.deinit(); - try u.file_list(try std.mem.concat(gpa, u8, &.{ cdpath, "/", self.clean_path }), &file_list_1); + const file_list_1 = try u.file_list(try std.mem.concat(gpa, u8, &.{ cdpath, "/", self.clean_path })); var file_list_2 = std.ArrayList(string).init(gpa); defer file_list_2.deinit(); - for (file_list_1.items) |item| { + for (file_list_1) |item| { const _a = u.trim_prefix(item, cdpath); const _b = u.trim_prefix(_a, self.clean_path); if (_b[0] == '.') continue;