chromium/components/url_pattern_index/url_pattern.cc

// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// The matching logic distinguishes between the terms URL pattern and
// subpattern. A URL pattern usually stands for the full thing, e.g.
// "example.com^*path*par=val^", whereas subpattern denotes a maximal substring
// of a pattern not containing the wildcard '*' character. For the example above
// the subpatterns are: "example.com^", "path" and "par=val^".
//
// The separator placeholder '^' symbol is used in subpatterns to match any
// separator character, which is any ASCII symbol except letters, digits, and
// the following: '_', '-', '.', '%'. Note that the separator placeholder
// character '^' is itself a separator, as well as '\0'.

#include "components/url_pattern_index/url_pattern.h"

#include <stddef.h>

#include <ostream>
#include <string_view>

#include "base/check_op.h"
#include "base/notreached.h"
#include "base/numerics/checked_math.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_util.h"
#include "components/url_pattern_index/flat/url_pattern_index_generated.h"
#include "components/url_pattern_index/fuzzy_pattern_matching.h"
#include "components/url_pattern_index/string_splitter.h"
#include "url/gurl.h"
#include "url/third_party/mozilla/url_parse.h"

namespace url_pattern_index {

namespace {

constexpr char kWildcard =;

class IsWildcard {};

proto::UrlPatternType ConvertUrlPatternType(flat::UrlPatternType type) {}

proto::AnchorType ConvertAnchorType(flat::AnchorType type) {}

std::string_view ConvertString(const flatbuffers::String* string) {}

bool HasAnyUpperAscii(std::string_view string) {}

// Returns whether |position| within the |url| belongs to its |host| component
// and corresponds to the beginning of a (sub-)domain.
inline bool IsSubdomainAnchored(std::string_view url,
                                url::Component host,
                                size_t position) {}

// Returns the position of the leftmost occurrence of a |subpattern| in the
// |text| starting no earlier than |from| the specified position. If the
// |subpattern| has separator placeholders, searches for a fuzzy occurrence.
size_t FindSubpattern(std::string_view text,
                      std::string_view subpattern,
                      size_t from = 0) {}

// Same as FindSubpattern(url, subpattern), but searches for an occurrence that
// starts at the beginning of a (sub-)domain within the url's |host| component.
size_t FindSubdomainAnchoredSubpattern(std::string_view url,
                                       url::Component host,
                                       std::string_view subpattern) {}

// Helper for DoesTextMatchLastSubpattern. Treats kSeparatorPlaceholder as not
// matching the end of the text.
bool DoesTextMatchLastSubpatternInternal(proto::AnchorType anchor_left,
                                         proto::AnchorType anchor_right,
                                         std::string_view text,
                                         url::Component url_host,
                                         std::string_view subpattern) {}

// Matches the last |subpattern| against |text|. Special treatment is required
// for the last subpattern since |kSeparatorPlaceholder| can also match the end
// of the text.
bool DoesTextMatchLastSubpattern(proto::AnchorType anchor_left,
                                 proto::AnchorType anchor_right,
                                 std::string_view text,
                                 url::Component url_host,
                                 std::string_view subpattern) {}

// Returns whether the given |url_pattern| matches the given |url_spec|.
// Compares the pattern the the url in a case-sensitive manner.
bool IsCaseSensitiveMatch(std::string_view url_pattern,
                          proto::AnchorType anchor_left,
                          proto::AnchorType anchor_right,
                          std::string_view url_spec,
                          url::Component url_host) {}

}  // namespace

UrlPattern::UrlInfo::UrlInfo(const GURL& url)
    :{}

std::string_view UrlPattern::UrlInfo::GetLowerCaseSpec() const {}

std::string_view UrlPattern::UrlInfo::GetStringHost() const {}

UrlPattern::UrlInfo::~UrlInfo() = default;

UrlPattern::UrlPattern() = default;

UrlPattern::UrlPattern(std::string_view url_pattern,
                       proto::UrlPatternType type,
                       MatchCase match_case)
    :{}

UrlPattern::UrlPattern(std::string_view url_pattern,
                       proto::AnchorType anchor_left,
                       proto::AnchorType anchor_right)
    :{}

UrlPattern::UrlPattern(const flat::UrlRule& rule)
    :{}

UrlPattern::~UrlPattern() = default;

bool UrlPattern::MatchesUrl(const UrlInfo& url) const {}

std::ostream& operator<<(std::ostream& out, const UrlPattern& pattern) {}

}  // namespace url_pattern_index