aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/util.hh
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-05-02 21:09:52 +0200
committerEelco Dolstra <edolstra@gmail.com>2020-03-24 13:44:04 +0100
commitedc34cc1a2865777cee6b325f705fb218955b593 (patch)
tree2d436d8aa1afec06e5b38c8c12411c151a830ef0 /src/libutil/util.hh
parent5a7e7fc35f934872a9e3e9e9043ff6894b36637a (diff)
Add function for quoting strings
(cherry picked from commit 7dcf5b011a0942ecf953f2b607c4c8d0e9e652c7)
Diffstat (limited to 'src/libutil/util.hh')
-rw-r--r--src/libutil/util.hh22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/libutil/util.hh b/src/libutil/util.hh
index 3bfebcd15..559ed4332 100644
--- a/src/libutil/util.hh
+++ b/src/libutil/util.hh
@@ -345,8 +345,26 @@ template<class C> C tokenizeString(std::string_view s, const string & separators
/* Concatenate the given strings with a separator between the
elements. */
-string concatStringsSep(const string & sep, const Strings & ss);
-string concatStringsSep(const string & sep, const StringSet & ss);
+template<class C>
+string concatStringsSep(const string & sep, const C & ss)
+{
+ string s;
+ for (auto & i : ss) {
+ if (s.size() != 0) s += sep;
+ s += i;
+ }
+ return s;
+}
+
+
+/* Add quotes around a collection of strings. */
+template<class C> Strings quoteStrings(const C & c)
+{
+ Strings res;
+ for (auto & s : c)
+ res.push_back("'" + s + "'");
+ return res;
+}
/* Remove trailing whitespace from a string. */