summaryrefslogtreecommitdiffstats
path: root/app/l10n_util.cc
diff options
context:
space:
mode:
authorkuan@chromium.org <kuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-02 15:53:44 +0000
committerkuan@chromium.org <kuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-02 15:53:44 +0000
commitf7eb4703666f6e8776ef084e6b60e19616edf7a4 (patch)
tree4f89249b66997767ac2aed0d6595a153b32f6ec7 /app/l10n_util.cc
parent931fae8fbb1766629f2d82d772c7f612b440c4b2 (diff)
downloadchromium_src-f7eb4703666f6e8776ef084e6b60e19616edf7a4.zip
chromium_src-f7eb4703666f6e8776ef084e6b60e19616edf7a4.tar.gz
chromium_src-f7eb4703666f6e8776ef084e6b60e19616edf7a4.tar.bz2
translate infobar: sort languages in menus by application locale
- provide string16 sorting methods (there were only std::wstring sorting methods before) - problem is fixed on win, mac, linux and chromeos BUG=39850 TEST=verify per bug report. Review URL: http://codereview.chromium.org/1542009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43484 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app/l10n_util.cc')
-rw-r--r--app/l10n_util.cc52
1 files changed, 38 insertions, 14 deletions
diff --git a/app/l10n_util.cc b/app/l10n_util.cc
index d4eeed1..2133066 100644
--- a/app/l10n_util.cc
+++ b/app/l10n_util.cc
@@ -751,32 +751,38 @@ string16 ToUpper(const string16& string) {
return result;
}
-// Compares the character data stored in two different strings by specified
-// Collator instance.
+// Compares the character data stored in two different string16 strings by
+// specified Collator instance.
+UCollationResult CompareString16WithCollator(const icu::Collator* collator,
+ const string16& lhs,
+ const string16& rhs) {
+ DCHECK(collator);
+ UErrorCode error = U_ZERO_ERROR;
+ UCollationResult result = collator->compare(
+ static_cast<const UChar*>(lhs.c_str()), static_cast<int>(lhs.length()),
+ static_cast<const UChar*>(rhs.c_str()), static_cast<int>(rhs.length()),
+ error);
+ DCHECK(U_SUCCESS(error));
+ return result;
+}
+
+// Compares the character data stored in two different std:wstring strings by
+// specified Collator instance.
UCollationResult CompareStringWithCollator(const icu::Collator* collator,
const std::wstring& lhs,
const std::wstring& rhs) {
DCHECK(collator);
- UErrorCode error = U_ZERO_ERROR;
+ UCollationResult result;
#if defined(WCHAR_T_IS_UTF32)
// Need to convert to UTF-16 to be compatible with UnicodeString's
// constructor.
string16 lhs_utf16 = WideToUTF16(lhs);
string16 rhs_utf16 = WideToUTF16(rhs);
- UCollationResult result = collator->compare(
- static_cast<const UChar*>(lhs_utf16.c_str()),
- static_cast<int>(lhs_utf16.length()),
- static_cast<const UChar*>(rhs_utf16.c_str()),
- static_cast<int>(rhs_utf16.length()),
- error);
+ result = CompareString16WithCollator(collator, lhs_utf16, rhs_utf16);
#else
- UCollationResult result = collator->compare(
- static_cast<const UChar*>(lhs.c_str()), static_cast<int>(lhs.length()),
- static_cast<const UChar*>(rhs.c_str()), static_cast<int>(rhs.length()),
- error);
+ result = CompareString16WithCollator(collator, lhs, rhs);
#endif
- DCHECK(U_SUCCESS(error));
return result;
}
@@ -791,11 +797,29 @@ bool StringComparator<std::wstring>::operator()(const std::wstring& lhs,
return CompareStringWithCollator(collator_, lhs, rhs) == UCOL_LESS;
};
+#if !defined(WCHAR_T_IS_UTF16)
+// Specialization of operator() method for string16 version.
+template <>
+bool StringComparator<string16>::operator()(const string16& lhs,
+ const string16& rhs) {
+ // If we can not get collator instance for specified locale, just do simple
+ // string compare.
+ if (!collator_)
+ return lhs < rhs;
+ return CompareString16WithCollator(collator_, lhs, rhs) == UCOL_LESS;
+};
+#endif // !defined(WCHAR_T_IS_UTF16)
+
void SortStrings(const std::string& locale,
std::vector<std::wstring>* strings) {
SortVectorWithStringKey(locale, strings, false);
}
+void SortStrings16(const std::string& locale,
+ std::vector<string16>* strings) {
+ SortVectorWithStringKey(locale, strings, false);
+}
+
const std::vector<std::string>& GetAvailableLocales() {
static std::vector<std::string> locales;
if (locales.empty()) {