diff options
author | 2021-07-28 20:56:29 -0700 | |
---|---|---|
committer | 2021-07-28 20:56:29 -0700 | |
commit | 4a8b2546526e97583a2743d17405f664cbf6a16e (patch) | |
tree | 7cfdef87ee13374afc908dd5b0860502036d1c70 /src/string_immutable.zig | |
parent | 86296897e55e0c80a3e93e27031e244525fb757c (diff) | |
download | bun-4a8b2546526e97583a2743d17405f664cbf6a16e.tar.gz bun-4a8b2546526e97583a2743d17405f664cbf6a16e.tar.zst bun-4a8b2546526e97583a2743d17405f664cbf6a16e.zip |
esmodules work?
Former-commit-id: 5cb5af4416c12518eb195d1b310990fc5c94d6c8
Diffstat (limited to 'src/string_immutable.zig')
-rw-r--r-- | src/string_immutable.zig | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/string_immutable.zig b/src/string_immutable.zig index b65b142bf..d5f41c82e 100644 --- a/src/string_immutable.zig +++ b/src/string_immutable.zig @@ -80,6 +80,30 @@ pub fn endsWithAny(self: string, str: string) bool { pub fn lastNonwhitespace(self: string, str: string) bool {} +pub fn quotedAlloc(allocator: *std.mem.Allocator, self: string) !string { + var count: usize = 0; + for (self) |char| { + count += @boolToInt(char == '"'); + } + + if (count == 0) { + return allocator.dupe(u8, self); + } + + var i: usize = 0; + var out = try allocator.alloc(u8, self.len + count); + for (self) |char| { + if (char == '"') { + out[i] = '\\'; + i += 1; + } + out[i] = char; + i += 1; + } + + return out; +} + pub fn endsWithAnyComptime(self: string, comptime str: string) bool { if (str.len < 10) { const last = self[self.len - 1]; |