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 #include "extensions/common/matcher/regex_set_matcher.h" | 5 #include "extensions/common/matcher/regex_set_matcher.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "extensions/common/matcher/substring_set_matcher.h" | 10 #include "extensions/common/matcher/substring_set_matcher.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 filtered_re2_->AllMatches(text, atoms, &re2_ids); | 54 filtered_re2_->AllMatches(text, atoms, &re2_ids); |
55 | 55 |
56 std::set<StringPattern::ID> matched_ids; | 56 std::set<StringPattern::ID> matched_ids; |
57 for (size_t i = 0; i < re2_ids.size(); ++i) { | 57 for (size_t i = 0; i < re2_ids.size(); ++i) { |
58 StringPattern::ID id = re2_id_map_[re2_ids[i]]; | 58 StringPattern::ID id = re2_id_map_[re2_ids[i]]; |
59 matches->insert(id); | 59 matches->insert(id); |
60 } | 60 } |
61 return old_number_of_matches != matches->size(); | 61 return old_number_of_matches != matches->size(); |
62 } | 62 } |
63 | 63 |
| 64 bool RegexSetMatcher::IsEmpty() const { |
| 65 return regexes_.empty(); |
| 66 } |
| 67 |
64 std::vector<RegexSetMatcher::RE2ID> RegexSetMatcher::FindSubstringMatches( | 68 std::vector<RegexSetMatcher::RE2ID> RegexSetMatcher::FindSubstringMatches( |
65 const std::string& text) const { | 69 const std::string& text) const { |
66 std::set<int> atoms_set; | 70 std::set<int> atoms_set; |
67 substring_matcher_->Match(text, &atoms_set); | 71 substring_matcher_->Match(text, &atoms_set); |
68 return std::vector<RE2ID>(atoms_set.begin(), atoms_set.end()); | 72 return std::vector<RE2ID>(atoms_set.begin(), atoms_set.end()); |
69 } | 73 } |
70 | 74 |
71 void RegexSetMatcher::RebuildMatcher() { | 75 void RegexSetMatcher::RebuildMatcher() { |
72 re2_id_map_.clear(); | 76 re2_id_map_.clear(); |
73 filtered_re2_.reset(new re2::FilteredRE2()); | 77 filtered_re2_.reset(new re2::FilteredRE2()); |
(...skipping 27 matching lines...) Expand all Loading... |
101 new StringPattern(strings_to_match[i], i)); | 105 new StringPattern(strings_to_match[i], i)); |
102 } | 106 } |
103 substring_matcher_->RegisterPatterns(substring_patterns_); | 107 substring_matcher_->RegisterPatterns(substring_patterns_); |
104 } | 108 } |
105 | 109 |
106 void RegexSetMatcher::DeleteSubstringPatterns() { | 110 void RegexSetMatcher::DeleteSubstringPatterns() { |
107 STLDeleteElements(&substring_patterns_); | 111 STLDeleteElements(&substring_patterns_); |
108 } | 112 } |
109 | 113 |
110 } // namespace extensions | 114 } // namespace extensions |
OLD | NEW |