diff options
author | 2022-08-10 21:26:20 -0700 | |
---|---|---|
committer | 2022-08-10 21:26:20 -0700 | |
commit | d9ae284463c25f6c1e6056c2ee4d5bf81f1d11cb (patch) | |
tree | e4221d5571233981da5b28f17b9076c5d183c550 /src/string_immutable.zig | |
parent | 00d5f6699b39799b383dc305d4120da7d79c7bce (diff) | |
download | bun-d9ae284463c25f6c1e6056c2ee4d5bf81f1d11cb.tar.gz bun-d9ae284463c25f6c1e6056c2ee4d5bf81f1d11cb.tar.zst bun-d9ae284463c25f6c1e6056c2ee4d5bf81f1d11cb.zip |
Fix console.log with typed arrays
Diffstat (limited to '')
-rw-r--r-- | src/string_immutable.zig | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/string_immutable.zig b/src/string_immutable.zig index 540572b6f..aaee55319 100644 --- a/src/string_immutable.zig +++ b/src/string_immutable.zig @@ -1014,7 +1014,13 @@ pub fn utf16Codepoint(comptime Type: type, input: Type) UTF16Replacement { } pub fn toUTF8AllocWithType(allocator: std.mem.Allocator, comptime Type: type, utf16: Type) ![]u8 { - var list = std.ArrayList(u8).initCapacity(allocator, utf16.len) catch unreachable; + var list = try std.ArrayList(u8).initCapacity(allocator, utf16.len); + list = try toUTF8ListWithType(list, Type, utf16); + return list.items; +} + +pub fn toUTF8ListWithType(list_: std.ArrayList(u8), comptime Type: type, utf16: Type) !std.ArrayList(u8) { + var list = list_; var utf16_remaining = utf16; while (firstNonASCII16(Type, utf16_remaining)) |i| { @@ -1048,8 +1054,7 @@ pub fn toUTF8AllocWithType(allocator: std.mem.Allocator, comptime Type: type, ut list.items.len += utf16_remaining.len; copyU16IntoU8(list.items[old_len..], Type, utf16_remaining); - // don't call toOwnedSlice() because our - return list.items; + return list; } pub const EncodeIntoResult = struct { |