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 delimiters,
bool trim)
37 string::size_type lastPos = str.find_first_not_of(delimiters, 0);
39 string::size_type pos = str.find_first_of(delimiters, lastPos);
41 while (string::npos != pos || string::npos != lastPos) {
43 std::string token = str.substr(lastPos, pos - lastPos);
47 tokens.push_back(token);
49 if (pos == string::npos)
break;
52 lastPos = str.find_first_not_of(delimiters, pos);
54 pos = str.find_first_of(delimiters, lastPos);
59 const std::vector<std::string>& tokens)
62 for (std::size_t i = 0; i < tokens.size(); i++) {
68 values.push_back(value);
73 const std::vector<std::string>& tokens)
76 for (std::size_t i = 0; i < tokens.size(); i++) {
82 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.