1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-14 22:42:41 +01:00

Introduce quoteString utility function

This commit is contained in:
John Ericson 2025-11-11 10:56:50 -05:00
parent 3645671570
commit b5cae2741b

View file

@ -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;
} }