Zig utility library
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

minor changes

IamPyu 1529d0b4 b9d5fa75

+41 -8
+11 -5
build.zig
··· 27 27 path: std.Build.LazyPath, 28 28 } = &.{ 29 29 .{ .name = "flag", .path = b.path("examples/flag.zig") }, 30 + .{ .name = "slice_iter", .path = b.path("examples/slice_iter.zig") }, 30 31 }; 31 32 for (examples) |e| { 32 33 const t = b.addExecutable(.{ 33 34 .name = e.name, 34 35 .root_module = b.createModule( 35 - .{ .target = target, .optimize = optimize, .root_source_file = e.path, .imports = &.{ 36 - .{ 37 - .name = "mitochondria", 38 - .module = mod, 36 + .{ 37 + .target = target, 38 + .optimize = optimize, 39 + .root_source_file = e.path, 40 + .imports = &.{ 41 + .{ 42 + .name = "mitochondria", 43 + .module = mod, 44 + }, 39 45 }, 40 - } }, 46 + }, 41 47 ), 42 48 }); 43 49 b.installArtifact(t);
+1 -1
examples/flag.zig
··· 2 2 const mito = @import("mitochondria"); 3 3 4 4 pub fn main() !void { 5 - var gpa = std.heap.GeneralPurposeAllocator(.{}).init; 5 + var gpa = std.heap.DebugAllocator(.{}).init; 6 6 7 7 const Parser = mito.flag.parser(&.{ 8 8 .{ .name = "help", .kind = .boolean, .desc = "Print this help message" },
+22
examples/slice_iter.zig
··· 1 + const std = @import("std"); 2 + const mitochondria = @import("mitochondria"); 3 + const SliceIterator = mitochondria.SliceIterator; 4 + 5 + pub fn main() void { 6 + const array_of_strings = [_][]const u8{ 7 + "Lorem ipsum dolor sit amet", 8 + "Foo bar baz qux", 9 + "Disturbing the peace,", 10 + "Look into my eyes,", 11 + "Now tell me the things you blabbing about", 12 + "Behind my back", 13 + "The tenacity I hold it's hard to break down", 14 + "It's too late for apologies", 15 + "It's going down now", 16 + }; 17 + 18 + var strings = SliceIterator([]const u8).init(&array_of_strings); 19 + while (strings.next()) |str| { 20 + std.debug.print("{s}\n", .{str}); 21 + } 22 + }
+7 -2
src/flag.zig
··· 105 105 if (std.mem.eql(u8, "-" ++ flag_name, a)) { 106 106 flag_found = true; 107 107 switch (flag_map.kinds[j]) { 108 - .boolean => @field(out_flags, flag_name) = !@field(out_flags, flag_name), 108 + .boolean => { 109 + @field(out_flags, flag_name) = !@field(out_flags, flag_name); 110 + }, 109 111 .valued => { 110 112 i += 1; 111 113 if (i == args.len) { 112 114 if (options.log) 113 - std.log.err("option '{s}' requires an argument but none was provided!", .{flag_name}); 115 + std.log.err( 116 + "option '{s}' requires an argument but none was provided!", 117 + .{flag_name}, 118 + ); 114 119 return error.MissingValue; 115 120 } 116 121