keyType Class Reference

A class for handling keywords in dictionaries. More...

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

Public Types

enum  option : unsigned char {
  LITERAL = 0, REGEX = 1, RECURSIVE = 0x80, LITERAL_RECURSIVE = (LITERAL | RECURSIVE),
  REGEX_RECURSIVE = (REGEX | RECURSIVE)
}
 Enumeration for the data type and search/match modes (bitmask) More...
 

Public Member Functions

 keyType ()
 Construct null. More...
 
 keyType (const keyType &s)
 Copy construct, retaining type (literal or regex) More...
 
 keyType (const word &s)
 Copy construct from word, treat as literal. More...
 
 keyType (const string &s)
 Copy construct from string, treat as regular expression. More...
 
 keyType (const char *s)
 Construct as copy of character array, treat as literal. More...
 
 keyType (const std::string &s, option opt)
 Copy construct from std::string with specified treatment. More...
 
 keyType (keyType &&s)
 Move construct, retaining type (literal or regex) More...
 
 keyType (word &&s)
 Move construct from word, treat as literal. More...
 
 keyType (string &&s)
 Move construct from string, treat as regular expression. More...
 
 keyType (std::string &&s, option opt)
 Move construct from std::string with specified treatment. More...
 
 keyType (Istream &is)
 Construct from Istream. More...
 
bool isLiteral () const
 The keyType is treated as literal, not as pattern. More...
 
bool isPattern () const
 The keyType is treated as a pattern, not as literal string. More...
 
void setType (option opt, bool adjust=false)
 Change the representation. More...
 
bool compile ()
 Mark as regular expression. More...
 
void uncompile (bool adjust=false)
 Mark as literal, instead of a regular expression. More...
 
void clear ()
 Clear string and set as literal. More...
 
void swap (keyType &s)
 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 keyType &s)
 Copy assignment, retaining type (literal or regex) More...
 
void operator= (keyType &&s)
 Move assignment, retaining type (literal or regex) More...
 
void operator= (const word &s)
 Assign as word, treat as literal. More...
 
void operator= (const string &s)
 Assign from Foam::string, treat as regular expression. More...
 
void operator= (const char *s)
 Assign as word, treat as literal. More...
 
 keyType (const std::string &s, bool isPattern)
 Deprecated(2019-08) construct as literal/regex. More...
 
- Public Member Functions inherited from word
 word ()=default
 Construct null. 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...
 
bool hasExt () const
 Return true if it has an extension or simply ends with a '.'. More...
 
bool hasExt (const word &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...
 
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)
 
- Public Member Functions inherited from string
 string ()=default
 Construct null. 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...
 
template<class String >
Foam::string quotemeta (const std::string &str, const char quote)
 

Static Public Member Functions

static bool valid (char c)
 Is this character valid for a keyType? 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 String >
static bool valid (const std::string &str)
 Does the string contain valid characters only? More...
 
template<class String >
static bool meta (const std::string &str, const char quote='\\')
 Does this string contain meta-characters? More...
 
template<class String >
static bool stripInvalid (std::string &str)
 Strip invalid characters from the given string. More...
 
template<class String >
static String validate (const std::string &str)
 Return a valid String from the given string. More...
 
template<class String >
static string quotemeta (const std::string &str, const char quote='\\')
 Return a String with quoted meta-characters from the given string. More...
 

Static Public Attributes

static const keyType null
 An empty keyType. 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 word &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 class for handling keywords in dictionaries.

A keyType is the keyword of a dictionary. It differs from word in that it also accepts patterns (regular expressions). It is very similar to wordRe, but doesn't store a regular expression.

Source files

Definition at line 60 of file keyType.H.

Member Enumeration Documentation

◆ option

enum option : unsigned char

Enumeration for the data type and search/match modes (bitmask)

eg, (keyType::REGEX | keyType::RECURSIVE)

Enumerator
LITERAL 

String literal.

REGEX 

Regular expression.

RECURSIVE 

Recursive search (eg, in dictionary)

LITERAL_RECURSIVE 
REGEX_RECURSIVE 

Definition at line 70 of file keyType.H.

Constructor & Destructor Documentation

◆ keyType() [1/12]

keyType ( )
inline

Construct null.

Definition at line 48 of file keyTypeI.H.

◆ keyType() [2/12]

keyType ( const keyType s)
inline

Copy construct, retaining type (literal or regex)

Definition at line 55 of file keyTypeI.H.

◆ keyType() [3/12]

keyType ( const word s)
inline

Copy construct from word, treat as literal.

Definition at line 62 of file keyTypeI.H.

◆ keyType() [4/12]

keyType ( const string s)
inline

Copy construct from string, treat as regular expression.

Definition at line 69 of file keyTypeI.H.

◆ keyType() [5/12]

keyType ( const char *  s)
inline

Construct as copy of character array, treat as literal.

Definition at line 76 of file keyTypeI.H.

◆ keyType() [6/12]

keyType ( const std::string &  s,
option  opt 
)
inline

Copy construct from std::string with specified treatment.

Definition at line 83 of file keyTypeI.H.

◆ keyType() [7/12]

keyType ( keyType &&  s)
inline

Move construct, retaining type (literal or regex)

Definition at line 90 of file keyTypeI.H.

References s.

◆ keyType() [8/12]

keyType ( word &&  s)
inline

Move construct from word, treat as literal.

Definition at line 99 of file keyTypeI.H.

◆ keyType() [9/12]

keyType ( string &&  s)
inline

Move construct from string, treat as regular expression.

Definition at line 106 of file keyTypeI.H.

◆ keyType() [10/12]

keyType ( std::string &&  s,
option  opt 
)
inline

Move construct from std::string with specified treatment.

Definition at line 113 of file keyTypeI.H.

◆ keyType() [11/12]

keyType ( Istream is)
explicit

Construct from Istream.

Treat as regular expression if surrounded by quotation marks.

Definition at line 40 of file keyType.C.

◆ keyType() [12/12]

keyType ( const std::string &  s,
bool  isPattern 
)
inline

Deprecated(2019-08) construct as literal/regex.

Deprecated:
(2019-08) - use Construct with option

Definition at line 219 of file keyType.H.

Member Function Documentation

◆ valid()

bool valid ( char  c)
inlinestatic

Is this character valid for a keyType?

This is largely identical with what word accepts, but also permit brace-brackets, which are valid for some regexs.

Definition at line 33 of file keyTypeI.H.

References Foam::constant::universal::c, and Foam::isspace().

Referenced by wordRe::valid().

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

◆ isLiteral()

bool isLiteral ( ) const
inline

The keyType is treated as literal, not as pattern.

Definition at line 122 of file keyTypeI.H.

Referenced by GeometricField< Type, PatchField, GeoMesh >::Boundary::readField().

Here is the caller graph for this function:

◆ isPattern()

◆ setType()

void setType ( option  opt,
bool  adjust = false 
)
inline

Change the representation.

Definition at line 134 of file keyTypeI.H.

References word::debug.

Referenced by Foam::operator>>().

Here is the caller graph for this function:

◆ compile()

bool compile ( )
inline

Mark as regular expression.

Definition at line 151 of file keyTypeI.H.

◆ uncompile()

void uncompile ( bool  adjust = false)
inline

Mark as literal, instead of a regular expression.

Optionally strip invalid word characters.

Definition at line 158 of file keyTypeI.H.

◆ clear()

void clear ( )
inline

Clear string and set as literal.

Definition at line 164 of file keyTypeI.H.

References clear().

Here is the call graph for this function:

◆ swap()

void swap ( keyType s)
inline

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

Definition at line 171 of file keyTypeI.H.

References s, and string::swap().

Here is the call graph for this function:

◆ match()

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

Smart match as regular expression or as a string.

Optionally force a literal match only

Definition at line 51 of file keyType.C.

References regExpCxx::match().

Here is the call 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 185 of file keyTypeI.H.

References Foam::stringOps::match().

Here is the call graph for this function:

◆ operator=() [1/5]

void operator= ( const keyType s)
inline

Copy assignment, retaining type (literal or regex)

Self-assignment is a no-op.

Definition at line 191 of file keyTypeI.H.

References Foam::FieldOps::assign(), and s.

Here is the call graph for this function:

◆ operator=() [2/5]

void operator= ( keyType &&  s)
inline

Move assignment, retaining type (literal or regex)

Self-assignment is a no-op.

Definition at line 203 of file keyTypeI.H.

References clear(), and s.

Here is the call graph for this function:

◆ operator=() [3/5]

void operator= ( const word s)
inline

Assign as word, treat as literal.

Definition at line 215 of file keyTypeI.H.

References Foam::FieldOps::assign(), and s.

Here is the call graph for this function:

◆ operator=() [4/5]

void operator= ( const string s)
inline

Assign from Foam::string, treat as regular expression.

Definition at line 222 of file keyTypeI.H.

References Foam::FieldOps::assign(), and s.

Here is the call graph for this function:

◆ operator=() [5/5]

void operator= ( const char *  s)
inline

Assign as word, treat as literal.

Definition at line 229 of file keyTypeI.H.

References Foam::FieldOps::assign(), and s.

Here is the call graph for this function:

Member Data Documentation

◆ null

const Foam::keyType null
static

An empty keyType.

Definition at line 103 of file keyType.H.


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