Skip to content

Commit 2cc0b1b

Browse files
committed
Introduce quoteString utility function
1 parent 5446d63 commit 2cc0b1b

File tree

1 file changed

+15
-2
lines changed
  • src/libutil/include/nix/util

1 file changed

+15
-2
lines changed

src/libutil/include/nix/util/util.hh

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,28 @@ auto concatStrings(Parts &&... parts)
3333
return concatStringsSep({}, views);
3434
}
3535

36+
/**
37+
* Add quotes around a string.
38+
*/
39+
inline std::string quoteString(std::string_view s, char quote = '\'')
40+
{
41+
std::string result;
42+
result.reserve(s.size() + 2);
43+
result += quote;
44+
result += s;
45+
result += quote;
46+
return result;
47+
}
48+
3649
/**
3750
* Add quotes around a collection of strings.
3851
*/
3952
template<class C>
40-
Strings quoteStrings(const C & c)
53+
Strings quoteStrings(const C & c, char quote = '\'')
4154
{
4255
Strings res;
4356
for (auto & s : c)
44-
res.push_back("'" + s + "'");
57+
res.push_back(quoteString(s, quote));
4558
return res;
4659
}
4760

0 commit comments

Comments
 (0)