mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-20 17:58:18 +03:00
Shell: Add support for \uhhhhhhhh escapes in strings
This will be replaced with the unicode character whose codepoint is given by the unsigned 32-bit number 'hhhhhhhh' (hex).
This commit is contained in:
parent
0f03960c1b
commit
22b244df45
Notes:
sideshowbarker
2024-07-18 18:23:37 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/22b244df458 Pull-request: https://github.com/SerenityOS/serenity/pull/7002 Issue: https://github.com/SerenityOS/serenity/issues/6986
@ -477,7 +477,8 @@ string :: '"' dquoted_string_inner '"'
|
||||
dquoted_string_inner :: '\' . dquoted_string_inner? {concat}
|
||||
| variable dquoted_string_inner? {compose}
|
||||
| . dquoted_string_inner?
|
||||
| '\' 'x' digit digit dquoted_string_inner?
|
||||
| '\' 'x' xdigit*2 dquoted_string_inner?
|
||||
| '\' 'u' xdigit*8 dquoted_string_inner?
|
||||
| '\' [abefrn] dquoted_string_inner?
|
||||
|
||||
variable :: variable_ref slice?
|
||||
|
@ -1315,6 +1315,18 @@ RefPtr<AST::Node> Parser::parse_doublequoted_string_inner()
|
||||
builder.append(to_byte(first_nibble, second_nibble));
|
||||
break;
|
||||
}
|
||||
case 'u': {
|
||||
if (m_input.length() <= m_offset + 8)
|
||||
break;
|
||||
size_t counter = 8;
|
||||
auto chars = consume_while([&](auto) { return counter-- > 0; });
|
||||
if (auto number = AK::StringUtils::convert_to_uint_from_hex(chars); number.has_value())
|
||||
builder.append(Utf32View { &number.value(), 1 });
|
||||
else
|
||||
builder.append(chars);
|
||||
|
||||
break;
|
||||
}
|
||||
case 'a':
|
||||
builder.append('\a');
|
||||
break;
|
||||
|
@ -265,7 +265,8 @@ string :: '"' dquoted_string_inner '"'
|
||||
dquoted_string_inner :: '\' . dquoted_string_inner? {concat}
|
||||
| variable dquoted_string_inner? {compose}
|
||||
| . dquoted_string_inner?
|
||||
| '\' 'x' digit digit dquoted_string_inner?
|
||||
| '\' 'x' xdigit*2 dquoted_string_inner?
|
||||
| '\' 'u' xdigit*8 dquoted_string_inner?
|
||||
| '\' [abefrn] dquoted_string_inner?
|
||||
|
||||
variable :: variable_ref slice?
|
||||
|
Loading…
Reference in New Issue
Block a user