Foam::stringOps Namespace Reference

Collection of static functions to do various simple string-related operations. More...

Functions

string expandEnvVar (const string &, const bool allowEmpty=false)
 Expand all occurrences of environment variables and paths. More...
 
stringinplaceExpandEnvVar (string &, const bool allowEmpty=false)
 Expand all occurrences of environment variables and paths. More...
 
stringinplaceExpandCodeString (string &, const dictionary &dict, const word &dictVar="dict", const char sigil='$')
 Inplace expand occurrences of variables according to the dictionary. More...
 
stringinplaceExpandCodeTemplate (string &, const HashTable< string, word, string::hash > &mapping, const char sigil='$')
 Inplace expand occurrences of variables according to the mapping. More...
 
stringinplaceExpandEntry (string &s, const dictionary &dict, const bool allowEnvVars, const bool allowEmpty, const char sigil='$')
 Inplace expand occurrences of variables according to the dictionary. More...
 
string trimLeft (const string &)
 Return string trimmed of leading whitespace. More...
 
stringinplaceTrimLeft (string &)
 Trim leading whitespace inplace. More...
 
string trimRight (const string &)
 Return string trimmed of trailing whitespace. More...
 
stringinplaceTrimRight (string &)
 Trim trailing whitespace inplace. More...
 
string trim (const string &)
 Return string trimmed of leading and trailing whitespace. More...
 
stringinplaceTrim (string &)
 Trim leading and trailing whitespace inplace. More...
 
string breakIntoIndentedLines (const string &str, const string::size_type nLength=80, const string::size_type nIndent=0)
 Break a string up into indented lines. More...
 

Detailed Description

Collection of static functions to do various simple string-related operations.

Source files

Function Documentation

◆ expandEnvVar()

Foam::string expandEnvVar ( const string original,
const bool  allowEmpty = false 
)

Expand all occurrences of environment variables and paths.

Expansion includes:

  1. environment variables
    • "$VAR", "${VAR}"
  2. current directory
    • leading "./" : the current directory
  3. tilde expansion
    • leading "~/" : home directory
    • leading "~user" : home directory for specified user
    • leading "~OpenFOAM" : site/user OpenFOAM configuration directory

Supports default values as per the Bourne/Korn shell.

"${parameter:-defValue}"

If parameter is unset or null, the defValue is substituted. Otherwise, the value of parameter is substituted.

Supports alternative values as per the Bourne/Korn shell.

"${parameter:+altValue}"

If parameter is unset or null, nothing is substituted. Otherwise the altValue is substituted.

Any unknown entries are removed silently, if allowEmpty is true.

Malformed entries (eg, brace mismatch, sigil followed by bad character) are left as is.

See also
Foam::findEtcFile

Definition at line 240 of file stringOps.C.

References inplaceExpandEnvVar(), and s().

Referenced by dynamicCode::copyOrCreateFiles(), and Foam::findConfigFile().

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

◆ inplaceExpandEnvVar()

Foam::string & inplaceExpandEnvVar ( string s,
const bool  allowEmpty = false 
)

Expand all occurrences of environment variables and paths.

See expandEnvVar

Definition at line 251 of file stringOps.C.

References Foam::exit(), Foam::FatalError, FatalErrorInFunction, Foam::findParameterAlternative(), Foam::getEnv(), Foam::inplaceExpandPath(), and s().

Referenced by string::expand(), expandEnvVar(), and inplaceExpandCodeString().

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

◆ inplaceExpandCodeString()

Foam::string & inplaceExpandCodeString ( string s,
const dictionary dict,
const word dictVar = "dict",
const char  sigil = '$' 
)

Inplace expand occurrences of variables according to the dictionary.

Expansion includes:

  1. variables
    • "$VAR", "${VAR}"

Any unknown entries are left as-is

Note
the leading sigil can be changed to avoid conflicts with other string expansions

Definition at line 409 of file stringOps.C.

References dict, entry::dict(), Foam::exit(), Foam::FatalIOError, FatalIOErrorInFunction, inplaceExpandEnvVar(), entry::isDict(), Foam::nl, OSstream::precision(), s(), Foam::scientific(), List< T >::size(), OStringStream::str(), and dictionary::write().

Referenced by dynamicCodeContext::dynamicCodeContext().

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

◆ inplaceExpandCodeTemplate()

Foam::string & inplaceExpandCodeTemplate ( string s,
const HashTable< string, word, string::hash > &  mapping,
const char  sigil = '$' 
)

Inplace expand occurrences of variables according to the mapping.

Expansion includes:

  1. variables
    • "$VAR", "${VAR}"

Any unknown entries are removed silently.

Note
the leading sigil can be changed to avoid conflicts with other string expansions

Definition at line 653 of file stringOps.C.

References HashTable< T, Key, Hash >::find(), and s().

Referenced by dynamicCode::copyAndFilter().

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

◆ inplaceExpandEntry()

Foam::string & inplaceExpandEntry ( string s,
const dictionary dict,
const bool  allowEnvVars,
const bool  allowEmpty,
const char  sigil = '$' 
)

Inplace expand occurrences of variables according to the dictionary.

and optionally environment variables Expansion includes:

  1. variables
    • "$VAR", "${VAR}"
  2. current directory
    • leading "./" : the current directory
  3. tilde expansion
    • leading "~/" : home directory
    • leading "~user" : home directory for specified user
    • leading "~OpenFOAM" : site/user OpenFOAM configuration directory

with the "${}" syntax doing a recursive substitution.

Any unknown entries are left as-is

Note
the leading sigil can be changed to avoid conflicts with other string expansions

Definition at line 759 of file stringOps.C.

References dict, Foam::expand(), Foam::getVariable(), Foam::inplaceExpandPath(), and s().

Referenced by calcIncludeEntry::execute(), includeEntry::includeFileName(), and entry::New().

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

◆ trimLeft()

Foam::string trimLeft ( const string s)

Return string trimmed of leading whitespace.

Definition at line 870 of file stringOps.C.

References Foam::isspace(), and s().

Referenced by trim().

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

◆ inplaceTrimLeft()

Foam::string & inplaceTrimLeft ( string s)

Trim leading whitespace inplace.

Definition at line 890 of file stringOps.C.

References Foam::isspace(), and s().

Referenced by inplaceTrim().

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

◆ trimRight()

Foam::string trimRight ( const string s)

Return string trimmed of trailing whitespace.

Definition at line 910 of file stringOps.C.

References Foam::isspace(), and s().

Referenced by trim().

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

◆ inplaceTrimRight()

Foam::string & inplaceTrimRight ( string s)

Trim trailing whitespace inplace.

Definition at line 930 of file stringOps.C.

References Foam::isspace(), and s().

Referenced by inplaceTrim().

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

◆ trim()

Foam::string trim ( const string original)

Return string trimmed of leading and trailing whitespace.

Definition at line 947 of file stringOps.C.

References trimLeft(), and trimRight().

Referenced by dynamicCodeContext::dynamicCodeContext(), PackedBoolList::operator^=(), and PackedBoolList::set().

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

◆ inplaceTrim()

Foam::string & inplaceTrim ( string s)

Trim leading and trailing whitespace inplace.

Definition at line 953 of file stringOps.C.

References inplaceTrimLeft(), inplaceTrimRight(), and s().

Here is the call graph for this function:

◆ breakIntoIndentedLines()

Foam::string breakIntoIndentedLines ( const string str,
const string::size_type  nLength = 80,
const string::size_type  nIndent = 0 
)

Break a string up into indented lines.

Definition at line 962 of file stringOps.C.

References Foam::indent().

Referenced by cyclicTransform::cyclicTransform(), mappedValueFvPatchField< Type >::mappedValueFvPatchField(), mappedPatchBaseBase::validateForField(), and mappedPatchBaseBase::validateMapForField().

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