diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-06-17 21:34:12 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-06-17 21:36:54 +0200 |
commit | ee347effac246618f282d64a221306b7452009f0 (patch) | |
tree | b3f89068c2eccaa0845e87a3b3228e708ea41cfd /AK/JsonObject.cpp | |
parent | 3b9fcab1afb992977c5dd5be3b8ebfd29d9e609c (diff) | |
download | serenity-ee347effac246618f282d64a221306b7452009f0.zip |
AK: Use a single StringBuilder throughout JSON serialization.
Diffstat (limited to 'AK/JsonObject.cpp')
-rw-r--r-- | AK/JsonObject.cpp | 15 |
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(); } + +} |