1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 09:04:59 +00:00

AK: Use a single StringBuilder throughout JSON serialization.

This commit is contained in:
Andreas Kling 2019-06-17 21:34:12 +02:00
parent 3b9fcab1af
commit ee347effac
6 changed files with 77 additions and 16 deletions

View file

@ -1,9 +1,10 @@
#include <AK/JsonObject.h>
#include <AK/StringBuilder.h>
String JsonObject::to_string() const
namespace AK {
void JsonObject::to_string(StringBuilder& builder) const
{
StringBuilder builder;
int index = 0;
builder.append('{');
for_each_member([&] (auto& key, auto& value) {
@ -11,11 +12,19 @@ String JsonObject::to_string() const
builder.append(key);
builder.append('"');
builder.append(':');
builder.append(value.to_string());
value.to_string(builder);
if (index != size() - 1)
builder.append(',');
++index;
});
builder.append('}');
}
String JsonObject::to_string() const
{
StringBuilder builder;
to_string(builder);
return builder.to_string();
}
}