Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(457)

Side by Side Diff: url/gurl.cc

Issue 2956643002: Add GURL::HostNoBracketsPiece() (Closed)
Patch Set: Simplify test Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « url/gurl.h ('k') | url/gurl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 // terminator. If we're an inner_url, our spec continues on into our outer 445 // terminator. If we're an inner_url, our spec continues on into our outer
446 // URL's path/query/ref. 446 // URL's path/query/ref.
447 int path_len = parsed_.path.len; 447 int path_len = parsed_.path.len;
448 if (parsed_.query.is_valid()) 448 if (parsed_.query.is_valid())
449 path_len = parsed_.query.end() - parsed_.path.begin; 449 path_len = parsed_.query.end() - parsed_.path.begin;
450 450
451 return std::string(spec_, parsed_.path.begin, path_len); 451 return std::string(spec_, parsed_.path.begin, path_len);
452 } 452 }
453 453
454 std::string GURL::HostNoBrackets() const { 454 std::string GURL::HostNoBrackets() const {
455 return HostNoBracketsPiece().as_string();
456 }
457
458 base::StringPiece GURL::HostNoBracketsPiece() const {
455 // If host looks like an IPv6 literal, strip the square brackets. 459 // If host looks like an IPv6 literal, strip the square brackets.
456 url::Component h(parsed_.host); 460 url::Component h(parsed_.host);
457 if (h.len >= 2 && spec_[h.begin] == '[' && spec_[h.end() - 1] == ']') { 461 if (h.len >= 2 && spec_[h.begin] == '[' && spec_[h.end() - 1] == ']') {
458 h.begin++; 462 h.begin++;
459 h.len -= 2; 463 h.len -= 2;
460 } 464 }
461 return ComponentString(h); 465 return ComponentStringPiece(h);
462 } 466 }
463 467
464 std::string GURL::GetContent() const { 468 std::string GURL::GetContent() const {
465 return is_valid_ ? ComponentString(parsed_.GetContent()) : std::string(); 469 return is_valid_ ? ComponentString(parsed_.GetContent()) : std::string();
466 } 470 }
467 471
468 bool GURL::HostIsIPAddress() const { 472 bool GURL::HostIsIPAddress() const {
469 return is_valid_ && url::HostIsIPAddress(host_piece()); 473 return is_valid_ && url::HostIsIPAddress(host_piece());
470 } 474 }
471 475
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 } 549 }
546 550
547 bool operator==(const GURL& x, const base::StringPiece& spec) { 551 bool operator==(const GURL& x, const base::StringPiece& spec) {
548 DCHECK_EQ(GURL(spec).possibly_invalid_spec(), spec); 552 DCHECK_EQ(GURL(spec).possibly_invalid_spec(), spec);
549 return x.possibly_invalid_spec() == spec; 553 return x.possibly_invalid_spec() == spec;
550 } 554 }
551 555
552 bool operator!=(const GURL& x, const base::StringPiece& spec) { 556 bool operator!=(const GURL& x, const base::StringPiece& spec) {
553 return !(x == spec); 557 return !(x == spec);
554 } 558 }
OLDNEW
« no previous file with comments | « url/gurl.h ('k') | url/gurl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698