MCPcopy Create free account
hub / github.com/chen3feng/toft / SplitStringToIteratorUsing

Function SplitStringToIteratorUsing

base/string/algorithm.cpp:229–265  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

227
228template <typename StringType, typename ITR>
229static inline
230void SplitStringToIteratorUsing(const StringPiece& full, const char* delim, ITR& result)
231{
232 // Optimize the common case where delim is a single character.
233 if (delim[0] != '\0' && delim[1] == '\0')
234 {
235 char c = delim[0];
236 const char* p = full.data();
237 const char* end = p + full.size();
238 while (p != end)
239 {
240 if (*p == c)
241 ++p;
242 else
243 {
244 const char* start = p;
245 while (++p != end && *p != c) {}
246 *result++ = StringType(start, p - start);
247 }
248 }
249 return;
250 }
251
252 std::string::size_type begin_index, end_index;
253 begin_index = full.find_first_not_of(delim);
254 while (begin_index != std::string::npos)
255 {
256 end_index = full.find_first_of(delim, begin_index);
257 if (end_index == std::string::npos)
258 {
259 *result++ = full.substr(begin_index).as_string();
260 return;
261 }
262 *result++ = full.substr(begin_index, (end_index - begin_index)).as_string();
263 begin_index = full.find_first_not_of(delim, end_index);
264 }
265}
266
267// Split a string using a character delimiter.
268void SplitStringByAnyOf(

Callers

nothing calls this directly

Calls 6

dataMethod · 0.80
find_first_not_ofMethod · 0.80
as_stringMethod · 0.80
substrMethod · 0.80
sizeMethod · 0.45
find_first_ofMethod · 0.45

Tested by

no test coverage detected