OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022

#include <StringUtils.hpp>

Static Public Member Functions

static std::string replace_oc_roots (const std::string &str)
 
static std::stringreplace_oc_roots (std::string &str)
 
static std::string insert_oc_roots (const std::string &str)
 
static std::stringinsert_oc_roots (std::string &str)
 
static std::string replace_all (const std::string &haystack, const char *needle, const char *replacement)
 
static std::stringreplace_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::stringstrip_enclosure (std::string &haystack, const char first, const char last)
 
static std::string strip_brackets (const std::string &haystack)
 
static std::stringstrip_brackets (std::string &haystack)
 
static std::string strip_quotes (const std::string &haystack)
 
static std::stringstrip_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)
 

Detailed Description

Static functions for parsing/processing/modifying strings.

String Replacement

String-to-Vector Examples

Quote/Bracket Stripping

Definition at line 26 of file StringUtils.hpp.

Member Function Documentation

◆ insert_oc_roots() [1/2]

static std::string insert_oc_roots ( const std::string str)
static

Replace paths in the input with $OCSSWROOT, $OCDATAROOT, etc, (returns a copy)

Parameters
strString containing paths to replace
Returns
A new string with the known environment variables inserted in place of absolute paths

◆ insert_oc_roots() [2/2]

static std::string& insert_oc_roots ( std::string str)
static

Replace paths in the input with $OCSSWROOT, $OCDATAROOT, etc, (in-place)

Parameters
strString containing paths to replace
Returns
reference to the input string with paths replaced

◆ replace_all() [1/2]

static std::string replace_all ( const std::string haystack,
const char *  needle,
const char *  replacement 
)
static

Replace all occurrences of a string (returns a copy)

Parameters
haystackString with text to replace
needleWhat to find within haystack
replacementWhat to insert into haystack
Returns
Copy of the input string with substrings replaced

◆ replace_all() [2/2]

static std::string& replace_all ( std::string haystack,
const char *  needle,
const char *  replacement 
)
static

Replace all occurrences of a string (in-place)

Parameters
haystackString with text to replace
needleWhat to find within haystack
replacementWhat to insert into haystack
Returns
Reference to input string

◆ replace_oc_roots() [1/2]

static std::string replace_oc_roots ( const std::string str)
static

Replace $OCSSWROOT, $OCDATAROOT, etc, in string (returns a copy)

Parameters
strString containing environment variables to replace
Returns
A new string with the known environment variables replaced

◆ replace_oc_roots() [2/2]

static std::string& replace_oc_roots ( std::string str)
static

Replace $OCSSWROOT, $OCDATAROOT, etc, in string, (in-place)

Parameters
strString containing environment variables to replace
Returns
Reference to the input string with environment variables replaced

◆ stov() [1/2]

static std::vector<T> stov ( std::string str,
const std::string delims,
bool  merge_multiple_delims,
default_value,
std::function< T(const std::string &)>  parser 
)
static

Convert delimited string to vector.

This should be implemented for custom types not already specialized.

Template Parameters
Ttype of elements in output vector
Parameters
strDelimited string
delimsThe substring separating elements with the string (defaults to comma)
merge_multiple_delimsWhether multiple, consecutive delimiters (i.e., an empty value) should be considered one delimiter.
default_valueWhat to insert if merging multiple delimiters.
parserThe function to use to convert the elements' strings to the desired type
Returns
Newly allocated vector of the template type

◆ stov() [2/2]

static std::vector<T> stov ( std::string str,
const std::string delims = ",",
bool  merge_multiple_delims = false,
default_value = T{} 
)
static

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
Ttype of elements in output vector
Parameters
strDelimited string
delimsThe substring separating elements with the string (defaults to comma)
merge_multiple_delimsWhether multiple, consecutive delimiters (i.e., an empty value) should be considered one delimiter.
default_valueWhat to insert if merging multiple delimiters.
Returns
Newly allocated vector of the template type

◆ strip_brackets() [1/2]

static std::string strip_brackets ( const std::string haystack)
static

Remove square brackets from ends of input string (returns a copy)

Only removes enclosure if first and last characters match as expected.

Parameters
haystackString to modify
Returns
reference to the input string with square brackets, if found, removed

◆ strip_brackets() [2/2]

static std::string& strip_brackets ( std::string haystack)
static

Remove square brackets from ends of input string (in-place)

Only removes enclosure if first and last characters match as expected.

Parameters
haystackString to modify
Returns
reference to the input string with square brackets, if found, removed

◆ strip_enclosure() [1/2]

static std::string strip_enclosure ( const std::string haystack,
const char  first,
const char  last 
)
static

Remove start/end characters from ends of a string (returns a copy)

Only removes enclosure if first and last characters match as expected.

Parameters
haystackString to modify
firstExpected first character of haystack
lastExpected last character of haystack
Returns
Copy of the input string with enclosure, if found, removed

◆ strip_enclosure() [2/2]

static std::string& strip_enclosure ( std::string haystack,
const char  first,
const char  last 
)
static

Remove start/end characters from ends of a string (in-place)

Only removes enclosure if first and last characters match as expected.

Parameters
haystackString to modify
firstExpected first character of haystack
lastExpected last character of haystack
Returns
reference to the input string with enclosure, if found, removed

◆ strip_quotes() [1/2]

static std::string strip_quotes ( const std::string haystack)
static

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
haystackString to modify
Returns
copy of the input string with quotes brackets, if found, removed

◆ strip_quotes() [2/2]

static std::string& strip_quotes ( std::string haystack)
static

Remove single- and double-quotes from ends of input string (in-place)

Only removes enclosure if first and last characters match as expected.

Parameters
haystackString to modify
Returns
reference to the input string with quotes, if found, removed

The documentation for this class was generated from the following file: