diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index ded4fc65e..75f2130a5 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -2358,7 +2358,7 @@ void cmLocalGenerator::AppendFlags(std::string& flags, //---------------------------------------------------------------------------- void cmLocalGenerator::AppendFlagEscape(std::string& flags, - const char* rawFlag) + const std::string& rawFlag) { 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; #if defined(_WIN32) && !defined(__CYGWIN__) @@ -3203,7 +3203,7 @@ std::string cmLocalGenerator::EscapeForShellOldStyle(const char* str) } return str; #else - for(const char* ch = str; *ch != '\0'; ++ch) + for(const char* ch = str.c_str(); *ch != '\0'; ++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 || - strcmp(str, ">") == 0 || - 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) + static std::set shellOperators; + if(shellOperators.empty()) { - 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) { // Do not escape shell operators. @@ -3279,28 +3281,28 @@ std::string cmLocalGenerator::EscapeForShell(const char* str, bool makeVars, // Compute the buffer size needed. int size = (this->WindowsShell ? - cmsysSystem_Shell_GetArgumentSizeForWindows(str, flags) : - cmsysSystem_Shell_GetArgumentSizeForUnix(str, flags)); + cmsysSystem_Shell_GetArgumentSizeForWindows(str.c_str(), flags) : + cmsysSystem_Shell_GetArgumentSizeForUnix(str.c_str(), flags)); // Compute the shell argument itself. std::vector arg(size); if(this->WindowsShell) { - cmsysSystem_Shell_GetArgumentForWindows(str, &arg[0], flags); + cmsysSystem_Shell_GetArgumentForWindows(str.c_str(), &arg[0], flags); } else { - cmsysSystem_Shell_GetArgumentForUnix(str, &arg[0], flags); + cmsysSystem_Shell_GetArgumentForUnix(str.c_str(), &arg[0], flags); } 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. std::string result = "\""; - for(const char* c = str; *c; ++c) + for(const char* c = str.c_str(); *c; ++c) { if(*c == '"') { diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index c1deb0921..633be5d9b 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -150,7 +150,8 @@ public: const char* config); ///! Append flags to a string. 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 std::string GetIncludeFlags(const std::vector &includes, cmGeneratorTarget* target, @@ -285,14 +286,14 @@ public: system to replace make variable references. Optionally adjust escapes for the special case of passing to the native echo command. */ - std::string EscapeForShell(const char* str, bool makeVars = false, + std::string EscapeForShell(const std::string& str, bool makeVars = false, bool forEcho = false); /** 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. */ - static std::string EscapeForCMake(const char* str); + static std::string EscapeForCMake(const std::string& str); enum FortranFormat { diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index 280320ffb..7b921a3d0 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -2100,7 +2100,7 @@ void cmLocalVisualStudio7Generator::WriteVCProjFooter(std::ostream& fout, << "\n"; } -std::string cmLocalVisualStudio7GeneratorEscapeForXML(const char* s) +std::string cmLocalVisualStudio7GeneratorEscapeForXML(const std::string& s) { std::string ret = s; cmSystemTools::ReplaceString(ret, "&", "&"); @@ -2111,7 +2111,7 @@ std::string cmLocalVisualStudio7GeneratorEscapeForXML(const char* s) return ret; } -std::string cmLocalVisualStudio7Generator::EscapeForXML(const char* s) +std::string cmLocalVisualStudio7Generator::EscapeForXML(const std::string& s) { return cmLocalVisualStudio7GeneratorEscapeForXML(s); } diff --git a/Source/cmLocalVisualStudio7Generator.h b/Source/cmLocalVisualStudio7Generator.h index 760716e3a..2823a2cc3 100644 --- a/Source/cmLocalVisualStudio7Generator.h +++ b/Source/cmLocalVisualStudio7Generator.h @@ -84,7 +84,7 @@ private: void WriteConfiguration(std::ostream& fout, const char* configName, 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 ConvertToXMLOutputPathSingle(const char* path); void OutputTargetRules(std::ostream& fout, const char* configName, diff --git a/Source/cmLocalXCodeGenerator.cxx b/Source/cmLocalXCodeGenerator.cxx index a9a27b90c..fb8c2d15e 100644 --- a/Source/cmLocalXCodeGenerator.cxx +++ b/Source/cmLocalXCodeGenerator.cxx @@ -37,7 +37,7 @@ cmLocalXCodeGenerator::GetTargetDirectory(cmTarget const&) const //---------------------------------------------------------------------------- void cmLocalXCodeGenerator::AppendFlagEscape(std::string& flags, - const char* rawFlag) + const std::string& rawFlag) { cmGlobalXCodeGenerator* gg = static_cast(this->GlobalGenerator); diff --git a/Source/cmLocalXCodeGenerator.h b/Source/cmLocalXCodeGenerator.h index edd2f5ba2..3bfe3a30a 100644 --- a/Source/cmLocalXCodeGenerator.h +++ b/Source/cmLocalXCodeGenerator.h @@ -28,7 +28,8 @@ public: virtual ~cmLocalXCodeGenerator(); 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 GenerateInstallRules(); private: diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 9b35e61d3..2b17fba73 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -179,10 +179,11 @@ void cmSystemTools::ExpandRegistryValues(std::string& source, KeyWOW64) } #endif -std::string cmSystemTools::EscapeQuotes(const char* str) +std::string cmSystemTools::EscapeQuotes(const std::string& str) { - std::string result = ""; - for(const char* ch = str; *ch != '\0'; ++ch) + std::string result; + result.reserve(str.size()); + for(const char* ch = str.c_str(); *ch != '\0'; ++ch) { if(*ch == '"') { diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index 51c103e2b..4a212c266 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -47,7 +47,7 @@ public: KeyWOW64 view = KeyWOW64_Default); ///! 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. */ static std::string HelpFileName(std::string);