std::vector<generic_string> tokenizeString(const generic_string & tokenString, const char delim) { //Vector is created on stack and copied on return std::vector<generic_string> tokens; // Skip delimiters at beginning. generic_string::size_type lastPos = tokenString.find_first_not_of(delim, 0); // Find first "non-delimiter". generic_string::size_type pos = tokenString.find_first_of(delim, lastPos); while (pos != std::string::npos || lastPos != std::string::npos) { // Found a token, add it to the vector. tokens.push_back(tokenString.substr(lastPos, pos - lastPos)); // Skip delimiters. Note the "not_of" lastPos = tokenString.find_first_not_of(delim, pos); // Find next "non-delimiter" pos = tokenString.find_first_of(delim, lastPos); } return tokens; }
generic_string stringTakeWhileAdmissable(const generic_string& input, const generic_string& admissable) { // Find first non-admissable character in "input", and remove everything after it. size_t idx = input.find_first_not_of(admissable); if (idx == std::string::npos) { return input; } else { return input.substr(0, idx); } }