| OLD | NEW |
| 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 22 matching lines...) Expand all Loading... |
| 33 url_parse::Component UTF8ComponentToUTF16Component( | 33 url_parse::Component UTF8ComponentToUTF16Component( |
| 34 const std::string& text_utf8, | 34 const std::string& text_utf8, |
| 35 const url_parse::Component& component_utf8) { | 35 const url_parse::Component& component_utf8) { |
| 36 if (component_utf8.len == -1) | 36 if (component_utf8.len == -1) |
| 37 return url_parse::Component(); | 37 return url_parse::Component(); |
| 38 | 38 |
| 39 std::string before_component_string = | 39 std::string before_component_string = |
| 40 text_utf8.substr(0, component_utf8.begin); | 40 text_utf8.substr(0, component_utf8.begin); |
| 41 std::string component_string = text_utf8.substr(component_utf8.begin, | 41 std::string component_string = text_utf8.substr(component_utf8.begin, |
| 42 component_utf8.len); | 42 component_utf8.len); |
| 43 string16 before_component_string_16 = UTF8ToUTF16(before_component_string); | 43 base::string16 before_component_string_16 = |
| 44 string16 component_string_16 = UTF8ToUTF16(component_string); | 44 UTF8ToUTF16(before_component_string); |
| 45 base::string16 component_string_16 = UTF8ToUTF16(component_string); |
| 45 url_parse::Component component_16(before_component_string_16.length(), | 46 url_parse::Component component_16(before_component_string_16.length(), |
| 46 component_string_16.length()); | 47 component_string_16.length()); |
| 47 return component_16; | 48 return component_16; |
| 48 } | 49 } |
| 49 | 50 |
| 50 void UTF8PartsToUTF16Parts(const std::string& text_utf8, | 51 void UTF8PartsToUTF16Parts(const std::string& text_utf8, |
| 51 const url_parse::Parsed& parts_utf8, | 52 const url_parse::Parsed& parts_utf8, |
| 52 url_parse::Parsed* parts) { | 53 url_parse::Parsed* parts) { |
| 53 if (IsStringASCII(text_utf8)) { | 54 if (IsStringASCII(text_utf8)) { |
| 54 *parts = parts_utf8; | 55 *parts = parts_utf8; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 73 UTF8ComponentToUTF16Component(text_utf8, parts_utf8.ref); | 74 UTF8ComponentToUTF16Component(text_utf8, parts_utf8.ref); |
| 74 } | 75 } |
| 75 | 76 |
| 76 TrimPositions TrimWhitespaceUTF8(const std::string& input, | 77 TrimPositions TrimWhitespaceUTF8(const std::string& input, |
| 77 TrimPositions positions, | 78 TrimPositions positions, |
| 78 std::string* output) { | 79 std::string* output) { |
| 79 // 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 |
| 80 // 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 |
| 81 // performance of Chrome. | 82 // performance of Chrome. |
| 82 DCHECK(IsStringUTF8(input)); | 83 DCHECK(IsStringUTF8(input)); |
| 83 string16 input16 = UTF8ToUTF16(input); | 84 base::string16 input16 = UTF8ToUTF16(input); |
| 84 string16 output16; | 85 base::string16 output16; |
| 85 TrimPositions result = TrimWhitespace(input16, positions, &output16); | 86 TrimPositions result = TrimWhitespace(input16, positions, &output16); |
| 86 *output = UTF16ToUTF8(output16); | 87 *output = UTF16ToUTF8(output16); |
| 87 return result; | 88 return result; |
| 88 } | 89 } |
| 89 | 90 |
| 90 // does some basic fixes for input that we want to test for file-ness | 91 // does some basic fixes for input that we want to test for file-ness |
| 91 void PrepareStringForFileOps(const base::FilePath& text, | 92 void PrepareStringForFileOps(const base::FilePath& text, |
| 92 base::FilePath::StringType* output) { | 93 base::FilePath::StringType* output) { |
| 93 #if defined(OS_WIN) | 94 #if defined(OS_WIN) |
| 94 TrimWhitespace(text.value(), TRIM_ALL, output); | 95 TrimWhitespace(text.value(), TRIM_ALL, output); |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 } | 477 } |
| 477 | 478 |
| 478 } // namespace | 479 } // namespace |
| 479 | 480 |
| 480 std::string URLFixerUpper::SegmentURL(const std::string& text, | 481 std::string URLFixerUpper::SegmentURL(const std::string& text, |
| 481 url_parse::Parsed* parts) { | 482 url_parse::Parsed* parts) { |
| 482 std::string mutable_text(text); | 483 std::string mutable_text(text); |
| 483 return SegmentURLInternal(&mutable_text, parts); | 484 return SegmentURLInternal(&mutable_text, parts); |
| 484 } | 485 } |
| 485 | 486 |
| 486 string16 URLFixerUpper::SegmentURL(const string16& text, | 487 base::string16 URLFixerUpper::SegmentURL(const base::string16& text, |
| 487 url_parse::Parsed* parts) { | 488 url_parse::Parsed* parts) { |
| 488 std::string text_utf8 = UTF16ToUTF8(text); | 489 std::string text_utf8 = UTF16ToUTF8(text); |
| 489 url_parse::Parsed parts_utf8; | 490 url_parse::Parsed parts_utf8; |
| 490 std::string scheme_utf8 = SegmentURL(text_utf8, &parts_utf8); | 491 std::string scheme_utf8 = SegmentURL(text_utf8, &parts_utf8); |
| 491 UTF8PartsToUTF16Parts(text_utf8, parts_utf8, parts); | 492 UTF8PartsToUTF16Parts(text_utf8, parts_utf8, parts); |
| 492 return UTF8ToUTF16(scheme_utf8); | 493 return UTF8ToUTF16(scheme_utf8); |
| 493 } | 494 } |
| 494 | 495 |
| 495 GURL URLFixerUpper::FixupURL(const std::string& text, | 496 GURL URLFixerUpper::FixupURL(const std::string& text, |
| 496 const std::string& desired_tld) { | 497 const std::string& desired_tld) { |
| 497 std::string trimmed; | 498 std::string trimmed; |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 | 637 |
| 637 if (part->is_valid()) { | 638 if (part->is_valid()) { |
| 638 // Offset the location of this component. | 639 // Offset the location of this component. |
| 639 part->begin += offset; | 640 part->begin += offset; |
| 640 | 641 |
| 641 // This part might not have existed in the original text. | 642 // This part might not have existed in the original text. |
| 642 if (part->begin < 0) | 643 if (part->begin < 0) |
| 643 part->reset(); | 644 part->reset(); |
| 644 } | 645 } |
| 645 } | 646 } |
| OLD | NEW |