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

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

Issue 6258015: Remove wstring from autocomplete.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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/browser/net/url_fixer_upper.h ('k') | chrome/browser/omnibox_search_hint.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) 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
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
75 119
76 TrimPositions TrimWhitespaceUTF8(const std::string& input, 120 TrimPositions TrimWhitespaceUTF8(const std::string& input,
77 TrimPositions positions, 121 TrimPositions positions,
78 std::string* output) { 122 std::string* output) {
79 // This implementation is not so fast since it converts the text encoding 123 // 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 124 // twice. Please feel free to file a bug if this function hurts the
81 // performance of Chrome. 125 // performance of Chrome.
82 DCHECK(IsStringUTF8(input)); 126 DCHECK(IsStringUTF8(input));
83 std::wstring input_wide = UTF8ToWide(input); 127 std::wstring input_wide = UTF8ToWide(input);
84 std::wstring output_wide; 128 std::wstring output_wide;
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 618
575 // Deprecated functions. To be removed when all callers are updated. 619 // Deprecated functions. To be removed when all callers are updated.
576 std::wstring URLFixerUpper::SegmentURL(const std::wstring& text, 620 std::wstring URLFixerUpper::SegmentURL(const std::wstring& text,
577 url_parse::Parsed* parts) { 621 url_parse::Parsed* parts) {
578 std::string text_utf8 = WideToUTF8(text); 622 std::string text_utf8 = WideToUTF8(text);
579 url_parse::Parsed parts_utf8; 623 url_parse::Parsed parts_utf8;
580 std::string scheme_utf8 = SegmentURL(text_utf8, &parts_utf8); 624 std::string scheme_utf8 = SegmentURL(text_utf8, &parts_utf8);
581 UTF8PartsToWideParts(text_utf8, parts_utf8, parts); 625 UTF8PartsToWideParts(text_utf8, parts_utf8, parts);
582 return UTF8ToWide(scheme_utf8); 626 return UTF8ToWide(scheme_utf8);
583 } 627 }
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
584 GURL URLFixerUpper::FixupRelativeFile(const std::wstring& base_dir, 638 GURL URLFixerUpper::FixupRelativeFile(const std::wstring& base_dir,
585 const std::wstring& text) { 639 const std::wstring& text) {
586 return FixupRelativeFile(FilePath::FromWStringHack(base_dir), 640 return FixupRelativeFile(FilePath::FromWStringHack(base_dir),
587 FilePath::FromWStringHack(text)); 641 FilePath::FromWStringHack(text));
588 } 642 }
589 643
590 void URLFixerUpper::OffsetComponent(int offset, url_parse::Component* part) { 644 void URLFixerUpper::OffsetComponent(int offset, url_parse::Component* part) {
591 DCHECK(part); 645 DCHECK(part);
592 646
593 if (part->is_valid()) { 647 if (part->is_valid()) {
594 // Offset the location of this component. 648 // Offset the location of this component.
595 part->begin += offset; 649 part->begin += offset;
596 650
597 // This part might not have existed in the original text. 651 // This part might not have existed in the original text.
598 if (part->begin < 0) 652 if (part->begin < 0)
599 part->reset(); 653 part->reset();
600 } 654 }
601 } 655 }
OLDNEW
« no previous file with comments | « chrome/browser/net/url_fixer_upper.h ('k') | chrome/browser/omnibox_search_hint.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698