mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
handle NULL pointer in regExp
This commit is contained in:
@ -1,3 +0,0 @@
|
|||||||
EXE_LIBS = \
|
|
||||||
$(FOAM_LIBBIN)/libOSspecific.o
|
|
||||||
|
|
||||||
|
|||||||
@ -76,6 +76,36 @@ int main(int argc, char *argv[])
|
|||||||
Info << endl;
|
Info << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Info<<"test regExp(const char*) ..." << endl;
|
||||||
|
string me("Mark");
|
||||||
|
|
||||||
|
if (regExp("[Mm]ar[ck]").match(me))
|
||||||
|
{
|
||||||
|
Info<< "matched: " << me << endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Info<< "no match" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (regExp("").match(me))
|
||||||
|
{
|
||||||
|
Info<< "matched: " << me << endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Info<< "no match" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (regExp(NULL).match(me))
|
||||||
|
{
|
||||||
|
Info<< "matched: " << me << endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Info<< "no match" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
Info<< endl;
|
Info<< endl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@ -37,6 +37,10 @@ License
|
|||||||
void Foam::regExp::compile(const char* pat) const
|
void Foam::regExp::compile(const char* pat) const
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
|
|
||||||
|
// avoid NULL and zero-length patterns
|
||||||
|
if (pat && *pat)
|
||||||
|
{
|
||||||
preg_ = new regex_t;
|
preg_ = new regex_t;
|
||||||
|
|
||||||
if (regcomp(preg_, pat, REG_EXTENDED) != 0)
|
if (regcomp(preg_, pat, REG_EXTENDED) != 0)
|
||||||
@ -48,6 +52,7 @@ void Foam::regExp::compile(const char* pat) const
|
|||||||
<< exit(FatalError);
|
<< exit(FatalError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Foam::regExp::clear() const
|
void Foam::regExp::clear() const
|
||||||
@ -60,6 +65,7 @@ void Foam::regExp::clear() const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::regExp::regExp()
|
Foam::regExp::regExp()
|
||||||
@ -83,6 +89,7 @@ Foam::regExp::regExp(const char* pat)
|
|||||||
compile(pat);
|
compile(pat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::regExp::~regExp()
|
Foam::regExp::~regExp()
|
||||||
@ -90,6 +97,7 @@ Foam::regExp::~regExp()
|
|||||||
clear();
|
clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
int Foam::regExp::ngroups() const
|
int Foam::regExp::ngroups() const
|
||||||
@ -110,6 +118,7 @@ bool Foam::regExp::match
|
|||||||
regmatch_t pmatch[1];
|
regmatch_t pmatch[1];
|
||||||
|
|
||||||
// match and also verify that the entire string was matched
|
// match and also verify that the entire string was matched
|
||||||
|
// pmatch[0] is the entire match
|
||||||
if
|
if
|
||||||
(
|
(
|
||||||
regexec(preg_, str.c_str(), nmatch, pmatch, 0) == 0
|
regexec(preg_, str.c_str(), nmatch, pmatch, 0) == 0
|
||||||
@ -141,6 +150,8 @@ bool Foam::regExp::match
|
|||||||
regmatch_t pmatch[nmatch];
|
regmatch_t pmatch[nmatch];
|
||||||
|
|
||||||
// match and also verify that the entire string was matched
|
// match and also verify that the entire string was matched
|
||||||
|
// pmatch[0] is the entire match
|
||||||
|
// pmatch[1..] are the (...) sub-groups
|
||||||
if
|
if
|
||||||
(
|
(
|
||||||
regexec(preg_, str.c_str(), nmatch, pmatch, 0) == 0
|
regexec(preg_, str.c_str(), nmatch, pmatch, 0) == 0
|
||||||
@ -179,8 +190,8 @@ bool Foam::regExp::match
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
void Foam::regExp::operator=(const string& pat)
|
void Foam::regExp::operator=(const string& pat)
|
||||||
{
|
{
|
||||||
@ -193,4 +204,5 @@ void Foam::regExp::operator=(const char* pat)
|
|||||||
compile(pat);
|
compile(pat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
Reference in New Issue
Block a user