| 132 | |
| 133 | template <typename Str, typename OutputStringType> |
| 134 | void SplitStringUsingSubstrT(BasicStringPiece<Str> input, |
| 135 | BasicStringPiece<Str> delimiter, |
| 136 | WhitespaceHandling whitespace, |
| 137 | SplitResult result_type, |
| 138 | std::vector<OutputStringType>* result) { |
| 139 | using Piece = BasicStringPiece<Str>; |
| 140 | using size_type = typename Piece::size_type; |
| 141 | |
| 142 | result->clear(); |
| 143 | for (size_type begin_index = 0, end_index = 0; end_index != Piece::npos; |
| 144 | begin_index = end_index + delimiter.size()) { |
| 145 | end_index = input.find(delimiter, begin_index); |
| 146 | Piece term = end_index == Piece::npos |
| 147 | ? input.substr(begin_index) |
| 148 | : input.substr(begin_index, end_index - begin_index); |
| 149 | |
| 150 | if (whitespace == TRIM_WHITESPACE) |
| 151 | term = TrimString(term, WhitespaceForType<Str>(), TRIM_ALL); |
| 152 | |
| 153 | if (result_type == SPLIT_WANT_ALL || !term.empty()) |
| 154 | result->push_back(PieceToOutputType<Str, OutputStringType>(term)); |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | } // namespace |
| 159 | |