aboutsummaryrefslogtreecommitdiff
path: root/bpkg/diagnostics.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-09-25 07:03:43 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-09-25 07:03:43 +0200
commit79f46e26a38414eadb701cc925d195d67371518e (patch)
treea7978c5ab3d893d04613daa1cadaf523c9110fb0 /bpkg/diagnostics.cxx
parent04ea94103db92d6d27230794e14606547aacf670 (diff)
Quote arguments with spaces in print_process()
Diffstat (limited to 'bpkg/diagnostics.cxx')
-rw-r--r--bpkg/diagnostics.cxx21
1 files changed, 17 insertions, 4 deletions
diff --git a/bpkg/diagnostics.cxx b/bpkg/diagnostics.cxx
index 221bded..ece3308 100644
--- a/bpkg/diagnostics.cxx
+++ b/bpkg/diagnostics.cxx
@@ -4,6 +4,7 @@
#include <bpkg/diagnostics>
+#include <cstring> // strchr()
#include <iostream>
#include <odb/statement.hxx>
@@ -34,10 +35,22 @@ namespace bpkg
r << " |"; // Trailing space will be added inside the loop.
for (m++; *p != nullptr; p++, m++)
- r << (p != args ? " " : "")
- << (**p == '\0' ? "\"" : "") // Quote empty arguments.
- << *p
- << (**p == '\0' ? "\"" : "");
+ {
+ if (p != args)
+ r << ' ';
+
+ // Quote if empty or contains spaces.
+ //
+ bool q (**p == '\0' || strchr (*p, ' ') != nullptr);
+
+ if (q)
+ r << '"';
+
+ r << *p;
+
+ if (q)
+ r << '"';
+ }
if (m < n) // Can we examine the next element?
{