mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
JsonParser: Support basic escaped string characters.
I didn't implement \uXXXX-style escape in this patch. That's a FIXME.
This commit is contained in:
parent
6469d7f043
commit
e9b619c4aa
Notes:
sideshowbarker
2024-07-19 13:29:20 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/e9b619c4aa5
1 changed files with 37 additions and 2 deletions
|
@ -54,9 +54,44 @@ void JsonParser::consume_specific(char expected_ch)
|
|||
String JsonParser::consume_quoted_string()
|
||||
{
|
||||
consume_specific('"');
|
||||
auto string = extract_while([](char ch) { return ch != '"'; });
|
||||
StringBuilder builder;
|
||||
for (;;) {
|
||||
char ch = peek();
|
||||
if (ch == '"')
|
||||
break;
|
||||
if (ch != '\\') {
|
||||
builder.append(consume());
|
||||
continue;
|
||||
}
|
||||
consume();
|
||||
char escaped_ch = consume();
|
||||
switch (escaped_ch) {
|
||||
case 'n':
|
||||
builder.append('\n');
|
||||
break;
|
||||
case 'r':
|
||||
builder.append('\n');
|
||||
break;
|
||||
case 't':
|
||||
builder.append('\t');
|
||||
break;
|
||||
case 'b':
|
||||
builder.append('\b');
|
||||
break;
|
||||
case 'f':
|
||||
builder.append('\f');
|
||||
break;
|
||||
case 'u':
|
||||
// FIXME: Implement \uXXXX
|
||||
ASSERT_NOT_REACHED();
|
||||
break;
|
||||
default:
|
||||
builder.append(escaped_ch);
|
||||
break;
|
||||
}
|
||||
}
|
||||
consume_specific('"');
|
||||
return string;
|
||||
return builder.to_string();
|
||||
}
|
||||
|
||||
JsonValue JsonParser::parse_object()
|
||||
|
|
Loading…
Reference in a new issue