| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 HostPortPair HostPortPair::FromIPEndPoint(const IPEndPoint& ipe) { | 31 HostPortPair HostPortPair::FromIPEndPoint(const IPEndPoint& ipe) { |
| 32 return HostPortPair(ipe.ToStringWithoutPort(), ipe.port()); | 32 return HostPortPair(ipe.ToStringWithoutPort(), ipe.port()); |
| 33 } | 33 } |
| 34 | 34 |
| 35 HostPortPair HostPortPair::FromString(const std::string& str) { | 35 HostPortPair HostPortPair::FromString(const std::string& str) { |
| 36 std::vector<base::StringPiece> key_port = base::SplitStringPiece( | 36 std::vector<base::StringPiece> key_port = base::SplitStringPiece( |
| 37 str, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 37 str, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 38 if (key_port.size() != 2) | 38 if (key_port.size() != 2) |
| 39 return HostPortPair(); | 39 return HostPortPair(); |
| 40 int port; | 40 int port; |
| 41 if (!ParseNonNegativeDecimalInt(key_port[1], &port)) | 41 if (!ParseInt32(key_port[1], ParseIntFormat::NON_NEGATIVE, &port)) |
| 42 return HostPortPair(); | 42 return HostPortPair(); |
| 43 if (!IsPortValid(port)) | 43 if (!IsPortValid(port)) |
| 44 return HostPortPair(); | 44 return HostPortPair(); |
| 45 HostPortPair host_port_pair; | 45 HostPortPair host_port_pair; |
| 46 host_port_pair.set_host(key_port[0].as_string()); | 46 host_port_pair.set_host(key_port[0].as_string()); |
| 47 host_port_pair.set_port(static_cast<uint16_t>(port)); | 47 host_port_pair.set_port(static_cast<uint16_t>(port)); |
| 48 return host_port_pair; | 48 return host_port_pair; |
| 49 } | 49 } |
| 50 | 50 |
| 51 std::string HostPortPair::ToString() const { | 51 std::string HostPortPair::ToString() const { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 68 // Check to see if the host is an IPv6 address. If so, added brackets. | 68 // Check to see if the host is an IPv6 address. If so, added brackets. |
| 69 if (host_.find(':') != std::string::npos) { | 69 if (host_.find(':') != std::string::npos) { |
| 70 DCHECK_NE(host_[0], '['); | 70 DCHECK_NE(host_[0], '['); |
| 71 return base::StringPrintf("[%s]", host_.c_str()); | 71 return base::StringPrintf("[%s]", host_.c_str()); |
| 72 } | 72 } |
| 73 | 73 |
| 74 return host_; | 74 return host_; |
| 75 } | 75 } |
| 76 | 76 |
| 77 } // namespace net | 77 } // namespace net |
| OLD | NEW |