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

Side by Side Diff: src/gurl.cc

Issue 113187: GURL: add a HostNoBrackets() method for bracketless IPv6 literals. (Closed) Base URL: http://google-url.googlecode.com/svn/trunk/
Patch Set: '' Created 11 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « src/gurl.h ('k') | src/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 2007, Google Inc. 1 // Copyright 2007, Google Inc.
2 // All rights reserved. 2 // All rights reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // * Redistributions of source code must retain the above copyright 8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer. 9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above 10 // * Redistributions in binary form must reproduce the above
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 // Clip off the reference when it exists. The reference starts after the # 342 // Clip off the reference when it exists. The reference starts after the #
343 // sign, so we have to subtract one to also remove it. 343 // sign, so we have to subtract one to also remove it.
344 return std::string(spec_, parsed_.path.begin, 344 return std::string(spec_, parsed_.path.begin,
345 parsed_.ref.begin - parsed_.path.begin - 1); 345 parsed_.ref.begin - parsed_.path.begin - 1);
346 } 346 }
347 347
348 // Use everything form the path to the end. 348 // Use everything form the path to the end.
349 return std::string(spec_, parsed_.path.begin); 349 return std::string(spec_, parsed_.path.begin);
350 } 350 }
351 351
352 std::string GURL::HostNoBrackets() const {
353 // If host looks like an IPv6 literal, strip the square brackets.
354 url_parse::Component h(parsed_.host);
355 if (h.len >= 2 && spec_[h.begin] == '[' && spec_[h.end() - 1] == ']') {
356 h.begin++;
357 h.len -= 2;
358 }
359 return ComponentString(h);
360 }
361
352 bool GURL::HostIsIPAddress() const { 362 bool GURL::HostIsIPAddress() const {
353 if (!is_valid_ || spec_.empty()) 363 if (!is_valid_ || spec_.empty())
354 return false; 364 return false;
355 365
356 url_canon::RawCanonOutputT<char, 128> ignored_output; 366 url_canon::RawCanonOutputT<char, 128> ignored_output;
357 url_parse::Component ignored_component; 367 url_parse::Component ignored_component;
358 return url_canon::CanonicalizeIPAddress(spec_.c_str(), parsed_.host, 368 return url_canon::CanonicalizeIPAddress(spec_.c_str(), parsed_.host,
359 &ignored_output, &ignored_component); 369 &ignored_output, &ignored_component);
360 } 370 }
361 371
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 440
431 return true; 441 return true;
432 } 442 }
433 443
434 void GURL::Swap(GURL* other) { 444 void GURL::Swap(GURL* other) {
435 spec_.swap(other->spec_); 445 spec_.swap(other->spec_);
436 std::swap(is_valid_, other->is_valid_); 446 std::swap(is_valid_, other->is_valid_);
437 std::swap(parsed_, other->parsed_); 447 std::swap(parsed_, other->parsed_);
438 } 448 }
439 449
OLDNEW
« no previous file with comments | « src/gurl.h ('k') | src/gurl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698