summaryrefslogtreecommitdiff
path: root/AK/JsonObject.cpp
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-06-17 21:34:12 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-06-17 21:36:54 +0200
commitee347effac246618f282d64a221306b7452009f0 (patch)
treeb3f89068c2eccaa0845e87a3b3228e708ea41cfd /AK/JsonObject.cpp
parent3b9fcab1afb992977c5dd5be3b8ebfd29d9e609c (diff)
downloadserenity-ee347effac246618f282d64a221306b7452009f0.zip
AK: Use a single StringBuilder throughout JSON serialization.
Diffstat (limited to 'AK/JsonObject.cpp')
-rw-r--r--AK/JsonObject.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/AK/JsonObject.cpp b/AK/JsonObject.cpp
index 11f01bd235..7817dc937e 100644
--- a/AK/JsonObject.cpp
+++ b/AK/JsonObject.cpp
@@ -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();
}
+
+}