Browse Source

EscapeForCMake: Add wrapQuotes parameter

Kyle Edwards 4 years ago
parent
commit
447fbf061a
2 changed files with 13 additions and 4 deletions
  1. 6 3
      Source/cmOutputConverter.cxx
  2. 7 1
      Source/cmOutputConverter.h

+ 6 - 3
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;
 }
 

+ 7 - 1
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.  */