regExpPosix Class Reference

Wrapper around POSIX extended regular expressions with some additional prefix-handling. The prefix-handling is loosely oriented on PCRE regular expressions and provides a simple means of tuning the expressions. More...

Public Types

typedef SubStrings< std::string > results_type
 Type for matches - similar to std::smatch. More...
 
using meta = regExpCxx::meta
 Functor wrapper for testing meta-characters. More...
 

Public Member Functions

 regExpPosix () noexcept
 Default construct. More...
 
 regExpPosix (const regExpPosix &)=delete
 Copy construct - disallowed. More...
 
 regExpPosix (regExpPosix &&rgx) noexcept
 Move construct. More...
 
 regExpPosix (const char *pattern, const bool ignoreCase=false)
 Construct from character array, optionally ignore case. More...
 
 regExpPosix (const std::string &pattern, const bool ignoreCase=false)
 Construct from string, optionally ignore case. More...
 
 ~regExpPosix ()
 Destructor. More...
 
bool empty () const noexcept
 Return true if a precompiled expression does not exist. More...
 
bool exists () const noexcept
 Return true if a precompiled expression exists. More...
 
bool negated () const noexcept
 True if pattern matching is negated. More...
 
bool negate (bool on) noexcept
 Change pattern negation, return previous value. More...
 
unsigned ngroups () const
 
bool clear ()
 Clear expression. More...
 
void swap (regExpPosix &rgx)
 Swap contents. More...
 
bool set (const char *pattern, bool ignoreCase=false)
 Compile pattern into a regular expression, optionally ignore case. More...
 
bool set (const std::string &pattern, bool ignoreCase=false)
 Compile pattern into a regular expression, optionally ignore case. More...
 
std::string::size_type find (const std::string &text) const
 Find position within the text. More...
 
bool match (const std::string &text) const
 True if the regex matches the entire text. More...
 
bool match (const std::string &text, results_type &matches) const
 True if the regex matches the text, set the matches. More...
 
bool search (const std::string &text) const
 Return true if the regex was found within the text. More...
 
bool operator() (const std::string &text) const
 Perform match on text. More...
 
void operator= (const regExpPosix &)=delete
 Copy assignment - disallowed. More...
 
void operator= (regExpPosix &&rgx)
 Move assignment. More...
 
void operator= (const char *pattern)
 Assign and compile pattern from a character array. More...
 
void operator= (const std::string &pattern)
 Assign and compile pattern from string. More...
 

Static Public Member Functions

static bool is_meta (const char c) noexcept
 Test if character is a regex meta-character. More...
 
static bool is_meta (const std::string &str, const char quote='\\')
 Test if string contains any (unquoted) meta-characters. More...
 

Static Public Attributes

static int grammar
 Grammar (unused) - for compatibility with Foam::regExpCxx. More...
 

Detailed Description

Wrapper around POSIX extended regular expressions with some additional prefix-handling. The prefix-handling is loosely oriented on PCRE regular expressions and provides a simple means of tuning the expressions.

The prefixes are detected as (?...) at the beginning of the regular expression. Any unknown/unsupported prefixes are silently ignored.

  • "(?!i)" : one or more embedded pattern-match modifiers for the entire pattern.
  • the 'i' indicates ignore-case
  • the '!' (exclamation) indicates negated (inverted) matching
See also
The manpage regex(7) for more information about POSIX regular expressions. These differ somewhat from Perl and sed regular expressions.
Foam::regExp and Foam::regExpCxx
Warning
This class should not be used directly. Use the Foam::regExp typedef instead.
Deprecated:
This class will be superseded by Foam::regExpCxx as compiler support for regular expressions continues to improve.
Source files

Definition at line 84 of file regExpPosix.H.

Member Typedef Documentation

◆ results_type

typedef SubStrings<std::string> results_type

Type for matches - similar to std::smatch.

Definition at line 112 of file regExpPosix.H.

◆ meta

Functor wrapper for testing meta-characters.

Definition at line 143 of file regExpPosix.H.

Constructor & Destructor Documentation

◆ regExpPosix() [1/5]

regExpPosix ( )
inlinenoexcept

Default construct.

Definition at line 32 of file regExpPosixI.H.

◆ regExpPosix() [2/5]

regExpPosix ( const regExpPosix )
delete

Copy construct - disallowed.

◆ regExpPosix() [3/5]

regExpPosix ( regExpPosix &&  rgx)
inlinenoexcept

Move construct.

Definition at line 39 of file regExpPosixI.H.

◆ regExpPosix() [4/5]

regExpPosix ( const char *  pattern,
const bool  ignoreCase = false 
)
inlineexplicit

Construct from character array, optionally ignore case.

Definition at line 49 of file regExpPosixI.H.

References regExpPosix::set().

Here is the call graph for this function:

◆ regExpPosix() [5/5]

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

Construct from string, optionally ignore case.

Definition at line 62 of file regExpPosixI.H.

References regExpPosix::set().

Here is the call graph for this function:

◆ ~regExpPosix()

~regExpPosix ( )
inline

Destructor.

Definition at line 77 of file regExpPosixI.H.

References clear().

Here is the call graph for this function:

Member Function Documentation

◆ is_meta() [1/2]

static bool is_meta ( const char  c)
inlinestaticnoexcept

Test if character is a regex meta-character.

Definition at line 124 of file regExpPosix.H.

References regExpCxx::is_meta().

Here is the call graph for this function:

◆ is_meta() [2/2]

static bool is_meta ( const std::string &  str,
const char  quote = '\\' 
)
inlinestatic

Test if string contains any (unquoted) meta-characters.

Definition at line 130 of file regExpPosix.H.

References regExpCxx::is_meta().

Here is the call graph for this function:

◆ empty()

bool empty ( ) const
inlinenoexcept

Return true if a precompiled expression does not exist.

Definition at line 85 of file regExpPosixI.H.

◆ exists()

bool exists ( ) const
inlinenoexcept

Return true if a precompiled expression exists.

Definition at line 91 of file regExpPosixI.H.

◆ negated()

bool negated ( ) const
inlinenoexcept

True if pattern matching is negated.

Definition at line 97 of file regExpPosixI.H.

◆ negate()

bool negate ( bool  on)
inlinenoexcept

Change pattern negation, return previous value.

Definition at line 103 of file regExpPosixI.H.

◆ ngroups()

unsigned ngroups ( ) const
inline

The number of capture groups for a non-empty, non-negated expressions

Definition at line 123 of file regExpPosixI.H.

◆ clear()

bool clear ( )

Clear expression.

Returns
True if expression had existed prior to the clear.

Definition at line 135 of file regExpPosix.C.

◆ swap()

void swap ( regExpPosix rgx)
inline

Swap contents.

Definition at line 167 of file regExpPosixI.H.

◆ set() [1/2]

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

Compile pattern into a regular expression, optionally ignore case.

Returns
True if the pattern was compiled

Definition at line 129 of file regExpPosixI.H.

Referenced by regExpPosix::regExpPosix().

Here is the caller graph for this function:

◆ set() [2/2]

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

Compile pattern into a regular expression, optionally ignore case.

Returns
True if the pattern was compiled

Definition at line 141 of file regExpPosixI.H.

◆ find()

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

Find position within the text.

Returns
The index where it begins or string::npos if not found
Note
does not properly work with negated regex!

Definition at line 151 of file regExpPosix.C.

◆ match() [1/2]

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

True if the regex matches the entire text.

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

Definition at line 194 of file regExpPosix.C.

◆ match() [2/2]

bool match ( const std::string &  text,
results_type matches 
) const

True if the regex matches the text, set the matches.

The first group starts at index 1 (0 is the entire match). The begin-of-line (^) and end-of-line ($) anchors are implicit

Note
does not properly work with negated regex!

◆ search()

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

Return true if the regex was found within the text.

Definition at line 152 of file regExpPosixI.H.

◆ operator()()

bool operator() ( const std::string &  text) const
inline

Perform match on text.

Definition at line 180 of file regExpPosixI.H.

◆ operator=() [1/4]

void operator= ( const regExpPosix )
delete

Copy assignment - disallowed.

◆ operator=() [2/4]

void operator= ( regExpPosix &&  rgx)
inline

Move assignment.

Definition at line 186 of file regExpPosixI.H.

References clear().

Here is the call graph for this function:

◆ operator=() [3/4]

void operator= ( const char *  pattern)
inline

Assign and compile pattern from a character array.

Matching is case sensitive.

Definition at line 197 of file regExpPosixI.H.

◆ operator=() [4/4]

void operator= ( const std::string &  pattern)
inline

Assign and compile pattern from string.

Matching is case sensitive.

Definition at line 203 of file regExpPosixI.H.

Member Data Documentation

◆ grammar

int grammar
static

Grammar (unused) - for compatibility with Foam::regExpCxx.

Definition at line 118 of file regExpPosix.H.


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