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 #include "base/compiler_specific.h" 12 13 namespace base { 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. 22 class BASE_EXPORT MatcherStringPattern { 23 public: 24 using ID = size_t; 25 26 // An invalid ID value. Clients must not use this as the id. 27 static constexpr ID kInvalidId = static_cast<ID>(-1); 28 29 MatcherStringPattern(std::string pattern, ID id); 30 31 MatcherStringPattern(const MatcherStringPattern&) = delete; 32 MatcherStringPattern& operator=(const MatcherStringPattern&) = delete; 33 34 ~MatcherStringPattern(); 35 MatcherStringPattern(MatcherStringPattern&&); 36 MatcherStringPattern& operator=(MatcherStringPattern&&); pattern()37 const std::string& pattern() const LIFETIME_BOUND { return pattern_; } id()38 ID id() const { return id_; } 39 40 bool operator<(const MatcherStringPattern& rhs) const; 41 42 private: 43 std::string pattern_; 44 ID id_; 45 }; 46 47 } // namespace base 48 49 #endif // BASE_SUBSTRING_SET_MATCHER_MATCHER_STRING_PATTERN_H_ 50