|
Public Types | |
typedef std::map< std::string, std::string > | conv_map_t |
Static Public Member Functions | |
static bool | startsWith (const std::string &s, const std::string &substring) |
static bool | endsWith (const std::string &s, const std::string &substring) |
static std::string & | upperCase (std::string &s, size_t n=std::numeric_limits< size_t >::max()) |
Turns n first characters uppercase. ASCII only. More... | |
static char | upperCase (char c) |
Turns a character to uppercase. ASCII only. | |
static std::string & | lowerCase (std::string &s, size_t n=std::numeric_limits< size_t >::max()) |
Turns n first characters lowercase. ASCII only. More... | |
static char | lowerCase (char c) |
Turns a character to lowercase. ASCII only. | |
static std::string | replace (const std::string &src, const std::string &from, const std::string &to) |
static void | replace (const conv_map_t &m, std::string &s, std::size_t pos=0) |
Replaces instances appearing as map keys to map values. More... | |
static void | replace (const std::string &src, const std::string &from, const std::string &to, std::string &dst) |
In src, replaces instances of 'from' to 'to', storing the result in dst. | |
static std::string | trim (const std::string &s, const std::string &trimChars=" \t\n\r") |
Returns a string without leading and trailing whitespace (or str undesired chars). | |
static std::string | trimSymmetric (const std::string &s, const std::string &leading="'\"", const std::string &trailing="") |
Coupled trimming: remove a single leading and trailing char, if both found. More... | |
static bool | trimScan (const std::string &s, size_t &pos1, size_t &pos2, const std::string &trimChars=" \t\n") |
Returns indices to trimmed segment of s such that it can be extracted as s.substr(pos1, pos2-pos1). More... | |
template<class T , class C > | |
static void | split (const std::string &s, T &sequence, const C &separators, const std::string &trimChars=" \t\n") |
Splits and trims a given std::string to a std Sequence. More... | |
template<class T1 , class T2 , class C > | |
static bool | split2 (const std::string &s, T1 &first, T2 &second, const C &separators, const std::string &trimChars=" \t\n") |
Splits and trims a given std::string to a std Sequence. More... | |
template<class T > | |
static std::ostream & | join (const T &container, std::ostream &ostr, char separator=0) |
Writes a STL Container (list, vector, set) to a stream, using an optional separator char (e.g. ','). More... | |
template<class T > | |
static std::string | join (T &container, char separator=0) |
Writes a STL Container (list, vector, set) to a string, using an optional separator char (like ','). More... | |
template<unsigned int S> | |
static void | read (std::istream &istr, std::string &s) |
Read input stream and append it to s. | |
template<class T > | |
static void | convert (const std::string &s, T &dst) |
Conversion from std::string to basic types, including std::string. More... | |
template<class T > | |
static T | convert (const std::string &s) |
Conversion from std::string to basic types, including std::string. More... | |
template<class T > | |
static std::string & | import (const T &src, std::string &target) |
template<class T > | |
static const T & | lazyConvert (const std::string &s, T &tmp) |
Convert only if needed. If T is std::string, returns s directly. More... | |
|
inlinestatic |
Conversion from std::string to basic types, including std::string.
This version is slow for string targets (T).
str | - input string |
|
inlinestatic |
Conversion from std::string to basic types, including std::string.
This version is slow for string targets (T).
str | - input string |
dst | - destination |
|
inlinestatic |
Writes a STL Container (list, vector, set) to a stream, using an optional separator char (e.g. ',').
|
inlinestatic |
Writes a STL Container (list, vector, set) to a string, using an optional separator char (like ',').
|
inlinestatic |
Convert only if needed. If T is std::string, returns s directly.
str | - input string |
tmp | - "hidden" temporary value; returned reference should be read instead of this. |
- | string or any class that does not clear the object upon identity assigment (obj=obj). |
Note: the classes of target objects first
and second
should have an assignment operator=() that does not clear the object when assigning itself obj=obj !
|
static |
Turns n first characters lowercase. ASCII only.
Turns n first characters lowercase. Ascii only.
|
static |
Replaces instances appearing as map keys to map values.
|
inlinestatic |
Replaces instances of 'from' to 'to' in src, storing the result in dst. In src, replaces instances of 'from' to 'to', returning the result. Safe. Uses temporary std::string.
|
static |
Splits and trims a given std::string to a std Sequence.
s | – string to be chopped |
sequence | – target sequence; must implement end() and insert() operators. |
separators | – single char, array or string |
trimChars | – single char, array or string |
Assumes that T::operator=(std::string) exists.
Given an empty std::string, returns a sequence containing an empty std::string. Hence, does not return an empty sequence.
Given a null or empty separator, returns a single-element sequence containing the original string.
|
static |
Splits and trims a given std::string to a std Sequence.
Splits and trims a given std::string to two substrings, by first separator encountered.
T1 | - target of 1st part ("key") |
T2 | - target of 1st part ("value") |
C | - character or string (any char in which will split) |
s | - source string |
first | - target of 1st part, typically the "key" |
second | - target of 2nd part, typically the "object" |
Given an empty std::string, returns empty (intact) destinations. Given a string that does contain a separator, assigns the string on first
, leaving empty/intact
.
Note: the classes of target objects first
and second
should have an assignment operator=() that does not clear the object when assigning itself obj=obj !
|
static |
Returns indices to trimmed segment of s such that it can be extracted as s.substr(pos1, pos2-pos1).
Starting from pos1, searches for the first segment not containing trimChars.
s | - string to be scanned |
pos1 | - before: index of 1st char to scan right, after: index of 1st char of the segment, if found; else s.size(). |
pos2 | - before: index of 1st char to scan left, after: index of the char after the segment, or s.size(). |
|
static |
Coupled trimming: remove a single leading and trailing char, if both found.
|
static |
Turns n first characters uppercase. ASCII only.
Turns n first characters uppercase. Ascii only.