MCPcopy Create free account
hub / github.com/aksnzhy/xlearn / SplitStringToIteratorUsing

Function SplitStringToIteratorUsing

src/base/split_string.h:88–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

86
87template <typename StringType, typename ITR>
88static inline
89void 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_

Callers 2

SplitStringUsingFunction · 0.85
SplitStringToSetUsingFunction · 0.85

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected