authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-28 01:26:19 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-28 01:26:19 -07:00
log12ab78a7eba0084eb1ffa7deabfe56757b2661a1
treee8e6914efe7d4a618bd1799bbf6ff897d18485ea
parent35a2971073cbbe0c2a4bcd49ac6a48a5f043143b

clean up more function signatures


2 files changed, 16 insertions(+), 11 deletions(-)

src/util/funcs.zig+14-7
...@@ -79,7 +79,7 @@ pub fn does_folder_exist(fpath: string) !bool {...@@ -79,7 +79,7 @@ pub fn does_folder_exist(fpath: string) !bool {
79 return true;79 return true;
80}80}
8181
82pub fn _join(comptime delim: string, comptime xs: []string) string {82pub fn _join(comptime delim: string, comptime xs: []const string) string {
83 var buf: string = "";83 var buf: string = "";
84 for (xs) |x, i| {84 for (xs) |x, i| {
85 buf = buf ++ x;85 buf = buf ++ x;
...@@ -96,12 +96,13 @@ pub fn trim_suffix(in: string, suffix: string) string {...@@ -96,12 +96,13 @@ pub fn trim_suffix(in: string, suffix: string) string {
96}96}
9797
98pub fn repeat(s: string, times: i32) !string {98pub fn repeat(s: string, times: i32) !string {
99 var list = std.ArrayList(string).init(gpa);99 var list = std.ArrayList(u8).init(gpa);
100 defer list.deinit();
100 var i: i32 = 0;101 var i: i32 = 0;
101 while (i < times) : (i += 1) {102 while (i < times) : (i += 1) {
102 try list.append(s);103 try list.appendSlice(s);
103 }104 }
104 return try std.mem.join(gpa, "", list.items);105 return list.toOwnedSlice();
105}106}
106107
107pub fn list_contains(haystack: []const string, needle: string) bool {108pub 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...@@ -122,7 +123,10 @@ pub fn list_contains_gen(comptime T: type, haystack: []const T, needle: T) bool
122 return false;123 return false;
123}124}
124125
125pub fn file_list(dpath: string, list: *std.ArrayList(string)) !void {126pub fn file_list(dpath: string) ![]const string {
127 var list = std.ArrayList(string).init(gpa);
128 defer list.deinit();
129
126 const dir = try std.fs.cwd().openDir(dpath, .{ .iterate = true });130 const dir = try std.fs.cwd().openDir(dpath, .{ .iterate = true });
127 var walk = try dir.walk(gpa);131 var walk = try dir.walk(gpa);
128 defer walk.deinit();132 defer walk.deinit();
...@@ -136,6 +140,7 @@ pub fn file_list(dpath: string, list: *std.ArrayList(string)) !void {...@@ -136,6 +140,7 @@ pub fn file_list(dpath: string, list: *std.ArrayList(string)) !void {
136 break;140 break;
137 }141 }
138 }142 }
143 return list.toOwnedSlice();
139}144}
140145
141pub fn run_cmd_raw(dir: ?string, args: []const string) !std.ChildProcess.ExecResult {146pub fn run_cmd_raw(dir: ?string, args: []const string) !std.ChildProcess.ExecResult {
...@@ -186,7 +191,7 @@ pub fn random_string(len: usize) !string {...@@ -186,7 +191,7 @@ pub fn random_string(len: usize) !string {
186 return buf;191 return buf;
187}192}
188193
189pub fn parse_split(comptime T: type, delim: string) type {194pub fn parse_split(comptime T: type, comptime delim: string) type {
190 return struct {195 return struct {
191 const Self = @This();196 const Self = @This();
192197
...@@ -195,8 +200,10 @@ pub fn parse_split(comptime T: type, delim: string) type {...@@ -195,8 +200,10 @@ pub fn parse_split(comptime T: type, delim: string) type {
195200
196 pub fn do(input: string) !Self {201 pub fn do(input: string) !Self {
197 var iter = std.mem.split(u8, input, delim);202 var iter = std.mem.split(u8, input, delim);
203 const start = iter.next() orelse return error.IterEmpty;
204 const id = std.meta.stringToEnum(T, start) orelse return error.NoMemberFound;
198 return Self{205 return Self{
199 .id = std.meta.stringToEnum(T, iter.next() orelse return error.IterEmpty) orelse return error.NoMemberFound,206 .id = id,
200 .string = iter.rest(),207 .string = iter.rest(),
201 };208 };
202 }209 }
src/util/module.zig+2-4
...@@ -55,13 +55,11 @@ pub const Module = struct {...@@ -55,13 +55,11 @@ pub const Module = struct {
55 }55 }
5656
57 pub fn get_hash(self: Module, cdpath: string) !string {57 pub fn get_hash(self: Module, cdpath: string) !string {
58 var file_list_1 = std.ArrayList(string).init(gpa);58 const file_list_1 = try u.file_list(try std.mem.concat(gpa, u8, &.{ cdpath, "/", self.clean_path }));
59 defer file_list_1.deinit();
60 try u.file_list(try std.mem.concat(gpa, u8, &.{ cdpath, "/", self.clean_path }), &file_list_1);
6159
62 var file_list_2 = std.ArrayList(string).init(gpa);60 var file_list_2 = std.ArrayList(string).init(gpa);
63 defer file_list_2.deinit();61 defer file_list_2.deinit();
64 for (file_list_1.items) |item| {62 for (file_list_1) |item| {
65 const _a = u.trim_prefix(item, cdpath);63 const _a = u.trim_prefix(item, cdpath);
66 const _b = u.trim_prefix(_a, self.clean_path);64 const _b = u.trim_prefix(_a, self.clean_path);
67 if (_b[0] == '.') continue;65 if (_b[0] == '.') continue;