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

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

Issue 10219009: Convert CalculateMinString() to string16. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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) 2011 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/browser/ui/omnibox/location_bar_util.h" 5 #include "chrome/browser/ui/omnibox/location_bar_util.h"
6 6
7 #include "base/i18n/rtl.h" 7 #include "base/i18n/rtl.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/search_engines/template_url.h" 10 #include "chrome/browser/search_engines/template_url.h"
11 #include "chrome/browser/search_engines/template_url_service.h" 11 #include "chrome/browser/search_engines/template_url_service.h"
12 #include "chrome/browser/search_engines/template_url_service_factory.h" 12 #include "chrome/browser/search_engines/template_url_service_factory.h"
13 #include "ui/base/l10n/l10n_util.h" 13 #include "ui/base/l10n/l10n_util.h"
14 #include "ui/base/text/text_elider.h" 14 #include "ui/base/text/text_elider.h"
15 15
16 namespace location_bar_util { 16 namespace location_bar_util {
17 17
18 std::wstring GetKeywordName(Profile* profile, const std::wstring& keyword) { 18 std::wstring GetKeywordName(Profile* profile, const std::wstring& keyword) {
19 // Make sure the TemplateURL still exists. 19 // Make sure the TemplateURL still exists.
20 // TODO(sky): Once LocationBarView adds a listener to the TemplateURLService 20 // TODO(sky): Once LocationBarView adds a listener to the TemplateURLService
21 // to track changes to the model, this should become a DCHECK. 21 // to track changes to the model, this should become a DCHECK.
22 const TemplateURL* template_url = 22 const TemplateURL* template_url =
23 TemplateURLServiceFactory::GetForProfile(profile)-> 23 TemplateURLServiceFactory::GetForProfile(profile)->
24 GetTemplateURLForKeyword(WideToUTF16Hack(keyword)); 24 GetTemplateURLForKeyword(WideToUTF16Hack(keyword));
25 if (template_url) 25 if (template_url)
26 return UTF16ToWideHack(template_url->AdjustedShortNameForLocaleDirection()); 26 return UTF16ToWideHack(template_url->AdjustedShortNameForLocaleDirection());
27 return std::wstring(); 27 return std::wstring();
28 } 28 }
29 29
30 std::wstring CalculateMinString(const std::wstring& description) { 30 string16 CalculateMinString(const string16& description) {
31 // Chop at the first '.' or whitespace. 31 // Chop at the first '.' or whitespace.
32 const size_t dot_index = description.find('.'); 32 const size_t dot_index = description.find('.');
33 const size_t ws_index = description.find_first_of(kWhitespaceWide); 33 const size_t ws_index = description.find_first_of(kWhitespaceUTF16);
34 size_t chop_index = std::min(dot_index, ws_index); 34 size_t chop_index = std::min(dot_index, ws_index);
35 string16 min_string; 35 string16 min_string;
36 if (chop_index == std::wstring::npos) { 36 if (chop_index == string16::npos) {
37 // No dot or whitespace, truncate to at most 3 chars. 37 // No dot or whitespace, truncate to at most 3 chars.
38 min_string = ui::TruncateString(WideToUTF16Hack(description), 3); 38 min_string = ui::TruncateString(description, 3);
39 } else { 39 } else {
40 min_string = WideToUTF16(description.substr(0, chop_index)); 40 min_string = description.substr(0, chop_index);
41 } 41 }
42 base::i18n::AdjustStringForLocaleDirection(&min_string); 42 base::i18n::AdjustStringForLocaleDirection(&min_string);
43 return UTF16ToWide(min_string); 43 return min_string;
44 } 44 }
45 45
46 } // namespace location_bar_util 46 } // namespace location_bar_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698