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

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

Issue 10533102: Allow the omnibox to recognize as URLs inputs that have a host component that ends with a hyphen. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 6 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 | « net/base/net_util.h ('k') | net/base/net_util_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 (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/net_util.h" 5 #include "net/base/net_util.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 #include <map> 9 #include <map>
10 10
(...skipping 1287 matching lines...) Expand 10 before | Expand all | Expand 10 after
1298 return (c >= '0') && (c <= '9'); 1298 return (c >= '0') && (c <= '9');
1299 } 1299 }
1300 1300
1301 bool IsCanonicalizedHostCompliant(const std::string& host, 1301 bool IsCanonicalizedHostCompliant(const std::string& host,
1302 const std::string& desired_tld) { 1302 const std::string& desired_tld) {
1303 if (host.empty()) 1303 if (host.empty())
1304 return false; 1304 return false;
1305 1305
1306 bool in_component = false; 1306 bool in_component = false;
1307 bool most_recent_component_started_alpha = false; 1307 bool most_recent_component_started_alpha = false;
1308 bool last_char_was_hyphen_or_underscore = false; 1308 bool last_char_was_underscore = false;
1309 1309
1310 for (std::string::const_iterator i(host.begin()); i != host.end(); ++i) { 1310 for (std::string::const_iterator i(host.begin()); i != host.end(); ++i) {
1311 const char c = *i; 1311 const char c = *i;
1312 if (!in_component) { 1312 if (!in_component) {
1313 most_recent_component_started_alpha = IsHostCharAlpha(c); 1313 most_recent_component_started_alpha = IsHostCharAlpha(c);
1314 if (!most_recent_component_started_alpha && !IsHostCharDigit(c) && 1314 if (!most_recent_component_started_alpha && !IsHostCharDigit(c) &&
1315 (c != '-')) 1315 (c != '-'))
1316 return false; 1316 return false;
1317 in_component = true; 1317 in_component = true;
1318 } else { 1318 } else {
1319 if (c == '.') { 1319 if (c == '.') {
1320 if (last_char_was_hyphen_or_underscore) 1320 if (last_char_was_underscore)
1321 return false; 1321 return false;
1322 in_component = false; 1322 in_component = false;
1323 } else if (IsHostCharAlpha(c) || IsHostCharDigit(c)) { 1323 } else if (IsHostCharAlpha(c) || IsHostCharDigit(c) || (c == '-')) {
1324 last_char_was_hyphen_or_underscore = false; 1324 last_char_was_underscore = false;
1325 } else if ((c == '-') || (c == '_')) { 1325 } else if (c == '_') {
1326 last_char_was_hyphen_or_underscore = true; 1326 last_char_was_underscore = true;
1327 } else { 1327 } else {
1328 return false; 1328 return false;
1329 } 1329 }
1330 } 1330 }
1331 } 1331 }
1332 1332
1333 return most_recent_component_started_alpha || 1333 return most_recent_component_started_alpha ||
1334 (!desired_tld.empty() && IsHostCharAlpha(desired_tld[0])); 1334 (!desired_tld.empty() && IsHostCharAlpha(desired_tld[0]));
1335 } 1335 }
1336 1336
(...skipping 1002 matching lines...) Expand 10 before | Expand all | Expand 10 after
2339 2339
2340 NetworkInterface::NetworkInterface(const std::string& name, 2340 NetworkInterface::NetworkInterface(const std::string& name,
2341 const IPAddressNumber& address) 2341 const IPAddressNumber& address)
2342 : name(name), address(address) { 2342 : name(name), address(address) {
2343 } 2343 }
2344 2344
2345 NetworkInterface::~NetworkInterface() { 2345 NetworkInterface::~NetworkInterface() {
2346 } 2346 }
2347 2347
2348 } // namespace net 2348 } // namespace net
OLDNEW
« no previous file with comments | « net/base/net_util.h ('k') | net/base/net_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698