Skip to content

Commit

Permalink
Refactor JSON::writeNext
Browse files Browse the repository at this point in the history
  • Loading branch information
m-holger authored and jberkenbilt committed Jan 28, 2023
1 parent dfa7d41 commit 3dde66d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
1 change: 0 additions & 1 deletion include/qpdf/JSON.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
17 changes: 6 additions & 11 deletions libqpdf/JSON.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,19 @@ 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
Expand Down

0 comments on commit 3dde66d

Please sign in to comment.