Parses any string type into a wide string. If the string is declared as a wide string (L""), then it is handled normally. Otherwise, things are fairly normal with the exception of escaped integers. Escaped integers are handled by:
pub fn parseQuotedStringAsWideString(allocator: std.mem.Allocator, bytes: SourceBytes, options: StringParseOptions) ![:0]u16
pub fn parseQuotedStringAsWideString(allocator: std.mem.Allocator, bytes: SourceBytes, options: StringParseOptions) ![:0]u16 {
std.debug.assert(bytes.slice.len >= 2); // ""
if (bytes.slice[0] == 'l' or bytes.slice[0] == 'L') {
return parseQuotedWideString(allocator, bytes, options);
}
// Note: We're only handling the case of parsing an ASCII string into a wide string from here on out.
// TODO: The logic below is similar to that in AcceleratorKeyCodepointTranslator, might be worth merging the two
var buf = try std.ArrayList(u16).initCapacity(allocator, bytes.slice.len);
errdefer buf.deinit(allocator);
var iterative_parser = IterativeStringParser.init(bytes, options);
while (try iterative_parser.next()) |parsed| {
const c = parsed.codepoint;
if (parsed.from_escaped_integer) {
std.debug.assert(c != code_pages.Codepoint.invalid);
const byte_to_interpret: u8 = @truncate(c);
const code_unit_to_encode: u16 = switch (options.output_code_page) {
.windows1252 => windows1252.toCodepoint(byte_to_interpret),
.utf8 => if (byte_to_interpret > 0x7F) '�' else byte_to_interpret,
};
try buf.append(allocator, std.mem.nativeToLittle(u16, code_unit_to_encode));
} else if (c == code_pages.Codepoint.invalid) {
try buf.append(allocator, std.mem.nativeToLittle(u16, '�'));
} else if (c < 0x10000) {
const short: u16 = @intCast(c);
try buf.append(allocator, std.mem.nativeToLittle(u16, short));
} else {
if (!parsed.escaped_surrogate_pair) {
const high = @as(u16, @intCast((c - 0x10000) >> 10)) + 0xD800;
try buf.append(allocator, std.mem.nativeToLittle(u16, high));
}
const low = @as(u16, @intCast(c & 0x3FF)) + 0xDC00;
try buf.append(allocator, std.mem.nativeToLittle(u16, low));
}
}
return buf.toOwnedSliceSentinel(allocator, 0);
}