authorgravatar for hello@nektro.netMeghan <hello@nektro.net> 2020-11-18 14:13:01 -08:00
committergravatar for hello@nektro.netMeghan <hello@nektro.net> 2020-11-18 14:13:01 -08:00
loge5857e217f0a01d95581464d52c1e4aa822ccc4f
treea93f41929f8e08d483ade6aa63ac77dbc7858eca
parent621af65c0a5cdb298b396d31c1ce59387d84fa62

add get_string_array to yaml.mapping


2 files changed, 17 insertions(+), 22 deletions(-)

src/util/modfile.zig+2-22
......@@ -31,26 +31,6 @@ pub const ModFile = struct {
3131 const name = doc.mapping.get("name").?.string;
3232 const main = doc.mapping.get("main").?.string;
3333
34 const cinclude_list = &std.ArrayList([]const u8).init(alloc);
35 if (doc.mapping.get("c_include_dirs")) |val| {
36 if (val == .sequence) {
37 for (val.sequence) |item, i| {
38 u.assert(item == .string, "modfile: {}[{}] is not a string", .{"c_include_dirs", i});
39 try cinclude_list.append(item.string);
40 }
41 }
42 }
43
44 const csrc_list = &std.ArrayList([]const u8).init(alloc);
45 if (doc.mapping.get("c_source_files")) |val| {
46 if (val == .sequence) {
47 for (val.sequence) |item, i| {
48 u.assert(item == .string, "modfile: {}[{}] is not a string", .{"c_source_files", i});
49 try csrc_list.append(item.string);
50 }
51 }
52 }
53
5434 const dep_list = &std.ArrayList(u.Dep).init(alloc);
5535 if (doc.mapping.get("dependencies")) |dep_seq| {
5636 if (dep_seq == .sequence) {
......@@ -71,8 +51,8 @@ pub const ModFile = struct {
7151 .alloc = alloc,
7252 .name = name,
7353 .main = main,
74 .c_include_dirs = cinclude_list.items,
75 .c_source_files = csrc_list.items,
54 .c_include_dirs = try doc.mapping.get_string_array(alloc, "c_include_dirs"),
55 .c_source_files = try doc.mapping.get_string_array(alloc, "c_source_files"),
7656 .deps = dep_list.items,
7757 };
7858 }
src/util/yaml.zig+15
......@@ -43,6 +43,21 @@ pub const Mapping = struct {
4343 }
4444 return null;
4545 }
46
47 pub fn get_string_array(self: Mapping, alloc: *std.mem.Allocator, k: []const u8) ![][]const u8 {
48 const list = &std.ArrayList([]const u8).init(alloc);
49 if (self.get(k)) |val| {
50 if (val == .sequence) {
51 for (val.sequence) |item, i| {
52 if (item != .string) {
53 continue;
54 }
55 try list.append(item.string);
56 }
57 }
58 }
59 return list.items;
60 }
4661};
4762
4863//