Extract printSpace helper

(cherry picked from commit 403c90ddf58a3f16a44dfe1f20004b6baa4e5ce2)
Change-Id: I53c9824e6b1c4c619b4dfd8346d39e5289d92265
This commit is contained in:
eldritch horrors 2024-03-08 08:27:00 +01:00
parent 73cdaf44cf
commit 6b11c2cd70

View file

@ -179,6 +179,21 @@ private:
} }
} }
/**
* Print a space (for separating items or attributes).
*
* If pretty-printing is enabled, a newline and the current `indent` is
* printed instead.
*/
void printSpace(bool prettyPrint)
{
if (prettyPrint) {
output << "\n" << indent;
} else {
output << " ";
}
}
void printRepeated() void printRepeated()
{ {
if (options.ansiColors) if (options.ansiColors)
@ -322,11 +337,7 @@ private:
auto prettyPrint = shouldPrettyPrintAttrs(sorted); auto prettyPrint = shouldPrettyPrintAttrs(sorted);
for (auto & i : sorted) { for (auto & i : sorted) {
if (prettyPrint) { printSpace(prettyPrint);
output << "\n" << indent;
} else {
output << " ";
}
if (attrsPrinted >= options.maxAttrs) { if (attrsPrinted >= options.maxAttrs) {
printElided(sorted.size() - attrsPrinted, "attribute", "attributes"); printElided(sorted.size() - attrsPrinted, "attribute", "attributes");
@ -341,11 +352,7 @@ private:
} }
decreaseIndent(); decreaseIndent();
if (prettyPrint) { printSpace(prettyPrint);
output << "\n" << indent;
} else {
output << " ";
}
output << "}"; output << "}";
} else { } else {
output << "{ ... }"; output << "{ ... }";
@ -387,11 +394,7 @@ private:
auto listItems = v.listItems(); auto listItems = v.listItems();
auto prettyPrint = shouldPrettyPrintList(listItems); auto prettyPrint = shouldPrettyPrintList(listItems);
for (auto elem : listItems) { for (auto elem : listItems) {
if (prettyPrint) { printSpace(prettyPrint);
output << "\n" << indent;
} else {
output << " ";
}
if (listItemsPrinted >= options.maxListItems) { if (listItemsPrinted >= options.maxListItems) {
printElided(v.listSize() - listItemsPrinted, "item", "items"); printElided(v.listSize() - listItemsPrinted, "item", "items");
@ -407,11 +410,7 @@ private:
} }
decreaseIndent(); decreaseIndent();
if (prettyPrint) { printSpace(prettyPrint);
output << "\n" << indent;
} else {
output << " ";
}
output << "]"; output << "]";
} else { } else {
output << "[ ... ]"; output << "[ ... ]";