mirror of
https://github.com/Kitware/CMake.git
synced 2026-04-22 14:23:10 -05:00
cmOutputConverter: Let EscapeForCMake accept a cm::string_view
This commit is contained in:
@@ -120,23 +120,23 @@ std::string cmOutputConverter::EscapeForShell(const std::string& str,
|
|||||||
return Shell__GetArgument(str.c_str(), flags);
|
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.
|
// Always double-quote the argument to take care of most escapes.
|
||||||
std::string result = "\"";
|
std::string result = "\"";
|
||||||
for (const char* c = str.c_str(); *c; ++c) {
|
for (const char c : str) {
|
||||||
if (*c == '"') {
|
if (c == '"') {
|
||||||
// Escape the double quote to avoid ending the argument.
|
// Escape the double quote to avoid ending the argument.
|
||||||
result += "\\\"";
|
result += "\\\"";
|
||||||
} else if (*c == '$') {
|
} else if (c == '$') {
|
||||||
// Escape the dollar to avoid expanding variables.
|
// Escape the dollar to avoid expanding variables.
|
||||||
result += "\\$";
|
result += "\\$";
|
||||||
} else if (*c == '\\') {
|
} else if (c == '\\') {
|
||||||
// Escape the backslash to avoid other escapes.
|
// Escape the backslash to avoid other escapes.
|
||||||
result += "\\\\";
|
result += "\\\\";
|
||||||
} else {
|
} else {
|
||||||
// Other characters will be parsed correctly.
|
// Other characters will be parsed correctly.
|
||||||
result += *c;
|
result += c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result += "\"";
|
result += "\"";
|
||||||
|
|||||||
@@ -5,9 +5,10 @@
|
|||||||
|
|
||||||
#include "cmConfigure.h" // IWYU pragma: keep
|
#include "cmConfigure.h" // IWYU pragma: keep
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "cmStateSnapshot.h"
|
#include "cmStateSnapshot.h"
|
||||||
|
#include "cm_string_view.hxx"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
class cmState;
|
class cmState;
|
||||||
|
|
||||||
@@ -76,7 +77,7 @@ public:
|
|||||||
bool forEcho = false,
|
bool forEcho = false,
|
||||||
bool useWatcomQuote = false) const;
|
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
|
/** Compute an escaped version of the given argument for use in a
|
||||||
windows shell. */
|
windows shell. */
|
||||||
|
|||||||
Reference in New Issue
Block a user