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 occurrences of variables according to the mapping. More... | |
string & | inplaceExpand (string &, const HashTable< string, word, string::hash > &mapping, const char sigil='$') |
Inplace expand occurrences of variables according to the mapping. More... | |
string | expand (const string &, const dictionary &dict, const char sigil='$') |
Expand occurrences 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... | |
string & | inplaceExpand (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 & | inplaceExpand (string &, const dictionary &dict, const char sigil='$') |
Inplace expand occurrences of variables according to the dictionary. More... | |
string | expand (const string &, const bool allowEmpty=false) |
Expand initial tildes and all occurrences of environment variables. More... | |
string & | inplaceExpand (string &, const bool allowEmpty=false) |
Expand initial tildes and all occurrences of environment variables. More... | |
string | trimLeft (const string &) |
Return string trimmed of leading whitespace. More... | |
string & | inplaceTrimLeft (string &) |
Trim leading whitespace inplace. More... | |
string | trimRight (const string &) |
Return string trimmed of trailing whitespace. More... | |
string & | inplaceTrimRight (string &) |
Trim trailing whitespace inplace. More... | |
string | trim (const string &) |
Return string trimmed of leading and trailing whitespace. More... | |
string & | inplaceTrim (string &) |
Trim leading and trailing whitespace inplace. More... | |
Collection of static functions to do various simple string-related operations.
Foam::string expand | ( | const string & | original, |
const HashTable< string, word, string::hash > & | mapping, | ||
const char | sigil = '$' |
||
) |
Expand occurrences of variables according to the mapping.
Expansion includes:
Supports default values as per the Bourne/Korn shell.
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.
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.
Definition at line 75 of file stringOps.C.
References inplaceExpand(), and s().
Referenced by chemkinReader::chemkinReader(), dynamicCode::copyOrCreateFiles(), dynamicCodeContext::dynamicCodeContext(), ifeqEntry::execute(), ifeqEntry::expand(), expand(), functionObjectList::findRegionDict(), getVariable(), inplaceExpand(), dlLibraryTable::open(), tabulated6DoFAcceleration::read(), and tabulated6DoFMotion::read().
Foam::string & inplaceExpand | ( | string & | s, |
const HashTable< string, word, string::hash > & | mapping, | ||
const char | sigil = '$' |
||
) |
Inplace expand occurrences of variables according to the mapping.
Expansion includes:
Supports default values as per the Bourne/Korn shell.
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.
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.
Definition at line 87 of file stringOps.C.
References expand(), HashTable< T, Key, Hash >::find(), and s().
Referenced by dynamicCode::copyAndFilter(), expand(), ifeqEntry::expand(), string::expand(), includeEntry::includeFileName(), inplaceExpand(), and entry::New().
Foam::string expand | ( | const string & | original, |
const dictionary & | dict, | ||
const char | sigil = '$' |
||
) |
Expand occurrences of variables according to the dictionary.
Expansion includes:
Any unknown entries are left as-is
Definition at line 241 of file stringOps.C.
References getVariable(), inplaceExpand(), and s().
Foam::string getVariable | ( | const word & | name, |
const dictionary & | dict, | ||
const bool | allowEnvVars, | ||
const bool | allowEmpty | ||
) |
Get dictionary or (optionally) environment variable.
Definition at line 253 of file stringOps.C.
References Foam::exit(), expand(), Foam::FatalIOError, FatalIOErrorInFunction, Foam::getEnv(), dictionary::lookupScopedEntryPtr(), OSstream::precision(), Foam::scientific(), OStringStream::str(), and Foam::blockMeshTools::write().
Referenced by expand(), and inplaceExpand().
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 311 of file stringOps.C.
References expand(), getVariable(), and inplaceExpand().
Foam::string & inplaceExpand | ( | 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:
with the "${}" syntax doing a recursive substitution. Any unknown entries are left as-is
Definition at line 345 of file stringOps.C.
References Foam::cwd(), expand(), Foam::file, Foam::findEtcFile(), getVariable(), Foam::home(), inplaceExpand(), and s().
Foam::string & inplaceExpand | ( | string & | s, |
const dictionary & | dict, | ||
const char | sigil = '$' |
||
) |
Inplace expand occurrences of variables according to the dictionary.
Expansion includes:
Any unknown entries are left as-is
Definition at line 502 of file stringOps.C.
References expand(), dictionary::lookupScopedEntryPtr(), OSstream::precision(), s(), Foam::scientific(), OStringStream::str(), and Foam::blockMeshTools::write().
Foam::string expand | ( | const string & | original, |
const bool | allowEmpty = false |
||
) |
Expand initial tildes and all occurrences of environment variables.
Expansion includes:
Supports default values as per the Bourne/Korn shell.
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.
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.
Definition at line 629 of file stringOps.C.
References inplaceExpand(), and s().
Foam::string & inplaceExpand | ( | string & | s, |
const bool | allowEmpty = false |
||
) |
Expand initial tildes and all occurrences of environment variables.
Expansion includes:
Supports default values as per the Bourne/Korn shell.
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.
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.
Definition at line 640 of file stringOps.C.
References Foam::cwd(), Foam::exit(), Foam::FatalError, FatalErrorInFunction, Foam::file, Foam::findEtcFile(), Foam::getEnv(), Foam::home(), and s().
Foam::string trimLeft | ( | const string & | s | ) |
Return string trimmed of leading whitespace.
Definition at line 846 of file stringOps.C.
References Foam::isspace(), and s().
Referenced by trim().
Foam::string & inplaceTrimLeft | ( | string & | s | ) |
Trim leading whitespace inplace.
Definition at line 866 of file stringOps.C.
References Foam::isspace(), and s().
Referenced by inplaceTrim().
Foam::string trimRight | ( | const string & | s | ) |
Return string trimmed of trailing whitespace.
Definition at line 886 of file stringOps.C.
References Foam::isspace(), and s().
Referenced by trim().
Foam::string & inplaceTrimRight | ( | string & | s | ) |
Trim trailing whitespace inplace.
Definition at line 906 of file stringOps.C.
References Foam::isspace(), and s().
Referenced by inplaceTrim().
Foam::string trim | ( | const string & | original | ) |
Return string trimmed of leading and trailing whitespace.
Definition at line 923 of file stringOps.C.
References trimLeft(), and trimRight().
Referenced by dynamicCodeContext::dynamicCodeContext(), and vtkUnstructuredReader::vtkUnstructuredReader().
Foam::string & inplaceTrim | ( | string & | s | ) |
Trim leading and trailing whitespace inplace.
Definition at line 929 of file stringOps.C.
References inplaceTrimLeft(), inplaceTrimRight(), and s().