wordRe Class Reference

A wordRe is a Foam::word, but can contain a regular expression for matching words or strings. More...

Inheritance diagram for wordRe:
[legend]
Collaboration diagram for wordRe:
[legend]

Public Types

enum  compOption {
  LITERAL = 0 , REGEX = 1 , ICASE = 2 , NOCASE = 2 ,
  DETECT = 4 , UNKNOWN = 4 , REGEX_ICASE = (REGEX|ICASE) , DETECT_ICASE = (DETECT|ICASE)
}
 Enumeration with compile options. More...
 

Public Member Functions

 wordRe ()
 Default construct, empty literal. More...
 
 wordRe (const wordRe &str)
 Copy construct. More...
 
 wordRe (wordRe &&str)
 Move construct. More...
 
 wordRe (const word &str)
 Implicit copy construct from word, as LITERAL. More...
 
 wordRe (word &&str)
 Implicit move construct from word, as LITERAL. More...
 
 wordRe (const std::string &str, const compOption opt=compOption::LITERAL)
 
 wordRe (const char *str, const compOption opt=compOption::LITERAL)
 
 wordRe (const keyType &str)
 Implicit copy construct from keyType, using its compile type. More...
 
 wordRe (Istream &is)
 Construct from Istream by reading a token. More...
 
bool isLiteral () const noexcept
 The wordRe is a literal string, not a pattern. More...
 
bool isPattern () const noexcept
 The wordRe is a pattern, not a literal string. More...
 
bool assign (const token &tok)
 Assign from word or string token. More...
 
bool compile ()
 Compile as regular expression (if possible) More...
 
void uncompile ()
 Mark as literal string, remove any regular expression. More...
 
bool compile (const compOption opt)
 Possibly compile the regular expression, with greater control. More...
 
void uncompile (bool adjust)
 
void set (const std::string &str, const compOption opt=DETECT)
 Copy string, auto-test for regular expression or other options. More...
 
void set (const char *str, const compOption opt=DETECT)
 Copy string, auto-test for regular expression or other options. More...
 
void clear ()
 Clear string and regular expression. More...
 
void swap (wordRe &str)
 Swap contents. Self-swapping is a no-op. More...
 
bool match (const std::string &text, bool literal=false) const
 Smart match as regular expression or as a string. More...
 
bool operator() (const std::string &text) const
 Perform smart match on text, as per match() More...
 
void operator= (const wordRe &str)
 Copy assignment, retaining type (literal or regex) More...
 
void operator= (const word &str)
 Copy word, never a regular expression. More...
 
void operator= (const keyType &str)
 Copy keyType and its type (literal or regex) More...
 
void operator= (const string &str)
 Copy string, auto-test for regular expression. More...
 
void operator= (const std::string &str)
 Copy string, auto-test for regular expression. More...
 
void operator= (const char *str)
 Copy string, auto-test for regular expression. More...
 
void operator= (wordRe &&str)
 Move assignment. More...
 
- Public Member Functions inherited from word
 word ()=default
 Default construct. More...
 
 word (const word &)=default
 Copy construct. More...
 
 word (word &&w)=default
 Move construct. More...
 
 word (const string &s, bool doStrip=true)
 Copy construct from Foam::string. More...
 
 word (string &&s, bool doStrip=true)
 Move construct from Foam::string. More...
 
 word (const std::string &s, bool doStrip=true)
 Copy construct from std::string. More...
 
 word (std::string &&s, bool doStrip=true)
 Move construct from std::string. More...
 
 word (const char *s, bool doStrip=true)
 Copy from character array. More...
 
 word (const char *s, size_type len, bool doStrip)
 Copy from buffer for a maximum number of characters. More...
 
 word (Istream &is)
 Construct from Istream. More...
 
void stripInvalid ()
 Strip invalid characters from this word. More...
 
word lessExt () const
 Return word without extension (part before last .) More...
 
word ext () const
 Return file name extension (part after last .) More...
 
wordext (const word &ending)
 Append a '.' and the ending, and return the object. More...
 
wordoperator= (const word &s)
 Copy assignment, no character validation required. More...
 
wordoperator= (word &&s)
 Move assignment, no character validation required. More...
 
wordoperator= (const string &s)
 Copy assignment from Foam::string, stripping invalid characters. More...
 
wordoperator= (string &&s)
 Move assignment from Foam::string, stripping invalid characters. More...
 
wordoperator= (const std::string &s)
 Copy assignment from std::string, stripping invalid characters. More...
 
wordoperator= (std::string &&s)
 Move assignment from std::string, stripping invalid characters. More...
 
wordoperator= (const char *s)
 Copy, stripping invalid characters. More...
 
template<class PrimitiveType >
Foam::word printf (const char *fmt, const PrimitiveType &val)
 
template<class PrimitiveType >
Foam::word printf (const std::string &fmt, const PrimitiveType &val)
 
bool hasExt () const
 Various checks for extensions. More...
 
bool hasExt (const char *ending) const
 Various checks for extensions. More...
 
bool hasExt (const std::string &ending) const
 Various checks for extensions. More...
 
bool hasExt (const wordRe &ending) const
 Various checks for extensions. More...
 
bool removeExt ()
 Remove extension, returning true if string changed. More...
 
- Public Member Functions inherited from string
 string ()=default
 Default construct. More...
 
 string (const std::string &str)
 Copy construct from std::string. More...
 
 string (std::string &&str)
 Move construct from std::string. More...
 
 string (const char *str)
 Construct as copy of character array. More...
 
 string (const char *str, const size_type len)
 Construct as copy with a maximum number of characters. More...
 
 string (const char c)
 Construct from a single character. More...
 
 string (const size_type len, const char c)
 Construct fill copies of a single character. More...
 
 string (Istream &is)
 Construct from Istream. More...
 
bool match (const std::string &text) const
 Test for equality. More...
 
stringreplace (const std::string &s1, const std::string &s2, size_type pos=0)
 
stringreplaceAll (const std::string &s1, const std::string &s2, size_type pos=0)
 
stringreplaceAny (const std::string &s1, const char c2, size_type pos=0)
 
stringexpand (const bool allowEmpty=false)
 
bool removeRepeated (const char character)
 Remove repeated characters. More...
 
bool removeStart (const std::string &text)
 Remove the given text from the start of the string. More...
 
bool removeStart (const char c)
 Remove leading character, unless string is a single character. More...
 
bool removeEnd (const std::string &text)
 Remove the given text from the end of the string. More...
 
bool removeEnd (const char c)
 Remove trailing character, unless string is a single character. More...
 
void swap (std::string &str)
 Swap contents. Self-swapping is a no-op. More...
 
bool operator() (const std::string &text) const
 Test for equality. Allows use as a predicate. More...
 
bool starts_with (const std::string &s) const
 True if string starts with the given prefix (cf. C++20) More...
 
bool starts_with (const char c) const
 True if string starts with the given character (cf. C++20) More...
 
bool ends_with (const std::string &s) const
 True if string ends with the given suffix (cf. C++20) More...
 
bool ends_with (const char c) const
 True if string ends with the given character (cf. C++20) More...
 
size_type count (const char c) const
 
bool startsWith (const std::string &s) const
 Deprecated(2019-11) More...
 
bool endsWith (const std::string &s) const
 Deprecated(2019-11) More...
 
bool removeTrailing (const char c)
 Deprecated(2019-11) More...
 

Static Public Member Functions

static bool valid (const char c)
 Test for valid wordRe character? More...
 
- Static Public Member Functions inherited from word
template<class PrimitiveType >
static word printf (const char *fmt, const PrimitiveType &val)
 Use a printf-style formatter for a primitive. More...
 
template<class PrimitiveType >
static word printf (const std::string &fmt, const PrimitiveType &val)
 Use a printf-style formatter for a primitive. More...
 
static bool valid (char c)
 Is this character valid for a word? More...
 
static word validate (const std::string &s, const bool prefix=false)
 Construct validated word (no invalid characters). More...
 
static word validate (const char *first, const char *last, const bool prefix=false)
 
- Static Public Member Functions inherited from string
template<class StringType >
static bool valid (const std::string &str)
 Does the string contain valid characters only? More...
 
template<class StringType >
static bool stripInvalid (std::string &str)
 Strip invalid characters from the given string. More...
 
template<class StringType >
static StringType validate (const std::string &str)
 Return a valid String from the given string. More...
 

Static Public Attributes

static const wordRe null
 An empty wordRe. More...
 
- Static Public Attributes inherited from word
static const char *const typeName = "word"
 The typeName. More...
 
static int debug
 Debugging. More...
 
static const word null
 An empty word. More...
 
- Static Public Attributes inherited from string
static const char *const typeName = "string"
 The type name "string". More...
 
static int debug
 The debug flag. More...
 
static const string null
 An empty string. More...
 

Additional Inherited Members

- Protected Member Functions inherited from string
std::string::size_type find_ext () const
 Find position of a file extension dot, return npos on failure. More...
 
word ext () const
 Return file name extension (part after last .) More...
 
bool ext (const word &ending)
 Append a '.' and the ending. More...
 
bool hasPath () const
 Return true if it contains a '/' character. More...
 
bool hasExt () const
 Return true if it has an extension or simply ends with a '.'. More...
 
bool hasExt (const char *ending) const
 Return true if the extension is the same as the given ending. More...
 
bool hasExt (const std::string &ending) const
 Return true if the extension is the same as the given ending. More...
 
bool hasExt (const wordRe &ending) const
 Return true if the extension matches the given ending. More...
 
bool removeExt ()
 Remove extension, returning true if string changed. More...
 
bool removePath ()
 Remove leading path, returning true if string changed. More...
 
- Static Protected Member Functions inherited from string
static std::string::size_type find_ext (const std::string &str)
 Find position of a file extension dot, return npos on failure. More...
 
template<class PrimitiveType >
static std::string::size_type string_printf (std::string &output, const char *fmt, const PrimitiveType &val)
 A printf-style formatter for a primitive. More...
 
template<class PrimitiveType >
static std::string::size_type string_printf (std::string &output, const std::string &fmt, const PrimitiveType &val)
 A printf-style formatter for a primitive. More...
 

Detailed Description

A wordRe is a Foam::word, but can contain a regular expression for matching words or strings.

By default the constructors will generally preserve the argument as a string literal and the assignment operators will use the wordRe::DETECT compOption to scan the string for regular expression meta characters and/or invalid word characters and react accordingly.

The exceptions are when constructing/assigning from another Foam::wordRe (preserve the same type) or from a Foam::word (always literal).

Note
If the string contents are changed - eg, by the operator+=() or by string::replace(), etc - it will be necessary to use compile() or uncompile() to synchronize the regular expression.
Source files

Definition at line 80 of file wordRe.H.

Member Enumeration Documentation

◆ compOption

enum compOption

Enumeration with compile options.

Note that 'REGEX' is implicit if 'ICASE' is specified alone.

Enumerator
LITERAL 

String literal.

REGEX 

Regular expression.

ICASE 

Ignore case in regular expression.

NOCASE 
Deprecated:
(2018-04) Alias for ICASE
DETECT 

Detect if the string contains meta-characters.

UNKNOWN 

Unknown content (for return value).

REGEX_ICASE 

Combined REGEX and ICASE.

DETECT_ICASE 

Combined DETECT and ICASE.

Definition at line 102 of file wordRe.H.

Constructor & Destructor Documentation

◆ wordRe() [1/9]

wordRe ( )
inline

Default construct, empty literal.

Definition at line 40 of file wordReI.H.

◆ wordRe() [2/9]

wordRe ( const wordRe str)
inline

Copy construct.

Definition at line 47 of file wordReI.H.

References wordRe::compile(), and wordRe::isPattern().

Here is the call graph for this function:

◆ wordRe() [3/9]

wordRe ( wordRe &&  str)
inline

Move construct.

Definition at line 58 of file wordReI.H.

◆ wordRe() [4/9]

wordRe ( const word str)
inline

Implicit copy construct from word, as LITERAL.

Definition at line 65 of file wordReI.H.

◆ wordRe() [5/9]

wordRe ( word &&  str)
inline

Implicit move construct from word, as LITERAL.

Definition at line 72 of file wordReI.H.

◆ wordRe() [6/9]

wordRe ( const std::string &  str,
const compOption  opt = compOption::LITERAL 
)
inline

Implicit copy construct from other string-types, with specified compile option (default is LITERAL)

Definition at line 79 of file wordReI.H.

References wordRe::compile(), and wordRe::LITERAL.

Here is the call graph for this function:

◆ wordRe() [7/9]

wordRe ( const char *  str,
const compOption  opt = compOption::LITERAL 
)
inline

Implicit construct from character array, with specified compile option (default is LITERAL)

Definition at line 91 of file wordReI.H.

References wordRe::compile(), and wordRe::LITERAL.

Here is the call graph for this function:

◆ wordRe() [8/9]

wordRe ( const keyType str)

Implicit copy construct from keyType, using its compile type.

Definition at line 41 of file wordRe.C.

References wordRe::compile(), and keyType::isPattern().

Here is the call graph for this function:

◆ wordRe() [9/9]

wordRe ( Istream is)
explicit

Construct from Istream by reading a token.

Words are treated as literals, strings with an auto-detect

Definition at line 53 of file wordRe.C.

Member Function Documentation

◆ valid()

bool valid ( const char  c)
inlinestatic

Test for valid wordRe character?

Like Foam::word, but with brace-brackets, which are valid for some regexs.

Definition at line 31 of file wordReI.H.

References interfaceEntry::valid().

Here is the call graph for this function:

◆ isLiteral()

bool isLiteral ( ) const
inlinenoexcept

The wordRe is a literal string, not a pattern.

Definition at line 105 of file wordReI.H.

References bool.

Referenced by string::hasExt().

Here is the caller graph for this function:

◆ isPattern()

bool isPattern ( ) const
inlinenoexcept

The wordRe is a pattern, not a literal string.

Definition at line 111 of file wordReI.H.

References bool.

Referenced by fieldSelection::containsPattern(), faBoundaryMesh::indices(), polyBoundaryMesh::indices(), ZoneMesh< ZoneType, MeshType >::indices(), Foam::operator<<(), wordRe::operator=(), triSurfaceLoader::select(), and wordRe::wordRe().

Here is the caller graph for this function:

◆ assign()

bool assign ( const token tok)

Assign from word or string token.

Words are treated as literals, strings with an auto-detect

Returns
false if the token was the incorrect type

Definition at line 64 of file wordRe.C.

References wordRe::DETECT, token::isQuotedString(), token::isWord(), token::stringToken(), and token::wordToken().

Referenced by Foam::operator>>().

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

◆ compile() [1/2]

bool compile ( )
inline

Compile as regular expression (if possible)

Definition at line 159 of file wordReI.H.

References bool.

Referenced by wordRe::wordRe().

Here is the caller graph for this function:

◆ uncompile() [1/2]

void uncompile ( )
inline

Mark as literal string, remove any regular expression.

Definition at line 176 of file wordReI.H.

◆ compile() [2/2]

bool compile ( const compOption  opt)
inline

Possibly compile the regular expression, with greater control.

Definition at line 117 of file wordReI.H.

References bool, wordRe::DETECT, wordRe::ICASE, regExpCxx::is_meta(), wordRe::LITERAL, and wordRe::REGEX.

Here is the call graph for this function:

◆ uncompile() [2/2]

void uncompile ( bool  adjust)
inline

Mark as literal string, optionally stripping invalid word characters when changing to a literal

Definition at line 182 of file wordReI.H.

References word::debug.

◆ set() [1/2]

void set ( const std::string &  str,
const compOption  opt = DETECT 
)
inline

Copy string, auto-test for regular expression or other options.

Definition at line 211 of file wordReI.H.

◆ set() [2/2]

void set ( const char *  str,
const compOption  opt = DETECT 
)
inline

Copy string, auto-test for regular expression or other options.

Definition at line 218 of file wordReI.H.

◆ clear()

void clear ( )
inline

Clear string and regular expression.

Definition at line 193 of file wordReI.H.

References interfaceDefinitions::clear().

Referenced by zoneMotion::zoneMotion(), zoneToCell::zones(), zoneToFace::zones(), and zoneToPoint::zones().

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

◆ swap()

void swap ( wordRe str)
inline

Swap contents. Self-swapping is a no-op.

Definition at line 226 of file wordReI.H.

◆ match()

bool match ( const std::string &  text,
bool  literal = false 
) const
inline

Smart match as regular expression or as a string.

Optionally force a literal match only

Definition at line 200 of file wordReI.H.

Referenced by string::hasExt(), faBoundaryMesh::indices(), polyBoundaryMesh::indices(), ZoneMesh< ZoneType, MeshType >::indices(), and solverFieldSelection::updateSelection().

Here is the caller graph for this function:

◆ operator()()

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

Perform smart match on text, as per match()

Allows use as a predicate.

Definition at line 240 of file wordReI.H.

◆ operator=() [1/7]

void operator= ( const wordRe str)
inline

Copy assignment, retaining type (literal or regex)

Self-assignment is a no-op.

Definition at line 246 of file wordReI.H.

References wordRe::isPattern().

Here is the call graph for this function:

◆ operator=() [2/7]

void operator= ( const word str)
inline

Copy word, never a regular expression.

Definition at line 265 of file wordReI.H.

◆ operator=() [3/7]

void operator= ( const keyType str)

Copy keyType and its type (literal or regex)

Always case sensitive

Definition at line 87 of file wordRe.C.

References keyType::isPattern().

Here is the call graph for this function:

◆ operator=() [4/7]

void operator= ( const string str)
inline

Copy string, auto-test for regular expression.

Always case sensitive

Definition at line 272 of file wordReI.H.

References wordRe::DETECT.

◆ operator=() [5/7]

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

Copy string, auto-test for regular expression.

Always case sensitive

Definition at line 279 of file wordReI.H.

References wordRe::DETECT.

◆ operator=() [6/7]

void operator= ( const char *  str)
inline

Copy string, auto-test for regular expression.

Always case sensitive

Definition at line 286 of file wordReI.H.

References wordRe::DETECT.

◆ operator=() [7/7]

void operator= ( wordRe &&  str)
inline

Move assignment.

Self-assignment is a no-op.

Definition at line 293 of file wordReI.H.

References clear().

Here is the call graph for this function:

Member Data Documentation

◆ null

const Foam::wordRe null
static

An empty wordRe.

Definition at line 95 of file wordRe.H.


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