stringapi: Take strings in escaping functions
This commit is contained in:
parent
4c53997f38
commit
215b1addf0
|
@ -2358,7 +2358,7 @@ void cmLocalGenerator::AppendFlags(std::string& flags,
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
void cmLocalGenerator::AppendFlagEscape(std::string& flags,
|
void cmLocalGenerator::AppendFlagEscape(std::string& flags,
|
||||||
const char* rawFlag)
|
const std::string& rawFlag)
|
||||||
{
|
{
|
||||||
this->AppendFlags(flags, this->EscapeForShell(rawFlag).c_str());
|
this->AppendFlags(flags, this->EscapeForShell(rawFlag).c_str());
|
||||||
}
|
}
|
||||||
|
@ -3187,7 +3187,7 @@ cmLocalGenerator
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
std::string cmLocalGenerator::EscapeForShellOldStyle(const char* str)
|
std::string cmLocalGenerator::EscapeForShellOldStyle(const std::string& str)
|
||||||
{
|
{
|
||||||
std::string result;
|
std::string result;
|
||||||
#if defined(_WIN32) && !defined(__CYGWIN__)
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
||||||
|
@ -3203,7 +3203,7 @@ std::string cmLocalGenerator::EscapeForShellOldStyle(const char* str)
|
||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
#else
|
#else
|
||||||
for(const char* ch = str; *ch != '\0'; ++ch)
|
for(const char* ch = str.c_str(); *ch != '\0'; ++ch)
|
||||||
{
|
{
|
||||||
if(*ch == ' ')
|
if(*ch == ' ')
|
||||||
{
|
{
|
||||||
|
@ -3216,28 +3216,30 @@ std::string cmLocalGenerator::EscapeForShellOldStyle(const char* str)
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
static bool cmLocalGeneratorIsShellOperator(const char* str)
|
static bool cmLocalGeneratorIsShellOperator(const std::string& str)
|
||||||
{
|
{
|
||||||
if(strcmp(str, "<") == 0 ||
|
static std::set<std::string> shellOperators;
|
||||||
strcmp(str, ">") == 0 ||
|
if(shellOperators.empty())
|
||||||
strcmp(str, "<<") == 0 ||
|
|
||||||
strcmp(str, ">>") == 0 ||
|
|
||||||
strcmp(str, "|") == 0 ||
|
|
||||||
strcmp(str, "||") == 0 ||
|
|
||||||
strcmp(str, "&&") == 0 ||
|
|
||||||
strcmp(str, "&>") == 0 ||
|
|
||||||
strcmp(str, "1>") == 0 ||
|
|
||||||
strcmp(str, "2>") == 0 ||
|
|
||||||
strcmp(str, "2>&1") == 0 ||
|
|
||||||
strcmp(str, "1>&2") == 0)
|
|
||||||
{
|
{
|
||||||
return true;
|
shellOperators.insert("<");
|
||||||
|
shellOperators.insert(">");
|
||||||
|
shellOperators.insert("<<");
|
||||||
|
shellOperators.insert(">>");
|
||||||
|
shellOperators.insert("|");
|
||||||
|
shellOperators.insert("||");
|
||||||
|
shellOperators.insert("&&");
|
||||||
|
shellOperators.insert("&>");
|
||||||
|
shellOperators.insert("1>");
|
||||||
|
shellOperators.insert("2>");
|
||||||
|
shellOperators.insert("2>&1");
|
||||||
|
shellOperators.insert("1>&2");
|
||||||
}
|
}
|
||||||
return false;
|
return shellOperators.count(str) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
std::string cmLocalGenerator::EscapeForShell(const char* str, bool makeVars,
|
std::string cmLocalGenerator::EscapeForShell(const std::string& str,
|
||||||
|
bool makeVars,
|
||||||
bool forEcho)
|
bool forEcho)
|
||||||
{
|
{
|
||||||
// Do not escape shell operators.
|
// Do not escape shell operators.
|
||||||
|
@ -3279,28 +3281,28 @@ std::string cmLocalGenerator::EscapeForShell(const char* str, bool makeVars,
|
||||||
|
|
||||||
// Compute the buffer size needed.
|
// Compute the buffer size needed.
|
||||||
int size = (this->WindowsShell ?
|
int size = (this->WindowsShell ?
|
||||||
cmsysSystem_Shell_GetArgumentSizeForWindows(str, flags) :
|
cmsysSystem_Shell_GetArgumentSizeForWindows(str.c_str(), flags) :
|
||||||
cmsysSystem_Shell_GetArgumentSizeForUnix(str, flags));
|
cmsysSystem_Shell_GetArgumentSizeForUnix(str.c_str(), flags));
|
||||||
|
|
||||||
// Compute the shell argument itself.
|
// Compute the shell argument itself.
|
||||||
std::vector<char> arg(size);
|
std::vector<char> arg(size);
|
||||||
if(this->WindowsShell)
|
if(this->WindowsShell)
|
||||||
{
|
{
|
||||||
cmsysSystem_Shell_GetArgumentForWindows(str, &arg[0], flags);
|
cmsysSystem_Shell_GetArgumentForWindows(str.c_str(), &arg[0], flags);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cmsysSystem_Shell_GetArgumentForUnix(str, &arg[0], flags);
|
cmsysSystem_Shell_GetArgumentForUnix(str.c_str(), &arg[0], flags);
|
||||||
}
|
}
|
||||||
return std::string(&arg[0]);
|
return std::string(&arg[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
std::string cmLocalGenerator::EscapeForCMake(const char* str)
|
std::string cmLocalGenerator::EscapeForCMake(const std::string& 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; ++c)
|
for(const char* c = str.c_str(); *c; ++c)
|
||||||
{
|
{
|
||||||
if(*c == '"')
|
if(*c == '"')
|
||||||
{
|
{
|
||||||
|
|
|
@ -150,7 +150,8 @@ public:
|
||||||
const char* config);
|
const char* config);
|
||||||
///! Append flags to a string.
|
///! Append flags to a string.
|
||||||
virtual void AppendFlags(std::string& flags, const char* newFlags);
|
virtual void AppendFlags(std::string& flags, const char* newFlags);
|
||||||
virtual void AppendFlagEscape(std::string& flags, const char* rawFlag);
|
virtual void AppendFlagEscape(std::string& flags,
|
||||||
|
const std::string& rawFlag);
|
||||||
///! Get the include flags for the current makefile and language
|
///! Get the include flags for the current makefile and language
|
||||||
std::string GetIncludeFlags(const std::vector<std::string> &includes,
|
std::string GetIncludeFlags(const std::vector<std::string> &includes,
|
||||||
cmGeneratorTarget* target,
|
cmGeneratorTarget* target,
|
||||||
|
@ -285,14 +286,14 @@ public:
|
||||||
system to replace make variable references. Optionally adjust
|
system to replace make variable references. Optionally adjust
|
||||||
escapes for the special case of passing to the native echo
|
escapes for the special case of passing to the native echo
|
||||||
command. */
|
command. */
|
||||||
std::string EscapeForShell(const char* str, bool makeVars = false,
|
std::string EscapeForShell(const std::string& str, bool makeVars = false,
|
||||||
bool forEcho = false);
|
bool forEcho = false);
|
||||||
|
|
||||||
/** Backwards-compatibility version of EscapeForShell. */
|
/** Backwards-compatibility version of EscapeForShell. */
|
||||||
std::string EscapeForShellOldStyle(const char* str);
|
std::string EscapeForShellOldStyle(const std::string& str);
|
||||||
|
|
||||||
/** Escape the given string as an argument in a CMake script. */
|
/** Escape the given string as an argument in a CMake script. */
|
||||||
static std::string EscapeForCMake(const char* str);
|
static std::string EscapeForCMake(const std::string& str);
|
||||||
|
|
||||||
enum FortranFormat
|
enum FortranFormat
|
||||||
{
|
{
|
||||||
|
|
|
@ -2100,7 +2100,7 @@ void cmLocalVisualStudio7Generator::WriteVCProjFooter(std::ostream& fout,
|
||||||
<< "</VisualStudioProject>\n";
|
<< "</VisualStudioProject>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string cmLocalVisualStudio7GeneratorEscapeForXML(const char* s)
|
std::string cmLocalVisualStudio7GeneratorEscapeForXML(const std::string& s)
|
||||||
{
|
{
|
||||||
std::string ret = s;
|
std::string ret = s;
|
||||||
cmSystemTools::ReplaceString(ret, "&", "&");
|
cmSystemTools::ReplaceString(ret, "&", "&");
|
||||||
|
@ -2111,7 +2111,7 @@ std::string cmLocalVisualStudio7GeneratorEscapeForXML(const char* s)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string cmLocalVisualStudio7Generator::EscapeForXML(const char* s)
|
std::string cmLocalVisualStudio7Generator::EscapeForXML(const std::string& s)
|
||||||
{
|
{
|
||||||
return cmLocalVisualStudio7GeneratorEscapeForXML(s);
|
return cmLocalVisualStudio7GeneratorEscapeForXML(s);
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,7 +84,7 @@ private:
|
||||||
void WriteConfiguration(std::ostream& fout,
|
void WriteConfiguration(std::ostream& fout,
|
||||||
const char* configName,
|
const char* configName,
|
||||||
const std::string& libName, cmTarget &tgt);
|
const std::string& libName, cmTarget &tgt);
|
||||||
std::string EscapeForXML(const char* s);
|
std::string EscapeForXML(const std::string& s);
|
||||||
std::string ConvertToXMLOutputPath(const char* path);
|
std::string ConvertToXMLOutputPath(const char* path);
|
||||||
std::string ConvertToXMLOutputPathSingle(const char* path);
|
std::string ConvertToXMLOutputPathSingle(const char* path);
|
||||||
void OutputTargetRules(std::ostream& fout, const char* configName,
|
void OutputTargetRules(std::ostream& fout, const char* configName,
|
||||||
|
|
|
@ -37,7 +37,7 @@ cmLocalXCodeGenerator::GetTargetDirectory(cmTarget const&) const
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
void cmLocalXCodeGenerator::AppendFlagEscape(std::string& flags,
|
void cmLocalXCodeGenerator::AppendFlagEscape(std::string& flags,
|
||||||
const char* rawFlag)
|
const std::string& rawFlag)
|
||||||
{
|
{
|
||||||
cmGlobalXCodeGenerator* gg =
|
cmGlobalXCodeGenerator* gg =
|
||||||
static_cast<cmGlobalXCodeGenerator*>(this->GlobalGenerator);
|
static_cast<cmGlobalXCodeGenerator*>(this->GlobalGenerator);
|
||||||
|
|
|
@ -28,7 +28,8 @@ public:
|
||||||
|
|
||||||
virtual ~cmLocalXCodeGenerator();
|
virtual ~cmLocalXCodeGenerator();
|
||||||
virtual std::string GetTargetDirectory(cmTarget const& target) const;
|
virtual std::string GetTargetDirectory(cmTarget const& target) const;
|
||||||
virtual void AppendFlagEscape(std::string& flags, const char* rawFlag);
|
virtual void AppendFlagEscape(std::string& flags,
|
||||||
|
const std::string& rawFlag);
|
||||||
virtual void Generate();
|
virtual void Generate();
|
||||||
virtual void GenerateInstallRules();
|
virtual void GenerateInstallRules();
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -179,10 +179,11 @@ void cmSystemTools::ExpandRegistryValues(std::string& source, KeyWOW64)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::string cmSystemTools::EscapeQuotes(const char* str)
|
std::string cmSystemTools::EscapeQuotes(const std::string& str)
|
||||||
{
|
{
|
||||||
std::string result = "";
|
std::string result;
|
||||||
for(const char* ch = str; *ch != '\0'; ++ch)
|
result.reserve(str.size());
|
||||||
|
for(const char* ch = str.c_str(); *ch != '\0'; ++ch)
|
||||||
{
|
{
|
||||||
if(*ch == '"')
|
if(*ch == '"')
|
||||||
{
|
{
|
||||||
|
|
|
@ -47,7 +47,7 @@ public:
|
||||||
KeyWOW64 view = KeyWOW64_Default);
|
KeyWOW64 view = KeyWOW64_Default);
|
||||||
|
|
||||||
///! Escape quotes in a string.
|
///! Escape quotes in a string.
|
||||||
static std::string EscapeQuotes(const char* str);
|
static std::string EscapeQuotes(const std::string& str);
|
||||||
|
|
||||||
/** Map help document name to file name. */
|
/** Map help document name to file name. */
|
||||||
static std::string HelpFileName(std::string);
|
static std::string HelpFileName(std::string);
|
||||||
|
|
Loading…
Reference in New Issue