OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/browser/net/url_fixer_upper.h" | 5 #include "chrome/browser/net/url_fixer_upper.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 parts->port = | 63 parts->port = |
64 UTF8ComponentToWideComponent(text_utf8, parts_utf8.port); | 64 UTF8ComponentToWideComponent(text_utf8, parts_utf8.port); |
65 parts->path = | 65 parts->path = |
66 UTF8ComponentToWideComponent(text_utf8, parts_utf8.path); | 66 UTF8ComponentToWideComponent(text_utf8, parts_utf8.path); |
67 parts->query = | 67 parts->query = |
68 UTF8ComponentToWideComponent(text_utf8, parts_utf8.query); | 68 UTF8ComponentToWideComponent(text_utf8, parts_utf8.query); |
69 parts->ref = | 69 parts->ref = |
70 UTF8ComponentToWideComponent(text_utf8, parts_utf8.ref); | 70 UTF8ComponentToWideComponent(text_utf8, parts_utf8.ref); |
71 } | 71 } |
72 | 72 |
| 73 TrimPositions TrimWhitespaceUTF8(const std::string& input, |
| 74 TrimPositions positions, |
| 75 std::string* output) { |
| 76 // This implementation is not so fast since it converts the text encoding |
| 77 // twice. Please feel free to file a bug if this function hurts the |
| 78 // performance of Chrome. |
| 79 DCHECK(IsStringUTF8(input)); |
| 80 std::wstring input_wide = UTF8ToWide(input); |
| 81 std::wstring output_wide; |
| 82 TrimPositions result = TrimWhitespace(input_wide, positions, &output_wide); |
| 83 *output = WideToUTF8(output_wide); |
| 84 return result; |
| 85 } |
| 86 |
73 } // namespace | 87 } // namespace |
74 | 88 |
75 // does some basic fixes for input that we want to test for file-ness | 89 // does some basic fixes for input that we want to test for file-ness |
76 static void PrepareStringForFileOps(const FilePath& text, | 90 static void PrepareStringForFileOps(const FilePath& text, |
77 FilePath::StringType* output) { | 91 FilePath::StringType* output) { |
78 #if defined(OS_WIN) | 92 #if defined(OS_WIN) |
79 TrimWhitespace(text.value(), TRIM_ALL, output); | 93 TrimWhitespace(text.value(), TRIM_ALL, output); |
80 replace(output->begin(), output->end(), '/', '\\'); | 94 replace(output->begin(), output->end(), '/', '\\'); |
81 #else | 95 #else |
82 TrimWhitespaceUTF8(text.value(), TRIM_ALL, output); | 96 TrimWhitespaceUTF8(text.value(), TRIM_ALL, output); |
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 } | 563 } |
550 wstring URLFixerUpper::FixupURL(const wstring& text, | 564 wstring URLFixerUpper::FixupURL(const wstring& text, |
551 const wstring& desired_tld) { | 565 const wstring& desired_tld) { |
552 return UTF8ToWide(FixupURL(WideToUTF8(text), WideToUTF8(desired_tld))); | 566 return UTF8ToWide(FixupURL(WideToUTF8(text), WideToUTF8(desired_tld))); |
553 } | 567 } |
554 wstring URLFixerUpper::FixupRelativeFile(const wstring& base_dir, | 568 wstring URLFixerUpper::FixupRelativeFile(const wstring& base_dir, |
555 const wstring& text) { | 569 const wstring& text) { |
556 return UTF8ToWide(FixupRelativeFile(FilePath::FromWStringHack(base_dir), | 570 return UTF8ToWide(FixupRelativeFile(FilePath::FromWStringHack(base_dir), |
557 FilePath::FromWStringHack(text))); | 571 FilePath::FromWStringHack(text))); |
558 } | 572 } |
OLD | NEW |