From 2c43de981f0862b7549429fb024e1b4c089918b6 Mon Sep 17 00:00:00 2001 From: Ryan Liptak Date: Sun, 29 Oct 2023 18:16:00 -0700 Subject: [PATCH] Potentially temporary fix for parsing a string as ascii while I investigate --- src/literals.zig | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/literals.zig b/src/literals.zig index ac78ac4..c423ebc 100644 --- a/src/literals.zig +++ b/src/literals.zig @@ -469,7 +469,15 @@ pub fn parseQuotedStringAsWideString(allocator: std.mem.Allocator, bytes: Source pub fn parseQuotedStringAsAsciiString(allocator: std.mem.Allocator, bytes: SourceBytes, options: StringParseOptions) ![]u8 { std.debug.assert(bytes.slice.len >= 2); // "" - return parseQuotedString(.ascii, allocator, bytes, options); + // This is slightly hacky, but L"\xABCD" will lead to an @intCast failure + // because to the L prefix makes the parser allow 4 hex digits in an escape sequence. + // To avoid this error and get the behavior we want, we just strip the L if it exists + // and parse the string as if there was no prefix. + var ascii_bytes = bytes; + if (bytes.slice[0] == 'L' or bytes.slice[0] == 'l') { + ascii_bytes.slice = ascii_bytes.slice[1..]; + } + return parseQuotedString(.ascii, allocator, ascii_bytes, options); } test "parse quoted ascii string" {