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
This commit is contained in:
parent
bf354fa308
commit
c1b3484c2d
@ -248,6 +248,7 @@ bool cmStringCommand::RegexMatch(std::vector<std::string> const& args)
|
|||||||
input += args[i];
|
input += args[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this->ClearMatches();
|
||||||
// Compile the regular expression.
|
// Compile the regular expression.
|
||||||
cmsys::RegularExpression re;
|
cmsys::RegularExpression re;
|
||||||
if(!re.compile(regex.c_str()))
|
if(!re.compile(regex.c_str()))
|
||||||
@ -262,6 +263,7 @@ bool cmStringCommand::RegexMatch(std::vector<std::string> const& args)
|
|||||||
std::string output;
|
std::string output;
|
||||||
if(re.find(input.c_str()))
|
if(re.find(input.c_str()))
|
||||||
{
|
{
|
||||||
|
this->StoreMatches(re);
|
||||||
std::string::size_type l = re.start();
|
std::string::size_type l = re.start();
|
||||||
std::string::size_type r = re.end();
|
std::string::size_type r = re.end();
|
||||||
if(r-l == 0)
|
if(r-l == 0)
|
||||||
@ -295,6 +297,7 @@ bool cmStringCommand::RegexMatchAll(std::vector<std::string> const& args)
|
|||||||
input += args[i];
|
input += args[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this->ClearMatches();
|
||||||
// Compile the regular expression.
|
// Compile the regular expression.
|
||||||
cmsys::RegularExpression re;
|
cmsys::RegularExpression re;
|
||||||
if(!re.compile(regex.c_str()))
|
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();
|
const char* p = input.c_str();
|
||||||
while(re.find(p))
|
while(re.find(p))
|
||||||
{
|
{
|
||||||
|
this->StoreMatches(re);
|
||||||
std::string::size_type l = re.start();
|
std::string::size_type l = re.start();
|
||||||
std::string::size_type r = re.end();
|
std::string::size_type r = re.end();
|
||||||
if(r-l == 0)
|
if(r-l == 0)
|
||||||
@ -397,6 +401,7 @@ bool cmStringCommand::RegexReplace(std::vector<std::string> const& args)
|
|||||||
input += args[i];
|
input += args[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this->ClearMatches();
|
||||||
// Compile the regular expression.
|
// Compile the regular expression.
|
||||||
cmsys::RegularExpression re;
|
cmsys::RegularExpression re;
|
||||||
if(!re.compile(regex.c_str()))
|
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;
|
std::string::size_type base = 0;
|
||||||
while(re.find(input.c_str()+base))
|
while(re.find(input.c_str()+base))
|
||||||
{
|
{
|
||||||
|
this->StoreMatches(re);
|
||||||
std::string::size_type l2 = re.start();
|
std::string::size_type l2 = re.start();
|
||||||
std::string::size_type r = re.end();
|
std::string::size_type r = re.end();
|
||||||
|
|
||||||
@ -472,6 +478,28 @@ bool cmStringCommand::RegexReplace(std::vector<std::string> const& args)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
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&
|
bool cmStringCommand::HandleCompareCommand(std::vector<std::string> const&
|
||||||
args)
|
args)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user