OLD | NEW |
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 "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 #if defined(OS_POSIX) | 9 #if defined(OS_POSIX) |
10 #include "base/environment.h" | 10 #include "base/environment.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 UTF8ComponentToWideComponent(text_utf8, parts_utf8.host); | 65 UTF8ComponentToWideComponent(text_utf8, parts_utf8.host); |
66 parts->port = | 66 parts->port = |
67 UTF8ComponentToWideComponent(text_utf8, parts_utf8.port); | 67 UTF8ComponentToWideComponent(text_utf8, parts_utf8.port); |
68 parts->path = | 68 parts->path = |
69 UTF8ComponentToWideComponent(text_utf8, parts_utf8.path); | 69 UTF8ComponentToWideComponent(text_utf8, parts_utf8.path); |
70 parts->query = | 70 parts->query = |
71 UTF8ComponentToWideComponent(text_utf8, parts_utf8.query); | 71 UTF8ComponentToWideComponent(text_utf8, parts_utf8.query); |
72 parts->ref = | 72 parts->ref = |
73 UTF8ComponentToWideComponent(text_utf8, parts_utf8.ref); | 73 UTF8ComponentToWideComponent(text_utf8, parts_utf8.ref); |
74 } | 74 } |
75 #if defined(WCHAR_T_IS_UTF32) | |
76 url_parse::Component UTF8ComponentToUTF16Component( | |
77 const std::string& text_utf8, | |
78 const url_parse::Component& component_utf8) { | |
79 if (component_utf8.len == -1) | |
80 return url_parse::Component(); | |
81 | |
82 std::string before_component_string = | |
83 text_utf8.substr(0, component_utf8.begin); | |
84 std::string component_string = text_utf8.substr(component_utf8.begin, | |
85 component_utf8.len); | |
86 string16 before_component_string_16 = UTF8ToUTF16(before_component_string); | |
87 string16 component_string_16 = UTF8ToUTF16(component_string); | |
88 url_parse::Component component_16(before_component_string_16.length(), | |
89 component_string_16.length()); | |
90 return component_16; | |
91 } | |
92 | |
93 void UTF8PartsToUTF16Parts(const std::string& text_utf8, | |
94 const url_parse::Parsed& parts_utf8, | |
95 url_parse::Parsed* parts) { | |
96 if (IsStringASCII(text_utf8)) { | |
97 *parts = parts_utf8; | |
98 return; | |
99 } | |
100 | |
101 parts->scheme = | |
102 UTF8ComponentToUTF16Component(text_utf8, parts_utf8.scheme); | |
103 parts ->username = | |
104 UTF8ComponentToUTF16Component(text_utf8, parts_utf8.username); | |
105 parts->password = | |
106 UTF8ComponentToUTF16Component(text_utf8, parts_utf8.password); | |
107 parts->host = | |
108 UTF8ComponentToUTF16Component(text_utf8, parts_utf8.host); | |
109 parts->port = | |
110 UTF8ComponentToUTF16Component(text_utf8, parts_utf8.port); | |
111 parts->path = | |
112 UTF8ComponentToUTF16Component(text_utf8, parts_utf8.path); | |
113 parts->query = | |
114 UTF8ComponentToUTF16Component(text_utf8, parts_utf8.query); | |
115 parts->ref = | |
116 UTF8ComponentToUTF16Component(text_utf8, parts_utf8.ref); | |
117 } | |
118 #endif | |
119 | 75 |
120 TrimPositions TrimWhitespaceUTF8(const std::string& input, | 76 TrimPositions TrimWhitespaceUTF8(const std::string& input, |
121 TrimPositions positions, | 77 TrimPositions positions, |
122 std::string* output) { | 78 std::string* output) { |
123 // This implementation is not so fast since it converts the text encoding | 79 // This implementation is not so fast since it converts the text encoding |
124 // twice. Please feel free to file a bug if this function hurts the | 80 // twice. Please feel free to file a bug if this function hurts the |
125 // performance of Chrome. | 81 // performance of Chrome. |
126 DCHECK(IsStringUTF8(input)); | 82 DCHECK(IsStringUTF8(input)); |
127 std::wstring input_wide = UTF8ToWide(input); | 83 std::wstring input_wide = UTF8ToWide(input); |
128 std::wstring output_wide; | 84 std::wstring output_wide; |
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 | 574 |
619 // Deprecated functions. To be removed when all callers are updated. | 575 // Deprecated functions. To be removed when all callers are updated. |
620 std::wstring URLFixerUpper::SegmentURL(const std::wstring& text, | 576 std::wstring URLFixerUpper::SegmentURL(const std::wstring& text, |
621 url_parse::Parsed* parts) { | 577 url_parse::Parsed* parts) { |
622 std::string text_utf8 = WideToUTF8(text); | 578 std::string text_utf8 = WideToUTF8(text); |
623 url_parse::Parsed parts_utf8; | 579 url_parse::Parsed parts_utf8; |
624 std::string scheme_utf8 = SegmentURL(text_utf8, &parts_utf8); | 580 std::string scheme_utf8 = SegmentURL(text_utf8, &parts_utf8); |
625 UTF8PartsToWideParts(text_utf8, parts_utf8, parts); | 581 UTF8PartsToWideParts(text_utf8, parts_utf8, parts); |
626 return UTF8ToWide(scheme_utf8); | 582 return UTF8ToWide(scheme_utf8); |
627 } | 583 } |
628 #if defined(WCHAR_T_IS_UTF32) | |
629 string16 URLFixerUpper::SegmentURL(const string16& text, | |
630 url_parse::Parsed* parts) { | |
631 std::string text_utf8 = UTF16ToUTF8(text); | |
632 url_parse::Parsed parts_utf8; | |
633 std::string scheme_utf8 = SegmentURL(text_utf8, &parts_utf8); | |
634 UTF8PartsToUTF16Parts(text_utf8, parts_utf8, parts); | |
635 return UTF8ToUTF16(scheme_utf8); | |
636 } | |
637 #endif | |
638 GURL URLFixerUpper::FixupRelativeFile(const std::wstring& base_dir, | 584 GURL URLFixerUpper::FixupRelativeFile(const std::wstring& base_dir, |
639 const std::wstring& text) { | 585 const std::wstring& text) { |
640 return FixupRelativeFile(FilePath::FromWStringHack(base_dir), | 586 return FixupRelativeFile(FilePath::FromWStringHack(base_dir), |
641 FilePath::FromWStringHack(text)); | 587 FilePath::FromWStringHack(text)); |
642 } | 588 } |
643 | 589 |
644 void URLFixerUpper::OffsetComponent(int offset, url_parse::Component* part) { | 590 void URLFixerUpper::OffsetComponent(int offset, url_parse::Component* part) { |
645 DCHECK(part); | 591 DCHECK(part); |
646 | 592 |
647 if (part->is_valid()) { | 593 if (part->is_valid()) { |
648 // Offset the location of this component. | 594 // Offset the location of this component. |
649 part->begin += offset; | 595 part->begin += offset; |
650 | 596 |
651 // This part might not have existed in the original text. | 597 // This part might not have existed in the original text. |
652 if (part->begin < 0) | 598 if (part->begin < 0) |
653 part->reset(); | 599 part->reset(); |
654 } | 600 } |
655 } | 601 } |
OLD | NEW |