8 static int replace(std::basic_string<T>& s,
const std::basic_string<T>& from,
const std::basic_string<T>& to)
13 if (s.length() != 0 && from.length() != 0)
15 while ((ii = s.find(from, ii)) != s.npos)
17 s.replace(ii, from.length(), to);
18 ii += (abs((
int)(to.length() - from.length())) + 1);
25 static void tokenize(
const std::basic_string<T>& ss, std::vector<std::basic_string<T>>& tokens,
const std::basic_string<T>& delim)
28 int begin = 0, end = 0;
29 std::basic_string<T> temp;
33 while ( (end = temp.find(delim)) != std::basic_string<T>::npos )
35 tokens.push_back( temp.substr(0, end) );
36 begin = end + delim.length();
37 temp = temp.substr(begin, temp.length() - begin);
40 tokens.push_back(temp.substr(0, temp.length()));
43 static std::basic_string<T>
join(
const std::vector<std::basic_string<T>>& tokens,
const std::basic_string<T>& delim)
45 std::basic_string<T> ss;
47 for (
unsigned int i = 0; i < tokens.size(); i++)
49 if (i > 0) ss.append(delim);
56 static std::basic_string<T>
join(
const std::list<std::basic_string<T>>& tokens,
const std::basic_string<T>& delim)
58 std::basic_string<T> ss;
61 for each (
const std::basic_string<T>& token
in tokens)
63 if (i > 0) ss.append(delim);
71 static void tokenizeWithSkip(
const std::basic_string<T>& ss, std::vector<std::basic_string<T>>& tokens,
const std::basic_string<T>& delims)
74 std::basic_string<T>::size_type lastpos = ss.find_first_not_of(delims, 0);
76 std::basic_string<T>::size_type pos = ss.find_first_of(delims, lastpos);
78 while (std::string::npos != pos || std::string::npos != lastpos)
81 tokens.push_back(ss.substr(lastpos, pos - lastpos));
83 lastpos = ss.find_first_not_of(delims, pos);
85 pos = ss.find_first_of(delims, lastpos);
90 static void tokenizeOnChar(
const std::basic_string<T>& ss, std::vector<std::basic_string<T>>& tokens,
const std::basic_string<T>& delims)
93 int begin = 0, end = 0;
95 for(
unsigned int i = 0; i < ss.length(); i++)
97 if ( delims.find(ss.substr(i, 1), 0) == std::basic_string<T>::npos )
103 tokens.push_back(ss.substr(begin, (end - begin)));
107 tokens.push_back(ss.substr(begin, (end - begin)));
110 static void ltrim(std::basic_string<T>& ss,
const std::basic_string<T>& whitespaces)
112 ss.erase(0, ss.find_first_not_of(whitespaces));
115 static void rtrim(std::basic_string<T>& ss,
const std::basic_string<T>& whitespaces)
117 ss.erase(ss.find_last_not_of(whitespaces) + 1);
120 static void lrtrim(std::basic_string<T>& ss,
const std::basic_string<T>& whitespaces)
122 ltrim(ss, whitespaces);
123 rtrim(ss, whitespaces);
126 static void lrtrimcrlf(std::basic_string<T>& ss,
const std::basic_string<T>& whitespaces)
128 ltrim(ss, whitespaces);
129 rtrim(ss, whitespaces);
134 std::transform(ss.begin(), ss.end(), ss.begin(), (int(*)(int)) toupper);
139 std::transform(ss.begin(), ss.end(), ss.begin(), (int(*)(int)) tolower);
142 static bool comparei(
const std::basic_string<T>& ss1,
const std::basic_string<T>& ss2)
144 std::basic_string<T> s1, s2;
151 static bool isNumber(
const std::basic_string<T>& ss)
155 if( ss.length() > 1 && ss[0] ==
'-') i = 1;
156 if( ss.length() == i )
return false;
158 for( ; i < ss.length(); i++ )
169 static bool startsWith(
const std::basic_string<T>& what,
const std::basic_string<T>& with)
171 if (what.length() < with.length())
173 if (what.substr(0, with.length()) == with)
178 static bool endsWith(
const std::basic_string<T>& what,
const std::basic_string<T>& with)
180 if (what.length() < with.length())
182 if (what.substr(what.length() - with.length(), what.length()) == with)
static bool endsWith(const std::basic_string< T > &what, const std::basic_string< T > &with)
Definition: StringUtilsImpl.h:178
static void lrtrimcrlf(std::basic_string< T > &ss, const std::basic_string< T > &whitespaces)
Definition: StringUtilsImpl.h:126
static void ltrim(std::basic_string< T > &ss, const std::basic_string< T > &whitespaces)
Definition: StringUtilsImpl.h:110
static void tokenize(const std::basic_string< T > &ss, std::vector< std::basic_string< T >> &tokens, const std::basic_string< T > &delim)
Definition: StringUtilsImpl.h:25
static std::basic_string< T > join(const std::vector< std::basic_string< T >> &tokens, const std::basic_string< T > &delim)
Definition: StringUtilsImpl.h:43
Definition: StringUtilsImpl.h:4
static void lrtrim(std::basic_string< T > &ss, const std::basic_string< T > &whitespaces)
Definition: StringUtilsImpl.h:120
static int replace(std::basic_string< T > &s, const std::basic_string< T > &from, const std::basic_string< T > &to)
Definition: StringUtilsImpl.h:8
static void uppercase(std::basic_string< T > &ss)
Definition: StringUtilsImpl.h:132
static bool isNumber(const std::basic_string< T > &ss)
Definition: StringUtilsImpl.h:151
static bool startsWith(const std::basic_string< T > &what, const std::basic_string< T > &with)
Definition: StringUtilsImpl.h:169
static void lowercase(std::basic_string< T > &ss)
Definition: StringUtilsImpl.h:137
static void rtrim(std::basic_string< T > &ss, const std::basic_string< T > &whitespaces)
Definition: StringUtilsImpl.h:115
static void tokenizeOnChar(const std::basic_string< T > &ss, std::vector< std::basic_string< T >> &tokens, const std::basic_string< T > &delims)
Definition: StringUtilsImpl.h:90
static void tokenizeWithSkip(const std::basic_string< T > &ss, std::vector< std::basic_string< T >> &tokens, const std::basic_string< T > &delims)
Definition: StringUtilsImpl.h:71
static bool comparei(const std::basic_string< T > &ss1, const std::basic_string< T > &ss2)
Definition: StringUtilsImpl.h:142
static std::basic_string< T > join(const std::list< std::basic_string< T >> &tokens, const std::basic_string< T > &delim)
Definition: StringUtilsImpl.h:56