ENH: ExpandVariables functions return a char * for convenience
This commit is contained in:
parent
7aa0d0d888
commit
0645a50061
|
@ -866,29 +866,29 @@ int cmMakefile::DumpDocumentationToFile(std::ostream& f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void cmMakefile::ExpandVariablesInString(std::string& source) const
|
const char *cmMakefile::ExpandVariablesInString(std::string& source) const
|
||||||
{
|
{
|
||||||
this->ExpandVariablesInString(source, false);
|
return this->ExpandVariablesInString(source, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmMakefile::ExpandVariablesInString(std::string& source,
|
const char *cmMakefile::ExpandVariablesInString(std::string& source,
|
||||||
bool escapeQuotes) const
|
bool escapeQuotes) const
|
||||||
{
|
{
|
||||||
// This method replaces ${VAR} and @VAR@ where VAR is looked up
|
// This method replaces ${VAR} and @VAR@ where VAR is looked up
|
||||||
// in the m_Definitions map, if not found in the map, nothing is expanded.
|
// in the m_Definitions map, if not found in the map, nothing is expanded.
|
||||||
// It also supports the $ENV{VAR} syntax where VAR is looked up in
|
// It also supports the $ENV{VAR} syntax where VAR is looked up in
|
||||||
// the current environment variables.
|
// the current environment variables.
|
||||||
|
|
||||||
// start by look for $ or @ in the string
|
// start by look for $ or @ in the string
|
||||||
std::string::size_type markerPos = source.find_first_of("$@");
|
std::string::size_type markerPos = source.find_first_of("$@");
|
||||||
// if not found, or found as the last character, then leave quickly as
|
// if not found, or found as the last character, then leave quickly as
|
||||||
// nothing needs to be expanded
|
// nothing needs to be expanded
|
||||||
if((markerPos == std::string::npos) || (markerPos >= source.size()-1))
|
if((markerPos == std::string::npos) || (markerPos >= source.size()-1))
|
||||||
{
|
{
|
||||||
return;
|
return source.c_str();
|
||||||
}
|
}
|
||||||
// current position
|
// current position
|
||||||
std::string::size_type currentPos =0; // start at 0
|
std::string::size_type currentPos =0; // start at 0
|
||||||
std::string result; // string with replacements
|
std::string result; // string with replacements
|
||||||
// go until the the end of the string
|
// go until the the end of the string
|
||||||
while((markerPos != std::string::npos) && (markerPos < source.size()-1))
|
while((markerPos != std::string::npos) && (markerPos < source.size()-1))
|
||||||
|
@ -907,7 +907,7 @@ void cmMakefile::ExpandVariablesInString(std::string& source,
|
||||||
markerStartSize = 2;
|
markerStartSize = 2;
|
||||||
}
|
}
|
||||||
// $ENV{var} case
|
// $ENV{var} case
|
||||||
else if(markerPos+4 < source.size() &&
|
else if(markerPos+4 < source.size() &&
|
||||||
source[markerPos+4] == '{' &&
|
source[markerPos+4] == '{' &&
|
||||||
!source.substr(markerPos+1, 3).compare("ENV"))
|
!source.substr(markerPos+1, 3).compare("ENV"))
|
||||||
{
|
{
|
||||||
|
@ -932,7 +932,7 @@ void cmMakefile::ExpandVariablesInString(std::string& source,
|
||||||
{
|
{
|
||||||
markerPos += markerStartSize; // move past marker
|
markerPos += markerStartSize; // move past marker
|
||||||
// find the end variable marker starting at the markerPos
|
// find the end variable marker starting at the markerPos
|
||||||
std::string::size_type endVariablePos =
|
std::string::size_type endVariablePos =
|
||||||
source.find(endVariableMarker, markerPos);
|
source.find(endVariableMarker, markerPos);
|
||||||
if(endVariablePos == std::string::npos)
|
if(endVariablePos == std::string::npos)
|
||||||
{
|
{
|
||||||
|
@ -955,7 +955,7 @@ void cmMakefile::ExpandVariablesInString(std::string& source,
|
||||||
if (markerStartSize == 5) // $ENV{
|
if (markerStartSize == 5) // $ENV{
|
||||||
{
|
{
|
||||||
char *ptr = getenv(var.c_str());
|
char *ptr = getenv(var.c_str());
|
||||||
if (ptr)
|
if (ptr)
|
||||||
{
|
{
|
||||||
if (escapeQuotes)
|
if (escapeQuotes)
|
||||||
{
|
{
|
||||||
|
@ -985,7 +985,7 @@ void cmMakefile::ExpandVariablesInString(std::string& source,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if found add to result, if not, then it gets blanked
|
// if found add to result, if not, then it gets blanked
|
||||||
if (!found)
|
if (!found)
|
||||||
{
|
{
|
||||||
// if no definition is found then add the var back
|
// if no definition is found then add the var back
|
||||||
if(endVariableMarker == '@')
|
if(endVariableMarker == '@')
|
||||||
|
@ -1006,9 +1006,10 @@ void cmMakefile::ExpandVariablesInString(std::string& source,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
markerPos = source.find_first_of("$@", currentPos);
|
markerPos = source.find_first_of("$@", currentPos);
|
||||||
}
|
}
|
||||||
result += source.substr(currentPos); // pick up the rest of the string
|
result += source.substr(currentPos); // pick up the rest of the string
|
||||||
source = result;
|
source = result;
|
||||||
|
return source.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmMakefile::RemoveVariablesInString(std::string& source) const
|
void cmMakefile::RemoveVariablesInString(std::string& source) const
|
||||||
|
|
|
@ -504,8 +504,8 @@ public:
|
||||||
* entry in the m_Definitions map. Also @var@ is
|
* entry in the m_Definitions map. Also @var@ is
|
||||||
* expanded to match autoconf style expansions.
|
* expanded to match autoconf style expansions.
|
||||||
*/
|
*/
|
||||||
void ExpandVariablesInString(std::string& source) const;
|
const char *ExpandVariablesInString(std::string& source) const;
|
||||||
void ExpandVariablesInString(std::string& source, bool escapeQuotes) const;
|
const char *ExpandVariablesInString(std::string& source, bool escapeQuotes) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove any remaining variables in the string. Anything with ${var} or
|
* Remove any remaining variables in the string. Anything with ${var} or
|
||||||
|
|
Loading…
Reference in New Issue