From 447fbf061a5f27abbad59a9fc943de4f8351f9fe Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Mon, 18 Oct 2021 16:45:55 -0400 Subject: EscapeForCMake: Add wrapQuotes parameter --- Source/cmOutputConverter.cxx | 9 ++++++--- Source/cmOutputConverter.h | 8 +++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Source/cmOutputConverter.cxx b/Source/cmOutputConverter.cxx index 2b785e1..02b4821 100644 --- a/Source/cmOutputConverter.cxx +++ b/Source/cmOutputConverter.cxx @@ -219,10 +219,11 @@ std::string cmOutputConverter::EscapeForShell( return Shell_GetArgument(str, flags); } -std::string cmOutputConverter::EscapeForCMake(cm::string_view str) +std::string cmOutputConverter::EscapeForCMake(cm::string_view str, + WrapQuotes wrapQuotes) { // Always double-quote the argument to take care of most escapes. - std::string result = "\""; + std::string result = (wrapQuotes == WrapQuotes::Wrap) ? "\"" : ""; for (const char c : str) { if (c == '"') { // Escape the double quote to avoid ending the argument. @@ -238,7 +239,9 @@ std::string cmOutputConverter::EscapeForCMake(cm::string_view str) result += c; } } - result += "\""; + if (wrapQuotes == WrapQuotes::Wrap) { + result += "\""; + } return result; } diff --git a/Source/cmOutputConverter.h b/Source/cmOutputConverter.h index 865df71..53ec247 100644 --- a/Source/cmOutputConverter.h +++ b/Source/cmOutputConverter.h @@ -94,7 +94,13 @@ public: bool forEcho = false, bool useWatcomQuote = false, bool unescapeNinjaConfiguration = false) const; - static std::string EscapeForCMake(cm::string_view str); + enum class WrapQuotes + { + Wrap, + NoWrap, + }; + static std::string EscapeForCMake(cm::string_view str, + WrapQuotes wrapQuotes = WrapQuotes::Wrap); /** Compute an escaped version of the given argument for use in a windows shell. */ -- cgit v0.12