Skip to content

Commit

Permalink
Potentially temporary fix for parsing a string as ascii while I inves…
Browse files Browse the repository at this point in the history
…tigate
  • Loading branch information
squeek502 committed Oct 30, 2023
1 parent cd4e15c commit 2c43de9
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/literals.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down

0 comments on commit 2c43de9

Please sign in to comment.