xref: /aosp_15_r20/external/cronet/base/substring_set_matcher/matcher_string_pattern.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2013 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef BASE_SUBSTRING_SET_MATCHER_MATCHER_STRING_PATTERN_H_
6 #define BASE_SUBSTRING_SET_MATCHER_MATCHER_STRING_PATTERN_H_
7 
8 #include <string>
9 
10 #include "base/base_export.h"
11 
12 namespace base {
13 
14 // An individual pattern of a substring or regex matcher. A pattern consists of
15 // a string (interpreted as individual bytes, no character encoding) and an
16 // identifier.
17 // IDs are returned to the caller of SubstringSetMatcher::Match() or
18 // RegexMatcher::MatchURL() to help the caller to figure out what
19 // patterns matched a string. All patterns registered to a matcher
20 // need to contain unique IDs.
21 class BASE_EXPORT MatcherStringPattern {
22  public:
23   using ID = size_t;
24 
25   // An invalid ID value. Clients must not use this as the id.
26   static constexpr ID kInvalidId = static_cast<ID>(-1);
27 
28   MatcherStringPattern(std::string pattern, ID id);
29 
30   MatcherStringPattern(const MatcherStringPattern&) = delete;
31   MatcherStringPattern& operator=(const MatcherStringPattern&) = delete;
32 
33   ~MatcherStringPattern();
34   MatcherStringPattern(MatcherStringPattern&&);
35   MatcherStringPattern& operator=(MatcherStringPattern&&);
pattern()36   const std::string& pattern() const { return pattern_; }
id()37   ID id() const { return id_; }
38 
39   bool operator<(const MatcherStringPattern& rhs) const;
40 
41  private:
42   std::string pattern_;
43   ID id_;
44 };
45 
46 }  // namespace base
47 
48 #endif  // BASE_SUBSTRING_SET_MATCHER_MATCHER_STRING_PATTERN_H_
49