Loading...
Searching...
No Matches
regExpCxx Class Reference

Wrapper around C++11 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...

#include <regExpCxx.H>

Classes

struct  meta
 Functor wrapper for testing meta-characters. More...

Public Types

typedef std::smatch results_type
 Type for matches.

Public Member Functions

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

Static Public Member Functions

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

Static Public Attributes

static int grammar
 The default grammar (extended | ECMAScript).

Detailed Description

Wrapper around C++11 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
Note
Uses either POSIX extended regular expressions or modified ECMAScript regular expression grammar

Since ECMAScript grammar may not work correctly on all installations, the current default is to use extended regular expressions.

The C++11 regular expressions may be broken on some compilers. For example, gcc 4.8 is known to fail. For these systems the POSIX implementation or alternative must be used.

Warning
This class should not be used directly. Use the Foam::regExp typedef instead.
Source files

Definition at line 79 of file regExpCxx.H.

Member Typedef Documentation

◆ results_type

typedef std::smatch results_type

Type for matches.

Definition at line 124 of file regExpCxx.H.

Constructor & Destructor Documentation

◆ regExpCxx() [1/5]

regExpCxx ( )
inline

Default construct.

Definition at line 75 of file regExpCxxI.H.

Referenced by operator=(), operator=(), regExpCxx(), regExpCxx(), swap(), and ~regExpCxx().

Here is the caller graph for this function:

◆ regExpCxx() [2/5]

regExpCxx ( const regExpCxx & rgx)
inline

Copy construct.

Definition at line 82 of file regExpCxxI.H.

References regExpCxx().

Here is the call graph for this function:

◆ regExpCxx() [3/5]

regExpCxx ( regExpCxx && rgx)
inlinenoexcept

Move construct.

Definition at line 89 of file regExpCxxI.H.

References Foam::noexcept, and regExpCxx().

Here is the call graph for this function:

◆ regExpCxx() [4/5]

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

Construct from character array, optionally ignore case.

Definition at line 98 of file regExpCxxI.H.

References set().

Here is the call graph for this function:

◆ regExpCxx() [5/5]

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

Construct from string, optionally ignore case.

Definition at line 111 of file regExpCxxI.H.

References set().

Here is the call graph for this function:

◆ ~regExpCxx()

~regExpCxx ( )
default

Destructor.

References clear(), exists(), find(), match(), negate(), negated(), ngroups(), nocase(), Foam::noexcept, regExpCxx(), search(), set(), and swap().

Here is the call graph for this function:

Member Function Documentation

◆ is_meta() [1/2]

bool is_meta ( const char c)
inlinestaticnoexcept

Test if character is a regex meta-character.

Returns
True if character is one of the following:
  • any character: '.'
  • quantifiers: '*', '+', '?'
  • grouping: '(', '|', ')'
  • range: '[', ']'
Note
Regex bounds '{', '}' are not considered

Definition at line 35 of file regExpCxxI.H.

Referenced by wordRe::compile(), is_meta(), regExpCxx::meta::operator()(), and regExpCxx::meta::operator()().

Here is the caller graph for this function:

◆ is_meta() [2/2]

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

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

Definition at line 47 of file regExpCxxI.H.

References is_meta().

Here is the call graph for this function:

◆ empty()

bool empty ( ) const
inlinenoexcept

True if expression is empty.

Definition at line 126 of file regExpCxxI.H.

References Foam::noexcept.

◆ exists()

bool exists ( ) const
inlinenoexcept

True if expression is non-empty.

Definition at line 132 of file regExpCxxI.H.

References Foam::noexcept.

Referenced by ~regExpCxx().

Here is the caller graph for this function:

◆ negated()

bool negated ( ) const
inlinenoexcept

True if pattern matching is negated.

Definition at line 138 of file regExpCxxI.H.

References Foam::noexcept.

Referenced by match(), and ~regExpCxx().

Here is the caller graph for this function:

◆ negate()

bool negate ( bool on)
inlinenoexcept

Change pattern negation, return previous value.

Definition at line 144 of file regExpCxxI.H.

Referenced by ~regExpCxx().

Here is the caller graph for this function:

◆ ngroups()

unsigned ngroups ( ) const
inline

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

Definition at line 164 of file regExpCxxI.H.

Referenced by ~regExpCxx().

Here is the caller graph for this function:

◆ nocase()

bool nocase ( ) const
inline

Definition at line 171 of file regExpCxxI.H.

Referenced by ~regExpCxx().

Here is the caller graph for this function:

◆ clear()

bool clear ( )
inline

Clear expression.

Returns
True if expression had existed prior to the clear.

Definition at line 177 of file regExpCxxI.H.

Referenced by ~regExpCxx().

Here is the caller graph for this function:

◆ swap()

void swap ( regExpCxx & rgx)
inline

Swap contents.

Definition at line 191 of file regExpCxxI.H.

References regExpCxx().

Referenced by operator=(), and ~regExpCxx().

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

◆ 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 202 of file regExpCxxI.H.

Referenced by operator=(), operator=(), regExpCxx(), regExpCxx(), and ~regExpCxx().

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 214 of file regExpCxxI.H.

◆ find()

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

Find position within the text.

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

Definition at line 226 of file regExpCxxI.H.

Referenced by ~regExpCxx().

Here is the caller graph for this function:

◆ match() [1/2]

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

True if the regex matches the entire text.

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

Definition at line 282 of file regExpCxxI.H.

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

Here is the caller graph for this function:

◆ match() [2/2]

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

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!

Definition at line 296 of file regExpCxxI.H.

References match(), and negated().

Here is the call graph for this function:

◆ search()

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

Return true if the regex was found within the text.

Definition at line 268 of file regExpCxxI.H.

Referenced by ~regExpCxx().

Here is the caller graph for this function:

◆ operator()()

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

Perform match on text.

Definition at line 315 of file regExpCxxI.H.

References match().

Here is the call graph for this function:

◆ operator=() [1/4]

void operator= ( const regExpCxx & rgx)
inline

Copy assignment.

Definition at line 321 of file regExpCxxI.H.

References regExpCxx().

Here is the call graph for this function:

◆ operator=() [2/4]

void operator= ( regExpCxx && rgx)
inline

Move assignment.

Definition at line 332 of file regExpCxxI.H.

References clear(), regExpCxx(), and swap().

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 343 of file regExpCxxI.H.

References set().

Here is the call graph for this function:

◆ operator=() [4/4]

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

Assign and compile pattern from string.

Matching is case sensitive.

Definition at line 349 of file regExpCxxI.H.

References set().

Here is the call graph for this function:

Member Data Documentation

◆ grammar

int grammar
static

The default grammar (extended | ECMAScript).

Definition at line 132 of file regExpCxx.H.


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