MCPcopy Create free account
hub / github.com/apache/nifi-minifi-cpp / countOccurrences

Method countOccurrences

libminifi/include/utils/StringUtils.h:500–512  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

498 static std::string replaceMap(std::string source_string, const std::map<std::string, std::string> &replace_map);
499
500 static std::pair<size_t, int> countOccurrences(const std::string &str, const std::string &pattern) {
501 if (pattern.empty()) {
502 return {str.size(), gsl::narrow<int>(str.size() + 1)};
503 }
504
505 size_t last_pos = 0;
506 int occurrences = 0;
507 for (size_t pos = 0; (pos = str.find(pattern, pos)) != std::string::npos; pos += pattern.size()) {
508 last_pos = pos;
509 ++occurrences;
510 }
511 return {last_pos, occurrences};
512 }
513
514 /**
515 * If the string starts and ends with the given character, the leading and trailing characters are removed.

Callers

nothing calls this directly

Calls 3

emptyMethod · 0.45
sizeMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected