Avi Drissman | e4622aa | 2022-09-08 20:36:06 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors |
[email protected] | 5bcf3b7 | 2012-09-14 00:20:28 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
Steinar H. Gunderson | f817493 | 2022-05-21 00:25:17 | [diff] [blame] | 5 | #ifndef BASE_SUBSTRING_SET_MATCHER_MATCHER_STRING_PATTERN_H_ |
6 | #define BASE_SUBSTRING_SET_MATCHER_MATCHER_STRING_PATTERN_H_ | ||||
[email protected] | 5bcf3b7 | 2012-09-14 00:20:28 | [diff] [blame] | 7 | |
8 | #include <string> | ||||
[email protected] | 5bcf3b7 | 2012-09-14 00:20:28 | [diff] [blame] | 9 | |
Steinar H. Gunderson | 5570febc | 2022-05-12 10:39:48 | [diff] [blame] | 10 | #include "base/base_export.h" |
Tom Sepez | 1705e3f0 | 2024-10-25 01:39:18 | [diff] [blame] | 11 | #include "base/compiler_specific.h" |
[email protected] | 5bcf3b7 | 2012-09-14 00:20:28 | [diff] [blame] | 12 | |
Steinar H. Gunderson | 5570febc | 2022-05-12 10:39:48 | [diff] [blame] | 13 | namespace base { |
[email protected] | 5bcf3b7 | 2012-09-14 00:20:28 | [diff] [blame] | 14 | |
15 | // An individual pattern of a substring or regex matcher. A pattern consists of | ||||
16 | // a string (interpreted as individual bytes, no character encoding) and an | ||||
17 | // identifier. | ||||
18 | // IDs are returned to the caller of SubstringSetMatcher::Match() or | ||||
19 | // RegexMatcher::MatchURL() to help the caller to figure out what | ||||
20 | // patterns matched a string. All patterns registered to a matcher | ||||
21 | // need to contain unique IDs. | ||||
Steinar H. Gunderson | f817493 | 2022-05-21 00:25:17 | [diff] [blame] | 22 | class BASE_EXPORT MatcherStringPattern { |
[email protected] | 5bcf3b7 | 2012-09-14 00:20:28 | [diff] [blame] | 23 | public: |
Peter Kasting | 78549f3 | 2022-05-31 18:20:20 | [diff] [blame] | 24 | using ID = size_t; |
[email protected] | 5bcf3b7 | 2012-09-14 00:20:28 | [diff] [blame] | 25 | |
Karan Bhatia | 60409e89 | 2020-02-11 04:14:36 | [diff] [blame] | 26 | // An invalid ID value. Clients must not use this as the id. |
Peter Kasting | 78549f3 | 2022-05-31 18:20:20 | [diff] [blame] | 27 | static constexpr ID kInvalidId = static_cast<ID>(-1); |
Karan Bhatia | 60409e89 | 2020-02-11 04:14:36 | [diff] [blame] | 28 | |
Steinar H. Gunderson | f817493 | 2022-05-21 00:25:17 | [diff] [blame] | 29 | MatcherStringPattern(std::string pattern, ID id); |
Peter Boström | 09c0182 | 2021-09-20 22:43:27 | [diff] [blame] | 30 | |
Steinar H. Gunderson | f817493 | 2022-05-21 00:25:17 | [diff] [blame] | 31 | MatcherStringPattern(const MatcherStringPattern&) = delete; |
32 | MatcherStringPattern& operator=(const MatcherStringPattern&) = delete; | ||||
Peter Boström | 09c0182 | 2021-09-20 22:43:27 | [diff] [blame] | 33 | |
Steinar H. Gunderson | f817493 | 2022-05-21 00:25:17 | [diff] [blame] | 34 | ~MatcherStringPattern(); |
35 | MatcherStringPattern(MatcherStringPattern&&); | ||||
36 | MatcherStringPattern& operator=(MatcherStringPattern&&); | ||||
Tom Sepez | 1705e3f0 | 2024-10-25 01:39:18 | [diff] [blame] | 37 | const std::string& pattern() const LIFETIME_BOUND { return pattern_; } |
[email protected] | 5bcf3b7 | 2012-09-14 00:20:28 | [diff] [blame] | 38 | ID id() const { return id_; } |
39 | |||||
Steinar H. Gunderson | f817493 | 2022-05-21 00:25:17 | [diff] [blame] | 40 | bool operator<(const MatcherStringPattern& rhs) const; |
[email protected] | 5bcf3b7 | 2012-09-14 00:20:28 | [diff] [blame] | 41 | |
42 | private: | ||||
43 | std::string pattern_; | ||||
44 | ID id_; | ||||
[email protected] | 5bcf3b7 | 2012-09-14 00:20:28 | [diff] [blame] | 45 | }; |
46 | |||||
Steinar H. Gunderson | 5570febc | 2022-05-12 10:39:48 | [diff] [blame] | 47 | } // namespace base |
[email protected] | 5bcf3b7 | 2012-09-14 00:20:28 | [diff] [blame] | 48 | |
Steinar H. Gunderson | f817493 | 2022-05-21 00:25:17 | [diff] [blame] | 49 | #endif // BASE_SUBSTRING_SET_MATCHER_MATCHER_STRING_PATTERN_H_ |