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);
65 void TokensToDoubles(std::vector<double> & values,
const std::vector<std::string> & tokens)
68 for(std::size_t i=0;i<tokens.size();i++) {
74 values.push_back(value);
78 void TokensToInts(std::vector<int> & values,
const std::vector<std::string> & tokens)
81 for(std::size_t i=0;i<tokens.size();i++) {
87 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.