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

Side by Side Diff: net/tools/dump_cache/url_utilities.cc

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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
OLDNEW
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/tools/dump_cache/url_utilities.h" 5 #include "net/tools/dump_cache/url_utilities.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_util.h" 9 #include "base/strings/string_util.h"
10 10
11 namespace net { 11 namespace net {
12 12
13 std::string UrlUtilities::GetUrlHost(const std::string& url) { 13 std::string UrlUtilities::GetUrlHost(const std::string& url) {
14 size_t b = url.find("//"); 14 size_t b = url.find("//");
15 if (b == std::string::npos) 15 if (b == std::string::npos)
16 b = 0; 16 b = 0;
17 else 17 else
18 b += 2; 18 b += 2;
19 size_t next_slash = url.find_first_of('/', b); 19 size_t next_slash = url.find_first_of('/', b);
20 size_t next_colon = url.find_first_of(':', b); 20 size_t next_colon = url.find_first_of(':', b);
21 if (next_slash != std::string::npos 21 if (next_slash != std::string::npos && next_colon != std::string::npos &&
22 && next_colon != std::string::npos 22 next_colon < next_slash) {
23 && next_colon < next_slash) {
24 return std::string(url, b, next_colon - b); 23 return std::string(url, b, next_colon - b);
25 } 24 }
26 if (next_slash == std::string::npos) { 25 if (next_slash == std::string::npos) {
27 if (next_colon != std::string::npos) { 26 if (next_colon != std::string::npos) {
28 return std::string(url, b, next_colon - b); 27 return std::string(url, b, next_colon - b);
29 } else { 28 } else {
30 next_slash = url.size(); 29 next_slash = url.size();
31 } 30 }
32 } 31 }
33 return std::string(url, b, next_slash - b); 32 return std::string(url, b, next_slash - b);
(...skipping 11 matching lines...) Expand all
45 std::string UrlUtilities::GetUrlPath(const std::string& url) { 44 std::string UrlUtilities::GetUrlPath(const std::string& url) {
46 size_t b = url.find("//"); 45 size_t b = url.find("//");
47 if (b == std::string::npos) 46 if (b == std::string::npos)
48 b = 0; 47 b = 0;
49 else 48 else
50 b += 2; 49 b += 2;
51 b = url.find("/", b); 50 b = url.find("/", b);
52 if (b == std::string::npos) 51 if (b == std::string::npos)
53 return "/"; 52 return "/";
54 53
55 size_t e = url.find("#", b+1); 54 size_t e = url.find("#", b + 1);
56 if (e != std::string::npos) 55 if (e != std::string::npos)
57 return std::string(url, b, (e - b)); 56 return std::string(url, b, (e - b));
58 return std::string(url, b); 57 return std::string(url, b);
59 } 58 }
60 59
61 namespace { 60 namespace {
62 61
63 // Parsing states for UrlUtilities::Unescape 62 // Parsing states for UrlUtilities::Unescape
64 enum UnescapeState { 63 enum UnescapeState {
65 NORMAL, // We are not in the middle of parsing an escape. 64 NORMAL, // We are not in the middle of parsing an escape.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 } 115 }
117 // Unexpected, % followed by end of string, pass it through. 116 // Unexpected, % followed by end of string, pass it through.
118 if (state == ESCAPE1 || state == ESCAPE2) { 117 if (state == ESCAPE1 || state == ESCAPE2) {
119 unescaped_url.push_back('%'); 118 unescaped_url.push_back('%');
120 unescaped_url.append(escape_text); 119 unescaped_url.append(escape_text);
121 } 120 }
122 return unescaped_url; 121 return unescaped_url;
123 } 122 }
124 123
125 } // namespace net 124 } // namespace net
126
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698