aboutsummaryrefslogtreecommitdiff
path: root/src/js_lexer.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/js_lexer.zig')
-rw-r--r--src/js_lexer.zig21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/js_lexer.zig b/src/js_lexer.zig
index e90886ead..512a5e5cd 100644
--- a/src/js_lexer.zig
+++ b/src/js_lexer.zig
@@ -1216,12 +1216,29 @@ pub const Lexer = struct {
// TODO: use wtf-8 encoding.
pub fn utf16ToStringWithValidation(lexer: *LexerType, js: JavascriptString) !string {
- return std.unicode.utf16leToUtf8Alloc(lexer.allocator, js);
+ // return std.unicode.utf16leToUtf8Alloc(lexer.allocator, js);
+ return utf16ToString(lexer, js);
}
// TODO: use wtf-8 encoding.
pub fn utf16ToString(lexer: *LexerType, js: JavascriptString) string {
- return std.unicode.utf16leToUtf8Alloc(lexer.allocator, js) catch unreachable;
+ var temp = std.mem.zeroes([4]u8);
+ var list = std.ArrayList(u8).initCapacity(lexer.allocator, js.len) catch unreachable;
+ var i: usize = 0;
+ while (i < js.len) : (i += 1) {
+ var r1 = @intCast(i32, js[i]);
+ if (r1 >= 0xD800 and r1 <= 0xDBFF and i + 1 < js.len) {
+ const r2 = @intCast(i32, js[i] + 1);
+ if (r2 >= 0xDC00 and r2 <= 0xDFFF) {
+ r1 = (r1 - 0xD800) << 10 | (r2 - 0xDC00) + 0x10000;
+ i += 1;
+ }
+ }
+ const width = strings.encodeWTF8Rune(&temp, r1);
+ list.appendSlice(temp[0..width]) catch unreachable;
+ }
+ return list.toOwnedSlice();
+ // return std.unicode.utf16leToUtf8Alloc(lexer.allocator, js) catch unreachable;
}
pub fn nextInsideJSXElement(lexer: *LexerType) !void {