| 85 | // Based on str_util::Split. |
| 86 | template <typename Predicate> |
| 87 | std::vector<StringPiece> SplitOnCharSet(const string& str, |
| 88 | const string& delim_set, Predicate p) { |
| 89 | std::vector<StringPiece> result; |
| 90 | StringPiece text(str); |
| 91 | StringPiece delims(delim_set); |
| 92 | size_t token_start = 0; |
| 93 | for (size_t i = 0; i < text.size() + 1; i++) { |
| 94 | if ((i == text.size()) || (delims.find(text[i]) != StringPiece::npos)) { |
| 95 | StringPiece token(text.data() + token_start, i - token_start); |
| 96 | if (p(token)) { |
| 97 | result.emplace_back(token); |
| 98 | } |
| 99 | token_start = i + 1; |
| 100 | } |
| 101 | } |
| 102 | return result; |
| 103 | } |
| 104 | |
| 105 | // Split input string `str` based on given delimiter. |
| 106 | // Returns a vector of StringPieces which are valid as long as input `str` |
no test coverage detected