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

Side by Side Diff: app/l10n_util.cc

Issue 6156001: Remove wstring from l10n_util. Part 8, the last part.... (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 | « app/l10n_util.h ('k') | app/l10n_util_collator.h » ('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 "app/l10n_util.h" 5 #include "app/l10n_util.h"
6 6
7 #if defined(TOOLKIT_USES_GTK) 7 #if defined(TOOLKIT_USES_GTK)
8 #include <glib/gutils.h> 8 #include <glib/gutils.h>
9 #endif 9 #endif
10 10
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 } 561 }
562 if (token_index == 0 && (token_len < 1 || token_len > 3)) { 562 if (token_index == 0 && (token_len < 1 || token_len > 3)) {
563 return false; 563 return false;
564 } else if (token_len < 1 || token_len > 8) { 564 } else if (token_len < 1 || token_len > 8) {
565 return false; 565 return false;
566 } 566 }
567 567
568 return true; 568 return true;
569 } 569 }
570 570
571 #if CRBUG_9911_OBSOLETE_GOING_AWAY
572 std::wstring GetString(int message_id) {
573 return UTF16ToWide(GetStringUTF16(message_id));
574 }
575 #endif
576
577 std::string GetStringUTF8(int message_id) { 571 std::string GetStringUTF8(int message_id) {
578 return UTF16ToUTF8(GetStringUTF16(message_id)); 572 return UTF16ToUTF8(GetStringUTF16(message_id));
579 } 573 }
580 574
581 string16 GetStringUTF16(int message_id) { 575 string16 GetStringUTF16(int message_id) {
582 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 576 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
583 string16 str = rb.GetLocalizedString(message_id); 577 string16 str = rb.GetLocalizedString(message_id);
584 AdjustParagraphDirectionality(&str); 578 AdjustParagraphDirectionality(&str);
585 579
586 return str; 580 return str;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 } 617 }
624 #endif 618 #endif
625 619
626 string16 formatted = ReplaceStringPlaceholders(format_string, replacements, 620 string16 formatted = ReplaceStringPlaceholders(format_string, replacements,
627 offsets); 621 offsets);
628 AdjustParagraphDirectionality(&formatted); 622 AdjustParagraphDirectionality(&formatted);
629 623
630 return formatted; 624 return formatted;
631 } 625 }
632 626
633 #if CRBUG_9911_OBSOLETE_GOING_AWAY
634 #if !defined(WCHAR_T_IS_UTF16)
635 std::wstring GetStringF(int message_id, const std::wstring& a) {
636 return UTF16ToWide(GetStringFUTF16(message_id, WideToUTF16(a)));
637 }
638
639 std::wstring GetStringF(int message_id,
640 const std::wstring& a,
641 const std::wstring& b) {
642 return UTF16ToWide(GetStringFUTF16(message_id, WideToUTF16(a),
643 WideToUTF16(b)));
644 }
645
646 std::wstring GetStringF(int message_id,
647 const std::wstring& a,
648 const std::wstring& b,
649 const std::wstring& c) {
650 return UTF16ToWide(GetStringFUTF16(message_id, WideToUTF16(a),
651 WideToUTF16(b), WideToUTF16(c)));
652 }
653
654 std::wstring GetStringF(int message_id,
655 const std::wstring& a,
656 const std::wstring& b,
657 const std::wstring& c,
658 const std::wstring& d) {
659 return UTF16ToWide(GetStringFUTF16(message_id, WideToUTF16(a), WideToUTF16(b),
660 WideToUTF16(c), WideToUTF16(d)));
661 }
662 #endif
663 #endif
664
665 std::string GetStringFUTF8(int message_id, 627 std::string GetStringFUTF8(int message_id,
666 const string16& a) { 628 const string16& a) {
667 return UTF16ToUTF8(GetStringFUTF16(message_id, a)); 629 return UTF16ToUTF8(GetStringFUTF16(message_id, a));
668 } 630 }
669 631
670 std::string GetStringFUTF8(int message_id, 632 std::string GetStringFUTF8(int message_id,
671 const string16& a, 633 const string16& a,
672 const string16& b) { 634 const string16& b) {
673 return UTF16ToUTF8(GetStringFUTF16(message_id, a, b)); 635 return UTF16ToUTF8(GetStringFUTF16(message_id, a, b));
674 } 636 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 const string16& c, 680 const string16& c,
719 const string16& d) { 681 const string16& d) {
720 std::vector<string16> replacements; 682 std::vector<string16> replacements;
721 replacements.push_back(a); 683 replacements.push_back(a);
722 replacements.push_back(b); 684 replacements.push_back(b);
723 replacements.push_back(c); 685 replacements.push_back(c);
724 replacements.push_back(d); 686 replacements.push_back(d);
725 return GetStringF(message_id, replacements, NULL); 687 return GetStringF(message_id, replacements, NULL);
726 } 688 }
727 689
728 #if CRBUG_9911_OBSOLETE_GOING_AWAY
729 std::wstring GetStringF(int message_id, const std::wstring& a, size_t* offset) {
730 DCHECK(offset);
731 std::vector<size_t> offsets;
732 std::vector<string16> replacements;
733 replacements.push_back(WideToUTF16(a));
734 string16 result = GetStringF(message_id, replacements, &offsets);
735 DCHECK(offsets.size() == 1);
736 *offset = offsets[0];
737 return UTF16ToWide(result);
738 }
739
740 std::wstring GetStringF(int message_id,
741 const std::wstring& a,
742 const std::wstring& b,
743 std::vector<size_t>* offsets) {
744 std::vector<string16> replacements;
745 replacements.push_back(WideToUTF16(a));
746 replacements.push_back(WideToUTF16(b));
747 return UTF16ToWide(GetStringF(message_id, replacements, offsets));
748 }
749 #endif
750
751 string16 GetStringFUTF16(int message_id, const string16& a, size_t* offset) { 690 string16 GetStringFUTF16(int message_id, const string16& a, size_t* offset) {
752 DCHECK(offset); 691 DCHECK(offset);
753 std::vector<size_t> offsets; 692 std::vector<size_t> offsets;
754 std::vector<string16> replacements; 693 std::vector<string16> replacements;
755 replacements.push_back(a); 694 replacements.push_back(a);
756 string16 result = GetStringF(message_id, replacements, &offsets); 695 string16 result = GetStringF(message_id, replacements, &offsets);
757 DCHECK(offsets.size() == 1); 696 DCHECK(offsets.size() == 1);
758 *offset = offsets[0]; 697 *offset = offsets[0];
759 return result; 698 return result;
760 } 699 }
761 700
762 string16 GetStringFUTF16(int message_id, 701 string16 GetStringFUTF16(int message_id,
763 const string16& a, 702 const string16& a,
764 const string16& b, 703 const string16& b,
765 std::vector<size_t>* offsets) { 704 std::vector<size_t>* offsets) {
766 std::vector<string16> replacements; 705 std::vector<string16> replacements;
767 replacements.push_back(a); 706 replacements.push_back(a);
768 replacements.push_back(b); 707 replacements.push_back(b);
769 return GetStringF(message_id, replacements, offsets); 708 return GetStringF(message_id, replacements, offsets);
770 } 709 }
771 710
772 #if CRBUG_9911_OBSOLETE_GOING_AWAY
773 std::wstring GetStringF(int message_id, int a) {
774 return GetStringF(message_id, UTF8ToWide(base::IntToString(a)));
775 }
776
777 std::wstring GetStringF(int message_id, int64 a) {
778 return GetStringF(message_id, UTF8ToWide(base::Int64ToString(a)));
779 }
780 #endif
781
782 string16 GetStringFUTF16Int(int message_id, int a) { 711 string16 GetStringFUTF16Int(int message_id, int a) {
783 return GetStringFUTF16(message_id, UTF8ToUTF16(base::IntToString(a))); 712 return GetStringFUTF16(message_id, UTF8ToUTF16(base::IntToString(a)));
784 } 713 }
785 714
786 string16 GetStringFUTF16Int(int message_id, int64 a) { 715 string16 GetStringFUTF16Int(int message_id, int64 a) {
787 return GetStringFUTF16(message_id, UTF8ToUTF16(base::Int64ToString(a))); 716 return GetStringFUTF16(message_id, UTF8ToUTF16(base::Int64ToString(a)));
788 } 717 }
789 718
790 string16 TruncateString(const string16& string, size_t length) { 719 string16 TruncateString(const string16& string, size_t length) {
791 if (string.size() <= length) 720 if (string.size() <= length)
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 DCHECK(collator); 805 DCHECK(collator);
877 UErrorCode error = U_ZERO_ERROR; 806 UErrorCode error = U_ZERO_ERROR;
878 UCollationResult result = collator->compare( 807 UCollationResult result = collator->compare(
879 static_cast<const UChar*>(lhs.c_str()), static_cast<int>(lhs.length()), 808 static_cast<const UChar*>(lhs.c_str()), static_cast<int>(lhs.length()),
880 static_cast<const UChar*>(rhs.c_str()), static_cast<int>(rhs.length()), 809 static_cast<const UChar*>(rhs.c_str()), static_cast<int>(rhs.length()),
881 error); 810 error);
882 DCHECK(U_SUCCESS(error)); 811 DCHECK(U_SUCCESS(error));
883 return result; 812 return result;
884 } 813 }
885 814
886 // Compares the character data stored in two different std:wstring strings by
887 // specified Collator instance.
888 UCollationResult CompareStringWithCollator(const icu::Collator* collator,
889 const std::wstring& lhs,
890 const std::wstring& rhs) {
891 DCHECK(collator);
892 UCollationResult result;
893 #if defined(WCHAR_T_IS_UTF32)
894 // Need to convert to UTF-16 to be compatible with UnicodeString's
895 // constructor.
896 string16 lhs_utf16 = WideToUTF16(lhs);
897 string16 rhs_utf16 = WideToUTF16(rhs);
898
899 result = CompareString16WithCollator(collator, lhs_utf16, rhs_utf16);
900 #else
901 result = CompareString16WithCollator(collator, lhs, rhs);
902 #endif
903 return result;
904 }
905
906 // Specialization of operator() method for string16 version. 815 // Specialization of operator() method for string16 version.
907 template <> 816 template <>
908 bool StringComparator<string16>::operator()(const string16& lhs, 817 bool StringComparator<string16>::operator()(const string16& lhs,
909 const string16& rhs) { 818 const string16& rhs) {
910 // If we can not get collator instance for specified locale, just do simple 819 // If we can not get collator instance for specified locale, just do simple
911 // string compare. 820 // string compare.
912 if (!collator_) 821 if (!collator_)
913 return lhs < rhs; 822 return lhs < rhs;
914 return CompareString16WithCollator(collator_, lhs, rhs) == UCOL_LESS; 823 return CompareString16WithCollator(collator_, lhs, rhs) == UCOL_LESS;
915 }; 824 };
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 for (size_t i = 0; i < arraysize(kAcceptLanguageList); ++i) { 867 for (size_t i = 0; i < arraysize(kAcceptLanguageList); ++i) {
959 if (!IsLocaleNameTranslated(kAcceptLanguageList[i], display_locale)) 868 if (!IsLocaleNameTranslated(kAcceptLanguageList[i], display_locale))
960 // TODO(jungshik) : Put them at the of the list with language codes 869 // TODO(jungshik) : Put them at the of the list with language codes
961 // enclosed by brackets instead of skipping. 870 // enclosed by brackets instead of skipping.
962 continue; 871 continue;
963 locale_codes->push_back(kAcceptLanguageList[i]); 872 locale_codes->push_back(kAcceptLanguageList[i]);
964 } 873 }
965 } 874 }
966 875
967 } // namespace l10n_util 876 } // namespace l10n_util
OLDNEW
« no previous file with comments | « app/l10n_util.h ('k') | app/l10n_util_collator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698