// Copyright 2013 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifdef UNSAFE_BUFFERS_BUILD // TODO(crbug.com/40285824): Remove this and convert code to safer constructs. #pragma allow_unsafe_buffers #endif #include "components/history/core/browser/url_utils.h" #include "base/ranges/algorithm.h" #include "base/strings/string_util.h" #include "url/gurl.h" namespace history { namespace { // Comparator to enforce '\0' < '?' < '#' < '/' < other characters. int GetURLCharPriority(char ch) { … } } // namespace // Instead of splitting URLs and extract path components, we can implement // CanonicalURLStringCompare() using string operations only. The key idea is, // treating '/' to be less than any valid path characters would make it behave // as a separator, so e.g., "test" < "test-case" would be enforced by // "test/..." < "test-case/...". We also force "?" < "/", so "test?query" < // "test/stuff". Since the routine is merely lexicographical string comparison // with remapping of character ordering, so it is a valid strict-weak ordering. bool CanonicalURLStringCompare(const std::string& s1, const std::string& s2) { … } bool HaveSameSchemeHostAndPort(const GURL&url1, const GURL& url2) { … } bool IsPathPrefix(const std::string& p1, const std::string& p2) { … } GURL ToggleHTTPAndHTTPS(const GURL& url) { … } std::string HostForTopHosts(const GURL& url) { … } } // namespace history