#include <StringUtils.hpp>
|
static std::string | replace_oc_roots (const std::string &str) |
|
static std::string & | replace_oc_roots (std::string &str) |
|
static std::string | insert_oc_roots (const std::string &str) |
|
static std::string & | insert_oc_roots (std::string &str) |
|
static std::string | replace_all (const std::string &haystack, const char *needle, const char *replacement) |
|
static std::string & | replace_all (std::string &haystack, const char *needle, const char *replacement) |
|
static std::string | strip_enclosure (const std::string &haystack, const char first, const char last) |
|
static std::string & | strip_enclosure (std::string &haystack, const char first, const char last) |
|
static std::string | strip_brackets (const std::string &haystack) |
|
static std::string & | strip_brackets (std::string &haystack) |
|
static std::string | strip_quotes (const std::string &haystack) |
|
static std::string & | strip_quotes (std::string &haystack) |
|
template<typename T > |
static std::vector< T > | stov (std::string &str, const std::string &delims=",", bool merge_multiple_delims=false, T default_value=T{}) |
|
template<typename T > |
static std::vector< T > | stov (std::string &str, const std::string &delims, bool merge_multiple_delims, T default_value, std::function< T(const std::string &)> parser) |
|
Static functions for parsing/processing/modifying strings.
String Replacement
String-to-Vector Examples
Quote/Bracket Stripping
Definition at line 26 of file StringUtils.hpp.
◆ insert_oc_roots() [1/2]
Replace paths in the input with $OCSSWROOT, $OCDATAROOT, etc, (returns a copy)
- Parameters
-
str | String containing paths to replace |
- Returns
- A new string with the known environment variables inserted in place of absolute paths
◆ insert_oc_roots() [2/2]
Replace paths in the input with $OCSSWROOT, $OCDATAROOT, etc, (in-place)
- Parameters
-
str | String containing paths to replace |
- Returns
- reference to the input string with paths replaced
◆ replace_all() [1/2]
Replace all occurrences of a string (returns a copy)
- Parameters
-
haystack | String with text to replace |
needle | What to find within haystack |
replacement | What to insert into haystack |
- Returns
- Copy of the input string with substrings replaced
◆ replace_all() [2/2]
Replace all occurrences of a string (in-place)
- Parameters
-
haystack | String with text to replace |
needle | What to find within haystack |
replacement | What to insert into haystack |
- Returns
- Reference to input string
◆ replace_oc_roots() [1/2]
Replace $OCSSWROOT, $OCDATAROOT, etc, in string (returns a copy)
- Parameters
-
str | String containing environment variables to replace |
- Returns
- A new string with the known environment variables replaced
◆ replace_oc_roots() [2/2]
Replace $OCSSWROOT, $OCDATAROOT, etc, in string, (in-place)
- Parameters
-
str | String containing environment variables to replace |
- Returns
- Reference to the input string with environment variables replaced
◆ stov() [1/2]
Convert delimited string to vector.
This should be implemented for custom types not already specialized.
- Template Parameters
-
T | type of elements in output vector |
- Parameters
-
str | Delimited string |
delims | The substring separating elements with the string (defaults to comma) |
merge_multiple_delims | Whether multiple, consecutive delimiters (i.e., an empty value) should be considered one delimiter. |
default_value | What to insert if merging multiple delimiters. |
parser | The function to use to convert the elements' strings to the desired type |
- Returns
- Newly allocated vector of the template type
◆ stov() [2/2]
Convert delimited string to vector.
This is declared to provide template specialization. The provided specializations are below. All default specializations do not check for validity, e.g., entire string matched, string wasn't empty, value wasn't narrowed.
- std::string (no conversion)
- float (std::stof)
- double (std::stod)
- int (std::stoi)
- long (std::stol)
- long double (std::stold)
- long long (std::stoll)
- unsigned (std::stoul)
- unsigned long (std::stoul)
- unsigned long long (std::stoull)
- Template Parameters
-
T | type of elements in output vector |
- Parameters
-
str | Delimited string |
delims | The substring separating elements with the string (defaults to comma) |
merge_multiple_delims | Whether multiple, consecutive delimiters (i.e., an empty value) should be considered one delimiter. |
default_value | What to insert if merging multiple delimiters. |
- Returns
- Newly allocated vector of the template type
◆ strip_brackets() [1/2]
Remove square brackets from ends of input string (returns a copy)
Only removes enclosure if first and last characters match as expected.
- Parameters
-
- Returns
- reference to the input string with square brackets, if found, removed
◆ strip_brackets() [2/2]
Remove square brackets from ends of input string (in-place)
Only removes enclosure if first and last characters match as expected.
- Parameters
-
- Returns
- reference to the input string with square brackets, if found, removed
◆ strip_enclosure() [1/2]
Remove start/end characters from ends of a string (returns a copy)
Only removes enclosure if first and last characters match as expected.
- Parameters
-
haystack | String to modify |
first | Expected first character of haystack |
last | Expected last character of haystack |
- Returns
- Copy of the input string with enclosure, if found, removed
◆ strip_enclosure() [2/2]
Remove start/end characters from ends of a string (in-place)
Only removes enclosure if first and last characters match as expected.
- Parameters
-
haystack | String to modify |
first | Expected first character of haystack |
last | Expected last character of haystack |
- Returns
- reference to the input string with enclosure, if found, removed
◆ strip_quotes() [1/2]
Remove single- and double-quotes from ends of input string (returns a copy)
Only removes enclosure if first and last characters match as expected.
- Parameters
-
- Returns
- copy of the input string with quotes brackets, if found, removed
◆ strip_quotes() [2/2]
Remove single- and double-quotes from ends of input string (in-place)
Only removes enclosure if first and last characters match as expected.
- Parameters
-
- Returns
- reference to the input string with quotes, if found, removed
The documentation for this class was generated from the following file: