| 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. |