17 const std::string whitespace(
" \t\n");
19 const auto strBegin = str.find_first_not_of(whitespace);
20 if (strBegin == std::string::npos) {
25 const auto strEnd = str.find_last_not_of(whitespace);
26 const auto strRange = strEnd - strBegin + 1;
28 str = str.substr(strBegin, strRange);
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) {
44 std::string token = str.substr(lastPos, pos - lastPos);
48 tokens.push_back(token);
50 if (pos == string::npos)
break;
53 lastPos = str.find_first_not_of(delimiters, pos);
55 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.