14 void trim(std::string& str)
16 const std::string whitespace(
" \t\n");
18 const auto strBegin = str.find_first_not_of(whitespace);
19 if (strBegin == std::string::npos) {
24 const auto strEnd = str.find_last_not_of(whitespace);
25 const auto strRange = strEnd - strBegin + 1;
27 str = str.substr(strBegin, strRange);
32 const std::string& str,
33 const std::string delimiters,
bool trim)
38 string::size_type lastPos = str.find_first_not_of(delimiters, 0);
40 string::size_type pos = str.find_first_of(delimiters, lastPos);
42 while (string::npos != pos || string::npos != lastPos) {
45 std::string token = str.substr(lastPos,pos-lastPos);
49 tokens.push_back(token);
55 lastPos = str.find_first_not_of(delimiters, pos);
57 pos = str.find_first_of(delimiters, lastPos);
void StringTokenizer(std::vector< std::string > &tokens, const std::string &str, const std::string delimiters, bool trim)
Tokenize a string, put tokens in a vector.