Chromium Code Reviews| Index: url/scheme_host_port.cc |
| diff --git a/url/scheme_host_port.cc b/url/scheme_host_port.cc |
| index 4d0f0007595561d99bb54ffb61c57cee033b21e5..bd1fce8ed3883227aa40a059561ab886e6019360 100644 |
| --- a/url/scheme_host_port.cc |
| +++ b/url/scheme_host_port.cc |
| @@ -13,6 +13,7 @@ |
| #include "base/numerics/safe_conversions.h" |
| #include "base/strings/string_number_conversions.h" |
| #include "url/gurl.h" |
| +#include "url/third_party/mozilla/url_parse.h" |
| #include "url/url_canon.h" |
| #include "url/url_canon_stdstring.h" |
| #include "url/url_constants.h" |
| @@ -167,6 +168,31 @@ std::string SchemeHostPort::Serialize() const { |
| return result; |
| } |
| +GURL SchemeHostPort::GetURL() const { |
| + std::string serialized = Serialize(); |
|
brettw
2016/09/30 20:18:48
I'm a little nervous about how this depends on the
Charlie Harrison
2016/10/03 17:28:47
Great idea. Done. The only problem I can see is th
|
| + if (serialized.empty()) |
| + return GURL(); |
| + |
| + static const int schemeSeparatorLength = strlen(kStandardSchemeSeparator); |
|
brettw
2016/09/30 20:18:48
style nit: use underscores and not camelCase (alth
Charlie Harrison
2016/10/03 17:28:47
oops, been working too long in Blink :P
|
| + |
| + Parsed parsed; |
| + parsed.scheme = Component(0, scheme().length()); |
| + |
| + int host_begin = scheme().length() + schemeSeparatorLength; |
| + parsed.host = Component(host_begin, host().length()); |
| + |
| + if (serialized.length() > host_begin + host().length()) { |
| + int port_begin = host_begin + host().length() + 1; |
| + parsed.port = Component(port_begin, serialized.length() - port_begin); |
| + } |
| + |
| + // Append a / on the end of the URL. |
| + parsed.path = Component(serialized.length(), 1); |
| + serialized.append("/"); |
| + |
| + return GURL(serialized.data(), serialized.length(), parsed, true); |
|
brettw
2016/09/30 20:18:48
I told you to use this constructor, but I realize
Charlie Harrison
2016/10/03 17:28:47
:) was hoping there was a better way here. Done!
|
| +} |
| + |
| bool SchemeHostPort::Equals(const SchemeHostPort& other) const { |
| return port_ == other.port() && scheme_ == other.scheme() && |
| host_ == other.host(); |