22 #include <boost/algorithm/string.hpp> 23 #include <boost/algorithm/string/replace.hpp> 42 std::stringstream ss(s);
49 static std::vector<std::string>
split(
const std::string& str,
const std::string& delimiters) {
50 std::vector<std::string> tokens;
51 boost::algorithm::split(tokens, str, boost::is_any_of(delimiters));
58 static std::vector<std::string>
tokenize(
const std::string& str,
const std::string& delimiters) {
59 std::vector<std::string> tokens;
62 std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
64 std::string::size_type pos = str.find_first_of(delimiters, lastPos);
66 while (std::string::npos != pos || std::string::npos != lastPos) {
68 tokens.push_back(str.substr(lastPos, pos - lastPos));
70 lastPos = str.find_first_not_of(delimiters, pos);
72 pos = str.find_first_of(delimiters, lastPos);
80 inline static std::string
toString(T
const& value) {
88 inline static std::string
toString(T
const& value,
int width,
char fill =
' ') {
90 ss << std::setw(width) << std::setfill(fill) << value;
95 static std::string
toLower(std::string
const& source) {
96 auto lower = [](
int c) ->
int {
return std::toupper(c); };
98 std::transform(source.begin(), source.end(), std::back_inserter(copy), lower);
103 static std::string
toUpper(std::string
const& source) {
104 auto upper = [](
int c) ->
int {
return std::toupper(c); };
106 std::transform(source.begin(), source.end(), std::back_inserter(copy), upper);
111 static std::string
trimRight(std::string
const& source, std::string
const& t =
" ") {
112 std::string str = source;
113 return str.erase(str.find_last_not_of(t) + 1);
117 static std::string
trimLeft(std::string
const& source, std::string
const& t =
" ") {
118 std::string str = source;
119 return str.erase(0, source.find_first_not_of(t));
123 static std::string
trim(std::string
const& source, std::string
const& t =
" ") {
124 std::string str = source;
129 static std::string
replace(std::string source, std::string from, std::string to) {
130 return boost::replace_all_copy(source, from, to);
static std::string replace(std::string source, std::string from, std::string to)
Replace all occurences of a string with another.
static std::vector< std::string > tokenize(const std::string &str, const std::string &delimiters)
Tokenize a string (in order of occurence) with the given delimiters.
static std::string toUpper(std::string const &source)
Builds a string with upper case characters only.
Time Dependent Person DataType.
static std::string toString(T const &value)
Builds a string representation of a value of type T.
static std::string toLower(std::string const &source)
Builds a string with lower case characters only.
static std::string trimLeft(std::string const &source, std::string const &t=" ")
Trim characters at left end of string.
static std::string trimRight(std::string const &source, std::string const &t=" ")
Trim characters at right end of string.
static T fromString(std::string const &s)
Builds a value of type T representation from a string.
static std::string trim(std::string const &source, std::string const &t=" ")
Trim characters at both ends of string.
static std::string toString(T const &value, int width, char fill= ' ')
Builds a string representation with minimum width of a value of type T.
static std::vector< std::string > split(const std::string &str, const std::string &delimiters)
Split a string (in order of occurence) by splitting it on the given delimiters.