aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/string_mutable.zig23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/string_mutable.zig b/src/string_mutable.zig
index 2849a4695..9d89ea9db 100644
--- a/src/string_mutable.zig
+++ b/src/string_mutable.zig
@@ -30,6 +30,20 @@ pub const MutableString = struct {
}
}
+ pub fn owns(this: *const MutableString, buffer: []const u8) bool {
+ if (this.list.capacity < buffer.len) {
+ return false;
+ }
+
+ if (@ptrToInt(this.list.items.ptr) <= @ptrToInt(buffer.ptr) and
+ @ptrToInt(buffer.ptr) + buffer.len <= @ptrToInt(this.list.items.ptr) + this.list.capacity)
+ {
+ return true;
+ }
+
+ return false;
+ }
+
pub fn growIfNeeded(self: *MutableString, amount: usize) !void {
try self.list.ensureUnusedCapacity(self.allocator, amount);
}
@@ -156,6 +170,15 @@ pub const MutableString = struct {
try self.list.appendSlice(self.allocator, slice);
}
+ pub inline fn appendSliceExact(self: *MutableString, slice: []const u8) !void {
+ if (slice.len == 0) return;
+
+ try self.list.ensureTotalCapacityPrecise(self.allocator, self.list.items.len + slice.len);
+ var end = self.list.items.ptr + self.list.items.len;
+ self.list.items.len += slice.len;
+ @memcpy(end, slice.ptr, slice.len);
+ }
+
pub inline fn reset(
self: *MutableString,
) void {