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:
Ali Mohammad Pur 2021-05-10 11:30:42 +04:30 committed by Andreas Kling
parent 0f03960c1b
commit 22b244df45
Notes: sideshowbarker 2024-07-18 18:23:37 +09:00
3 changed files with 16 additions and 2 deletions

View File

@ -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?

View File

@ -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;

View File

@ -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?