| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 GURL::GURL(const GURL& other) | 72 GURL::GURL(const GURL& other) |
| 73 : spec_(other.spec_), | 73 : spec_(other.spec_), |
| 74 is_valid_(other.is_valid_), | 74 is_valid_(other.is_valid_), |
| 75 parsed_(other.parsed_) { | 75 parsed_(other.parsed_) { |
| 76 if (other.inner_url_) | 76 if (other.inner_url_) |
| 77 inner_url_.reset(new GURL(*other.inner_url_)); | 77 inner_url_.reset(new GURL(*other.inner_url_)); |
| 78 // Valid filesystem urls should always have an inner_url_. | 78 // Valid filesystem urls should always have an inner_url_. |
| 79 DCHECK(!is_valid_ || !SchemeIsFileSystem() || inner_url_); | 79 DCHECK(!is_valid_ || !SchemeIsFileSystem() || inner_url_); |
| 80 } | 80 } |
| 81 | 81 |
| 82 GURL::GURL(GURL&& other) |
| 83 : spec_(std::move(other.spec_)), |
| 84 is_valid_(other.is_valid_), |
| 85 parsed_(other.parsed_), |
| 86 inner_url_(std::move(other.inner_url_)) { |
| 87 other.is_valid_ = false; |
| 88 other.parsed_ = url::Parsed(); |
| 89 } |
| 90 |
| 82 GURL::GURL(base::StringPiece url_string) { | 91 GURL::GURL(base::StringPiece url_string) { |
| 83 InitCanonical(url_string, true); | 92 InitCanonical(url_string, true); |
| 84 } | 93 } |
| 85 | 94 |
| 86 GURL::GURL(base::StringPiece16 url_string) { | 95 GURL::GURL(base::StringPiece16 url_string) { |
| 87 InitCanonical(url_string, true); | 96 InitCanonical(url_string, true); |
| 88 } | 97 } |
| 89 | 98 |
| 90 GURL::GURL(const std::string& url_string, RetainWhiteSpaceSelector) { | 99 GURL::GURL(const std::string& url_string, RetainWhiteSpaceSelector) { |
| 91 InitCanonical(base::StringPiece(url_string), false); | 100 InitCanonical(base::StringPiece(url_string), false); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 DCHECK(test_url.parsed_.query == parsed_.query); | 170 DCHECK(test_url.parsed_.query == parsed_.query); |
| 162 DCHECK(test_url.parsed_.ref == parsed_.ref); | 171 DCHECK(test_url.parsed_.ref == parsed_.ref); |
| 163 } | 172 } |
| 164 } | 173 } |
| 165 #endif | 174 #endif |
| 166 } | 175 } |
| 167 | 176 |
| 168 GURL::~GURL() { | 177 GURL::~GURL() { |
| 169 } | 178 } |
| 170 | 179 |
| 171 GURL& GURL::operator=(GURL other) { | 180 GURL& GURL::operator=(const GURL& other) { |
| 172 Swap(&other); | 181 spec_ = other.spec_; |
| 182 is_valid_ = other.is_valid_; |
| 183 parsed_ = other.parsed_; |
| 184 |
| 185 if (!other.inner_url_) |
| 186 inner_url_.reset(); |
| 187 else if (inner_url_) |
| 188 *inner_url_ = *other.inner_url_; |
| 189 else |
| 190 inner_url_.reset(new GURL(*other.inner_url_)); |
| 191 |
| 173 return *this; | 192 return *this; |
| 174 } | 193 } |
| 175 | 194 |
| 195 GURL& GURL::operator=(GURL&& other) { |
| 196 spec_ = std::move(other.spec_); |
| 197 is_valid_ = other.is_valid_; |
| 198 parsed_ = other.parsed_; |
| 199 inner_url_ = std::move(other.inner_url_); |
| 200 |
| 201 other.is_valid_ = false; |
| 202 other.parsed_ = url::Parsed(); |
| 203 return *this; |
| 204 } |
| 205 |
| 176 const std::string& GURL::spec() const { | 206 const std::string& GURL::spec() const { |
| 177 if (is_valid_ || spec_.empty()) | 207 if (is_valid_ || spec_.empty()) |
| 178 return spec_; | 208 return spec_; |
| 179 | 209 |
| 180 DCHECK(false) << "Trying to get the spec of an invalid URL!"; | 210 DCHECK(false) << "Trying to get the spec of an invalid URL!"; |
| 181 return EmptyStringForGURL(); | 211 return EmptyStringForGURL(); |
| 182 } | 212 } |
| 183 | 213 |
| 184 bool GURL::operator<(const GURL& other) const { | 214 bool GURL::operator<(const GURL& other) const { |
| 185 return spec_ < other.spec_; | 215 return spec_ < other.spec_; |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 } | 545 } |
| 516 | 546 |
| 517 bool operator==(const GURL& x, const base::StringPiece& spec) { | 547 bool operator==(const GURL& x, const base::StringPiece& spec) { |
| 518 DCHECK_EQ(GURL(spec).possibly_invalid_spec(), spec); | 548 DCHECK_EQ(GURL(spec).possibly_invalid_spec(), spec); |
| 519 return x.possibly_invalid_spec() == spec; | 549 return x.possibly_invalid_spec() == spec; |
| 520 } | 550 } |
| 521 | 551 |
| 522 bool operator!=(const GURL& x, const base::StringPiece& spec) { | 552 bool operator!=(const GURL& x, const base::StringPiece& spec) { |
| 523 return !(x == spec); | 553 return !(x == spec); |
| 524 } | 554 } |
| OLD | NEW |