16StringType
trim(
const StringType& text,
const char* whiteChars) {
17 size_t end = text.length();
18 while (end > 0 && std::strchr(whiteChars, text[end - 1]) !=
nullptr) {
25 while (start < end && std::strchr(whiteChars, text[start]) !=
nullptr) {
28 if (start > 0 || end < text.length()) {
29 return text.substr(start, end - start);
42tokenize(
const std::string& inputString,
const std::string& delimiters,
const bool trim) {
43 if (inputString.empty()) {
47 std::vector<std::string> results;
51 while ((pos = inputString.find_first_of(delimiters, lastPos)) != std::string::npos) {
52 const std::string res = inputString.substr(lastPos, pos - lastPos);
55 if (!res.empty() || !
trim) {
56 results.push_back(res);
60 const std::string res = inputString.substr(lastPos);
61 if (!res.empty() || !
trim) {
62 results.push_back(res);
69tokenize(std::string_view inputString,
const std::string_view delimiters,
const bool trim) {
70 if (inputString.empty()) {
74 std::vector<std::string_view> results;
78 while ((pos = inputString.find_first_of(delimiters, lastPos)) != std::string::npos) {
79 auto res = inputString.substr(lastPos, pos - lastPos);
81 if (!res.empty() || !
trim) {
82 results.push_back(res);
86 auto res = inputString.substr(lastPos);
87 if (!res.empty() || !
trim) {
88 results.push_back(res);
std::vector< std::string > tokenize(const std::string &inputString, const std::string &delimiters, const bool trim)
Tokenizes a string using the specified single-byte delimiter characters.