AK: JsonParser, replace char type to u32 for code point
This commit is contained in:
parent
174987f930
commit
0aad21fff2
Notes:
sideshowbarker
2024-07-19 05:37:32 +09:00
Author: https://github.com/asliturk Commit: https://github.com/SerenityOS/serenity/commit/0aad21fff2e Pull-request: https://github.com/SerenityOS/serenity/pull/2541
1 changed files with 12 additions and 12 deletions
|
@ -72,7 +72,7 @@ String JsonParser::consume_quoted_string()
|
||||||
{
|
{
|
||||||
if (!consume_specific('"'))
|
if (!consume_specific('"'))
|
||||||
return {};
|
return {};
|
||||||
Vector<char, 1024> buffer;
|
Vector<u32, 1024> buffer;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
size_t peek_index = m_index;
|
size_t peek_index = m_index;
|
||||||
|
@ -87,8 +87,11 @@ String JsonParser::consume_quoted_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (peek_index != m_index) {
|
if (peek_index != m_index) {
|
||||||
buffer.append(m_input.characters_without_null_termination() + m_index, peek_index - m_index);
|
while (peek_index != m_index) {
|
||||||
m_index = peek_index;
|
u32 value = m_input.characters_without_null_termination()[m_index];
|
||||||
|
buffer.append(value);
|
||||||
|
m_index++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_index == m_input.length())
|
if (m_index == m_input.length())
|
||||||
|
@ -125,10 +128,9 @@ String JsonParser::consume_quoted_string()
|
||||||
sb.append(consume());
|
sb.append(consume());
|
||||||
|
|
||||||
auto codepoint = AK::StringUtils::convert_to_uint_from_hex(sb.to_string());
|
auto codepoint = AK::StringUtils::convert_to_uint_from_hex(sb.to_string());
|
||||||
if (codepoint.has_value() && codepoint.value() < 0x80) {
|
if (codepoint.has_value()) {
|
||||||
buffer.append((char)codepoint.value());
|
buffer.append(codepoint.value());
|
||||||
} else {
|
} else {
|
||||||
// FIXME: This is obviously not correct, but we don't have non-ASCII support so meh.
|
|
||||||
buffer.append('?');
|
buffer.append('?');
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
@ -143,14 +145,12 @@ String JsonParser::consume_quoted_string()
|
||||||
if (buffer.is_empty())
|
if (buffer.is_empty())
|
||||||
return String::empty();
|
return String::empty();
|
||||||
|
|
||||||
auto& last_string_starting_with_character = m_last_string_starting_with_character[(u8)buffer.first()];
|
StringBuilder final_sb;
|
||||||
if (last_string_starting_with_character.length() == buffer.size()) {
|
for (auto cp : buffer) {
|
||||||
if (!memcmp(last_string_starting_with_character.characters(), buffer.data(), buffer.size()))
|
final_sb.append_codepoint(cp);
|
||||||
return last_string_starting_with_character;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
last_string_starting_with_character = String::copy(buffer);
|
return final_sb.to_string();
|
||||||
return last_string_starting_with_character;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<JsonValue> JsonParser::parse_object()
|
Optional<JsonValue> JsonParser::parse_object()
|
||||||
|
|
Loading…
Add table
Reference in a new issue