cmMakefile: Improve ExpandVariablesInString return type

Return `std::string const&` instead of a `const char*` that points
into a string anyway.  Update call sites accordingly.
This commit is contained in:
Vitaly Stakhovsky
2018-04-27 11:28:30 -04:00
committed by Brad King
parent b542e0c74f
commit e13fa223fc
3 changed files with 12 additions and 11 deletions

View File

@@ -405,7 +405,8 @@ char CCONV* cmExpandVariablesInString(void* arg, const char* source,
{
cmMakefile* mf = static_cast<cmMakefile*>(arg);
std::string barf = source;
std::string result = mf->ExpandVariablesInString(barf, escapeQuotes, atOnly);
std::string const& result =
mf->ExpandVariablesInString(barf, escapeQuotes, atOnly);
return strdup(result.c_str());
}

View File

@@ -2412,12 +2412,13 @@ std::vector<std::string> cmMakefile::GetDefinitions() const
return res;
}
const char* cmMakefile::ExpandVariablesInString(std::string& source) const
const std::string& cmMakefile::ExpandVariablesInString(
std::string& source) const
{
return this->ExpandVariablesInString(source, false, false);
}
const char* cmMakefile::ExpandVariablesInString(
const std::string& cmMakefile::ExpandVariablesInString(
std::string& source, bool escapeQuotes, bool noEscapes, bool atOnly,
const char* filename, long line, bool removeEmpty, bool replaceAt) const
{
@@ -2433,7 +2434,7 @@ const char* cmMakefile::ExpandVariablesInString(
this->IssueMessage(cmake::INTERNAL_ERROR,
"ExpandVariablesInString @ONLY called "
"on something with escapes.");
return source.c_str();
return source;
}
// Variables used in the WARN case.
@@ -2515,7 +2516,7 @@ const char* cmMakefile::ExpandVariablesInString(
this->IssueMessage(cmake::AUTHOR_WARNING, msg);
}
return source.c_str();
return source;
}
cmake::MessageType cmMakefile::ExpandVariablesInStringOld(

View File

@@ -565,12 +565,11 @@ public:
* entry in the this->Definitions map. Also \@var\@ is
* expanded to match autoconf style expansions.
*/
const char* ExpandVariablesInString(std::string& source) const;
const char* ExpandVariablesInString(std::string& source, bool escapeQuotes,
bool noEscapes, bool atOnly = false,
const char* filename = nullptr,
long line = -1, bool removeEmpty = false,
bool replaceAt = false) const;
const std::string& ExpandVariablesInString(std::string& source) const;
const std::string& ExpandVariablesInString(
std::string& source, bool escapeQuotes, bool noEscapes,
bool atOnly = false, const char* filename = nullptr, long line = -1,
bool removeEmpty = false, bool replaceAt = false) const;
/**
* Remove any remaining variables in the string. Anything with ${var} or