authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-08-26 20:44:50 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-08-26 20:44:50 -07:00
log4d2b9a70c8347fd5ce877eb087e1b3cad54e3cae
tree25249a8e56102d2ac73d5e94c8161ef0372f9cd6
parent8691b110468d7b6d170e6fec0e0ecfe7ede6372c

add addSentinel


1 files changed, 8 insertions(+), 0 deletions(-)

src/lib.zig+8
......@@ -22,3 +22,11 @@ pub fn reduceNumber(alloc: *std.mem.Allocator, input: u64, comptime unit: u64, c
2222pub fn intToFloat(n: u64) f64 {
2323 return @intToFloat(f64, n);
2424}
25
26pub fn addSentinel(alloc: *std.mem.Allocator, comptime T: type, input: []const T, comptime sentinel: T) ![:sentinel]const T {
27 var list = try std.ArrayList(T).initCapacity(alloc, input.len + 1);
28 try list.appendSlice(input);
29 try list.append(sentinel);
30 const str = list.toOwnedSlice();
31 return str[0 .. str.len - 1 :sentinel];
32}