diff options
Diffstat (limited to 'src/string_mutable.zig')
-rw-r--r-- | src/string_mutable.zig | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/string_mutable.zig b/src/string_mutable.zig index 25709fd40..249ab7394 100644 --- a/src/string_mutable.zig +++ b/src/string_mutable.zig @@ -154,10 +154,21 @@ pub const MutableString = struct { return self.list.toOwnedSlice(self.allocator); } - pub fn toOwnedSliceLeaky(self: *MutableString) string { + pub fn toOwnedSliceLeaky(self: *MutableString) []u8 { return self.list.items; } + pub fn toOwnedSentinelLeaky(self: *MutableString) [:0]u8 { + if (self.list.items.len > 0 and self.list.items[self.list.items.len - 1] != 0) { + self.list.append( + self.allocator, + 0, + ) catch unreachable; + } + + return self.list.items[0 .. self.list.items.len - 1 :0]; + } + pub fn toOwnedSliceLength(self: *MutableString, length: usize) string { self.list.shrinkAndFree(self.allocator, length); return self.list.toOwnedSlice(self.allocator); |