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

Side by Side Diff: chrome/browser/ui/omnibox/location_bar_util.cc

Issue 6322001: Remove wstring from TemplateURL and friends.... (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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/ui/omnibox/location_bar_util.h" 5 #include "chrome/browser/ui/omnibox/location_bar_util.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/i18n/rtl.h" 8 #include "base/i18n/rtl.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/search_engines/template_url.h" 11 #include "chrome/browser/search_engines/template_url.h"
12 #include "chrome/browser/search_engines/template_url_model.h" 12 #include "chrome/browser/search_engines/template_url_model.h"
13 13
14 namespace location_bar_util { 14 namespace location_bar_util {
15 15
16 std::wstring GetKeywordName(Profile* profile, const std::wstring& keyword) { 16 std::wstring GetKeywordName(Profile* profile, const std::wstring& keyword) {
17 // Make sure the TemplateURL still exists. 17 // Make sure the TemplateURL still exists.
18 // TODO(sky): Once LocationBarView adds a listener to the TemplateURLModel 18 // TODO(sky): Once LocationBarView adds a listener to the TemplateURLModel
19 // to track changes to the model, this should become a DCHECK. 19 // to track changes to the model, this should become a DCHECK.
20 const TemplateURL* template_url = 20 const TemplateURL* template_url =
21 profile->GetTemplateURLModel()->GetTemplateURLForKeyword(keyword); 21 profile->GetTemplateURLModel()->GetTemplateURLForKeyword(
22 WideToUTF16Hack(keyword));
22 if (template_url) 23 if (template_url)
23 return template_url->AdjustedShortNameForLocaleDirection(); 24 return UTF16ToWideHack(template_url->AdjustedShortNameForLocaleDirection());
24 return std::wstring(); 25 return std::wstring();
25 } 26 }
26 27
27 std::wstring CalculateMinString(const std::wstring& description) { 28 std::wstring CalculateMinString(const std::wstring& description) {
28 // Chop at the first '.' or whitespace. 29 // Chop at the first '.' or whitespace.
29 const size_t dot_index = description.find(L'.'); 30 const size_t dot_index = description.find(L'.');
30 const size_t ws_index = description.find_first_of(kWhitespaceWide); 31 const size_t ws_index = description.find_first_of(kWhitespaceWide);
31 size_t chop_index = std::min(dot_index, ws_index); 32 size_t chop_index = std::min(dot_index, ws_index);
32 std::wstring min_string; 33 std::wstring min_string;
33 if (chop_index == std::wstring::npos) { 34 if (chop_index == std::wstring::npos) {
34 // No dot or whitespace, truncate to at most 3 chars. 35 // No dot or whitespace, truncate to at most 3 chars.
35 min_string = UTF16ToWideHack( 36 min_string = UTF16ToWideHack(
36 l10n_util::TruncateString(WideToUTF16Hack(description), 3)); 37 l10n_util::TruncateString(WideToUTF16Hack(description), 3));
37 } else { 38 } else {
38 min_string = description.substr(0, chop_index); 39 min_string = description.substr(0, chop_index);
39 } 40 }
40 base::i18n::AdjustStringForLocaleDirection(&min_string); 41 base::i18n::AdjustStringForLocaleDirection(&min_string);
41 return min_string; 42 return min_string;
42 } 43 }
43 44
44 } // namespace location_bar_util 45 } // namespace location_bar_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698