blob: 39d67b1f03c88b6cb552a78d9a63d5791106f9bf [file] [log] [blame]
Avi Drissmane4622aa2022-09-08 20:36:061// Copyright 2013 The Chromium Authors
[email protected]5bcf3b72012-09-14 00:20:282// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Steinar H. Gundersonf8174932022-05-21 00:25:175#ifndef BASE_SUBSTRING_SET_MATCHER_MATCHER_STRING_PATTERN_H_
6#define BASE_SUBSTRING_SET_MATCHER_MATCHER_STRING_PATTERN_H_
[email protected]5bcf3b72012-09-14 00:20:287
8#include <string>
[email protected]5bcf3b72012-09-14 00:20:289
Steinar H. Gunderson5570febc2022-05-12 10:39:4810#include "base/base_export.h"
Tom Sepez1705e3f02024-10-25 01:39:1811#include "base/compiler_specific.h"
[email protected]5bcf3b72012-09-14 00:20:2812
Steinar H. Gunderson5570febc2022-05-12 10:39:4813namespace base {
[email protected]5bcf3b72012-09-14 00:20:2814
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. Gundersonf8174932022-05-21 00:25:1722class BASE_EXPORT MatcherStringPattern {
[email protected]5bcf3b72012-09-14 00:20:2823 public:
Peter Kasting78549f32022-05-31 18:20:2024 using ID = size_t;
[email protected]5bcf3b72012-09-14 00:20:2825
Karan Bhatia60409e892020-02-11 04:14:3626 // An invalid ID value. Clients must not use this as the id.
Peter Kasting78549f32022-05-31 18:20:2027 static constexpr ID kInvalidId = static_cast<ID>(-1);
Karan Bhatia60409e892020-02-11 04:14:3628
Steinar H. Gundersonf8174932022-05-21 00:25:1729 MatcherStringPattern(std::string pattern, ID id);
Peter Boström09c01822021-09-20 22:43:2730
Steinar H. Gundersonf8174932022-05-21 00:25:1731 MatcherStringPattern(const MatcherStringPattern&) = delete;
32 MatcherStringPattern& operator=(const MatcherStringPattern&) = delete;
Peter Boström09c01822021-09-20 22:43:2733
Steinar H. Gundersonf8174932022-05-21 00:25:1734 ~MatcherStringPattern();
35 MatcherStringPattern(MatcherStringPattern&&);
36 MatcherStringPattern& operator=(MatcherStringPattern&&);
Tom Sepez1705e3f02024-10-25 01:39:1837 const std::string& pattern() const LIFETIME_BOUND { return pattern_; }
[email protected]5bcf3b72012-09-14 00:20:2838 ID id() const { return id_; }
39
Steinar H. Gundersonf8174932022-05-21 00:25:1740 bool operator<(const MatcherStringPattern& rhs) const;
[email protected]5bcf3b72012-09-14 00:20:2841
42 private:
43 std::string pattern_;
44 ID id_;
[email protected]5bcf3b72012-09-14 00:20:2845};
46
Steinar H. Gunderson5570febc2022-05-12 10:39:4847} // namespace base
[email protected]5bcf3b72012-09-14 00:20:2848
Steinar H. Gundersonf8174932022-05-21 00:25:1749#endif // BASE_SUBSTRING_SET_MATCHER_MATCHER_STRING_PATTERN_H_