| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "net/base/host_port_pair.h" | 5 #include "net/base/host_port_pair.h" |
| 6 |
| 6 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "base/stringprintf.h" |
| 7 #include "googleurl/src/gurl.h" | 9 #include "googleurl/src/gurl.h" |
| 8 | 10 |
| 9 namespace net { | 11 namespace net { |
| 10 | 12 |
| 11 HostPortPair::HostPortPair() : port_(0) {} | 13 HostPortPair::HostPortPair() : port_(0) {} |
| 12 HostPortPair::HostPortPair(const std::string& in_host, uint16 in_port) | 14 HostPortPair::HostPortPair(const std::string& in_host, uint16 in_port) |
| 13 : host_(in_host), port_(in_port) {} | 15 : host_(in_host), port_(in_port) {} |
| 14 | 16 |
| 15 // static | 17 // static |
| 16 HostPortPair HostPortPair::FromURL(const GURL& url) { | 18 HostPortPair HostPortPair::FromURL(const GURL& url) { |
| 17 return HostPortPair(url.HostNoBrackets(), url.EffectiveIntPort()); | 19 return HostPortPair(url.HostNoBrackets(), url.EffectiveIntPort()); |
| 18 } | 20 } |
| 19 | 21 |
| 20 std::string HostPortPair::ToString() const { | 22 std::string HostPortPair::ToString() const { |
| 21 return StringPrintf("%s:%u", HostForURL().c_str(), port_); | 23 return base::StringPrintf("%s:%u", HostForURL().c_str(), port_); |
| 22 } | 24 } |
| 23 | 25 |
| 24 std::string HostPortPair::HostForURL() const { | 26 std::string HostPortPair::HostForURL() const { |
| 25 // Check to see if the host is an IPv6 address. If so, added brackets. | 27 // Check to see if the host is an IPv6 address. If so, added brackets. |
| 26 if (host_.find(':') != std::string::npos) { | 28 if (host_.find(':') != std::string::npos) { |
| 27 DCHECK_NE(host_[0], '['); | 29 DCHECK_NE(host_[0], '['); |
| 28 return StringPrintf("[%s]", host_.c_str()); | 30 return base::StringPrintf("[%s]", host_.c_str()); |
| 29 } | 31 } |
| 30 | 32 |
| 31 return host_; | 33 return host_; |
| 32 } | 34 } |
| 33 | 35 |
| 34 } // namespace net | 36 } // namespace net |
| OLD | NEW |