From c1b3484c2d5e2bce3234fba775af4a39182ccbc4 Mon Sep 17 00:00:00 2001 From: Alexander Neundorf Date: Tue, 21 Aug 2007 11:30:09 -0400 Subject: 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 --- Source/cmStringCommand.cxx | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) 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 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 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 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 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 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 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 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 const& args) { -- cgit v0.12