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

Function SplitUsingStringDelimiterToIterator

base/string/algorithm.cpp:279–317  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

277
278template <typename StringType, typename ITR>
279static inline
280void 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
319void SplitString(const StringPiece& full,
320 const char* delim,

Callers

nothing calls this directly

Calls 6

as_stringMethod · 0.80
findMethod · 0.80
substrMethod · 0.80
dataMethod · 0.80
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected