mirror of
https://github.com/NixOS/nix.git
synced 2025-11-14 14:32:42 +01:00
Introduce quoteString utility function
This commit is contained in:
parent
3645671570
commit
b5cae2741b
1 changed files with 15 additions and 2 deletions
|
|
@ -33,15 +33,28 @@ auto concatStrings(Parts &&... parts)
|
||||||
return concatStringsSep({}, views);
|
return concatStringsSep({}, views);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add quotes around a string.
|
||||||
|
*/
|
||||||
|
inline std::string quoteString(std::string_view s, char quote = '\'')
|
||||||
|
{
|
||||||
|
std::string result;
|
||||||
|
result.reserve(s.size() + 2);
|
||||||
|
result += quote;
|
||||||
|
result += s;
|
||||||
|
result += quote;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add quotes around a collection of strings.
|
* Add quotes around a collection of strings.
|
||||||
*/
|
*/
|
||||||
template<class C>
|
template<class C>
|
||||||
Strings quoteStrings(const C & c)
|
Strings quoteStrings(const C & c, char quote = '\'')
|
||||||
{
|
{
|
||||||
Strings res;
|
Strings res;
|
||||||
for (auto & s : c)
|
for (auto & s : c)
|
||||||
res.push_back("'" + s + "'");
|
res.push_back(quoteString(s, quote));
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue