[cmake-commits] alex committed cmStringCommand.cxx 1.23 1.24

cmake-commits at cmake.org cmake-commits at cmake.org
Tue Aug 21 11:30:12 EDT 2007


Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv2458

Modified Files:
	cmStringCommand.cxx 
Log Message:

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


Index: cmStringCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmStringCommand.cxx,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- cmStringCommand.cxx	27 Apr 2007 01:50:52 -0000	1.23
+++ cmStringCommand.cxx	21 Aug 2007 15:30:09 -0000	1.24
@@ -248,6 +248,7 @@
     input += args[i];
     }
   
+  this->ClearMatches();
   // Compile the regular expression.
   cmsys::RegularExpression re;
   if(!re.compile(regex.c_str()))
@@ -262,6 +263,7 @@
   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 @@
     input += args[i];
     }
   
+  this->ClearMatches();
   // Compile the regular expression.
   cmsys::RegularExpression re;
   if(!re.compile(regex.c_str()))
@@ -311,6 +314,7 @@
   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 @@
     input += args[i];
     }
   
+  this->ClearMatches();
   // Compile the regular expression.
   cmsys::RegularExpression re;
   if(!re.compile(regex.c_str()))
@@ -413,6 +418,7 @@
   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 @@
 }
 
 //----------------------------------------------------------------------------
+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)
 {



More information about the Cmake-commits mailing list