Index: url/url_canon_host.cc |
diff --git a/url/url_canon_host.cc b/url/url_canon_host.cc |
index d4cdfd52bc566d3d4df295f80f5af3e630236e22..3de8f980a74fb3a661bf232e280ac99d3c6dda7d 100644 |
--- a/url/url_canon_host.cc |
+++ b/url/url_canon_host.cc |
@@ -309,6 +309,25 @@ bool DoComplexHost(const base::char16* host, int host_len, |
} |
template<typename CHAR, typename UCHAR> |
+bool DoHostSubstring(const CHAR* spec, |
+ const Component& host, |
+ CanonOutput* output) { |
+ bool has_non_ascii, has_escaped; |
+ ScanHostname<CHAR, UCHAR>(spec, host, &has_non_ascii, &has_escaped); |
+ |
+ bool success; |
+ if (!has_non_ascii && !has_escaped) { |
+ success = DoSimpleHost(&spec[host.begin], host.len, |
+ output, &has_non_ascii); |
+ DCHECK(!has_non_ascii); |
+ } else { |
+ success = DoComplexHost(&spec[host.begin], host.len, |
+ has_non_ascii, has_escaped, output); |
+ } |
+ return success; |
Peter Kasting
2016/10/22 05:04:20
Nit: Slightly simpler:
if (has_non_ascii || has
brettw
2016/10/24 21:45:24
Done.
|
+} |
+ |
+template<typename CHAR, typename UCHAR> |
void DoHost(const CHAR* spec, |
const Component& host, |
CanonOutput* output, |
@@ -320,23 +339,10 @@ void DoHost(const CHAR* spec, |
return; |
} |
- bool has_non_ascii, has_escaped; |
- ScanHostname<CHAR, UCHAR>(spec, host, &has_non_ascii, &has_escaped); |
- |
// Keep track of output's initial length, so we can rewind later. |
const int output_begin = output->length(); |
- bool success; |
- if (!has_non_ascii && !has_escaped) { |
- success = DoSimpleHost(&spec[host.begin], host.len, |
- output, &has_non_ascii); |
- DCHECK(!has_non_ascii); |
- } else { |
- success = DoComplexHost(&spec[host.begin], host.len, |
- has_non_ascii, has_escaped, output); |
- } |
- |
- if (!success) { |
+ if (!DoHostSubstring<CHAR, UCHAR>(spec, host, output)) { |
Peter Kasting
2016/10/22 05:04:20
Nit: Reverse conditional and arms, so "else" does
brettw
2016/10/24 21:45:24
Done.
|
// Canonicalization failed. Set BROKEN to notify the caller. |
host_info->family = CanonHostInfo::BROKEN; |
} else { |
@@ -396,4 +402,16 @@ void CanonicalizeHostVerbose(const base::char16* spec, |
DoHost<base::char16, base::char16>(spec, host, output, host_info); |
} |
+bool CanonicalizeHostSubstring(const char* spec, |
+ const Component& host, |
+ CanonOutput* output) { |
+ return DoHostSubstring<char, unsigned char>(spec, host, output); |
+} |
+ |
+bool CanonicalizeHostSubstring(const base::char16* spec, |
+ const Component& host, |
+ CanonOutput* output) { |
+ return DoHostSubstring<base::char16, base::char16>(spec, host, output); |
+} |
+ |
} // namespace url |