30 inline std::string&
ltrim(std::string& str)
32 auto it = std::find_if(str.begin(), str.end(), [](
char ch)
34 return !std::isspace<char>(ch, std::locale::classic());
36 str.erase(str.begin() , it);
41 inline std::string&
rtrim(std::string& str)
43 auto it = std::find_if(str.rbegin(), str.rend(), [](
char ch)
45 return !std::isspace<char>(ch, std::locale::classic());
47 str.erase(it.base(), str.end());
52 inline std::string&
trim(std::string& str)
58 inline std::string
trim_copy(std::string
const& str)
65 template <
class InputIter,
class T,
class Func>
66 void split(InputIter first, InputIter end, T
const& t, Func f)
72 InputIter found = std::find(first, end, t);
80 template <
class InputIter,
class SeparatorIter,
class Func>
81 void split(InputIter first, InputIter end, SeparatorIter s_first, SeparatorIter s_end, Func f)
87 InputIter found = std::find_first_of(first, end, s_first, s_end);
96 inline void replaceAll(std::string& str, std::string
const& from, std::string
const& to)
100 std::size_t start_pos = 0;
101 while ((start_pos = str.find(from, start_pos)) != std::string::npos)
103 str.replace(start_pos, from.length(), to);
104 start_pos += to.length();
109 template <
class InputIter>
110 std::string
join (InputIter first, InputIter end, std::string sep =
" ")
115 std::ostringstream os;
118 os << sep << *first++;
std::string to_upper(std::string input)
convert all characters in a string to upper case
Definition: string.hh:14
std::string trim_copy(std::string const &str)
trim a (copy of the) string from both sides
Definition: string.hh:58
void replaceAll(std::string &str, std::string const &from, std::string const &to)
Replace all occurences of substring from with to in source str.
Definition: string.hh:96
std::string & trim(std::string &str)
trim a string from both sides
Definition: string.hh:52
std::string to_lower(std::string input)
convert all characters in a string to upper case
Definition: string.hh:22
std::string & ltrim(std::string &str)
trim a string from the left
Definition: string.hh:30
std::string & rtrim(std::string &str)
trim a string from the right
Definition: string.hh:41
void split(InputIter first, InputIter end, T const &t, Func f)
Definition: string.hh:66
std::string join(InputIter first, InputIter end, std::string sep=" ")
Definition: string.hh:110