| 61 | |
| 62 | template <typename Predicate> |
| 63 | std::vector<StringPiece> SplitOnChar(const string& str, |
| 64 | const char delim, Predicate p) { |
| 65 | std::vector<StringPiece> result; |
| 66 | StringPiece text(str); |
| 67 | auto f = text.find(delim); |
| 68 | while (f != StringPiece::npos) { |
| 69 | StringPiece token = text.substr(0, f); |
| 70 | if (p(token)) { |
| 71 | result.emplace_back(token); |
| 72 | } |
| 73 | text.remove_prefix(f + 1); |
| 74 | f = text.find(delim); |
| 75 | } |
| 76 | if (p(text)) { |
| 77 | result.push_back(text); |
| 78 | } |
| 79 | return result; |
| 80 | } |
| 81 | |
| 82 | // Split input string `str` based on a set of character delimiters. |
| 83 | // Returns a vector of StringPieces which are valid as long as input `str` |
no test coverage detected