| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/history/core/browser/url_utils.h" | 5 #include "components/history/core/browser/url_utils.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "url/gurl.h" | 10 #include "url/gurl.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 while (*ch1 && *ch2 && *ch1 == *ch2) { | 39 while (*ch1 && *ch2 && *ch1 == *ch2) { |
| 40 ++ch1; | 40 ++ch1; |
| 41 ++ch2; | 41 ++ch2; |
| 42 } | 42 } |
| 43 int pri_diff = GetURLCharPriority(*ch1) - GetURLCharPriority(*ch2); | 43 int pri_diff = GetURLCharPriority(*ch1) - GetURLCharPriority(*ch2); |
| 44 // We want false to be returned if |pri_diff| > 0. | 44 // We want false to be returned if |pri_diff| > 0. |
| 45 return (pri_diff != 0) ? pri_diff < 0 : *ch1 < *ch2; | 45 return (pri_diff != 0) ? pri_diff < 0 : *ch1 < *ch2; |
| 46 } | 46 } |
| 47 | 47 |
| 48 bool HaveSameSchemeHostAndPort(const GURL&url1, const GURL& url2) { | 48 bool HaveSameSchemeHostAndPort(const GURL&url1, const GURL& url2) { |
| 49 return url1.scheme() == url2.scheme() && url1.host() == url2.host() && | 49 return url1.scheme_piece() == url2.scheme_piece() && |
| 50 url1.port() == url2.port(); | 50 url1.host_piece() == url2.host_piece() && url1.port() == url2.port(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 bool IsPathPrefix(const std::string& p1, const std::string& p2) { | 53 bool IsPathPrefix(const std::string& p1, const std::string& p2) { |
| 54 if (p1.length() > p2.length()) | 54 if (p1.length() > p2.length()) |
| 55 return false; | 55 return false; |
| 56 std::pair<std::string::const_iterator, std::string::const_iterator> | 56 std::pair<std::string::const_iterator, std::string::const_iterator> |
| 57 first_diff = std::mismatch(p1.begin(), p1.end(), p2.begin()); | 57 first_diff = std::mismatch(p1.begin(), p1.end(), p2.begin()); |
| 58 // Necessary condition: |p1| is a string prefix of |p2|. | 58 // Necessary condition: |p1| is a string prefix of |p2|. |
| 59 if (first_diff.first != p1.end()) | 59 if (first_diff.first != p1.end()) |
| 60 return false; // E.g.: (|p1| = "/test", |p2| = "/exam") => false. | 60 return false; // E.g.: (|p1| = "/test", |p2| = "/exam") => false. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 87 } | 87 } |
| 88 | 88 |
| 89 std::string HostForTopHosts(const GURL& url) { | 89 std::string HostForTopHosts(const GURL& url) { |
| 90 std::string host = url.host(); | 90 std::string host = url.host(); |
| 91 if (base::StartsWith(host, "www.", base::CompareCase::SENSITIVE)) | 91 if (base::StartsWith(host, "www.", base::CompareCase::SENSITIVE)) |
| 92 host.assign(host, 4, std::string::npos); | 92 host.assign(host, 4, std::string::npos); |
| 93 return host; | 93 return host; |
| 94 } | 94 } |
| 95 | 95 |
| 96 } // namespace history | 96 } // namespace history |
| OLD | NEW |