16 void trim(std::string& str)
18 const std::string whitespace(
" \t\n");
20 const auto strBegin = str.find_first_not_of(whitespace);
21 if (strBegin == std::string::npos) {
26 const auto strEnd = str.find_last_not_of(whitespace);
27 const auto strRange = strEnd - strBegin + 1;
29 str = str.substr(strBegin, strRange);
34 const std::string& str,
35 const std::string delimiters,
bool trim)
40 string::size_type lastPos = str.find_first_not_of(delimiters, 0);
42 string::size_type pos = str.find_first_of(delimiters, lastPos);
44 while (string::npos != pos || string::npos != lastPos) {
47 std::string token = str.substr(lastPos,pos-lastPos);
52 tokens.push_back(token);
58 lastPos = str.find_first_not_of(delimiters, pos);
60 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.