OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef EXTENSIONS_COMMON_MATCHER_REGEX_SET_MATCHER_H_ | 5 #ifndef EXTENSIONS_COMMON_MATCHER_REGEX_SET_MATCHER_H_ |
6 #define EXTENSIONS_COMMON_MATCHER_REGEX_SET_MATCHER_H_ | 6 #define EXTENSIONS_COMMON_MATCHER_REGEX_SET_MATCHER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 25 matching lines...) Expand all Loading... |
36 void AddPatterns(const std::vector<const StringPattern*>& regex_list); | 36 void AddPatterns(const std::vector<const StringPattern*>& regex_list); |
37 | 37 |
38 // Removes all regex patterns. | 38 // Removes all regex patterns. |
39 void ClearPatterns(); | 39 void ClearPatterns(); |
40 | 40 |
41 // Appends the IDs of regular expressions in our set that match the |text| | 41 // Appends the IDs of regular expressions in our set that match the |text| |
42 // to |matches|. | 42 // to |matches|. |
43 bool Match(const std::string& text, | 43 bool Match(const std::string& text, |
44 std::set<StringPattern::ID>* matches) const; | 44 std::set<StringPattern::ID>* matches) const; |
45 | 45 |
| 46 bool IsEmpty() const; |
| 47 |
46 private: | 48 private: |
47 typedef int RE2ID; | 49 typedef int RE2ID; |
48 typedef std::map<StringPattern::ID, const StringPattern*> RegexMap; | 50 typedef std::map<StringPattern::ID, const StringPattern*> RegexMap; |
49 typedef std::vector<StringPattern::ID> RE2IDMap; | 51 typedef std::vector<StringPattern::ID> RE2IDMap; |
50 | 52 |
51 // Use Aho-Corasick SubstringSetMatcher to find which literal patterns | 53 // Use Aho-Corasick SubstringSetMatcher to find which literal patterns |
52 // match the |text|. | 54 // match the |text|. |
53 std::vector<RE2ID> FindSubstringMatches(const std::string& text) const; | 55 std::vector<RE2ID> FindSubstringMatches(const std::string& text) const; |
54 | 56 |
55 // Rebuild FilteredRE2 from scratch. Needs to be called whenever | 57 // Rebuild FilteredRE2 from scratch. Needs to be called whenever |
(...skipping 15 matching lines...) Expand all Loading... |
71 scoped_ptr<SubstringSetMatcher> substring_matcher_; | 73 scoped_ptr<SubstringSetMatcher> substring_matcher_; |
72 | 74 |
73 // The substring patterns from FilteredRE2, which are used in | 75 // The substring patterns from FilteredRE2, which are used in |
74 // |substring_matcher_| but whose lifetime is managed here. | 76 // |substring_matcher_| but whose lifetime is managed here. |
75 std::vector<const StringPattern*> substring_patterns_; | 77 std::vector<const StringPattern*> substring_patterns_; |
76 }; | 78 }; |
77 | 79 |
78 } // namespace extensions | 80 } // namespace extensions |
79 | 81 |
80 #endif // EXTENSIONS_COMMON_MATCHER_REGEX_SET_MATCHER_H_ | 82 #endif // EXTENSIONS_COMMON_MATCHER_REGEX_SET_MATCHER_H_ |
OLD | NEW |