Chromium Code Reviews| Index: chrome/browser/history/url_utils.h |
| diff --git a/chrome/browser/history/url_utils.h b/chrome/browser/history/url_utils.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b00b34d30abe91757d2c8408a3c56c0e7b9b3478 |
| --- /dev/null |
| +++ b/chrome/browser/history/url_utils.h |
| @@ -0,0 +1,43 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_HISTORY_URL_UTILS_H_ |
| +#define CHROME_BROWSER_HISTORY_URL_UTILS_H_ |
| + |
| +#include <string> |
| + |
| +#include "chrome/browser/history/history_types.h" |
| + |
| +namespace history { |
| + |
| +// CanonicalURLStringCompare performs lexicographical comparison of two strings |
| +// that represent valid URLs, so that if the pre-path (scheme, host, and port) |
| +// parts are equal, then the path parts are compared by treating path components |
| +// (deliminted by "/") as separate tokens that form units of comparison. |
|
sky
2013/09/12 23:51:41
delimited
huangs
2013/09/13 02:30:37
Done.
|
| +// For example, let us compare |s1| and |s2|, with |
| +// |s1| = "http://www.google.com:80/base/test/ab/cd?query/stuff" |
| +// |s2| = "http://www.google.com:80/base/test-case/yz#ref/stuff" |
| +// The pre-path parts "http://www.google.com:80/" match, so we the path is |
| +// treated as |
| +// |s1| => ["base", "test", "ab", "cd"] |
| +// |s2| => ["base", "test-case", "yz"] |
| +// Component 1 "base" matches. Component 2 produces "test" < "test-case", thus |
| +// resulting in |s1| < |s2|, and we return true. Note that naive string |
| +// comparison would yield the opposite (|s1| > |s2|), since '/' > '-' in ASCII. |
| +// Note that path is terminated by "?query" or "#ref". The post-path parts |
| +// are compared in an arbitrary (but consistent) way. |
| +bool CanonicalURLStringCompare(const std::string& s1, const std::string& s2); |
| + |
| +// Returns whether or not |url1| is a "URL prefix" of |url2|. Criteria: |
| +// - Scheme, host, port: exact match required. |
| +// - Path: treated as a list of path components (e.g., ["a", "bb"] for "/a/bb"), |
| +// and |url1|'s list must be a prefix of |url2|'s list. |
| +// - Query and ref: ignored. |
| +// Note that "http://www.google.com/test" is NOT a prefix of |
| +// "http://www.google.com/testing", although "test" is a prefix of "testing". |
| +bool UrlIsPrefix(const GURL& url1, const GURL& url2); |
| + |
| +} // namespace history |
| + |
| +#endif // CHROME_BROWSER_HISTORY_URL_UTILS_H_ |