wip cloneArray
may not turn out to be useful though
This commit is contained in:
parent
fad7c9fbaf
commit
88d88af111
@ -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" {
|
||||
|
Loading…
Reference in New Issue
Block a user