exprString Class Reference

A variant of Foam::string with expansion of dictionary variables into a comma-separated form. More...

Inheritance diagram for exprString:
Collaboration diagram for exprString:

Public Member Functions

 exprString ()=default
 Default construct. More...
 
 exprString (const exprString &rhs)=default
 Copy construct. More...
 
 exprString (exprString &&rhs)=default
 Move construct. More...
 
 exprString (const std::string &s, bool doCheck=true)
 Copy construct from std::string. More...
 
 exprString (std::string &&s, bool doCheck=true)
 Move construct from std::string. More...
 
 exprString (const char *s, bool doCheck=true)
 Construct as copy of character array. More...
 
 exprString (const word &entryName, const dictionary &dict, const bool mandatory=true)
 Construct from dictionary entry lookup. Expands dictionary variables and strips and strips any embedded C/C++ comments. More...
 
 exprString (Istream &is, const dictionary &dict, const bool stripComments=true)
 Construct from Istream with dictionary context for expanding dictionary variables. Strips any embedded C/C++ comments. More...
 
 ~exprString ()=default
 Destructor. More...
 
bool valid () const
 Check for unexpanded '$' entries. Fatal if any exist. More...
 
void expand (const dictionary &dict, const bool stripComments=true)
 Inplace expansion with dictionary variables, and strip any embedded C/C++ comments. More...
 
void trim ()
 Inplace trim leading and trailing whitespace. More...
 
bool readEntry (const word &keyword, const dictionary &dict, IOobjectOption::readOption readOpt=IOobjectOption::MUST_READ)
 Read/expand entry with dictionary variables, and strip any embedded C/C++ comments from the input. More...
 
bool readIfPresent (const word &keyword, const dictionary &dict)
 Read/expand optional entry with dictionary variables, and strip any embedded C/C++ comments from the input. More...
 
exprStringoperator= (const exprString &str)=default
 Copy assign. More...
 
exprStringoperator= (exprString &&str)=default
 Move assign. More...
 
exprStringoperator= (const char *str)
 Copy assign from c-string. No expansions, no comment stripping. More...
 
exprStringoperator= (const std::string &str)
 Copy assign from string. No expansions, no comment stripping. More...
 
exprStringoperator= (std::string &&str)
 Move assign from string. No expansions, no comment stripping. More...
 
bool writeEntry (const word &keyword, Ostream &os, bool writeEmpty=false) const
 Dictionary entry for expression string, normally suppressing empty strings. Generally uses verbatim output (readability) 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)
 Replace first occurrence of sub-string s1 with s2, beginning at pos. More...
 
stringreplaceAll (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. More...
 
stringreplaceAny (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. More...
 
stringexpand (const bool allowEmpty=false)
 Inplace expand initial tags, tildes, and all occurrences of environment variables as per stringOps::expand. More...
 
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 contains (char c) const noexcept
 True if string contains given character (cf. C++23) More...
 
bool contains (const std::string &s) const noexcept
 True if string contains given [string view] substring (cf. C++23) More...
 
bool contains (const char *s) const
 True if string contains given substring (cf. C++23) More...
 
bool starts_with (char c) const
 True if string starts with given character (cf. C++20) More...
 
bool starts_with (const std::string &s) const
 True if string starts with given [string view] prefix (C++20) More...
 
bool starts_with (const char *s) const
 True if string starts with given prefix (C++20) More...
 
bool ends_with (char c) const
 True if string ends with given character (cf. C++20) More...
 
bool ends_with (const std::string &s) const
 True if string ends with given [string view] suffix (cf. C++20) More...
 
bool ends_with (const char *s) const
 True if string ends with given suffix (cf. C++20) More...
 
size_type count (const char c) const
 Count the number of occurrences of the specified character in the string. More...
 
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 exprString toExpr (const std::string &str)
 Copy convert string to exprString. More...
 
static exprString toExpr (std::string &&str)
 Move convert string to exprString. More...
 
static exprString toExpr (const std::string &str, const dictionary &dict, const bool stripComments=true)
 Copy convert string to exprString with dictionary expansions, stripping any embedded C/C++ comments. More...
 
static exprString toExpr (std::string &&str, const dictionary &dict, const bool stripComments=true)
 Move convert string to exprString with dictionary expansions, stripping any embedded C/C++ comments. More...
 
static void inplaceExpand (std::string &str, const dictionary &dict, const bool stripComments=true)
 Inplace expansion with dictionary variables, and strip any embedded C/C++ comments. More...
 
- Static Public Member Functions inherited from string
static std::string::size_type length (const char *s)
 Length of the character sequence (with nullptr protection) More...
 
static std::string::size_type length (const std::string &s)
 The length of the string. More...
 
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...
 

Additional Inherited Members

- 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...
 
- 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 has_ext () const
 Return true if it has an extension or simply ends with a '.'. More...
 
bool has_ext (const char *ending) const
 Return true if the extension is the same as the given ending. More...
 
bool has_ext (const std::string &ending) const
 Return true if the extension is the same as the given ending. More...
 
bool has_ext (const wordRe &ending) const
 Return true if the extension matches the given ending. More...
 
bool remove_path ()
 Remove leading path, return true if string changed. More...
 
bool remove_ext ()
 Remove extension, return 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 variant of Foam::string with expansion of dictionary variables into a comma-separated form.

Source files
See also
Foam::exprTools::expressionEntry

Definition at line 55 of file exprString.H.

Constructor & Destructor Documentation

◆ exprString() [1/8]

exprString ( )
default

Default construct.

◆ exprString() [2/8]

exprString ( const exprString rhs)
default

Copy construct.

◆ exprString() [3/8]

exprString ( exprString &&  rhs)
default

Move construct.

◆ exprString() [4/8]

exprString ( const std::string &  s,
bool  doCheck = true 
)
inlineexplicit

Copy construct from std::string.

Definition at line 27 of file exprStringI.H.

◆ exprString() [5/8]

exprString ( std::string &&  s,
bool  doCheck = true 
)
inlineexplicit

Move construct from std::string.

Definition at line 44 of file exprStringI.H.

◆ exprString() [6/8]

exprString ( const char *  s,
bool  doCheck = true 
)
inlineexplicit

Construct as copy of character array.

Definition at line 61 of file exprStringI.H.

◆ exprString() [7/8]

exprString ( const word entryName,
const dictionary dict,
const bool  mandatory = true 
)
inline

Construct from dictionary entry lookup. Expands dictionary variables and strips and strips any embedded C/C++ comments.

Parameters
entryNameLookup key. LITERAL (not REGEX)

Definition at line 78 of file exprStringI.H.

References dict, and readIfPresent().

Here is the call graph for this function:

◆ exprString() [8/8]

exprString ( Istream is,
const dictionary dict,
const bool  stripComments = true 
)
inline

Construct from Istream with dictionary context for expanding dictionary variables. Strips any embedded C/C++ comments.

Definition at line 96 of file exprStringI.H.

References dict, Foam::stringOps::expand(), and Foam::stringOps::removeComments().

Here is the call graph for this function:

◆ ~exprString()

~exprString ( )
default

Destructor.

Member Function Documentation

◆ toExpr() [1/4]

Foam::expressions::exprString toExpr ( const std::string &  str)
inlinestatic

Copy convert string to exprString.

No expansions, know what you are doing.

Definition at line 111 of file exprStringI.H.

Referenced by exprDriver::addVariables().

Here is the caller graph for this function:

◆ toExpr() [2/4]

Foam::expressions::exprString toExpr ( std::string &&  str)
inlinestatic

Move convert string to exprString.

No expansions, know what you are doing.

Definition at line 122 of file exprStringI.H.

◆ toExpr() [3/4]

Foam::expressions::exprString toExpr ( const std::string &  str,
const dictionary dict,
const bool  stripComments = true 
)
inlinestatic

Copy convert string to exprString with dictionary expansions, stripping any embedded C/C++ comments.

See also
inplaceExpand() for expansion details

Definition at line 134 of file exprStringI.H.

References dict.

◆ toExpr() [4/4]

Foam::expressions::exprString toExpr ( std::string &&  str,
const dictionary dict,
const bool  stripComments = true 
)
inlinestatic

Move convert string to exprString with dictionary expansions, stripping any embedded C/C++ comments.

See also
inplaceExpand() for expansion details

Definition at line 151 of file exprStringI.H.

References dict.

◆ inplaceExpand()

void inplaceExpand ( std::string &  str,
const dictionary dict,
const bool  stripComments = true 
)
static

Inplace expansion with dictionary variables, and strip any embedded C/C++ comments.

Expansion behaviour
  • alternatives = True
  • environment = True
  • allow empty = True
  • subDict = False

Definition at line 29 of file exprString.C.

References dict, Foam::stringOps::inplaceExpand(), and Foam::stringOps::inplaceRemoveComments().

Here is the call graph for this function:

◆ valid()

bool valid ( ) const
inline

Check for unexpanded '$' entries. Fatal if any exist.

Definition at line 168 of file exprStringI.H.

References Foam::exit(), Foam::FatalError, FatalErrorInFunction, and Foam::nl.

Here is the call graph for this function:

◆ expand()

void expand ( const dictionary dict,
const bool  stripComments = true 
)

Inplace expansion with dictionary variables, and strip any embedded C/C++ comments.

See also
inplaceExpand() for expansion details

Definition at line 47 of file exprString.C.

References dict, and Foam::stringOps::inplaceExpand().

Here is the call graph for this function:

◆ trim()

void trim ( )

Inplace trim leading and trailing whitespace.

Definition at line 60 of file exprString.C.

References Foam::stringOps::inplaceTrim().

Here is the call graph for this function:

◆ readEntry()

bool readEntry ( const word keyword,
const dictionary dict,
IOobjectOption::readOption  readOpt = IOobjectOption::MUST_READ 
)

Read/expand entry with dictionary variables, and strip any embedded C/C++ comments from the input.

Parameters
keywordLookup key. Uses LITERAL (not REGEX)

Definition at line 67 of file exprString.C.

References clear(), dict, Foam::stringOps::expand(), and keyType::LITERAL.

Here is the call graph for this function:

◆ readIfPresent()

bool readIfPresent ( const word keyword,
const dictionary dict 
)
inline

Read/expand optional entry with dictionary variables, and strip any embedded C/C++ comments from the input.

Parameters
keywordLookup key. Uses LITERAL (not REGEX)

Definition at line 186 of file exprStringI.H.

References dict, Foam::glTF::key(), and IOobjectOption::READ_IF_PRESENT.

Here is the call graph for this function:

◆ operator=() [1/5]

exprString& operator= ( const exprString str)
default

Copy assign.

◆ operator=() [2/5]

exprString& operator= ( exprString &&  str)
default

Move assign.

◆ operator=() [3/5]

Foam::expressions::exprString & operator= ( const char *  str)
inline

Copy assign from c-string. No expansions, no comment stripping.

Definition at line 198 of file exprStringI.H.

◆ operator=() [4/5]

Foam::expressions::exprString & operator= ( const std::string &  str)
inline

Copy assign from string. No expansions, no comment stripping.

Definition at line 211 of file exprStringI.H.

◆ operator=() [5/5]

Foam::expressions::exprString & operator= ( std::string &&  str)
inline

Move assign from string. No expansions, no comment stripping.

Definition at line 224 of file exprStringI.H.

◆ writeEntry()

bool writeEntry ( const word keyword,
Ostream os,
bool  writeEmpty = false 
) const

Dictionary entry for expression string, normally suppressing empty strings. Generally uses verbatim output (readability)

Returns
true if entry was written

Definition at line 89 of file exprString.C.

References Ostream::endEntry(), token::setType(), Ostream::write(), and Ostream::writeKeyword().

Here is the call graph for this function:

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