Tarun Bansal | ee55605 | 2018-08-13 20:10:42 | [diff] [blame] | 1 | // Copyright 2018 The Chromium Authors. All rights reserved. |
| 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 COMPONENTS_OPTIMIZATION_GUIDE_URL_PATTERN_WITH_WILDCARDS_H_ |
| 6 | #define COMPONENTS_OPTIMIZATION_GUIDE_URL_PATTERN_WITH_WILDCARDS_H_ |
| 7 | |
| 8 | #include <stddef.h> |
| 9 | |
| 10 | #include <string> |
| 11 | #include <vector> |
| 12 | |
Tarun Bansal | ee55605 | 2018-08-13 20:10:42 | [diff] [blame] | 13 | #include "base/macros.h" |
| 14 | |
| 15 | namespace optimization_guide { |
| 16 | |
| 17 | // URLPatternWithWildcards parses and stores one URL pattern. A URL pattern is a |
| 18 | // single substring to match against a URL. A URL pattern may |
| 19 | // contain multiple wildcard characters ('*'), each of which can match more than |
| 20 | // one character. An implicit wildcard character ('*') is assumed to be present |
| 21 | // at the beginning and end of a pattern. |
| 22 | class URLPatternWithWildcards { |
| 23 | public: |
| 24 | explicit URLPatternWithWildcards(const std::string& url_pattern); |
Josh Simmons | 17cc88f | 2020-01-08 00:55:27 | [diff] [blame] | 25 | URLPatternWithWildcards(const URLPatternWithWildcards& other); |
Tarun Bansal | ee55605 | 2018-08-13 20:10:42 | [diff] [blame] | 26 | ~URLPatternWithWildcards(); |
| 27 | |
Josh Simmons | 17cc88f | 2020-01-08 00:55:27 | [diff] [blame] | 28 | URLPatternWithWildcards& operator=(const URLPatternWithWildcards&) = default; |
| 29 | |
Tarun Bansal | ee55605 | 2018-08-13 20:10:42 | [diff] [blame] | 30 | // Returns true if |url_string| matches |this| pattern. |
| 31 | bool Matches(const std::string& url_string) const; |
| 32 | |
| 33 | private: |
| 34 | // A single pattern string is split into multiple strings (each separated by |
| 35 | // '*'), and stored in |split_subpatterns_|. |
Josh Simmons | 17cc88f | 2020-01-08 00:55:27 | [diff] [blame] | 36 | std::vector<std::string> split_subpatterns_; |
Tarun Bansal | ee55605 | 2018-08-13 20:10:42 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | } // namespace optimization_guide |
| 40 | |
| 41 | #endif // COMPONENTS_OPTIMIZATION_GUIDE_URL_PATTERN_WITH_WILDCARDS_H_ |