mirror of
https://github.com/NixOS/nix
synced 2025-06-27 21:01:16 +02:00
Add function for quoting strings
(cherry picked from commit 7dcf5b011a
)
This commit is contained in:
parent
5a7e7fc35f
commit
edc34cc1a2
4 changed files with 22 additions and 31 deletions
|
@ -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. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue