summaryrefslogtreecommitdiffstats
path: root/Source/cmStringCommand.cxx
diff options
context:
space:
mode:
authorAlexander Neundorf <neundorf@kde.org>2007-08-21 15:30:09 (GMT)
committerAlexander Neundorf <neundorf@kde.org>2007-08-21 15:30:09 (GMT)
commitc1b3484c2d5e2bce3234fba775af4a39182ccbc4 (patch)
tree91dbe4b83af44c5f0921f2de41aef41b3946130b /Source/cmStringCommand.cxx
parentbf354fa308d4ff6923d0811697e162f9625fdec9 (diff)
downloadCMake-c1b3484c2d5e2bce3234fba775af4a39182ccbc4.zip
CMake-c1b3484c2d5e2bce3234fba775af4a39182ccbc4.tar.gz
CMake-c1b3484c2d5e2bce3234fba775af4a39182ccbc4.tar.bz2
ENH: store the matches for paren-delimited subexpression in
CMAKE_MATCH_[0..9] variables, so to get multiple subexpressions from one string STRING(REGEX MATCH) has to be executed only once Alex
Diffstat (limited to 'Source/cmStringCommand.cxx')
-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)
{