diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2024-01-08 12:19:03 +0600 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2024-01-08 13:05:31 +0100 |
commit | 7413b4ad50b38cf9839fc3e3d4d0bec6ada90a6a (patch) | |
tree | 8db609349e3472422c733c3b4e92b8f3e407c8dc /tools | |
parent | 60150ef4b8fc1d0a30f20c3d9ed6ba0725da16a5 (diff) |
Simplify JsonWriter a bit
Change-Id: Ifa4278cfd62df4179dd3ae627369c077e31dbd00
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161780
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/qa/cppunit/test_json_writer.cxx | 2 | ||||
-rw-r--r-- | tools/source/misc/json_writer.cxx | 50 |
2 files changed, 10 insertions, 42 deletions
diff --git a/tools/qa/cppunit/test_json_writer.cxx b/tools/qa/cppunit/test_json_writer.cxx index a82fc769be31..05f19515e1e4 100644 --- a/tools/qa/cppunit/test_json_writer.cxx +++ b/tools/qa/cppunit/test_json_writer.cxx @@ -81,7 +81,7 @@ void JsonWriterTest::testArray() { tools::JsonWriter aJson; { - tools::ScopedJsonWriterArray aArray = aJson.startArray("items"); + auto aArray = aJson.startArray("items"); aJson.putSimpleValue("foo"); aJson.putSimpleValue("bar"); } diff --git a/tools/source/misc/json_writer.cxx b/tools/source/misc/json_writer.cxx index e3e27bf756b4..277164ee12cc 100644 --- a/tools/source/misc/json_writer.cxx +++ b/tools/source/misc/json_writer.cxx @@ -40,78 +40,46 @@ JsonWriter::~JsonWriter() free(mpBuffer); } -ScopedJsonWriterNode JsonWriter::startNode(std::string_view pNodeName) +JsonWriter::ScopedJsonWriterNode<'}'> JsonWriter::startNode(std::string_view pNodeName) { putLiteral(pNodeName, "{ "); mStartNodeCount++; mbFirstFieldInNode = true; - return ScopedJsonWriterNode(*this); + return { *this }; } -void JsonWriter::endNode() +void JsonWriter::endNode(char closing) { assert(mStartNodeCount && "mismatched StartNode/EndNode somewhere"); --mStartNodeCount; ensureSpace(1); - *mPos = '}'; + *mPos = closing; ++mPos; mbFirstFieldInNode = false; validate(); } -ScopedJsonWriterArray JsonWriter::startArray(std::string_view pNodeName) +JsonWriter::ScopedJsonWriterNode<']'> JsonWriter::startArray(std::string_view pNodeName) { putLiteral(pNodeName, "[ "); mStartNodeCount++; mbFirstFieldInNode = true; - return ScopedJsonWriterArray(*this); + return { *this }; } -void JsonWriter::endArray() +JsonWriter::ScopedJsonWriterNode<'}'> JsonWriter::startStruct() { - assert(mStartNodeCount && "mismatched StartNode/EndNode somewhere"); - --mStartNodeCount; - ensureSpace(1); - *mPos = ']'; - ++mPos; - mbFirstFieldInNode = false; + putRaw("{ "); - validate(); -} - -ScopedJsonWriterStruct JsonWriter::startStruct() -{ - ensureSpace(6); - - addCommaBeforeField(); - - *mPos = '{'; - ++mPos; - *mPos = ' '; - ++mPos; mStartNodeCount++; mbFirstFieldInNode = true; - validate(); - - return ScopedJsonWriterStruct(*this); -} - -void JsonWriter::endStruct() -{ - assert(mStartNodeCount && "mismatched StartNode/EndNode somewhere"); - --mStartNodeCount; - ensureSpace(1); - *mPos = '}'; - ++mPos; - mbFirstFieldInNode = false; - - validate(); + return { *this }; } static char getEscapementChar(char ch) |