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:
parent
3b9fcab1af
commit
ee347effac
6 changed files with 77 additions and 16 deletions
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue