| 277 | |
| 278 | template <typename StringType, typename ITR> |
| 279 | static inline |
| 280 | void SplitUsingStringDelimiterToIterator(const StringPiece& full, |
| 281 | const char* delim, |
| 282 | ITR& result) |
| 283 | { |
| 284 | if (full.empty()) |
| 285 | { |
| 286 | return; |
| 287 | } |
| 288 | if (delim[0] == '\0') |
| 289 | { |
| 290 | *result++ = full.as_string(); |
| 291 | return; |
| 292 | } |
| 293 | |
| 294 | // Optimize the common case where delim is a single character. |
| 295 | if (delim[1] == '\0') |
| 296 | { |
| 297 | SplitStringToIteratorUsing<StringType>(full, delim, result); |
| 298 | return; |
| 299 | } |
| 300 | |
| 301 | size_t delim_length = strlen(delim); |
| 302 | for (size_t begin_index = 0; begin_index < full.size();) |
| 303 | { |
| 304 | size_t end_index = full.find(delim, begin_index); |
| 305 | if (end_index == std::string::npos) |
| 306 | { |
| 307 | *result++ = full.substr(begin_index).as_string(); |
| 308 | return; |
| 309 | } |
| 310 | if (end_index > begin_index) |
| 311 | { |
| 312 | StringType value(full.data() + begin_index, end_index - begin_index); |
| 313 | *result++ = value; |
| 314 | } |
| 315 | begin_index = end_index + delim_length; |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | void SplitString(const StringPiece& full, |
| 320 | const char* delim, |