aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorm-holger <m-holger@kubitscheck.org>2023-01-28 12:15:27 +0100
committerJay Berkenbilt <jberkenbilt@users.noreply.github.com>2023-01-28 20:49:32 +0100
commit3dde66ddcd6ad38a90bf46c4017c87f9a8656c0e (patch)
tree4c2abd503a0f58a701e156a6d3306237b1d18d97
parentdfa7d414f56d08b68cbf72023c9cceb0c9e5a6d9 (diff)
downloadqpdf-3dde66ddcd6ad38a90bf46c4017c87f9a8656c0e.tar.zst
Refactor JSON::writeNext
-rw-r--r--include/qpdf/JSON.hh1
-rw-r--r--libqpdf/JSON.cc17
2 files changed, 6 insertions, 12 deletions
diff --git a/include/qpdf/JSON.hh b/include/qpdf/JSON.hh
index 77c4b108..64f3792c 100644
--- a/include/qpdf/JSON.hh
+++ b/include/qpdf/JSON.hh
@@ -338,7 +338,6 @@ class JSON
static std::string encode_string(std::string const& utf8);
static void
writeClose(Pipeline* p, bool first, size_t depth, char const* delimeter);
- static void writeIndent(Pipeline* p, size_t depth);
struct JSON_value
{
diff --git a/libqpdf/JSON.cc b/libqpdf/JSON.cc
index 7bdf01d4..fd76e628 100644
--- a/libqpdf/JSON.cc
+++ b/libqpdf/JSON.cc
@@ -42,23 +42,18 @@ JSON::writeClose(Pipeline* p, bool first, size_t depth, char const* delimiter)
}
void
-JSON::writeIndent(Pipeline* p, size_t depth)
-{
- for (size_t i = 0; i < depth; ++i) {
- *p << " ";
- }
-}
-
-void
JSON::writeNext(Pipeline* p, bool& first, size_t depth)
{
if (first) {
first = false;
+ std::string s{"\n"};
+ s.append(2 * depth, ' ');
+ *p << s;
} else {
- *p << ",";
+ std::string s{",\n"};
+ s.append(2 * depth, ' ');
+ *p << s;
}
- *p << "\n";
- writeIndent(p, depth);
}
void