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 "url/gurl.h" | 5 #include "url/gurl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <ostream> | 10 #include <ostream> |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 GURL::GURL(const GURL& other) | 71 GURL::GURL(const GURL& other) |
72 : spec_(other.spec_), | 72 : spec_(other.spec_), |
73 is_valid_(other.is_valid_), | 73 is_valid_(other.is_valid_), |
74 parsed_(other.parsed_) { | 74 parsed_(other.parsed_) { |
75 if (other.inner_url_) | 75 if (other.inner_url_) |
76 inner_url_.reset(new GURL(*other.inner_url_)); | 76 inner_url_.reset(new GURL(*other.inner_url_)); |
77 // Valid filesystem urls should always have an inner_url_. | 77 // Valid filesystem urls should always have an inner_url_. |
78 DCHECK(!is_valid_ || !SchemeIsFileSystem() || inner_url_); | 78 DCHECK(!is_valid_ || !SchemeIsFileSystem() || inner_url_); |
79 } | 79 } |
80 | 80 |
81 GURL::GURL(const std::string& url_string) { | 81 GURL::GURL(base::StringPiece url_string) { |
82 InitCanonical(url_string, true); | 82 InitCanonical(url_string, true); |
83 } | 83 } |
84 | 84 |
85 GURL::GURL(const base::string16& url_string) { | 85 GURL::GURL(base::StringPiece16 url_string) { |
86 InitCanonical(url_string, true); | 86 InitCanonical(url_string, true); |
87 } | 87 } |
88 | 88 |
89 GURL::GURL(const std::string& url_string, RetainWhiteSpaceSelector) { | 89 GURL::GURL(const std::string& url_string, RetainWhiteSpaceSelector) { |
90 InitCanonical(url_string, false); | 90 InitCanonical(base::StringPiece(url_string), false); |
91 } | 91 } |
92 | 92 |
93 GURL::GURL(const char* canonical_spec, | 93 GURL::GURL(const char* canonical_spec, |
94 size_t canonical_spec_len, | 94 size_t canonical_spec_len, |
95 const url::Parsed& parsed, | 95 const url::Parsed& parsed, |
96 bool is_valid) | 96 bool is_valid) |
97 : spec_(canonical_spec, canonical_spec_len), | 97 : spec_(canonical_spec, canonical_spec_len), |
98 is_valid_(is_valid), | 98 is_valid_(is_valid), |
99 parsed_(parsed) { | 99 parsed_(parsed) { |
100 InitializeFromCanonicalSpec(); | 100 InitializeFromCanonicalSpec(); |
101 } | 101 } |
102 | 102 |
103 GURL::GURL(std::string canonical_spec, const url::Parsed& parsed, bool is_valid) | 103 GURL::GURL(std::string canonical_spec, const url::Parsed& parsed, bool is_valid) |
104 : is_valid_(is_valid), | 104 : is_valid_(is_valid), |
105 parsed_(parsed) { | 105 parsed_(parsed) { |
106 spec_.swap(canonical_spec); | 106 spec_.swap(canonical_spec); |
107 InitializeFromCanonicalSpec(); | 107 InitializeFromCanonicalSpec(); |
108 } | 108 } |
109 | 109 |
110 template<typename STR> | 110 template<typename STR> |
111 void GURL::InitCanonical(const STR& input_spec, bool trim_path_end) { | 111 void GURL::InitCanonical(base::BasicStringPiece<STR> input_spec, |
| 112 bool trim_path_end) { |
112 // Reserve enough room in the output for the input, plus some extra so that | 113 // Reserve enough room in the output for the input, plus some extra so that |
113 // we have room if we have to escape a few things without reallocating. | 114 // we have room if we have to escape a few things without reallocating. |
114 spec_.reserve(input_spec.size() + 32); | 115 spec_.reserve(input_spec.size() + 32); |
115 url::StdStringCanonOutput output(&spec_); | 116 url::StdStringCanonOutput output(&spec_); |
116 is_valid_ = url::Canonicalize( | 117 is_valid_ = url::Canonicalize( |
117 input_spec.data(), static_cast<int>(input_spec.length()), trim_path_end, | 118 input_spec.data(), static_cast<int>(input_spec.length()), trim_path_end, |
118 NULL, &output, &parsed_); | 119 NULL, &output, &parsed_); |
119 | 120 |
120 output.Complete(); // Must be done before using string. | 121 output.Complete(); // Must be done before using string. |
121 if (is_valid_ && SchemeIsFileSystem()) { | 122 if (is_valid_ && SchemeIsFileSystem()) { |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 void GURL::Swap(GURL* other) { | 533 void GURL::Swap(GURL* other) { |
533 spec_.swap(other->spec_); | 534 spec_.swap(other->spec_); |
534 std::swap(is_valid_, other->is_valid_); | 535 std::swap(is_valid_, other->is_valid_); |
535 std::swap(parsed_, other->parsed_); | 536 std::swap(parsed_, other->parsed_); |
536 inner_url_.swap(other->inner_url_); | 537 inner_url_.swap(other->inner_url_); |
537 } | 538 } |
538 | 539 |
539 std::ostream& operator<<(std::ostream& out, const GURL& url) { | 540 std::ostream& operator<<(std::ostream& out, const GURL& url) { |
540 return out << url.possibly_invalid_spec(); | 541 return out << url.possibly_invalid_spec(); |
541 } | 542 } |
OLD | NEW |