48 void trim(std::string& str)
50 const std::string whitespace(
" \t\n");
52 const auto strBegin = str.find_first_not_of(whitespace);
53 if (strBegin == std::string::npos) {
58 const auto strEnd = str.find_last_not_of(whitespace);
59 const auto strRange = strEnd - strBegin + 1;
61 str = str.substr(strBegin, strRange);
66 const std::string& str,
67 const std::string delimiters,
bool trim)
72 string::size_type lastPos = str.find_first_not_of(delimiters, 0);
74 string::size_type pos = str.find_first_of(delimiters, lastPos);
76 while (string::npos != pos || string::npos != lastPos) {
79 std::string token = str.substr(lastPos,pos-lastPos);
84 tokens.push_back(token);
90 lastPos = str.find_first_not_of(delimiters, pos);
92 pos = str.find_first_of(delimiters, lastPos);
97 void TokensToDoubles(std::vector<double> & values,
const std::vector<std::string> & tokens)
100 for(std::size_t i=0;i<tokens.size();i++) {
102 std::stringstream ss;
106 values.push_back(value);
110 void TokensToInts(std::vector<int> & values,
const std::vector<std::string> & tokens)
113 for(std::size_t i=0;i<tokens.size();i++) {
115 std::stringstream ss;
119 values.push_back(value);
void TokensToInts(std::vector< int > &values, const std::vector< std::string > &tokens)
Turn a vector of tokens into a vector of ints.
void trim(std::string &str)
Removes whitespace at beginning and end of string.
void TokensToDoubles(std::vector< double > &values, const std::vector< std::string > &tokens)
Turn a vector of tokens into a vector of doubles.
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.