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);
50 tokens.push_back(token);
56 lastPos = str.find_first_not_of(delimiters, pos);
58 pos = str.find_first_of(delimiters, lastPos);
64 const std::vector<std::string> & tokens)
67 for(std::size_t i=0;i<tokens.size();i++) {
73 values.push_back(value);
78 const std::vector<std::string> & tokens)
81 for(std::size_t i=0;i<tokens.size();i++) {
87 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.