wordRe Class Reference

A wordRe is a word, but can also have a regular expression for matching words. More...

Inheritance diagram for wordRe:
Collaboration diagram for wordRe:

Public Types

enum  compOption {
  literal = 0, detect = 1, regExp = 2, noCase = 4,
  detectNoCase = detect | noCase, regExpNoCase = regExp | noCase
}
 Enumeration with compile options. More...
 

Public Member Functions

 wordRe ()
 Construct null. More...
 
 wordRe (const wordRe &)
 Copy constructor. More...
 
 wordRe (const keyType &)
 Construct from keyType. More...
 
 wordRe (const keyType &, const compOption)
 Construct from keyType. More...
 
 wordRe (const word &)
 Copy constructor of word. More...
 
 wordRe (const char *, const compOption=compOption::literal)
 Copy constructor of character array. More...
 
 wordRe (const string &, const compOption=compOption::literal)
 Copy constructor of string. More...
 
 wordRe (const std::string &, const compOption=compOption::literal)
 Copy constructor of std::string. More...
 
 wordRe (Istream &)
 Construct from Istream. More...
 
bool isPattern () const
 Should be treated as a match rather than a literal string? More...
 
bool compile () const
 Compile the regular expression. More...
 
bool compile (const compOption) const
 Possibly compile the regular expression, with greater control. More...
 
bool recompile () const
 Recompile an existing regular expression. More...
 
void uncompile (const bool doStripInvalid=false) const
 Frees precompiled regular expression, making wordRe a literal. More...
 
void set (const std::string &, const compOption=compOption::detect)
 Copy string, auto-test for regular expression or other options. More...
 
void set (const char *, const compOption=compOption::detect)
 Copy string, auto-test for regular expression or other options. More...
 
void clear ()
 Clear string and precompiled regular expression. More...
 
bool match (const std::string &, bool literalMatch=false) const
 Smart match as regular expression or as a string. More...
 
string quotemeta () const
 Return a string with quoted meta-characters. More...
 
Ostreaminfo (Ostream &) const
 Output some basic info. More...
 
void operator= (const wordRe &)
 Assign copy. More...
 
void operator= (const word &)
 Copy word, never a regular expression. More...
 
void operator= (const keyType &)
 Copy keyType, auto-test for regular expression. More...
 
void operator= (const string &)
 Copy string, auto-test for regular expression. More...
 
void operator= (const std::string &)
 Copy string, auto-test for regular expression. More...
 
void operator= (const char *)
 Copy string, auto-test for regular expression. More...
 
- Public Member Functions inherited from word
 word ()
 Construct null. More...
 
 word (const word &)
 Copy constructor. More...
 
 word (const char *, const bool doStripInvalid=true)
 Copy constructor of character array. More...
 
 word (const char *, const size_type, const bool doStripInvalid)
 Copy constructor with a maximum number of characters. More...
 
 word (const string &, const bool doStripInvalid=true)
 Copy constructor of string. More...
 
 word (const std::string &, const bool doStripInvalid=true)
 Copy constructor of std::string. More...
 
 word (Istream &)
 Construct from Istream. More...
 
word capitalise () const
 Return the word with the first letter capitalised. More...
 
void operator= (const word &)
 
void operator= (const string &)
 
void operator= (const std::string &)
 
void operator= (const char *)
 
- Public Member Functions inherited from string
 string ()
 Construct null. More...
 
 string (const std::string &)
 Construct from std::string. More...
 
 string (const string &)
 Copy constructor. More...
 
 string (string &&)
 Move constructor. More...
 
 string (const char *)
 Construct as copy of character array. More...
 
 string (const UList< char > &)
 Construct as copy of UList of character. More...
 
 string (const char *, const size_type)
 Construct as copy of specified number of characters. More...
 
 string (const char)
 Construct from a single character. More...
 
 string (const size_type, const char)
 Construct from copies of a single character. More...
 
 string (Istream &)
 Construct from Istream. More...
 
size_type count (const char) const
 Count and return the number of a given character in the string. More...
 
bool match (const std::string &) const
 True when strings match literally. More...
 
stringreplace (const string &oldStr, const string &newStr, size_type start=0)
 Replace first occurrence of sub-string oldStr with newStr. More...
 
stringreplaceAll (const string &oldStr, const string &newStr, size_type start=0)
 Replace all occurrences of sub-string oldStr with newStr. More...
 
stringexpand (const bool allowEmpty=false)
 Expand initial tildes and all occurrences of environment variables. More...
 
bool removeRepeated (const char)
 Remove repeated characters returning true if string changed. More...
 
string removeRepeated (const char) const
 Return string with repeated characters removed. More...
 
bool removeTrailing (const char)
 Remove trailing character returning true if string changed. More...
 
string removeTrailing (const char) const
 Return string with trailing character removed. More...
 
bool removeTrailing (const string &)
 Remove trailing string returning true if string changed. More...
 
string removeTrailing (const string &) const
 Return string with trailing string removed. More...
 
void strip (const string &)
 Strip characters from the start and end of the string. More...
 
string operator() (const size_type i, const size_type n) const
 Return the sub-string from the i-th character for n characters. More...
 
string operator() (const size_type n) const
 Return the sub-string from the first character for n characters. More...
 
void operator= (const string &)
 
void operator= (string &&)
 
template<class String >
Foam::string quotemeta (const string &str, const char quote)
 

Static Public Member Functions

static bool meta (char)
 Is this a meta character? More...
 
static bool isPattern (const string &)
 Test string for regular expression meta characters. More...
 
- Static Public Member Functions inherited from word
static bool valid (char)
 Is this character valid for a word. More...
 
- Static Public Member Functions inherited from string
template<class String >
static bool valid (const string &)
 Is this string type valid? More...
 
template<class String >
static bool meta (const string &, const char quote='\\')
 Does this string have particular meta-characters? More...
 
template<class String >
static bool stripInvalid (string &)
 Strip invalid characters from the given string. More...
 
template<class String >
static String validate (const string &)
 Return a valid String from the given string. More...
 
template<class String >
static string quotemeta (const string &, const char quote='\\')
 Return a String with quoted meta-characters 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"
 
static int debug
 
static const word null
 An empty word. More...
 
- Static Public Attributes inherited from string
static const char *const typeName = "string"
 
static int debug
 
static const string null
 An empty string. More...
 

Friends

Istreamoperator>> (Istream &, wordRe &)
 
Ostreamoperator<< (Ostream &, const wordRe &)
 

Detailed Description

A wordRe is a word, but can also have a regular expression for matching words.

By default the constructors will generally preserve the argument as a string literal and the assignment operators will use the wordRe::compOption::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 recompile() to synchronise the regular expression.
Source files

Definition at line 74 of file wordRe.H.

Member Enumeration Documentation

◆ compOption

enum compOption
strong

Enumeration with compile options.

Note that 'regexp' is implicit if 'noCase' is specified alone.

Enumerator
literal 

treat as a string literal

detect 

detect if the string contains meta-characters

regExp 

treat as regular expression

noCase 

ignore case in regular expression

detectNoCase 
regExpNoCase 

Definition at line 95 of file wordRe.H.

Constructor & Destructor Documentation

◆ wordRe() [1/9]

wordRe ( )
inline

Construct null.

Definition at line 42 of file wordReI.H.

◆ wordRe() [2/9]

wordRe ( const wordRe str)
inline

Copy constructor.

Definition at line 49 of file wordReI.H.

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

Here is the call graph for this function:

◆ wordRe() [3/9]

wordRe ( const keyType str)
inline

Construct from keyType.

Definition at line 68 of file wordReI.H.

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

Here is the call graph for this function:

◆ wordRe() [4/9]

wordRe ( const keyType str,
const compOption  opt 
)
inline

Construct from keyType.

Definition at line 80 of file wordReI.H.

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

Here is the call graph for this function:

◆ wordRe() [5/9]

wordRe ( const word str)
inline

Copy constructor of word.

Definition at line 61 of file wordReI.H.

◆ wordRe() [6/9]

wordRe ( const char *  str,
const compOption  opt = compOption::literal 
)
inlineexplicit

Copy constructor of character array.

Optionally specify how it should be treated.

Definition at line 92 of file wordReI.H.

References wordRe::compile().

Here is the call graph for this function:

◆ wordRe() [7/9]

wordRe ( const string str,
const compOption  opt = compOption::literal 
)
inlineexplicit

Copy constructor of string.

Optionally specify how it should be treated.

Definition at line 101 of file wordReI.H.

References wordRe::compile().

Here is the call graph for this function:

◆ wordRe() [8/9]

wordRe ( const std::string &  str,
const compOption  opt = compOption::literal 
)
inlineexplicit

Copy constructor of std::string.

Optionally specify how it should be treated.

Definition at line 110 of file wordReI.H.

References wordRe::compile().

Here is the call graph for this function:

◆ wordRe() [9/9]

wordRe ( Istream is)

Construct from Istream.

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

Definition at line 37 of file wordRe.C.

Member Function Documentation

◆ meta()

bool meta ( char  c)
inlinestatic

Is this a meta character?

Definition at line 28 of file wordReI.H.

References regExp::meta().

Here is the call graph for this function:

◆ isPattern() [1/2]

bool isPattern ( const string str)
inlinestatic

Test string for regular expression meta characters.

Definition at line 34 of file wordReI.H.

Referenced by MeshZones< cellZone, polyMesh >::findIndex(), polyBoundaryMesh::findIndex(), MeshZones< cellZone, polyMesh >::findIndices(), polyBoundaryMesh::findIndices(), Foam::operator<<(), wordRe::operator=(), and wordRe::wordRe().

Here is the caller graph for this function:

◆ isPattern() [2/2]

bool isPattern ( ) const
inline

Should be treated as a match rather than a literal string?

Definition at line 121 of file wordReI.H.

References regExp::exists().

Referenced by wordRe::info().

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

◆ compile() [1/2]

bool compile ( ) const
inline

Compile the regular expression.

Definition at line 161 of file wordReI.H.

References regExp::exists().

Referenced by functionObjectList::findDict(), wordRe::operator=(), wordRe::set(), and wordRe::wordRe().

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

◆ compile() [2/2]

bool compile ( const compOption  opt) const
inline

Possibly compile the regular expression, with greater control.

Definition at line 127 of file wordReI.H.

References regExp::clear(), wordRe::detect, regExp::exists(), wordRe::noCase, wordRe::regExp, and regExp::set().

Here is the call graph for this function:

◆ recompile()

bool recompile ( ) const
inline

Recompile an existing regular expression.

Definition at line 168 of file wordReI.H.

References regExp::exists().

Here is the call graph for this function:

◆ uncompile()

void uncompile ( const bool  doStripInvalid = false) const
inline

Frees precompiled regular expression, making wordRe a literal.

Optionally strips invalid word characters

Definition at line 179 of file wordReI.H.

References regExp::clear(), and word::debug.

Here is the call graph for this function:

◆ set() [1/2]

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

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

Definition at line 223 of file wordReI.H.

References wordRe::compile(), and string::operator=().

Here is the call graph for this function:

◆ set() [2/2]

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

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

Definition at line 230 of file wordReI.H.

References wordRe::compile(), and string::operator=().

Here is the call graph for this function:

◆ clear()

void clear ( )
inline

Clear string and precompiled regular expression.

Definition at line 195 of file wordReI.H.

References clear(), and regExp::clear().

Here is the call graph for this function:

◆ match()

bool match ( const std::string &  str,
bool  literalMatch = false 
) const
inline

Smart match as regular expression or as a string.

Optionally force a literal match only

Definition at line 202 of file wordReI.H.

References regExp::exists(), and regExp::match().

Referenced by functionObjectList::findDict(), IOobjectList::lookup(), and objectRegistry::names().

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

◆ quotemeta()

Foam::string quotemeta ( ) const
inline

Return a string with quoted meta-characters.

Definition at line 217 of file wordReI.H.

◆ info()

Foam::Ostream & info ( Ostream os) const

Output some basic info.

Definition at line 103 of file wordRe.C.

References Ostream::flush(), and wordRe::isPattern().

Here is the call graph for this function:

◆ operator=() [1/6]

void operator= ( const wordRe str)
inline

Assign copy.

Always case sensitive

Definition at line 239 of file wordReI.H.

References regExp::clear(), wordRe::compile(), wordRe::isPattern(), and string::operator=().

Here is the call graph for this function:

◆ operator=() [2/6]

void operator= ( const word str)
inline

Copy word, never a regular expression.

Definition at line 254 of file wordReI.H.

References regExp::clear(), and word::operator=().

Here is the call graph for this function:

◆ operator=() [3/6]

void operator= ( const keyType str)
inline

Copy keyType, auto-test for regular expression.

Always case sensitive

Definition at line 261 of file wordReI.H.

References wordRe::compile(), keyType::isPattern(), and string::operator=().

Here is the call graph for this function:

◆ operator=() [4/6]

void operator= ( const string str)
inline

Copy string, auto-test for regular expression.

Always case sensitive

Definition at line 271 of file wordReI.H.

References wordRe::compile(), wordRe::detect, and string::operator=().

Here is the call graph for this function:

◆ operator=() [5/6]

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

Copy string, auto-test for regular expression.

Always case sensitive

Definition at line 278 of file wordReI.H.

References wordRe::compile(), wordRe::detect, and string::operator=().

Here is the call graph for this function:

◆ operator=() [6/6]

void operator= ( const char *  str)
inline

Copy string, auto-test for regular expression.

Always case sensitive

Definition at line 285 of file wordReI.H.

References wordRe::compile(), wordRe::detect, and string::operator=().

Here is the call graph for this function:

Friends And Related Function Documentation

◆ operator>>

Istream& operator>> ( Istream ,
wordRe  
)
friend

◆ operator<<

Ostream& operator<< ( Ostream ,
const wordRe  
)
friend

Member Data Documentation

◆ null

const Foam::wordRe null
static

An empty wordRe.

Definition at line 88 of file wordRe.H.


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