Index: components/subresource_filter/core/common/fuzzy_pattern_matching.cc |
diff --git a/components/subresource_filter/core/common/fuzzy_pattern_matching.cc b/components/subresource_filter/core/common/fuzzy_pattern_matching.cc |
index 96b0f5cb7876d04fa4e0b762985f367b657c8ccb..f0a4dfd50aa9c87c0f1d4f37060fea2b6acac6fa 100644 |
--- a/components/subresource_filter/core/common/fuzzy_pattern_matching.cc |
+++ b/components/subresource_filter/core/common/fuzzy_pattern_matching.cc |
@@ -4,6 +4,8 @@ |
#include "components/subresource_filter/core/common/fuzzy_pattern_matching.h" |
+#include <algorithm> |
+ |
namespace subresource_filter { |
namespace { |
@@ -35,4 +37,23 @@ bool EndsWithFuzzy(base::StringPiece text, base::StringPiece subpattern) { |
subpattern); |
} |
+size_t FindFuzzy(base::StringPiece text, |
+ base::StringPiece subpattern, |
+ size_t from) { |
+ if (from > text.size()) |
+ return base::StringPiece::npos; |
+ if (subpattern.empty()) |
+ return from; |
+ |
+ auto fuzzy_compare = [](char text_char, char subpattern_char) { |
+ return text_char == subpattern_char || |
+ (subpattern_char == kSeparatorPlaceholder && IsSeparator(text_char)); |
+ }; |
+ |
+ base::StringPiece::const_iterator found = |
+ std::search(text.begin() + from, text.end(), subpattern.begin(), |
+ subpattern.end(), fuzzy_compare); |
+ return found == text.end() ? base::StringPiece::npos : found - text.begin(); |
+} |
+ |
} // namespace subresource_filter |