Chromium Code Reviews| Index: url/gurl.cc |
| diff --git a/url/gurl.cc b/url/gurl.cc |
| index 15de85af73adade3a7322537a286f0d177a85eba..e36fdf7b2a767b693634de1ab144ee28db8916bf 100644 |
| --- a/url/gurl.cc |
| +++ b/url/gurl.cc |
| @@ -17,27 +17,32 @@ |
| #include "url/url_canon_stdstring.h" |
| #include "url/url_util.h" |
| -namespace { |
| +// TODO(joth): Move to appropriate place in file, justing putting this here |
|
brettw
2013/11/20 00:03:51
Thanks, I think you can move this now.
joth
2013/11/21 00:08:45
Done.
|
| +// to make initial code review iterations easier to diff. |
| // External template that can handle initialization of either character type. |
| // The input spec is given, and the canonical version will be placed in |
| // |*canonical|, along with the parsing of the canonical spec in |*parsed|. |
| template<typename STR> |
| -bool InitCanonical(const STR& input_spec, |
| - std::string* canonical, |
| - url_parse::Parsed* parsed) { |
| +void GURL::InitCanonical(const STR& input_spec, |
| + bool trim_path_end) { |
|
brettw
2013/11/20 00:03:51
One line.
joth
2013/11/21 00:08:45
Done.
|
| // Reserve enough room in the output for the input, plus some extra so that |
| // we have room if we have to escape a few things without reallocating. |
| - canonical->reserve(input_spec.size() + 32); |
| - url_canon::StdStringCanonOutput output(canonical); |
| - bool success = url_util::Canonicalize( |
| - input_spec.data(), static_cast<int>(input_spec.length()), |
| - NULL, &output, parsed); |
| + spec_.reserve(input_spec.size() + 32); |
| + url_canon::StdStringCanonOutput output(&spec_); |
| + is_valid_ = url_util::Canonicalize( |
| + input_spec.data(), static_cast<int>(input_spec.length()), trim_path_end, |
| + NULL, &output, &parsed_); |
| output.Complete(); // Must be done before using string. |
| - return success; |
| + if (is_valid_ && SchemeIsFileSystem()) { |
| + inner_url_.reset(new GURL(spec_.data(), parsed_.Length(), |
| + *parsed_.inner_parsed(), true)); |
| + } |
| } |
| +namespace { |
| + |
| static std::string* empty_string = NULL; |
| static GURL* empty_gurl = NULL; |
| @@ -94,21 +99,15 @@ GURL::GURL(const GURL& other) |
| } |
| GURL::GURL(const std::string& url_string) { |
| - is_valid_ = InitCanonical(url_string, &spec_, &parsed_); |
| - if (is_valid_ && SchemeIsFileSystem()) { |
| - inner_url_.reset( |
| - new GURL(spec_.data(), parsed_.Length(), |
| - *parsed_.inner_parsed(), true)); |
| - } |
| + InitCanonical(url_string, true); |
| } |
| GURL::GURL(const base::string16& url_string) { |
| - is_valid_ = InitCanonical(url_string, &spec_, &parsed_); |
| - if (is_valid_ && SchemeIsFileSystem()) { |
| - inner_url_.reset( |
| - new GURL(spec_.data(), parsed_.Length(), |
| - *parsed_.inner_parsed(), true)); |
| - } |
| + InitCanonical(url_string, true); |
| +} |
| + |
| +GURL::GURL(const std::string& url_string, RetainWhiteSpaceSelector) { |
| + InitCanonical(url_string, false); |
| } |
| GURL::GURL(const char* canonical_spec, size_t canonical_spec_len, |
| @@ -146,7 +145,7 @@ void GURL::InitializeFromCanonicalSpec() { |
| // We can't do this check on the inner_url of a filesystem URL, as |
| // canonical_spec actually points to the start of the outer URL, so we'd |
| // end up with infinite recursion in this constructor. |
| - GURL test_url(spec_); |
| + GURL test_url(spec_, RETAIN_TRAILING_PATH_WHITEPACE); |
|
joth
2013/11/21 00:08:45
I added an extra comment here too:
// We nee
|
| DCHECK(test_url.is_valid_ == is_valid_); |
| DCHECK(test_url.spec_ == spec_); |