From b5cae2741b98bdfdb304bd21b2be3d895916be39 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 11 Nov 2025 10:56:50 -0500 Subject: [PATCH] Introduce `quoteString` utility function --- src/libutil/include/nix/util/util.hh | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/libutil/include/nix/util/util.hh b/src/libutil/include/nix/util/util.hh index ffec8f1a4..eca98df6d 100644 --- a/src/libutil/include/nix/util/util.hh +++ b/src/libutil/include/nix/util/util.hh @@ -33,15 +33,28 @@ auto concatStrings(Parts &&... parts) 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. */ template -Strings quoteStrings(const C & c) +Strings quoteStrings(const C & c, char quote = '\'') { Strings res; for (auto & s : c) - res.push_back("'" + s + "'"); + res.push_back(quoteString(s, quote)); return res; }