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

Side by Side Diff: ui/base/l10n/l10n_util.cc

Issue 135963010: Prepare to enable icu_use_data_file_flat on CrOS (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: UTF18 -> UTF8 Created 6 years, 10 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) 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 "ui/base/l10n/l10n_util.h" 5 #include "ui/base/l10n/l10n_util.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cstdlib> 8 #include <cstdlib>
9 #include <iterator> 9 #include <iterator>
10 #include <string> 10 #include <string>
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 void AdjustParagraphDirectionality(base::string16* paragraph) { 256 void AdjustParagraphDirectionality(base::string16* paragraph) {
257 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) 257 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
258 if (base::i18n::IsRTL() && 258 if (base::i18n::IsRTL() &&
259 base::i18n::StringContainsStrongRTLChars(*paragraph)) { 259 base::i18n::StringContainsStrongRTLChars(*paragraph)) {
260 paragraph->insert(0, 1, 260 paragraph->insert(0, 1,
261 static_cast<base::char16>(base::i18n::kRightToLeftMark)); 261 static_cast<base::char16>(base::i18n::kRightToLeftMark));
262 } 262 }
263 #endif 263 #endif
264 } 264 }
265 265
266 base::string16 GetStringUTF16Raw(int message_id) {
267 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
268 return rb.GetLocalizedString(message_id);
269 }
270
266 #if defined(OS_WIN) 271 #if defined(OS_WIN)
267 std::string GetCanonicalLocale(const std::string& locale) { 272 std::string GetCanonicalLocale(const std::string& locale) {
268 return base::i18n::GetCanonicalLocale(locale.c_str()); 273 return base::i18n::GetCanonicalLocale(locale.c_str());
269 } 274 }
270 #endif 275 #endif
271 276
272 struct AvailableLocalesTraits 277 struct AvailableLocalesTraits
273 : base::DefaultLazyInstanceTraits<std::vector<std::string> > { 278 : base::DefaultLazyInstanceTraits<std::vector<std::string> > {
274 static std::vector<std::string>* New(void* instance) { 279 static std::vector<std::string>* New(void* instance) {
275 std::vector<std::string>* locales = 280 std::vector<std::string>* locales =
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 } 658 }
654 if (token_index == 0 && (token_len < 1 || token_len > 3)) { 659 if (token_index == 0 && (token_len < 1 || token_len > 3)) {
655 return false; 660 return false;
656 } else if (token_len < 1 || token_len > 8) { 661 } else if (token_len < 1 || token_len > 8) {
657 return false; 662 return false;
658 } 663 }
659 664
660 return true; 665 return true;
661 } 666 }
662 667
668 std::string GetStringUTF8Raw(int message_id) {
669 return base::UTF16ToUTF8(GetStringUTF16Raw(message_id));
670 }
671
663 std::string GetStringUTF8(int message_id) { 672 std::string GetStringUTF8(int message_id) {
664 return base::UTF16ToUTF8(GetStringUTF16(message_id)); 673 return base::UTF16ToUTF8(GetStringUTF16(message_id));
665 } 674 }
666 675
667 base::string16 GetStringUTF16(int message_id) { 676 base::string16 GetStringUTF16(int message_id) {
668 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 677 base::string16 str = GetStringUTF16Raw(message_id);
669 base::string16 str = rb.GetLocalizedString(message_id);
670 AdjustParagraphDirectionality(&str); 678 AdjustParagraphDirectionality(&str);
671 679
672 return str; 680 return str;
673 } 681 }
674 682
675 base::string16 GetStringFUTF16(int message_id, 683 base::string16 GetStringFUTF16(int message_id,
676 const std::vector<base::string16>& replacements, 684 const std::vector<base::string16>& replacements,
677 std::vector<size_t>* offsets) { 685 std::vector<size_t>* offsets) {
678 // TODO(tc): We could save a string copy if we got the raw string as 686 // TODO(tc): We could save a string copy if we got the raw string as
679 // a StringPiece and were able to call ReplaceStringPlaceholders with 687 // a StringPiece and were able to call ReplaceStringPlaceholders with
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 } 889 }
882 890
883 int GetLocalizedContentsWidthInPixels(int pixel_resource_id) { 891 int GetLocalizedContentsWidthInPixels(int pixel_resource_id) {
884 int width = 0; 892 int width = 0;
885 base::StringToInt(l10n_util::GetStringUTF8(pixel_resource_id), &width); 893 base::StringToInt(l10n_util::GetStringUTF8(pixel_resource_id), &width);
886 DCHECK_GT(width, 0); 894 DCHECK_GT(width, 0);
887 return width; 895 return width;
888 } 896 }
889 897
890 } // namespace l10n_util 898 } // namespace l10n_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698