summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/cmStringCommand.cxx28
1 files changed, 28 insertions, 0 deletions
diff --git a/Source/cmStringCommand.cxx b/Source/cmStringCommand.cxx
index 4bc9ca6..437b121 100644
--- a/Source/cmStringCommand.cxx
+++ b/Source/cmStringCommand.cxx
@@ -248,6 +248,7 @@ bool cmStringCommand::RegexMatch(std::vector<std::string> const& args)
input += args[i];
}
+ this->ClearMatches();
// Compile the regular expression.
cmsys::RegularExpression re;
if(!re.compile(regex.c_str()))
@@ -262,6 +263,7 @@ bool cmStringCommand::RegexMatch(std::vector<std::string> const& args)
std::string output;
if(re.find(input.c_str()))
{
+ this->StoreMatches(re);
std::string::size_type l = re.start();
std::string::size_type r = re.end();
if(r-l == 0)
@@ -295,6 +297,7 @@ bool cmStringCommand::RegexMatchAll(std::vector<std::string> const& args)
input += args[i];
}
+ this->ClearMatches();
// Compile the regular expression.
cmsys::RegularExpression re;
if(!re.compile(regex.c_str()))
@@ -311,6 +314,7 @@ bool cmStringCommand::RegexMatchAll(std::vector<std::string> const& args)
const char* p = input.c_str();
while(re.find(p))
{
+ this->StoreMatches(re);
std::string::size_type l = re.start();
std::string::size_type r = re.end();
if(r-l == 0)
@@ -397,6 +401,7 @@ bool cmStringCommand::RegexReplace(std::vector<std::string> const& args)
input += args[i];
}
+ this->ClearMatches();
// Compile the regular expression.
cmsys::RegularExpression re;
if(!re.compile(regex.c_str()))
@@ -413,6 +418,7 @@ bool cmStringCommand::RegexReplace(std::vector<std::string> const& args)
std::string::size_type base = 0;
while(re.find(input.c_str()+base))
{
+ this->StoreMatches(re);
std::string::size_type l2 = re.start();
std::string::size_type r = re.end();
@@ -473,6 +479,28 @@ bool cmStringCommand::RegexReplace(std::vector<std::string> const& args)
}
//----------------------------------------------------------------------------
+void cmStringCommand::ClearMatches()
+{
+ for (unsigned int i=0; i<10; i++)
+ {
+ char name[128];
+ sprintf(name, "CMAKE_MATCH_%d", i);
+ this->Makefile->AddDefinition(name, "");
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmStringCommand::StoreMatches(cmsys::RegularExpression& re)
+{
+ for (unsigned int i=0; i<10; i++)
+ {
+ char name[128];
+ sprintf(name, "CMAKE_MATCH_%d", i);
+ this->Makefile->AddDefinition(name, re.match(i).c_str());
+ }
+}
+
+//----------------------------------------------------------------------------
bool cmStringCommand::HandleCompareCommand(std::vector<std::string> const&
args)
{