#include "services/network/shared_dictionary/simple_url_pattern_matcher.h"
#include <memory>
#include <optional>
#include <string_view>
#include "base/logging.h"
#include "base/ranges/algorithm.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/types/expected.h"
#include "components/url_pattern/url_pattern_util.h"
#include "third_party/liburlpattern/constructor_string_parser.h"
#include "third_party/liburlpattern/parse.h"
#include "third_party/liburlpattern/pattern.h"
#include "third_party/liburlpattern/utils.h"
#include "third_party/re2/src/re2/re2.h"
#include "url/gurl.h"
#include "url/url_util.h"
namespace network {
namespace {
constexpr liburlpattern::Options kDefaultOptions = …;
constexpr liburlpattern::Options kHostnameOptions = …;
constexpr liburlpattern::Options kPathnameOptions = …;
std::string EscapePatternString(std::string_view input) { … }
bool IsAbsolutePathname(std::string_view pathname) { … }
std::string ResolveRelativePathnamePattern(const GURL& base_url,
std::string_view pathname) { … }
}
SimpleUrlPatternMatcher::PatternInit::PatternInit(
std::optional<std::string> protocol,
std::optional<std::string> username,
std::optional<std::string> password,
std::optional<std::string> hostname,
std::optional<std::string> port,
std::optional<std::string> pathname,
std::optional<std::string> search,
std::optional<std::string> hash)
: … { … }
SimpleUrlPatternMatcher::PatternInit::~PatternInit() = default;
SimpleUrlPatternMatcher::PatternInit::PatternInit(PatternInit&&) = default;
SimpleUrlPatternMatcher::PatternInit&
SimpleUrlPatternMatcher::PatternInit::operator=(PatternInit&&) = default;
base::expected<SimpleUrlPatternMatcher::Component, std::string>
SimpleUrlPatternMatcher::Component::Create(
std::optional<std::string_view> pattern,
liburlpattern::EncodeCallback encode_callback,
const liburlpattern::Options& options) { … }
SimpleUrlPatternMatcher::Component::Component(liburlpattern::Pattern pattern,
std::unique_ptr<re2::RE2> regex,
base::PassKey<Component>)
: … { … }
SimpleUrlPatternMatcher::Component::Component(Component&&) = default;
SimpleUrlPatternMatcher::Component&
SimpleUrlPatternMatcher::Component::operator=(Component&&) = default;
SimpleUrlPatternMatcher::Component::~Component() = default;
bool SimpleUrlPatternMatcher::Component::Match(std::string_view value) const { … }
base::expected<std::unique_ptr<SimpleUrlPatternMatcher>, std::string>
SimpleUrlPatternMatcher::Create(std::string_view constructor_string,
const GURL& base_url) { … }
base::expected<SimpleUrlPatternMatcher::PatternInit, std::string>
SimpleUrlPatternMatcher::CreatePatternInit(
std::string_view constructor_string,
const GURL& base_url,
std::optional<Component>* protocol_component_out,
bool* protocol_matches_a_special_scheme_flag_out) { … }
base::expected<std::unique_ptr<SimpleUrlPatternMatcher>, std::string>
SimpleUrlPatternMatcher::CreateFromPatternInit(
const PatternInit& pattern,
std::optional<Component> precomputed_protocol_component,
bool protocol_matches_a_special_scheme_flag) { … }
SimpleUrlPatternMatcher::SimpleUrlPatternMatcher(
Component protocol,
Component username,
Component password,
Component hostname,
Component port,
Component pathname,
Component search,
Component hash,
base::PassKey<SimpleUrlPatternMatcher>)
: … { … }
bool SimpleUrlPatternMatcher::Match(const GURL& url) const { … }
SimpleUrlPatternMatcher::~SimpleUrlPatternMatcher() = default;
}