MCPcopy Create free account
hub / github.com/apache/impala / CountSubstring

Function CountSubstring

be/src/gutil/strings/util.cc:456–466  ·  view source on GitHub ↗

---------------------------------------------------------------------- CountSubstring() Return the number times a "substring" appears in the "text" NOTE: this function's complexity is O(|text| * |substring|) It is meant for short "text" (such as to ensure the printf format string has the right number of arguments). DO NOT pass in long "text". -------------------------------------------------------

Source from the content-addressed store, hash-verified

454// DO NOT pass in long "text".
455// ----------------------------------------------------------------------
456int CountSubstring(StringPiece text, StringPiece substring) {
457 CHECK_GT(substring.length(), 0);
458
459 int count = 0;
460 StringPiece::size_type curr = 0;
461 while (StringPiece::npos != (curr = text.find(substring, curr))) {
462 ++count;
463 ++curr;
464 }
465 return count;
466}
467
468// ----------------------------------------------------------------------
469// strstr_delimited()

Callers

nothing calls this directly

Calls 2

lengthMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected