15 void trim(std::string& str)
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);
60 const std::vector<std::string>& tokens)
63 for (std::size_t i = 0; i < tokens.size(); i++) {
69 values.push_back(value);
74 const std::vector<std::string>& tokens)
77 for (std::size_t i = 0; i < tokens.size(); i++) {
83 values.push_back(value);
void TokensToDoubles(std::vector< double > &values, const std::vector< std::string > &tokens)
Turn a vector of tokens into a vector of doubles.
void trim(std::string &str)
Removes whitespace at beginning and end of string.
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.
void TokensToInts(std::vector< int > &values, const std::vector< std::string > &tokens)
Turn a vector of tokens into a vector of ints.