ENH: also store the group matches from IF( MATCHES) in CMAKE_MATCH_(0..9)
Alex
This commit is contained in:
parent
fb43c64476
commit
e80acd971c
|
@ -15,6 +15,8 @@
|
|||
|
||||
=========================================================================*/
|
||||
#include "cmIfCommand.h"
|
||||
#include "cmStringCommand.h"
|
||||
|
||||
#include <stdlib.h> // required for atof
|
||||
#include <list>
|
||||
#include <cmsys/RegularExpression.hxx>
|
||||
|
@ -215,7 +217,7 @@ namespace
|
|||
|
||||
|
||||
bool cmIfCommand::IsTrue(const std::vector<std::string> &args,
|
||||
char **errorString, const cmMakefile *makefile)
|
||||
char **errorString, cmMakefile *makefile)
|
||||
{
|
||||
// check for the different signatures
|
||||
const char *def;
|
||||
|
@ -369,6 +371,7 @@ bool cmIfCommand::IsTrue(const std::vector<std::string> &args,
|
|||
{
|
||||
def = cmIfCommand::GetVariableOrString(arg->c_str(), makefile);
|
||||
const char* rex = (argP2)->c_str();
|
||||
cmStringCommand::ClearMatches(makefile);
|
||||
cmsys::RegularExpression regEntry;
|
||||
if ( !regEntry.compile(rex) )
|
||||
{
|
||||
|
@ -382,6 +385,7 @@ bool cmIfCommand::IsTrue(const std::vector<std::string> &args,
|
|||
if (regEntry.find(def))
|
||||
{
|
||||
*arg = "1";
|
||||
cmStringCommand::StoreMatches(makefile, regEntry);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -174,7 +174,7 @@ public:
|
|||
// arguments were valid, and if so, was the response true. If there is
|
||||
// an error, the errorString will be set.
|
||||
static bool IsTrue(const std::vector<std::string> &args,
|
||||
char** errorString, const cmMakefile *mf);
|
||||
char** errorString, cmMakefile *mf);
|
||||
|
||||
// Get a definition from the makefile. If it doesn't exist,
|
||||
// return the original string.
|
||||
|
|
|
@ -248,7 +248,7 @@ bool cmStringCommand::RegexMatch(std::vector<std::string> const& args)
|
|||
input += args[i];
|
||||
}
|
||||
|
||||
this->ClearMatches();
|
||||
this->ClearMatches(this->Makefile);
|
||||
// Compile the regular expression.
|
||||
cmsys::RegularExpression re;
|
||||
if(!re.compile(regex.c_str()))
|
||||
|
@ -263,7 +263,7 @@ bool cmStringCommand::RegexMatch(std::vector<std::string> const& args)
|
|||
std::string output;
|
||||
if(re.find(input.c_str()))
|
||||
{
|
||||
this->StoreMatches(re);
|
||||
this->StoreMatches(this->Makefile, re);
|
||||
std::string::size_type l = re.start();
|
||||
std::string::size_type r = re.end();
|
||||
if(r-l == 0)
|
||||
|
@ -297,7 +297,7 @@ bool cmStringCommand::RegexMatchAll(std::vector<std::string> const& args)
|
|||
input += args[i];
|
||||
}
|
||||
|
||||
this->ClearMatches();
|
||||
this->ClearMatches(this->Makefile);
|
||||
// Compile the regular expression.
|
||||
cmsys::RegularExpression re;
|
||||
if(!re.compile(regex.c_str()))
|
||||
|
@ -314,7 +314,7 @@ bool cmStringCommand::RegexMatchAll(std::vector<std::string> const& args)
|
|||
const char* p = input.c_str();
|
||||
while(re.find(p))
|
||||
{
|
||||
this->StoreMatches(re);
|
||||
this->StoreMatches(this->Makefile, re);
|
||||
std::string::size_type l = re.start();
|
||||
std::string::size_type r = re.end();
|
||||
if(r-l == 0)
|
||||
|
@ -401,7 +401,7 @@ bool cmStringCommand::RegexReplace(std::vector<std::string> const& args)
|
|||
input += args[i];
|
||||
}
|
||||
|
||||
this->ClearMatches();
|
||||
this->ClearMatches(this->Makefile);
|
||||
// Compile the regular expression.
|
||||
cmsys::RegularExpression re;
|
||||
if(!re.compile(regex.c_str()))
|
||||
|
@ -418,7 +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);
|
||||
this->StoreMatches(this->Makefile, re);
|
||||
std::string::size_type l2 = re.start();
|
||||
std::string::size_type r = re.end();
|
||||
|
||||
|
@ -479,24 +479,24 @@ bool cmStringCommand::RegexReplace(std::vector<std::string> const& args)
|
|||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmStringCommand::ClearMatches()
|
||||
void cmStringCommand::ClearMatches(cmMakefile* mf)
|
||||
{
|
||||
for (unsigned int i=0; i<10; i++)
|
||||
{
|
||||
char name[128];
|
||||
sprintf(name, "CMAKE_MATCH_%d", i);
|
||||
this->Makefile->AddDefinition(name, "");
|
||||
mf->AddDefinition(name, "");
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmStringCommand::StoreMatches(cmsys::RegularExpression& re)
|
||||
void cmStringCommand::StoreMatches(cmMakefile* mf,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());
|
||||
mf->AddDefinition(name, re.match(i).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include "cmCommand.h"
|
||||
|
||||
class cmMakefile;
|
||||
namespace cmsys
|
||||
{
|
||||
class RegularExpression;
|
||||
|
@ -122,6 +123,8 @@ public:
|
|||
}
|
||||
|
||||
cmTypeMacro(cmStringCommand, cmCommand);
|
||||
static void ClearMatches(cmMakefile* mf);
|
||||
static void StoreMatches(cmMakefile* mf, cmsys::RegularExpression& re);
|
||||
protected:
|
||||
bool HandleConfigureCommand(std::vector<std::string> const& args);
|
||||
bool HandleAsciiCommand(std::vector<std::string> const& args);
|
||||
|
@ -137,8 +140,6 @@ protected:
|
|||
bool HandleSubstringCommand(std::vector<std::string> const& args);
|
||||
bool HandleStripCommand(std::vector<std::string> const& args);
|
||||
bool HandleRandomCommand(std::vector<std::string> const& args);
|
||||
void ClearMatches();
|
||||
void StoreMatches(cmsys::RegularExpression& re);
|
||||
|
||||
class RegexReplacement
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue