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

Side by Side Diff: chrome/common/net/url_fixer_upper.cc

Issue 183853011: Move TrimWhitespace to the base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 | « chrome/common/importer/firefox_importer_utils.cc ('k') | chrome/installer/util/install_util.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 "chrome/common/net/url_fixer_upper.h" 5 #include "chrome/common/net/url_fixer_upper.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #if defined(OS_POSIX) 9 #if defined(OS_POSIX)
10 #include "base/environment.h" 10 #include "base/environment.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 parts->port = 67 parts->port =
68 UTF8ComponentToUTF16Component(text_utf8, parts_utf8.port); 68 UTF8ComponentToUTF16Component(text_utf8, parts_utf8.port);
69 parts->path = 69 parts->path =
70 UTF8ComponentToUTF16Component(text_utf8, parts_utf8.path); 70 UTF8ComponentToUTF16Component(text_utf8, parts_utf8.path);
71 parts->query = 71 parts->query =
72 UTF8ComponentToUTF16Component(text_utf8, parts_utf8.query); 72 UTF8ComponentToUTF16Component(text_utf8, parts_utf8.query);
73 parts->ref = 73 parts->ref =
74 UTF8ComponentToUTF16Component(text_utf8, parts_utf8.ref); 74 UTF8ComponentToUTF16Component(text_utf8, parts_utf8.ref);
75 } 75 }
76 76
77 TrimPositions TrimWhitespaceUTF8(const std::string& input, 77 base::TrimPositions TrimWhitespaceUTF8(const std::string& input,
78 TrimPositions positions, 78 base::TrimPositions positions,
79 std::string* output) { 79 std::string* output) {
80 // This implementation is not so fast since it converts the text encoding 80 // This implementation is not so fast since it converts the text encoding
81 // twice. Please feel free to file a bug if this function hurts the 81 // twice. Please feel free to file a bug if this function hurts the
82 // performance of Chrome. 82 // performance of Chrome.
83 DCHECK(IsStringUTF8(input)); 83 DCHECK(IsStringUTF8(input));
84 base::string16 input16 = base::UTF8ToUTF16(input); 84 base::string16 input16 = base::UTF8ToUTF16(input);
85 base::string16 output16; 85 base::string16 output16;
86 TrimPositions result = TrimWhitespace(input16, positions, &output16); 86 base::TrimPositions result =
87 base::TrimWhitespace(input16, positions, &output16);
87 *output = base::UTF16ToUTF8(output16); 88 *output = base::UTF16ToUTF8(output16);
88 return result; 89 return result;
89 } 90 }
90 91
91 // does some basic fixes for input that we want to test for file-ness 92 // does some basic fixes for input that we want to test for file-ness
92 void PrepareStringForFileOps(const base::FilePath& text, 93 void PrepareStringForFileOps(const base::FilePath& text,
93 base::FilePath::StringType* output) { 94 base::FilePath::StringType* output) {
94 #if defined(OS_WIN) 95 #if defined(OS_WIN)
95 TrimWhitespace(text.value(), TRIM_ALL, output); 96 base::TrimWhitespace(text.value(), base::TRIM_ALL, output);
96 replace(output->begin(), output->end(), '/', '\\'); 97 replace(output->begin(), output->end(), '/', '\\');
97 #else 98 #else
98 TrimWhitespaceUTF8(text.value(), TRIM_ALL, output); 99 TrimWhitespaceUTF8(text.value(), base::TRIM_ALL, output);
99 #endif 100 #endif
100 } 101 }
101 102
102 // Tries to create a full path from |text|. If the result is valid and the 103 // Tries to create a full path from |text|. If the result is valid and the
103 // file exists, returns true and sets |full_path| to the result. Otherwise, 104 // file exists, returns true and sets |full_path| to the result. Otherwise,
104 // returns false and leaves |full_path| unchanged. 105 // returns false and leaves |full_path| unchanged.
105 bool ValidPathForFile(const base::FilePath::StringType& text, 106 bool ValidPathForFile(const base::FilePath::StringType& text,
106 base::FilePath* full_path) { 107 base::FilePath* full_path) {
107 base::FilePath file_path = base::MakeAbsoluteFilePath(base::FilePath(text)); 108 base::FilePath file_path = base::MakeAbsoluteFilePath(base::FilePath(text));
108 if (file_path.empty()) 109 if (file_path.empty())
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 } 383 }
383 384
384 // Performs the work for URLFixerUpper::SegmentURL. |text| may be modified on 385 // Performs the work for URLFixerUpper::SegmentURL. |text| may be modified on
385 // output on success: a semicolon following a valid scheme is replaced with a 386 // output on success: a semicolon following a valid scheme is replaced with a
386 // colon. 387 // colon.
387 std::string SegmentURLInternal(std::string* text, url_parse::Parsed* parts) { 388 std::string SegmentURLInternal(std::string* text, url_parse::Parsed* parts) {
388 // Initialize the result. 389 // Initialize the result.
389 *parts = url_parse::Parsed(); 390 *parts = url_parse::Parsed();
390 391
391 std::string trimmed; 392 std::string trimmed;
392 TrimWhitespaceUTF8(*text, TRIM_ALL, &trimmed); 393 TrimWhitespaceUTF8(*text, base::TRIM_ALL, &trimmed);
393 if (trimmed.empty()) 394 if (trimmed.empty())
394 return std::string(); // Nothing to segment. 395 return std::string(); // Nothing to segment.
395 396
396 #if defined(OS_WIN) 397 #if defined(OS_WIN)
397 int trimmed_length = static_cast<int>(trimmed.length()); 398 int trimmed_length = static_cast<int>(trimmed.length());
398 if (url_parse::DoesBeginWindowsDriveSpec(trimmed.data(), 0, trimmed_length) || 399 if (url_parse::DoesBeginWindowsDriveSpec(trimmed.data(), 0, trimmed_length) ||
399 url_parse::DoesBeginUNCPath(trimmed.data(), 0, trimmed_length, true)) 400 url_parse::DoesBeginUNCPath(trimmed.data(), 0, trimmed_length, true))
400 return "file"; 401 return "file";
401 #elif defined(OS_POSIX) 402 #elif defined(OS_POSIX)
402 if (base::FilePath::IsSeparator(trimmed.data()[0]) || 403 if (base::FilePath::IsSeparator(trimmed.data()[0]) ||
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 std::string text_utf8 = base::UTF16ToUTF8(text); 495 std::string text_utf8 = base::UTF16ToUTF8(text);
495 url_parse::Parsed parts_utf8; 496 url_parse::Parsed parts_utf8;
496 std::string scheme_utf8 = SegmentURL(text_utf8, &parts_utf8); 497 std::string scheme_utf8 = SegmentURL(text_utf8, &parts_utf8);
497 UTF8PartsToUTF16Parts(text_utf8, parts_utf8, parts); 498 UTF8PartsToUTF16Parts(text_utf8, parts_utf8, parts);
498 return base::UTF8ToUTF16(scheme_utf8); 499 return base::UTF8ToUTF16(scheme_utf8);
499 } 500 }
500 501
501 GURL URLFixerUpper::FixupURL(const std::string& text, 502 GURL URLFixerUpper::FixupURL(const std::string& text,
502 const std::string& desired_tld) { 503 const std::string& desired_tld) {
503 std::string trimmed; 504 std::string trimmed;
504 TrimWhitespaceUTF8(text, TRIM_ALL, &trimmed); 505 TrimWhitespaceUTF8(text, base::TRIM_ALL, &trimmed);
505 if (trimmed.empty()) 506 if (trimmed.empty())
506 return GURL(); // Nothing here. 507 return GURL(); // Nothing here.
507 508
508 // Segment the URL. 509 // Segment the URL.
509 url_parse::Parsed parts; 510 url_parse::Parsed parts;
510 std::string scheme(SegmentURLInternal(&trimmed, &parts)); 511 std::string scheme(SegmentURLInternal(&trimmed, &parts));
511 512
512 // For view-source: URLs, we strip "view-source:", do fixup, and stick it back 513 // For view-source: URLs, we strip "view-source:", do fixup, and stick it back
513 // on. This allows us to handle things like "view-source:google.com". 514 // on. This allows us to handle things like "view-source:google.com".
514 if (scheme == content::kViewSourceScheme) { 515 if (scheme == content::kViewSourceScheme) {
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 644
644 if (part->is_valid()) { 645 if (part->is_valid()) {
645 // Offset the location of this component. 646 // Offset the location of this component.
646 part->begin += offset; 647 part->begin += offset;
647 648
648 // This part might not have existed in the original text. 649 // This part might not have existed in the original text.
649 if (part->begin < 0) 650 if (part->begin < 0)
650 part->reset(); 651 part->reset();
651 } 652 }
652 } 653 }
OLDNEW
« no previous file with comments | « chrome/common/importer/firefox_importer_utils.cc ('k') | chrome/installer/util/install_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698