diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2019-05-02 21:09:52 +0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2019-05-02 21:09:52 +0200 |
commit | 7dcf5b011a0942ecf953f2b607c4c8d0e9e652c7 (patch) | |
tree | f972208955b1099711ab6407f875e544918ffeef /src/libutil/util.hh | |
parent | 2b8c63f303de7d1da133cb3e9a00d509dca40f57 (diff) |
Add function for quoting strings
Diffstat (limited to 'src/libutil/util.hh')
-rw-r--r-- | src/libutil/util.hh | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/libutil/util.hh b/src/libutil/util.hh index 9f239bff3..8bd57d2e4 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -334,8 +334,26 @@ template<class C> C tokenizeString(const string & 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. */ |