AK: A few JSON improvements

* Add double number to object serializer

* Handle negative double numbers correctly

* Handle \r and \n in quoted strings independently
  This improves the situation when keys contain \r or \n that currently
  has the effect that "a\rkey" and "a\nkey" in an JSON object are the
  same key value.
This commit is contained in:
Emanuel Sprung 2020-03-31 13:30:09 +02:00 committed by Andreas Kling
parent c925aaceb2
commit c54855682c
2 changed files with 10 additions and 1 deletions

View file

@ -109,6 +109,12 @@ public:
m_builder.appendf("%llu", value);
}
void add(const StringView& key, double value)
{
begin_item(key);
m_builder.appendf("%f", value);
}
JsonArraySerializer<Builder> add_array(const StringView& key)
{
begin_item(key);

View file

@ -100,9 +100,11 @@ String JsonParser::consume_quoted_string()
char escaped_ch = consume();
switch (escaped_ch) {
case 'n':
case 'r':
buffer.append('\n');
break;
case 'r':
buffer.append('\r');
break;
case 't':
buffer.append('\t');
break;
@ -225,6 +227,7 @@ JsonValue JsonParser::parse_number()
ASSERT(ok);
int fraction = fraction_string.to_uint(ok);
fraction *= (whole < 0) ? -1 : 1;
ASSERT(ok);
auto divider = 1;