mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-22 09:19:03 +00:00
JSON: Templatize the JSON serialization code
This makes it possible to use something other than a StringBuilder for serialization (and to produce something other than a String.) :^)
This commit is contained in:
@@ -3,28 +3,4 @@
|
||||
|
||||
namespace AK {
|
||||
|
||||
void JsonObject::serialize(StringBuilder& builder) const
|
||||
{
|
||||
int index = 0;
|
||||
builder.append('{');
|
||||
for_each_member([&] (auto& key, auto& value) {
|
||||
builder.append('"');
|
||||
builder.append(key);
|
||||
builder.append('"');
|
||||
builder.append(':');
|
||||
value.serialize(builder);
|
||||
if (index != size() - 1)
|
||||
builder.append(',');
|
||||
++index;
|
||||
});
|
||||
builder.append('}');
|
||||
}
|
||||
|
||||
String JsonObject::serialized() const
|
||||
{
|
||||
StringBuilder builder;
|
||||
serialize(builder);
|
||||
return builder.to_string();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user