Functions
Foam::stringOps Namespace Reference

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

Functions

string expand (const string &, const HashTable< string, word, string::hash > &mapping, const char sigil='$')
 Expand occurences of variables according to the mapping. More...
 
stringinplaceExpand (string &, const HashTable< string, word, string::hash > &mapping, const char sigil='$')
 Inplace expand occurences of variables according to the mapping. More...
 
string expand (const string &, const dictionary &dict, const char sigil='$')
 Expand occurences of variables according to the dictionary. More...
 
string getVariable (const word &name, const dictionary &dict, const bool allowEnvVars, const bool allowEmpty)
 Get dictionary or (optionally) environment variable. More...
 
string expand (const string &s, string::size_type &index, const dictionary &dict, const bool allowEnvVars, const bool allowEmpty)
 Recursively expands (dictionary or environment) variable. More...
 
stringinplaceExpand (string &s, const dictionary &dict, const bool allowEnvVars, const bool allowEmpty, const char sigil='$')
 Inplace expand occurences of variables according to the dictionary. More...
 
stringinplaceExpand (string &, const dictionary &dict, const char sigil='$')
 Inplace expand occurences of variables according to the dictionary. More...
 
string expand (const string &, const bool allowEmpty=false)
 Expand initial tildes and all occurences of environment variables. More...
 
stringinplaceExpand (string &, const bool allowEmpty=false)
 Expand initial tildes and all occurences of environment variables. 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...
 

Detailed Description

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

Source files

Function Documentation

◆ expand() [1/4]

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

Expand occurences of variables according to the mapping.

Expansion includes:

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

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.

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

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

Definition at line 74 of file stringOps.C.

References inplaceExpand(), and s().

Referenced by dynamicCode::copyOrCreateFiles(), expand(), inplaceExpand(), main(), and Foam::operator<<().

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

◆ inplaceExpand() [1/4]

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

Inplace expand occurences of variables according to the mapping.

Expansion includes:

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

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.

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

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

Definition at line 86 of file stringOps.C.

References HashTable::find(), and s().

Referenced by dynamicCode::copyAndFilter(), dynamicCodeContext::dynamicCodeContext(), expand(), string::expand(), primitiveEntry::expandVariable(), includeEtcEntry::includeEtcFileName(), includeEntry::includeFileName(), entry::New(), codedFunctionObject::read(), and CodedSource< Type >::read().

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

◆ expand() [2/4]

Foam::string expand ( const string original,
const dictionary dict,
const char  sigil = '$' 
)

Expand occurences 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 240 of file stringOps.C.

References dict, inplaceExpand(), and s().

Here is the call graph for this function:

◆ getVariable()

Foam::string getVariable ( const word name,
const dictionary dict,
const bool  allowEnvVars,
const bool  allowEmpty 
)

Get dictionary or (optionally) environment variable.

Definition at line 252 of file stringOps.C.

References dict, Foam::exit(), Foam::FatalIOError, FatalIOErrorInFunction, Foam::fixed(), Foam::getEnv(), Foam::name(), OSstream::precision(), and OStringStream::str().

Referenced by expand(), and inplaceExpand().

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

◆ expand() [3/4]

Foam::string expand ( const string s,
string::size_type index,
const dictionary dict,
const bool  allowEnvVars,
const bool  allowEmpty 
)

Recursively expands (dictionary or environment) variable.

starting at index in string. Updates index.

Definition at line 310 of file stringOps.C.

References dict, expand(), getVariable(), and s().

Here is the call graph for this function:

◆ inplaceExpand() [2/4]

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

Inplace expand occurences of variables according to the dictionary.

and optionally environment variables Expansion includes:

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

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 344 of file stringOps.C.

References Foam::cwd(), dict, expand(), Foam::findEtcFile(), getVariable(), Foam::home(), and s().

Here is the call graph for this function:

◆ inplaceExpand() [3/4]

Foam::string & inplaceExpand ( string s,
const dictionary dict,
const char  sigil = '$' 
)

Inplace expand occurences 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 501 of file stringOps.C.

References dict, entry::dict(), Foam::fixed(), entry::isDict(), OSstream::precision(), s(), OStringStream::str(), and dictionary::write().

Here is the call graph for this function:

◆ expand() [4/4]

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

Expand initial tildes and all occurences of environment variables.

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 628 of file stringOps.C.

References inplaceExpand(), and s().

Here is the call graph for this function:

◆ inplaceExpand() [4/4]

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

Expand initial tildes and all occurences of environment variables.

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.

Any unknown entries are removed silently if allowEmpty is true.

See also
Foam::findEtcFile

Definition at line 639 of file stringOps.C.

References Foam::cwd(), Foam::exit(), Foam::FatalError, FatalErrorInFunction, Foam::findEtcFile(), Foam::getEnv(), Foam::home(), and s().

Here is the call graph for this function:

◆ trimLeft()

Foam::string trimLeft ( const string s)

Return string trimmed of leading whitespace.

Definition at line 845 of file stringOps.C.

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

Referenced by main(), and 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 865 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 885 of file stringOps.C.

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

Referenced by main(), and 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 905 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 922 of file stringOps.C.

References trimLeft(), and trimRight().

Referenced by dynamicCodeContext::dynamicCodeContext(), main(), PackedBoolList::operator^=(), codedFunctionObject::read(), CodedSource< Type >::read(), 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 928 of file stringOps.C.

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

Here is the call graph for this function: