aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr
diff options
context:
space:
mode:
authoreldritch horrors <pennae@lix.systems>2024-03-08 08:27:00 +0100
committereldritch horrors <pennae@lix.systems>2024-03-09 07:20:23 -0700
commit6b11c2cd7020869b796dc8e6904b358c9e41a23c (patch)
tree3c45c04afa82fd9a0956a50ea881e2de9fe8844f /src/libexpr
parent73cdaf44cf85d3a96596172edb10c9bc0509c1e0 (diff)
Extract `printSpace` helper
(cherry picked from commit 403c90ddf58a3f16a44dfe1f20004b6baa4e5ce2) Change-Id: I53c9824e6b1c4c619b4dfd8346d39e5289d92265
Diffstat (limited to 'src/libexpr')
-rw-r--r--src/libexpr/print.cc39
1 files changed, 19 insertions, 20 deletions
diff --git a/src/libexpr/print.cc b/src/libexpr/print.cc
index 572db25ed..df79718fb 100644
--- a/src/libexpr/print.cc
+++ b/src/libexpr/print.cc
@@ -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()
{
if (options.ansiColors)
@@ -322,11 +337,7 @@ private:
auto prettyPrint = shouldPrettyPrintAttrs(sorted);
for (auto & i : sorted) {
- if (prettyPrint) {
- output << "\n" << indent;
- } else {
- output << " ";
- }
+ printSpace(prettyPrint);
if (attrsPrinted >= options.maxAttrs) {
printElided(sorted.size() - attrsPrinted, "attribute", "attributes");
@@ -341,11 +352,7 @@ private:
}
decreaseIndent();
- if (prettyPrint) {
- output << "\n" << indent;
- } else {
- output << " ";
- }
+ printSpace(prettyPrint);
output << "}";
} else {
output << "{ ... }";
@@ -387,11 +394,7 @@ private:
auto listItems = v.listItems();
auto prettyPrint = shouldPrettyPrintList(listItems);
for (auto elem : listItems) {
- if (prettyPrint) {
- output << "\n" << indent;
- } else {
- output << " ";
- }
+ printSpace(prettyPrint);
if (listItemsPrinted >= options.maxListItems) {
printElided(v.listSize() - listItemsPrinted, "item", "items");
@@ -407,11 +410,7 @@ private:
}
decreaseIndent();
- if (prettyPrint) {
- output << "\n" << indent;
- } else {
- output << " ";
- }
+ printSpace(prettyPrint);
output << "]";
} else {
output << "[ ... ]";