diff options
author | 2022-03-06 07:35:16 -0800 | |
---|---|---|
committer | 2022-03-06 07:35:16 -0800 | |
commit | 7c5c6cd5192acde43006070e740bbe51cfd49255 (patch) | |
tree | 53f1e3cb999a477791dd76f4f2bedd3c56084756 /src/string_mutable.zig | |
parent | 093807391a9563ad36c2b04a286da23d09fad835 (diff) | |
download | bun-7c5c6cd5192acde43006070e740bbe51cfd49255.tar.gz bun-7c5c6cd5192acde43006070e740bbe51cfd49255.tar.zst bun-7c5c6cd5192acde43006070e740bbe51cfd49255.zip |
source maps work for app code in `bun dev`!
Diffstat (limited to 'src/string_mutable.zig')
-rw-r--r-- | src/string_mutable.zig | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/src/string_mutable.zig b/src/string_mutable.zig index e8a46af9b..7ef05fbe7 100644 --- a/src/string_mutable.zig +++ b/src/string_mutable.zig @@ -50,6 +50,12 @@ pub const MutableString = struct { std.ArrayListUnmanaged(u8){} }; } + pub fn initEmpty(allocator: std.mem.Allocator) MutableString { + return MutableString{ .allocator = allocator, .list = .{} }; + } + + pub const ensureUnusedCapacity = growIfNeeded; + pub fn initCopy(allocator: std.mem.Allocator, str: anytype) !MutableString { var mutable = try MutableString.init(allocator, std.mem.len(str)); try mutable.copy(str); @@ -146,6 +152,10 @@ pub const MutableString = struct { try self.list.ensureUnusedCapacity(self.allocator, amount); } + pub inline fn appendSlice(self: *MutableString, slice: []const u8) !void { + try self.list.appendSlice(self.allocator, slice); + } + pub inline fn reset( self: *MutableString, ) void { @@ -202,23 +212,23 @@ pub const MutableString = struct { // self.list.swapRemove(i); // } - pub fn containsChar(self: *MutableString, char: u8) bool { + pub fn containsChar(self: *const MutableString, char: u8) bool { return self.indexOfChar(char) != null; } - pub fn indexOfChar(self: *MutableString, char: u8) ?usize { - return std.mem.indexOfScalar(@TypeOf(char), self.list.items, char); + pub fn indexOfChar(self: *const MutableString, char: u8) ?usize { + return strings.indexOfChar(self.list.items, char); } - pub fn lastIndexOfChar(self: *MutableString, char: u8) ?usize { - return std.mem.lastIndexOfScalar(@TypeOf(char), self.list.items, char); + pub fn lastIndexOfChar(self: *const MutableString, char: u8) ?usize { + return strings.lastIndexOfChar(self.list.items, char); } - pub fn lastIndexOf(self: *MutableString, str: u8) ?usize { - return std.mem.lastIndexOf(u8, self.list.items, str); + pub fn lastIndexOf(self: *const MutableString, str: u8) ?usize { + return strings.lastIndexOfChar(self.list.items, str); } - pub fn indexOf(self: *MutableString, str: u8) ?usize { + pub fn indexOf(self: *const MutableString, str: u8) ?usize { return std.mem.indexOf(u8, self.list.items, str); } @@ -226,6 +236,15 @@ pub const MutableString = struct { return std.mem.eql(u8, self.list.items, other); } + pub fn toSocketBuffers(self: *MutableString, comptime count: usize, ranges: anytype) [count]std.x.os.Buffer { + var buffers: [count]std.x.os.Buffer = undefined; + comptime var i: usize = 0; + inline while (i < count) : (i += 1) { + buffers[i] = std.x.os.Buffer.from(self.list.items[ranges[i][0]..ranges[i][1]]); + } + return buffers; + } + pub const BufferedWriter = struct { context: *MutableString, buffer: [max]u8 = undefined, |