summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Holtermann <sebholt@xwmw.org>2019-07-28 14:39:03 +0200
committerSebastian Holtermann <sebholt@xwmw.org>2019-07-28 17:47:26 +0200
commit6675f785bec2d777720abbdc062f514bd838b879 (patch)
tree15fbabf02891fb27aee22ad032ef9238f369f3f4
parent09977c181641dd4feea8fc13bf718f0f9cfe05bb (diff)
downloadcmake-6675f785bec2d777720abbdc062f514bd838b879.tar.gz
cmOutputConverter: Let EscapeForCMake accept a cm::string_view
-rw-r--r--Source/cmOutputConverter.cxx12
-rw-r--r--Source/cmOutputConverter.h7
2 files changed, 10 insertions, 9 deletions
diff --git a/Source/cmOutputConverter.cxx b/Source/cmOutputConverter.cxx
index d7bcf7e279..55d9bd687b 100644
--- a/Source/cmOutputConverter.cxx
+++ b/Source/cmOutputConverter.cxx
@@ -120,23 +120,23 @@ std::string cmOutputConverter::EscapeForShell(const std::string& str,
return Shell__GetArgument(str.c_str(), flags);
}
-std::string cmOutputConverter::EscapeForCMake(const std::string& str)
+std::string cmOutputConverter::EscapeForCMake(cm::string_view str)
{
// Always double-quote the argument to take care of most escapes.
std::string result = "\"";
- for (const char* c = str.c_str(); *c; ++c) {
- if (*c == '"') {
+ for (const char c : str) {
+ if (c == '"') {
// Escape the double quote to avoid ending the argument.
result += "\\\"";
- } else if (*c == '$') {
+ } else if (c == '$') {
// Escape the dollar to avoid expanding variables.
result += "\\$";
- } else if (*c == '\\') {
+ } else if (c == '\\') {
// Escape the backslash to avoid other escapes.
result += "\\\\";
} else {
// Other characters will be parsed correctly.
- result += *c;
+ result += c;
}
}
result += "\"";
diff --git a/Source/cmOutputConverter.h b/Source/cmOutputConverter.h
index deca767c64..fe39fe6590 100644
--- a/Source/cmOutputConverter.h
+++ b/Source/cmOutputConverter.h
@@ -5,9 +5,10 @@
#include "cmConfigure.h" // IWYU pragma: keep
-#include <string>
-
#include "cmStateSnapshot.h"
+#include "cm_string_view.hxx"
+
+#include <string>
class cmState;
@@ -76,7 +77,7 @@ public:
bool forEcho = false,
bool useWatcomQuote = false) const;
- static std::string EscapeForCMake(const std::string& str);
+ static std::string EscapeForCMake(cm::string_view str);
/** Compute an escaped version of the given argument for use in a
windows shell. */