tools: fix nfdc::text::ItemAttributes evaluation order bug

When multiple ItemAttributes::operator() invocations appear on the same
expression, they are not always evaluated left-to-right, causing incorrect
text output.

refs #3864

Change-Id: I4c99c5bc4a76b4becf83f368c9f253c0b254fc05
diff --git a/tools/nfdc/format-helpers.cpp b/tools/nfdc/format-helpers.cpp
index b6b8258..3d851dd 100644
--- a/tools/nfdc/format-helpers.cpp
+++ b/tools/nfdc/format-helpers.cpp
@@ -128,17 +128,7 @@
 ItemAttributes::Attribute
 ItemAttributes::operator()(const std::string& attribute)
 {
-  ++m_count;
-  if (m_wantMultiLine) {
-    return {m_count > 1,
-            {m_maxAttributeWidth - static_cast<int>(attribute.size())},
-            attribute};
-  }
-  else {
-    return {false,
-            {m_count > 1 ? 1 : 0},
-            attribute};
-  }
+  return {*this, attribute};
 }
 
 std::string
@@ -150,13 +140,21 @@
 std::ostream&
 operator<<(std::ostream& os, const ItemAttributes::Attribute& attr)
 {
-  if (attr.wantNewline) {
-    os << '\n';
+  ++attr.ia.m_count;
+  if (attr.ia.m_wantMultiLine) {
+    if (attr.ia.m_count > 1) {
+      os << '\n';
+    }
+    os << Spaces{attr.ia.m_maxAttributeWidth - static_cast<int>(attr.attribute.size())};
   }
-  return os << attr.spaces << attr.attribute << '=';
+  else {
+    if (attr.ia.m_count > 1) {
+      os << ' ';
+    }
+  }
+  return os << attr.attribute << '=';
 }
 
-
 std::string
 formatSeconds(time::seconds d, bool isLong)
 {