| 86 | |
| 87 | template <typename StringType, typename ITR> |
| 88 | static inline |
| 89 | void SplitStringToIteratorUsing(const StringType& full, |
| 90 | const char* delim, |
| 91 | ITR& result) { |
| 92 | // Optimize the common case where delim is a single character. |
| 93 | if (delim[0] != '\0' && delim[1] == '\0') { |
| 94 | char c = delim[0]; |
| 95 | const char* p = full.data(); |
| 96 | const char* end = p + full.size(); |
| 97 | while (p != end) { |
| 98 | if (*p == c) { |
| 99 | ++p; |
| 100 | } else { |
| 101 | const char* start = p; |
| 102 | while (++p != end && *p != c) { |
| 103 | // Skip to the next occurence of the delimiter. |
| 104 | } |
| 105 | *result++ = StringType(start, p - start); |
| 106 | } |
| 107 | } |
| 108 | return; |
| 109 | } |
| 110 | |
| 111 | std::string::size_type begin_index, end_index; |
| 112 | begin_index = full.find_first_not_of(delim); |
| 113 | while (begin_index != std::string::npos) { |
| 114 | end_index = full.find_first_of(delim, begin_index); |
| 115 | if (end_index == std::string::npos) { |
| 116 | *result++ = full.substr(begin_index); |
| 117 | return; |
| 118 | } |
| 119 | *result++ = full.substr(begin_index, (end_index - begin_index)); |
| 120 | begin_index = full.find_first_not_of(delim, end_index); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | #endif // XLEARN_BASE_SPLIT_STRING_H_ |
no test coverage detected