Collection of static functions for various string-related operations. More...
Classes | |
| struct | natural_sort |
| Encapsulation of natural order sorting for algorithms. More... | |
Functions | |
| std::string::size_type | count (const char *s, const char c) |
| Count the number of occurrences of the specified character. | |
| std::string::size_type | count (const std::string &s, const char c) |
| Count the number of occurrences of the specified character. | |
| bool | match (const UList< wordRe > &selectors, const std::string &text) |
| True if text matches one of the selector expressions. | |
| template<class StringType, class UnaryPredicate> | |
| StringType | quotemeta (const StringType &str, const UnaryPredicate &meta, const char quote='\\') |
| Quote any meta-characters in given string. | |
| string | expand (const std::string &s, const HashTable< string > &mapping, const char sigil='$') |
| Expand occurrences of variables according to the mapping and return the expanded string. | |
| void | inplaceExpand (std::string &s, const HashTable< string > &mapping, const char sigil='$') |
| Inplace expand occurrences of variables according to the mapping. Does not use environment values. | |
| void | inplaceExpand (std::string &s, const dictionary &dict, const bool allowEnv, const bool allowEmpty, const bool allowSubDict=false, const char sigil='$') |
| Inplace expand occurrences of variables according to the dictionary and (optionally) environment variables. | |
| string | expand (const std::string &s, const dictionary &dict, const char sigil='$') |
| Expand occurrences of dictionary or environment variables. | |
| void | inplaceExpand (std::string &s, const dictionary &dict, const char sigil='$') |
| Inplace expand occurrences of dictionary or environment variables. | |
| string | expand (const std::string &s, const bool allowEmpty=false) |
| Expand initial tags, tildes, and all occurrences of environment variables. | |
| void | inplaceExpand (std::string &s, const bool allowEmpty=false) |
| Expand initial tags, tildes, and all occurrences of environment variables. | |
| bool | inplaceReplaceVar (std::string &s, const word &varName) |
| Replace environment variable contents with its name. | |
| template<class StringType, class UnaryPredicate> | |
| StringType | validate (const std::string &str, const UnaryPredicate &accept, const bool invert=false) |
| Return a copy of the input string with validated characters. | |
| std::pair< size_t, size_t > | findTrim (const std::string &s, size_t pos=0, size_t len=std::string::npos) |
| Find (first, last) non-space locations in string or sub-string. | |
| string | trimLeft (const std::string &s) |
| Return string trimmed of leading whitespace. | |
| void | inplaceTrimLeft (std::string &s) |
| Trim leading whitespace inplace. | |
| string | trimRight (const std::string &s) |
| Return string trimmed of trailing whitespace. | |
| void | inplaceTrimRight (std::string &s) |
| Trim trailing whitespace inplace. | |
| string | trim (const std::string &s) |
| Return string trimmed of leading and trailing whitespace. | |
| void | inplaceTrim (std::string &s) |
| Trim leading and trailing whitespace inplace. | |
| void | inplaceRemoveSpace (std::string &s) |
| Eliminate whitespace inplace. | |
| string | removeComments (const std::string &s) |
| Return string with C/C++ comments removed. | |
| void | inplaceRemoveComments (std::string &s) |
| Remove C/C++ comments inplace. | |
| string | lower (const std::string &s) |
| Return string copy transformed with std::tolower on each character. | |
| void | inplaceLower (std::string &s) |
| Inplace transform string with std::tolower on each character. | |
| string | upper (const std::string &s) |
| Return string copy transformed with std::toupper on each character. | |
| void | inplaceUpper (std::string &s) |
| Inplace transform string with std::toupper on each character. | |
| label | splitFunctionArgs (const std::string &str, wordRes &args, List< Tuple2< word, string > > &namedArgs) |
| Split out arguments (named or unnamed) from an input string. | |
| Foam::SubStrings | split (const std::string &str, const char delim, std::string::size_type pos=0, const bool keepEmpty=false) |
| Split string into sub-strings at the delimiter character. | |
| Foam::SubStrings | split (const std::string &str, const std::string &delim, std::string::size_type pos=0, const bool keepEmpty=false) |
| Split string into sub-strings using delimiter string. | |
| Foam::SubStrings | splitAny (const std::string &str, const std::string &delim, std::string::size_type pos=0) |
| Split string into sub-strings using any characters in delimiter. | |
| Foam::SubStrings | splitFixed (const std::string &str, const std::string::size_type width, std::string::size_type pos=0) |
| Split string into sub-strings using a fixed field width. | |
| Foam::SubStrings | splitSpace (const std::string &str, std::string::size_type pos=0) |
| Split string into sub-strings at whitespace (TAB, NL, VT, FF, CR, SPC). | |
| void | writeWrapped (OSstream &os, const std::string &str, const std::string::size_type width, const std::string::size_type indent=0, const bool escape=false) |
| Output string with text wrapping. | |
| string | evaluate (label fieldWidth, const std::string &s, size_t pos=0, size_t len=std::string::npos) |
| String evaluation with specified (positive, non-zero) field width. | |
| string | evaluate (const std::string &s, size_t pos=0, size_t len=std::string::npos) |
| A simple string evaluation that handles various basic expressions. For trivial input, use readScalar instead (faster). | |
| int | natstrcmp (const char *s1, const char *s2) |
| 'Natural' compare for C-strings | |
Collection of static functions for various string-related operations.
| std::string::size_type count | ( | const char * | s, |
| const char | c ) |
Count the number of occurrences of the specified character.
Correctly handles nullptr.
References s().
Referenced by string::count().


| std::string::size_type count | ( | const std::string & | s, |
| const char | c ) |
Count the number of occurrences of the specified character.
References s().

True if text matches one of the selector expressions.
Definition at line 79 of file stringOps.H.
References wordRes::match().

| StringType quotemeta | ( | const StringType & | str, |
| const UnaryPredicate & | meta, | ||
| const char | quote = '\\' ) |
Quote any meta-characters in given string.
Referenced by ddt2::read().

| string expand | ( | const std::string & | s, |
| const HashTable< string > & | mapping, | ||
| const char | sigil = '$' ) |
Expand occurrences of variables according to the mapping and return the expanded string.
References s().
Referenced by dynamicCode::copyOrCreateFiles(), argList::displayDoc(), and functionObjectList::findDict().


Inplace expand occurrences of variables according to the mapping. Does not use environment values.
Expansion includes:
$VAR ${VAR} ${parameter:-defValue} If parameter is unset or null, the defValue is substituted. Otherwise, the value of parameter is substituted.${parameter:+altValue} If parameter is unset or null, nothing is substituted. Otherwise the altValue is substituted.General behaviour:
| [in,out] | s | The string to modify inplace. |
| mapping | The lookup table | |
| sigil | The leading sigil. Can be changed to avoid conflict with other string expansions. (default: '$') |
References s().
Referenced by dynamicCode::copyAndFilter(), string::expand(), dynamicCodeContext::inplaceExpand(), expressionEntry::inplaceExpand(), entry::New(), includeEtcEntry::resolveEtcFile(), and includeEntry::resolveFile().


| void inplaceExpand | ( | std::string & | s, |
| const dictionary & | dict, | ||
| const bool | allowEnv, | ||
| const bool | allowEmpty, | ||
| const bool | allowSubDict = false, | ||
| const char | sigil = '$' ) |
Inplace expand occurrences of variables according to the dictionary and (optionally) environment variables.
Expansion includes:
$VAR ${VAR} ${VAR:-defValue} ${VAR:+altValue} ${{EXPR}} $FOAM_CASE directory$FOAM_CASE/constant directory$FOAM_CASE/system directory${parameter:-defValue} If parameter is unset or null, the defValue is substituted. Otherwise, the value of parameter is substituted.${parameter:+altValue} If parameter is unset or null, nothing is substituted. Otherwise the altValue is substituted.General behaviour:
| [in,out] | s | The string to modify inplace |
| dict | The dictionary context for the expansion | |
| allowEnv | Allow use of environment values as fallback | |
| allowEmpty | Allow empty expansions, or treat as Fatal | |
| allowSubDict | Allow expansion of subDict entries as well as primitive entries (default: false) | |
| sigil | The leading sigil. Can be changed to avoid conflict with other string expansions. (default: '$') |

| string expand | ( | const std::string & | s, |
| const dictionary & | dict, | ||
| const char | sigil = '$' ) |
Expand occurrences of dictionary or environment variables.
Empty expansions are allowed. Serialization of subDict entries is permitted.

| void inplaceExpand | ( | std::string & | s, |
| const dictionary & | dict, | ||
| const char | sigil = '$' ) |
Inplace expand occurrences of dictionary or environment variables.
Empty expansions are allowed. Serialization of subDict entries is permitted.

| string expand | ( | const std::string & | s, |
| const bool | allowEmpty = false ) |
Expand initial tags, tildes, and all occurrences of environment variables.
References s().

| void inplaceExpand | ( | std::string & | s, |
| const bool | allowEmpty = false ) |
Expand initial tags, tildes, and all occurrences of environment variables.
The expansion behaviour is identical to stringOps::inplaceExpand (std::string&, const dictionary&, bool, bool, bool, char) except that there is no dictionary and the environment variables are always enabled.
References s().

| bool inplaceReplaceVar | ( | std::string & | s, |
| const word & | varName ) |
Replace environment variable contents with its name.
This is essentially the inverse operation for inplaceExpand for a single element. Return true if a replacement was successful.
References s().

| StringType validate | ( | const std::string & | str, |
| const UnaryPredicate & | accept, | ||
| const bool | invert = false ) |
Return a copy of the input string with validated characters.
| invert | Invert the test logic |
References Foam::invert().

| std::pair< size_t, size_t > findTrim | ( | const std::string & | s, |
| size_t | pos = 0, | ||
| size_t | len = std::string::npos ) |
Find (first, last) non-space locations in string or sub-string.
This may change to std::string_view in the future.
References Foam::pos(), and s().

| string trimLeft | ( | const std::string & | s | ) |
Return string trimmed of leading whitespace.
References s().

| void inplaceTrimLeft | ( | std::string & | s | ) |
| string trimRight | ( | const std::string & | s | ) |
Return string trimmed of trailing whitespace.
References s().

| void inplaceTrimRight | ( | std::string & | s | ) |
Trim trailing whitespace inplace.
References s().
Referenced by Foam::readEnsightString(), and ensightSurfaceReader::readLine().


| string trim | ( | const std::string & | s | ) |
Return string trimmed of leading and trailing whitespace.
References s().
Referenced by exprDriver::addVariables(), and substitutionModel::cleanKey().


| void inplaceTrim | ( | std::string & | s | ) |
Trim leading and trailing whitespace inplace.
References s().
Referenced by exprDriver::addVariables(), dynamicCodeContext::inplaceExpand(), expressionEntry::inplaceExpand(), and exprString::trim().


| void inplaceRemoveSpace | ( | std::string & | s | ) |
Eliminate whitespace inplace.
References s().
Referenced by Foam::getIdentifier().


| string removeComments | ( | const std::string & | s | ) |
Return string with C/C++ comments removed.
References s().

| void inplaceRemoveComments | ( | std::string & | s | ) |
Remove C/C++ comments inplace.
References s().
Referenced by exprString::inplaceExpand().


| string lower | ( | const std::string & | s | ) |
Return string copy transformed with std::tolower on each character.
References s().
Referenced by STLAsciiParseManual::execute().


| void inplaceLower | ( | std::string & | s | ) |
Inplace transform string with std::tolower on each character.
References s().
Referenced by STARCDMeshReader::readBoundary().


| string upper | ( | const std::string & | s | ) |
Return string copy transformed with std::toupper on each character.
References s().
Referenced by ABAQUSCore::readHelper::addNewElset(), substitutionModel::cleanKey(), Foam::getIdentifier(), argList::printMan(), ABAQUSCore::readHelper::read(), ABAQUSCore::readHelper::readSurfaceElements(), and Foam::writeCoordHeader().


| void inplaceUpper | ( | std::string & | s | ) |
Inplace transform string with std::toupper on each character.
References s().

| label splitFunctionArgs | ( | const std::string & | str, |
| wordRes & | args, | ||
| List< Tuple2< word, string > > & | namedArgs ) |
Split out arguments (named or unnamed) from an input string.
For example,
* (U) * -> named = () * -> unnamed = (U) * * (patch=inlet, p) * -> named = ((patch inlet)) * -> unnamed = (p) * * testing, start=100, stop=200 * -> named = ((start 100)(stop 200)) * -> unnamed = (testing) *
References args.
Referenced by functionObjectList::readFunctionObject().

| Foam::SubStrings split | ( | const std::string & | str, |
| const char | delim, | ||
| std::string::size_type | pos = 0, | ||
| const bool | keepEmpty = false ) |
Split string into sub-strings at the delimiter character.
Empty sub-strings are normally suppressed. Behaviour is ill-defined if delim is a NUL character.
| str | The string to split |
| delim | The delimiter for splitting. Ill-defined if NUL character |
| pos | Offset within string to start splitting |
| keepEmpty | Retain empty fields |
References Foam::pos().
Referenced by exprDriver::addVariables(), dictionary::cfindScopedDict(), fileName::component(), fileName::components(), loadLibrary(), dictionary::makeScopedDict(), and NASsurfaceFormat< Face >::read().


| Foam::SubStrings split | ( | const std::string & | str, |
| const std::string & | delim, | ||
| std::string::size_type | pos = 0, | ||
| const bool | keepEmpty = false ) |
Split string into sub-strings using delimiter string.
Empty sub-strings are normally suppressed.
| str | The string to split |
| delim | The delimiters for splitting. Ill-defined if empty |
| pos | Offset within string to start splitting |
| keepEmpty | Retain empty fields |
References Foam::pos().

| Foam::SubStrings splitAny | ( | const std::string & | str, |
| const std::string & | delim, | ||
| std::string::size_type | pos = 0 ) |
Split string into sub-strings using any characters in delimiter.
Empty sub-strings are normally suppressed. Behaviour is ill-defined if delim is an empty string.
| str | The string to split |
| delim | The delimiters for splitting. Ill-defined if empty! |
| pos | Offset within string to start splitting |
References Foam::pos().
Referenced by Foam::splitStringToList(), and basicThermo::splitThermoName().


| Foam::SubStrings splitFixed | ( | const std::string & | str, |
| const std::string::size_type | width, | ||
| std::string::size_type | pos = 0 ) |
Split string into sub-strings using a fixed field width.
Behaviour is ill-defined if width is zero.
| str | The string to split |
| width | Fixed field width for each sub-string |
| pos | Offset within string to start splitting |
References Foam::pos().

| Foam::SubStrings splitSpace | ( | const std::string & | str, |
| std::string::size_type | pos = 0 ) |
Split string into sub-strings at whitespace (TAB, NL, VT, FF, CR, SPC).
Empty sub-strings are suppressed.
| str | The string to split |
| pos | Offset within string to start splitting |
References Foam::pos().
Referenced by argList::displayDoc(), ensightReadFile::getTimeStepFooter(), OBJedgeFormat::read(), OBJsurfaceFormat< Face >::read(), and ensightSurfaceReader::readCase().


| void writeWrapped | ( | OSstream & | os, |
| const std::string & | str, | ||
| const std::string::size_type | width, | ||
| const std::string::size_type | indent = 0, | ||
| const bool | escape = false ) |
Output string with text wrapping.
Always includes a trailing newline, unless the string itself is empty.
| os | The output stream |
| str | The text to be output |
| width | The max-width before wrapping |
| indent | Indentation for continued lines |
| escape | Escape any backslashes on output |
References Foam::indent(), and os().
Referenced by argList::printMan(), Foam::printManOption(), argList::printNotes(), and Foam::printOptionUsage().


| string evaluate | ( | label | fieldWidth, |
| const std::string & | s, | ||
| size_t | pos = 0, | ||
| size_t | len = std::string::npos ) |
String evaluation with specified (positive, non-zero) field width.
References Foam::pos(), and s().

| string evaluate | ( | const std::string & | s, |
| size_t | pos = 0, | ||
| size_t | len = std::string::npos ) |
A simple string evaluation that handles various basic expressions. For trivial input, use readScalar instead (faster).
The evaluation supports the following:
References Foam::pos(), and s().

| int natstrcmp | ( | const char * | s1, |
| const char * | s2 ) |
'Natural' compare for C-strings
Uses algorithm and code from Jan-Marten Spit jmspi.nosp@m.t@eu.nosp@m.ronet.nosp@m..nl
In the 'natural' comparison, strings are compared alphabetically and numerically. Thus 'file010.txt' sorts after 'file2.txt'
| s1 | left string |
| s2 | right string |
Referenced by natural_sort::compare().
