A class for handling keywords in dictionaries. More...
#include <keyType.H>


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 () | |
| Default construct, empty literal. | |
| keyType (const keyType &)=default | |
| Copy construct. | |
| keyType (keyType &&)=default | |
| Move construct. | |
| keyType (const word &str) | |
| Implicit copy construct from word, treat as LITERAL. | |
| keyType (word &&str) | |
| Implicit move construct from word, treat as LITERAL. | |
| keyType (const string &str) | |
| Implicit copy construct from Foam::string, treat as REGEX. | |
| keyType (string &&str) | |
| Implicit move construct from Foam::string, treat as REGEX. | |
| keyType (const std::string &str, option opt) | |
| Copy construct from std::string with specified treatment. | |
| keyType (std::string &&str, option opt) | |
| Move construct from std::string with specified treatment. | |
| keyType (const char *str, option opt=option::LITERAL) | |
| Implicit construct from character array, with specified compile option (default is LITERAL). | |
| keyType (Istream &is) | |
| Construct from Istream by reading a token. | |
| bool | isLiteral () const noexcept |
| The keyType is treated as literal, not as pattern. | |
| bool | isPattern () const noexcept |
| The keyType is treated as a pattern, not as literal string. | |
| bool | assign (const token &tok) |
| Assign from word or string token. | |
| void | setType (option opt, bool adjust=false) |
| Change the representation, optionally stripping invalid word characters when changing to a literal. | |
| bool | compile () noexcept |
| Mark as regular expression. | |
| void | uncompile () noexcept |
| Mark as literal string. | |
| void | uncompile (bool adjust) |
| Mark as literal string, optionally strip invalid word characters when changing to a literal. | |
| void | clear () |
| Clear string and set as literal. | |
| void | swap (keyType &rhs) |
| Swap contents. Self-swapping is a no-op. | |
| bool | match (const std::string &text, bool literal=false) const |
| Smart match as regular expression or as a string. | |
| bool | operator() (const std::string &text) const |
| Perform smart match on text, as per match(). | |
| void | operator= (const std::string &)=delete |
| No assignment where type could be indeterminate. | |
| void | operator= (const keyType &str) |
| Copy assignment, retaining type (literal or regex). | |
| void | operator= (keyType &&str) |
| Move assignment, retaining type (literal or regex). | |
| void | operator= (const word &str) |
| Assign from word, treat as literal. | |
| void | operator= (const string &str) |
| Assign from Foam::string, treat as regular expression. | |
| void | operator= (const char *str) |
| Assign from character array, treat as literal. | |
| keyType (const std::string &s, bool isPattern) | |
| Deprecated(2019-08) construct as literal/regex. | |
| Public Member Functions inherited from word | |
| word ()=default | |
| Default construct. | |
| word (const word &)=default | |
| Copy construct. | |
| word (word &&w)=default | |
| Move construct. | |
| word (const string &s, bool doStrip=true) | |
| Copy construct from Foam::string. | |
| word (string &&s, bool doStrip=true) | |
| Move construct from Foam::string. | |
| word (const std::string &s, bool doStrip=true) | |
| Copy construct from std::string. | |
| word (std::string &&s, bool doStrip=true) | |
| Move construct from std::string. | |
| word (const char *s, bool doStrip=true) | |
| Copy from character array. | |
| word (const char *s, size_type len, bool doStrip) | |
| Copy from buffer for a maximum number of characters. | |
| word (Istream &is) | |
| Construct from Istream. | |
| void | stripInvalid () |
| Strip invalid characters from this word. | |
| word | ext () const |
| Return file name extension (part after last .). | |
| word & | ext (const word &ending) |
| Append a '.' and the ending, and return the object. | |
| word & | replace_ext (const word &ending) |
| Remove extension (if any) and append a new one. | |
| word | lessExt () const |
| Return word without extension (part before last .). | |
| word & | operator= (const word &s) |
| Copy assignment, no character validation required. | |
| word & | operator= (word &&s) |
| Move assignment, no character validation required. | |
| word & | operator= (const string &s) |
| Copy assignment from Foam::string, stripping invalid characters. | |
| word & | operator= (string &&s) |
| Move assignment from Foam::string, stripping invalid characters. | |
| word & | operator= (const std::string &s) |
| Copy assignment from std::string, stripping invalid characters. | |
| word & | operator= (std::string &&s) |
| Move assignment from std::string, stripping invalid characters. | |
| word & | operator= (const char *s) |
| Copy, stripping invalid characters. | |
| bool | hasExt () const |
| Same as has_ext(). | |
| bool | hasExt (const std::string &s) const |
| Same as has_ext(). | |
| bool | removeExt () |
| Same as remove_ext(). | |
| 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 | remove_ext () |
| Remove extension, return true if string changed. | |
| bool | has_ext () const |
| Various checks for extensions. | |
| bool | has_ext (const char *ending) const |
| Various checks for extensions. | |
| bool | has_ext (const std::string &ending) const |
| Various checks for extensions. | |
| bool | has_ext (const wordRe &ending) const |
| Various checks for extensions. | |
| Public Member Functions inherited from string | |
| string ()=default | |
| Default construct. | |
| string (const std::string &str) | |
| Copy construct from std::string. | |
| string (std::string &&str) | |
| Move construct from std::string. | |
| string (const char *str) | |
| Construct as copy of character array. | |
| string (const char *str, const size_type len) | |
| Construct as copy with a maximum number of characters. | |
| string (const char c) | |
| Construct from a single character. | |
| string (const size_type len, const char c) | |
| Construct fill copies of a single character. | |
| string (Istream &is) | |
| Construct from Istream. | |
| bool | match (const std::string &text) const |
| Test for equality. | |
| string & | replace (const std::string &s1, const std::string &s2, size_type pos=0) |
| Replace first occurrence of sub-string s1 with s2, beginning at pos. | |
| string & | replaceAll (const std::string &s1, const std::string &s2, size_type pos=0) |
| Replace all occurrences of sub-string s1 with s2, beginning at pos in the string. | |
| string & | replaceAny (const std::string &s1, const char c2, size_type pos=0) |
| Replace any occurrence of s1 characters with c2, beginning at pos in the string. | |
| string & | expand (const bool allowEmpty=false) |
| Inplace expand initial tags, tildes, and all occurrences of environment variables as per stringOps::expand. | |
| bool | removeRepeated (const char character) |
| Remove repeated characters. | |
| bool | removeStart (const std::string &text) |
| Remove the given text from the start of the string. | |
| bool | removeStart (const char c) |
| Remove leading character, unless string is a single character. | |
| bool | removeEnd (const std::string &text) |
| Remove the given text from the end of the string. | |
| bool | removeEnd (const char c) |
| Remove trailing character, unless string is a single character. | |
| void | swap (std::string &str) |
| Swap contents. Self-swapping is a no-op. | |
| bool | operator() (const std::string &text) const |
| Test for equality. Allows use as a predicate. | |
| bool | contains (char c) const noexcept |
| True if string contains given character (cf. C++23). | |
| bool | contains (const std::string &s) const noexcept |
| True if string contains given [string view] substring (cf. C++23). | |
| bool | contains (const char *s) const |
| True if string contains given substring (cf. C++23). | |
| bool | starts_with (char c) const |
| True if string starts with given character (cf. C++20). | |
| bool | starts_with (const std::string &s) const |
| True if string starts with given [string view] prefix (C++20). | |
| bool | starts_with (const char *s) const |
| True if string starts with given prefix (C++20). | |
| bool | ends_with (char c) const |
| True if string ends with given character (cf. C++20). | |
| bool | ends_with (const std::string &s) const |
| True if string ends with given [string view] suffix (cf. C++20). | |
| bool | ends_with (const char *s) const |
| True if string ends with given suffix (cf. C++20). | |
| size_type | count (const char c) const |
| Count the number of occurrences of the specified character in the string. | |
| bool | startsWith (const std::string &s) const |
| Deprecated(2019-11). | |
| bool | endsWith (const std::string &s) const |
| Deprecated(2019-11). | |
| bool | removeTrailing (const char c) |
| Deprecated(2019-11). | |
Static Public Member Functions | |
| static bool | valid (const char c) |
| Test for valid keyType character? | |
| 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. | |
| template<class PrimitiveType> | |
| static word | printf (const std::string &fmt, const PrimitiveType &val) |
| Use a printf-style formatter for a primitive. | |
| static bool | valid (char c) |
| Is this character valid for a word? | |
| static word | validate (const std::string &s, const bool prefix=false) |
| Construct validated word (no invalid characters). | |
| static word | validate (const char *first, const char *last, const bool prefix=false) |
| Construct validated word (no invalid characters) from a sequence of characters in the range [first,last),. | |
| Static Public Member Functions inherited from string | |
| static std::string::size_type | length (const char *s) |
| Length of the character sequence (with nullptr protection). | |
| static std::string::size_type | length (const std::string &s) |
| The length of the string. | |
| template<class StringType> | |
| static bool | valid (const std::string &str) |
| Does the string contain valid characters only? | |
| template<class StringType> | |
| static bool | stripInvalid (std::string &str) |
| Strip invalid characters from the given string. | |
| template<class StringType> | |
| static StringType | validate (const std::string &str) |
| Return a valid String from the given string. | |
Static Public Attributes | |
| static const keyType | null |
| An empty keyType. | |
| Static Public Attributes inherited from word | |
| static const char *const | typeName = "word" |
| The typeName. | |
| static int | debug |
| Debugging. | |
| static const word | null |
| An empty word. | |
| Static Public Attributes inherited from string | |
| static const char *const | typeName = "string" |
| The type name "string". | |
| static int | debug |
| The debug flag. | |
| static const string | null |
| An empty string. | |
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. | |
| word | ext () const |
| Return file name extension (part after last .). | |
| bool | ext (const word &ending) |
| Append a '.' and the ending. | |
| bool | has_ext () const |
| Return true if it has an extension or simply ends with a '.'. | |
| bool | has_ext (const char *ending) const |
| Return true if the extension is the same as the given ending. | |
| bool | has_ext (const std::string &ending) const |
| Return true if the extension is the same as the given ending. | |
| bool | has_ext (const wordRe &ending) const |
| Return true if the extension matches the given ending. | |
| bool | remove_path () |
| Remove leading path, return true if string changed. | |
| bool | remove_ext () |
| Remove extension, return true if string changed. | |
| 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. | |
| 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. | |
| 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. | |
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.
| 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 | |
|
inline |
Default construct, empty literal.
Definition at line 33 of file keyTypeI.H.
References LITERAL, and word::word().
Referenced by keyType(), keyType(), keyType(), operator=(), operator=(), operator=(), and swap().


|
default |
|
default |
Move construct.
References assign(), clear(), compile(), isPattern(), keyType(), LITERAL, match(), Foam::noexcept, Foam::rhs(), setType(), swap(), uncompile(), and word::word().

|
inline |
Implicit copy construct from word, treat as LITERAL.
Definition at line 40 of file keyTypeI.H.
References LITERAL, and word::word().

|
inline |
Implicit move construct from word, treat as LITERAL.
Definition at line 47 of file keyTypeI.H.
References LITERAL, and word::word().

|
inline |
Implicit copy construct from Foam::string, treat as REGEX.
Definition at line 54 of file keyTypeI.H.
References REGEX, and word::word().

|
inline |
Implicit move construct from Foam::string, treat as REGEX.
Definition at line 61 of file keyTypeI.H.
References REGEX, and word::word().

|
inline |
Copy construct from std::string with specified treatment.
Definition at line 68 of file keyTypeI.H.
References word::word().

|
inline |
Move construct from std::string with specified treatment.
Definition at line 75 of file keyTypeI.H.
References word::word().

|
inline |
Implicit construct from character array, with specified compile option (default is LITERAL).
Definition at line 82 of file keyTypeI.H.
References word::word().

|
explicit |
|
inline |
Deprecated(2019-08) construct as literal/regex.
Definition at line 312 of file keyType.H.
References isPattern(), keyType(), LITERAL, REGEX, and s().

|
inlinestatic |
Test for valid keyType character?
Like Foam::word, but with brace-brackets, which are valid for some regexs.
Definition at line 24 of file keyTypeI.H.
References word::valid().

|
inlinenoexcept |
The keyType is treated as literal, not as pattern.
Definition at line 91 of file keyTypeI.H.
References Foam::noexcept, and REGEX.
Referenced by GeometricBoundaryField< scalar, Foam::fvPatchField, Foam::volMesh >::evaluate().

|
inlinenoexcept |
The keyType is treated as a pattern, not as literal string.
Definition at line 97 of file keyTypeI.H.
References Foam::noexcept, and REGEX.
Referenced by dictionary::add(), Ostream::beginBlock(), dictionary::changeKeyword(), Foam::findStrings(), Foam::getAcceptableFunctionKeys(), Foam::inplaceSubsetStrings(), keyType(), keyType(), match(), Foam::operator<<(), wordRe::operator=(), setType(), Foam::subsetStrings(), uncompile(), wordRe::wordRe(), Ostream::write(), and Ostream::writeKeyword().

| bool assign | ( | const token & | tok | ) |
Assign from word or string token.
Words are treated as literals, strings as regex
Definition at line 66 of file keyType.C.
References assign(), compile(), token::isQuotedString(), token::isWord(), token::stringToken(), uncompile(), and token::wordToken().
Referenced by assign(), keyType(), operator=(), operator=(), operator=(), operator=(), and Foam::operator>>().


|
inline |
Change the representation, optionally stripping invalid word characters when changing to a literal.
Definition at line 103 of file keyTypeI.H.
References word::debug, isPattern(), and string::stripInvalid().
Referenced by keyType().


|
inlinenoexcept |
Mark as regular expression.
Definition at line 120 of file keyTypeI.H.
References Foam::noexcept, and REGEX.
Referenced by assign(), and keyType().

|
inlinenoexcept |
Mark as literal string.
Definition at line 127 of file keyTypeI.H.
References LITERAL, and Foam::noexcept.
Referenced by assign(), and keyType().

|
inline |
Mark as literal string, optionally strip invalid word characters when changing to a literal.
Definition at line 133 of file keyTypeI.H.
References word::debug, isPattern(), LITERAL, and string::stripInvalid().

|
inline |
Clear string and set as literal.
Definition at line 145 of file keyTypeI.H.
References LITERAL.
Referenced by keyType().

| void swap | ( | keyType & | rhs | ) |
Swap contents. Self-swapping is a no-op.
Definition at line 43 of file keyType.C.
References keyType(), Foam::rhs(), string::swap(), and word::word().
Referenced by keyType(), and operator=().


| 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 55 of file keyType.C.
References isPattern(), and regExpCxx::match().
Referenced by keyType(), and operator()().


|
inline |
Perform smart match on text, as per match().
Allows use as a predicate.
Definition at line 154 of file keyTypeI.H.
References match().

|
delete |
No assignment where type could be indeterminate.
References Foam::FOAM_DEPRECATED_FOR(), keyType(), and word::word().

|
inline |
Copy assignment, retaining type (literal or regex).
Self-assignment is a no-op.
Definition at line 160 of file keyTypeI.H.
References assign(), and keyType().

|
inline |
Move assignment, retaining type (literal or regex).
Self-assignment is a no-op.
Definition at line 172 of file keyTypeI.H.
References clear(), keyType(), and swap().

|
inline |
Assign from word, treat as literal.
Definition at line 191 of file keyTypeI.H.
References assign(), LITERAL, and word::word().

|
inline |
Assign from Foam::string, treat as regular expression.
Definition at line 198 of file keyTypeI.H.
References assign(), and REGEX.

|
inline |
Assign from character array, treat as literal.
Definition at line 184 of file keyTypeI.H.
References assign(), and LITERAL.

|
static |