Refactor JSON::writeNext

This commit is contained in:
m-holger 2023-01-28 11:15:27 +00:00 committed by Jay Berkenbilt
parent dfa7d414f5
commit 3dde66ddcd
2 changed files with 6 additions and 12 deletions

View File

@ -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
{

View File

@ -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