diff --git a/lib/Group.zig b/lib/Group.zig index 92ca99b..d2c115f 100644 --- a/lib/Group.zig +++ b/lib/Group.zig @@ -37,6 +37,25 @@ pub fn someMembers( return bufset; } +// cloneArray clones an array of strings. This may be needed +// to change members to []const []const u8 +fn cloneArray(allocator: Allocator, arr: []const []const u8) error{OutOfMemory}![]const []const u8 { + const total_len = blk: { + var sum: usize = 0; + for (arr) |elem| sum += elem.len; + break :blk sum; + }; + var buf = try allocator.alloc(u8, total_len); + var ret = try allocator.alloc([]const u8, arr.len); + ret.len = arr.len; + for (arr) |elem, i| { + const old_len = buf.len; + mem.copy(u8, buf[old_len..], elem); + ret[i] = buf[old_len .. old_len + elem.len]; + } + return ret; +} + const testing = std.testing; test "Group.clone" {