blob: a66bb8e37085b91fb33af492af86b92378d1a25a [file] [log] [blame]
Tarun Bansalee556052018-08-13 20:10:421// 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 Bansalee556052018-08-13 20:10:4213#include "base/macros.h"
14
15namespace 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.
22class URLPatternWithWildcards {
23 public:
24 explicit URLPatternWithWildcards(const std::string& url_pattern);
Josh Simmons17cc88f2020-01-08 00:55:2725 URLPatternWithWildcards(const URLPatternWithWildcards& other);
Tarun Bansalee556052018-08-13 20:10:4226 ~URLPatternWithWildcards();
27
Josh Simmons17cc88f2020-01-08 00:55:2728 URLPatternWithWildcards& operator=(const URLPatternWithWildcards&) = default;
29
Tarun Bansalee556052018-08-13 20:10:4230 // 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 Simmons17cc88f2020-01-08 00:55:2736 std::vector<std::string> split_subpatterns_;
Tarun Bansalee556052018-08-13 20:10:4237};
38
39} // namespace optimization_guide
40
41#endif // COMPONENTS_OPTIMIZATION_GUIDE_URL_PATTERN_WITH_WILDCARDS_H_