aboutsummaryrefslogtreecommitdiff
path: root/src/string_mutable.zig
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-05-20 00:59:50 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-05-20 00:59:50 -0700
commit8a3a5c3b74565b1dd3d5e3d381b8ded95ba386c3 (patch)
treea41dfc47e2b9a80b4049819c76c932a23cde84c9 /src/string_mutable.zig
parent99d61877d6f411f33e0db578f04b333fb2110ddd (diff)
downloadbun-8a3a5c3b74565b1dd3d5e3d381b8ded95ba386c3.tar.gz
bun-8a3a5c3b74565b1dd3d5e3d381b8ded95ba386c3.tar.zst
bun-8a3a5c3b74565b1dd3d5e3d381b8ded95ba386c3.zip
Update string_mutable.zig
Diffstat (limited to 'src/string_mutable.zig')
-rw-r--r--src/string_mutable.zig10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/string_mutable.zig b/src/string_mutable.zig
index 7be903d93..a8a97e1c4 100644
--- a/src/string_mutable.zig
+++ b/src/string_mutable.zig
@@ -284,6 +284,10 @@ pub const MutableString = struct {
}
const E = @import("./js_ast.zig").E;
+
+ /// Write a E.String to the buffer.
+ /// This automatically encodes UTF-16 into UTF-8 using
+ /// the same code path as TextEncoder
pub fn writeString(this: *BufferedWriter, bytes: *E.String) anyerror!usize {
if (bytes.isUTF8()) {
return try this.writeAll(bytes.slice(this.context.allocator));
@@ -292,6 +296,9 @@ pub const MutableString = struct {
return try this.writeAll16(bytes.slice16());
}
+ /// Write a UTF-16 string to the (UTF-8) buffer
+ /// This automatically encodes UTF-16 into UTF-8 using
+ /// the same code path as TextEncoder
pub fn writeAll16(this: *BufferedWriter, bytes: []const u16) anyerror!usize {
var pending = bytes;
@@ -334,6 +341,7 @@ pub const MutableString = struct {
pub fn writeHTMLAttributeValue(this: *BufferedWriter, bytes: []const u8) anyerror!void {
var slice = bytes;
while (slice.len > 0) {
+ // TODO: SIMD
if (strings.indexOfAny(slice, "\"<>")) |j| {
_ = try this.writeAll(slice[0..j]);
_ = switch (slice[j]) {
@@ -356,6 +364,8 @@ pub const MutableString = struct {
var slice = bytes;
while (slice.len > 0) {
if (strings.indexOfAny16(slice, "\"<>")) |j| {
+ // this won't handle strings larger than 4 GB
+ // that's fine though, 4 GB of SSR'd HTML is quite a lot...
_ = try this.writeAll16(slice[0..j]);
_ = switch (slice[j]) {
'"' => try this.writeAll("&quot;"),