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

Side by Side Diff: net/base/host_port_pair.cc

Issue 1215933004: New new versions of Starts/EndsWith and SplitString in net (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@starts_with
Patch Set: Created 5 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 | « net/base/host_mapping_rules.cc ('k') | net/base/ip_address_number.h » ('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 (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 14 matching lines...) Expand all
25 return HostPortPair(url.HostNoBrackets(), 25 return HostPortPair(url.HostNoBrackets(),
26 static_cast<uint16_t>(url.EffectiveIntPort())); 26 static_cast<uint16_t>(url.EffectiveIntPort()));
27 } 27 }
28 28
29 // static 29 // static
30 HostPortPair HostPortPair::FromIPEndPoint(const IPEndPoint& ipe) { 30 HostPortPair HostPortPair::FromIPEndPoint(const IPEndPoint& ipe) {
31 return HostPortPair(ipe.ToStringWithoutPort(), ipe.port()); 31 return HostPortPair(ipe.ToStringWithoutPort(), ipe.port());
32 } 32 }
33 33
34 HostPortPair HostPortPair::FromString(const std::string& str) { 34 HostPortPair HostPortPair::FromString(const std::string& str) {
35 std::vector<std::string> key_port; 35 std::vector<base::StringPiece> key_port = base::SplitStringPiece(
36 base::SplitString(str, ':', &key_port); 36 str, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
37 if (key_port.size() != 2) 37 if (key_port.size() != 2)
38 return HostPortPair(); 38 return HostPortPair();
39 int port; 39 int port;
40 if (!base::StringToInt(key_port[1], &port)) 40 if (!base::StringToInt(key_port[1], &port))
41 return HostPortPair(); 41 return HostPortPair();
42 if (!IsPortValid(port)) 42 if (!IsPortValid(port))
43 return HostPortPair(); 43 return HostPortPair();
44 HostPortPair host_port_pair; 44 HostPortPair host_port_pair;
45 host_port_pair.set_host(key_port[0]); 45 host_port_pair.set_host(key_port[0].as_string());
46 host_port_pair.set_port(static_cast<uint16_t>(port)); 46 host_port_pair.set_port(static_cast<uint16_t>(port));
47 return host_port_pair; 47 return host_port_pair;
48 } 48 }
49 49
50 std::string HostPortPair::ToString() const { 50 std::string HostPortPair::ToString() const {
51 std::string ret(HostForURL()); 51 std::string ret(HostForURL());
52 ret += ':'; 52 ret += ':';
53 ret += base::IntToString(port_); 53 ret += base::IntToString(port_);
54 return ret; 54 return ret;
55 } 55 }
(...skipping 11 matching lines...) Expand all
67 // Check to see if the host is an IPv6 address. If so, added brackets. 67 // Check to see if the host is an IPv6 address. If so, added brackets.
68 if (host_.find(':') != std::string::npos) { 68 if (host_.find(':') != std::string::npos) {
69 DCHECK_NE(host_[0], '['); 69 DCHECK_NE(host_[0], '[');
70 return base::StringPrintf("[%s]", host_.c_str()); 70 return base::StringPrintf("[%s]", host_.c_str());
71 } 71 }
72 72
73 return host_; 73 return host_;
74 } 74 }
75 75
76 } // namespace net 76 } // namespace net
OLDNEW
« no previous file with comments | « net/base/host_mapping_rules.cc ('k') | net/base/ip_address_number.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698