summaryrefslogtreecommitdiff
path: root/AK/JsonParser.cpp
diff options
context:
space:
mode:
authorHüseyin ASLITÜRK <asliturk@hotmail.com>2020-06-13 13:54:32 +0300
committerAndreas Kling <kling@serenityos.org>2020-06-16 13:15:17 +0200
commit0aad21fff2e1335d433de726d269e2693769cd69 (patch)
tree3fb7ff2040280a33a82d99e9251db5da6ab63749 /AK/JsonParser.cpp
parent174987f930e38c5fd7335c85f87e06c39b2d5b58 (diff)
downloadserenity-0aad21fff2e1335d433de726d269e2693769cd69.zip
AK: JsonParser, replace char type to u32 for code point
Diffstat (limited to 'AK/JsonParser.cpp')
-rw-r--r--AK/JsonParser.cpp24
1 files changed, 12 insertions, 12 deletions
diff --git a/AK/JsonParser.cpp b/AK/JsonParser.cpp
index 142c797a47..578b84741c 100644
--- a/AK/JsonParser.cpp
+++ b/AK/JsonParser.cpp
@@ -72,7 +72,7 @@ String JsonParser::consume_quoted_string()
{
if (!consume_specific('"'))
return {};
- Vector<char, 1024> buffer;
+ Vector<u32, 1024> buffer;
for (;;) {
size_t peek_index = m_index;
@@ -87,8 +87,11 @@ String JsonParser::consume_quoted_string()
}
if (peek_index != m_index) {
- buffer.append(m_input.characters_without_null_termination() + m_index, peek_index - m_index);
- m_index = peek_index;
+ while (peek_index != m_index) {
+ u32 value = m_input.characters_without_null_termination()[m_index];
+ buffer.append(value);
+ m_index++;
+ }
}
if (m_index == m_input.length())
@@ -125,10 +128,9 @@ String JsonParser::consume_quoted_string()
sb.append(consume());
auto codepoint = AK::StringUtils::convert_to_uint_from_hex(sb.to_string());
- if (codepoint.has_value() && codepoint.value() < 0x80) {
- buffer.append((char)codepoint.value());
+ if (codepoint.has_value()) {
+ buffer.append(codepoint.value());
} else {
- // FIXME: This is obviously not correct, but we don't have non-ASCII support so meh.
buffer.append('?');
}
} break;
@@ -143,14 +145,12 @@ String JsonParser::consume_quoted_string()
if (buffer.is_empty())
return String::empty();
- auto& last_string_starting_with_character = m_last_string_starting_with_character[(u8)buffer.first()];
- if (last_string_starting_with_character.length() == buffer.size()) {
- if (!memcmp(last_string_starting_with_character.characters(), buffer.data(), buffer.size()))
- return last_string_starting_with_character;
+ StringBuilder final_sb;
+ for (auto cp : buffer) {
+ final_sb.append_codepoint(cp);
}
- last_string_starting_with_character = String::copy(buffer);
- return last_string_starting_with_character;
+ return final_sb.to_string();
}
Optional<JsonValue> JsonParser::parse_object()