OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
StringUtils.hpp
Go to the documentation of this file.
1 #ifndef FOCS_STRINGUTILS
2 #define FOCS_STRINGUTILS
3 
4 
5 #include <functional>
6 
7 #include <string>
8 #include <vector>
9 
10 namespace focs {
11 
26 class StringUtils {
27  public:
69  static std::string replace_all(const std::string& haystack, const char *needle, const char *replacement);
79  static std::string& replace_all(std::string& haystack, const char *needle, const char *replacement);
80 
92  static std::string strip_enclosure(const std::string& haystack, const char first, const char last);
104  static std::string& strip_enclosure(std::string& haystack, const char first, const char last);
105 
115  static std::string strip_brackets(const std::string& haystack);
125  static std::string& strip_brackets(std::string& haystack);
135  static std::string strip_quotes(const std::string& haystack);
145  static std::string& strip_quotes(std::string& haystack);
146 
176  template<typename T>
177  static std::vector<T> stov(std::string& str, const std::string& delims=",", bool merge_multiple_delims=false, T default_value=T{});
178 
195  template<typename T>
196  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);
197 
198  // TODO: provide things like this, to make it easier to customize? (All this does is reorder the params and provide some defaults.
199  // template<typename T>
200  // static std::vector<T> stov(std::string& str, const std::string& delims, std::function<T(const std::string&)> parser, bool merge_multiple_delims=false, T default_value=T{});
201  private:
202 
203 };
204 
205 
206 } // namespace focs
207 
208 #endif // FOCS_STRINGUTILS
static std::string insert_oc_roots(const std::string &str)
Replace paths in the input with $OCSSWROOT, $OCDATAROOT, etc, (returns a copy)
Definition: argpar.c:27
static std::string replace_all(const std::string &haystack, const char *needle, const char *replacement)
Replace all occurrences of a string (returns a copy)
static std::string replace_oc_roots(const std::string &str)
Replace $OCSSWROOT, $OCDATAROOT, etc, in string (returns a copy)
@ string
static std::string strip_enclosure(const std::string &haystack, const char first, const char last)
Remove start/end characters from ends of a string (returns a copy)
static std::vector< T > stov(std::string &str, const std::string &delims=",", bool merge_multiple_delims=false, T default_value=T{})
Convert delimited string to vector.
static std::string strip_brackets(const std::string &haystack)
Remove square brackets from ends of input string (returns a copy)
const char * str
Definition: l1c_msi.cpp:35
static std::string strip_quotes(const std::string &haystack)
Remove single- and double-quotes from ends of input string (returns a copy)
Static functions for parsing/processing/modifying strings.
Definition: StringUtils.hpp:26