I like this direction

Former-commit-id: 3a95a74b7f
This commit is contained in:
Jarred Sumner
2021-06-24 22:55:42 -07:00
parent d09194f05a
commit b55e64ffa3
10 changed files with 1047 additions and 27 deletions

View File

@@ -305,12 +305,17 @@ pub fn encodeWTF8Rune(p: []u8, r: i32) u3 {
}
pub fn toUTF16Buf(in: string, out: []u16) usize {
var utf8Iterator = std.unicode.Utf8Iterator{ .bytes = in, .i = 0 };
var utf8Iterator = CodepointIterator{ .bytes = in, .i = 0 };
var c: u21 = 0;
var i: usize = 0;
while (utf8Iterator.nextCodepoint()) |code_point| {
while (true) {
const code_point = utf8Iterator.nextCodepoint();
switch (code_point) {
-1 => {
return i;
},
0...0xFFFF => {
out[i] = @intCast(u16, code_point);
i += 1;
@@ -329,7 +334,7 @@ pub fn toUTF16Buf(in: string, out: []u16) usize {
}
pub fn toUTF16Alloc(in: string, allocator: *std.mem.Allocator) !JavascriptString {
var utf8Iterator = std.unicode.Utf8Iterator{ .bytes = in, .i = 0 };
var utf8Iterator = CodepointIterator{ .bytes = in, .i = 0 };
var out = try std.ArrayList(u16).initCapacity(allocator, in.len);
var c: u21 = 0;