Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
regExp Class Reference

Wrapper around POSIX extended regular expressions. More...

Public Member Functions

 regExp ()
 Construct null. More...
 
 regExp (const char *, const bool ignoreCase=false)
 Construct from character array, optionally ignoring case. More...
 
 regExp (const std::string &, const bool ignoreCase=false)
 Construct from std::string (or string), optionally ignoring case. More...
 
 ~regExp ()
 Destructor. More...
 
bool empty () const
 Return true if a precompiled expression does not exist. More...
 
bool exists () const
 Does a precompiled expression exist? More...
 
int ngroups () const
 Return the number of (groups) More...
 
void set (const char *, const bool ignoreCase=false) const
 Compile pattern into a regular expression,. More...
 
void set (const std::string &, const bool ignoreCase=false) const
 Compile pattern into a regular expression,. More...
 
bool clear () const
 Release precompiled expression. More...
 
std::string::size_type find (const std::string &str) const
 Find position within string. More...
 
bool match (const std::string &) const
 Return true if it matches the entire string. More...
 
bool match (const std::string &, List< std::string > &groups) const
 Return true if it matches and sets the sub-groups matched. More...
 
bool match (const std::string &, List< string > &groups) const
 Return true if it matches and sets the sub-groups matched. More...
 
bool search (const std::string &str) const
 Return true if the regex was found within string. More...
 
void operator= (const char *)
 Assign and compile pattern from a character array. More...
 
void operator= (const std::string &)
 Assign and compile pattern from string. More...
 

Static Public Member Functions

static bool meta (char c)
 Is character a regular expression meta-character? More...
 

Private Member Functions

 regExp (const regExp &)
 Disallow default bitwise copy construct. More...
 
void operator= (const regExp &)
 Disallow default bitwise assignment. More...
 
template<class StringType >
bool matchGrouping (const std::string &, List< StringType > &groups) const
 Return true if it matches and sets the sub-groups matched. More...
 

Private Attributes

regex_t * preg_
 Precompiled regular expression. More...
 

Detailed Description

Wrapper around POSIX extended regular expressions.

The PCRE '(?i)' extension is provided to compile the regular expression as being case-insensitive.

See also
The manpage regex(7) for more information about POSIX regular expressions. These differ somewhat from Perl and sed regular expressions.
Source files

Definition at line 61 of file regExp.H.

Constructor & Destructor Documentation

◆ regExp() [1/4]

regExp ( const regExp )
private

Disallow default bitwise copy construct.

◆ regExp() [2/4]

regExp ( )

Construct null.

Definition at line 84 of file regExp.C.

◆ regExp() [3/4]

regExp ( const char *  pattern,
const bool  ignoreCase = false 
)

Construct from character array, optionally ignoring case.

Definition at line 90 of file regExp.C.

References regExp::set().

Here is the call graph for this function:

◆ regExp() [4/4]

regExp ( const std::string &  pattern,
const bool  ignoreCase = false 
)

Construct from std::string (or string), optionally ignoring case.

Definition at line 98 of file regExp.C.

References regExp::set().

Here is the call graph for this function:

◆ ~regExp()

~regExp ( )

Destructor.

Definition at line 108 of file regExp.C.

References clear().

Here is the call graph for this function:

Member Function Documentation

◆ operator=() [1/3]

void operator= ( const regExp )
private

Disallow default bitwise assignment.

◆ matchGrouping()

bool matchGrouping ( const std::string &  str,
List< StringType > &  groups 
) const
private

Return true if it matches and sets the sub-groups matched.

Templated to support both std::string and Foam::string

Definition at line 34 of file regExp.C.

References List::clear(), and List::setSize().

Here is the call graph for this function:

◆ meta()

static bool meta ( char  c)
inlinestatic

Is character a regular expression meta-character?

any character: '.'
quantifiers: '*', '+', '?'
grouping: '(', '|', ')'
range: '[', ']'
Don't bother checking for '{digit}' bounds

Definition at line 98 of file regExp.H.

Referenced by wordRe::meta().

Here is the caller graph for this function:

◆ empty()

bool empty ( ) const
inline

Return true if a precompiled expression does not exist.

Definition at line 131 of file regExp.H.

References regExp::preg_.

◆ exists()

bool exists ( ) const
inline

Does a precompiled expression exist?

Definition at line 137 of file regExp.H.

References regExp::preg_.

◆ ngroups()

int ngroups ( ) const
inline

Return the number of (groups)

Definition at line 143 of file regExp.H.

References regExp::preg_.

◆ set() [1/2]

void set ( const char *  pattern,
const bool  ignoreCase = false 
) const

Compile pattern into a regular expression,.

optionally ignoring case

Definition at line 116 of file regExp.C.

References clear(), Foam::exit(), Foam::FatalError, FatalErrorInFunction, and Foam::nl.

Referenced by regExp::regExp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set() [2/2]

void set ( const std::string &  pattern,
const bool  ignoreCase = false 
) const

Compile pattern into a regular expression,.

optionally ignoring case

Definition at line 163 of file regExp.C.

◆ clear()

bool clear ( ) const

Release precompiled expression.

Returns true if precompiled expression existed before clear

Definition at line 169 of file regExp.C.

◆ find()

std::string::size_type find ( const std::string &  str) const

Find position within string.

Returns the index where it begins or string::npos if not found

Definition at line 184 of file regExp.C.

Referenced by regExp::search().

Here is the caller graph for this function:

◆ match() [1/3]

bool match ( const std::string &  str) const

Return true if it matches the entire string.

The begin-of-line (^) and end-of-line ($) anchors are implicit

Definition at line 201 of file regExp.C.

Referenced by keyType::match(), and STARCDsurfaceFormatCore::readInpCellTable().

Here is the caller graph for this function:

◆ match() [2/3]

bool match ( const std::string &  str,
List< std::string > &  groups 
) const

Return true if it matches and sets the sub-groups matched.

The begin-of-line (^) and end-of-line ($) anchors are implicit

Definition at line 225 of file regExp.C.

◆ match() [3/3]

bool match ( const std::string &  str,
List< string > &  groups 
) const

Return true if it matches and sets the sub-groups matched.

The begin-of-line (^) and end-of-line ($) anchors are implicit

Definition at line 235 of file regExp.C.

◆ search()

bool search ( const std::string &  str) const
inline

Return true if the regex was found within string.

Definition at line 183 of file regExp.H.

References regExp::find().

Here is the call graph for this function:

◆ operator=() [2/3]

void operator= ( const char *  pat)

Assign and compile pattern from a character array.

Always case sensitive

Definition at line 246 of file regExp.C.

◆ operator=() [3/3]

void operator= ( const std::string &  pat)

Assign and compile pattern from string.

Always case sensitive

Definition at line 252 of file regExp.C.

Field Documentation

◆ preg_

regex_t* preg_
mutableprivate

Precompiled regular expression.

Definition at line 66 of file regExp.H.

Referenced by regExp::empty(), regExp::exists(), and regExp::ngroups().


The documentation for this class was generated from the following files: