OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/autofill/core/common/autofill_l10n_util.h" | 5 #include "components/autofill/core/common/autofill_l10n_util.h" |
6 | 6 |
7 #include "base/i18n/string_compare.h" | 7 #include "base/i18n/string_compare.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
10 | 10 |
11 namespace autofill { | 11 namespace autofill { |
12 namespace l10n { | 12 namespace l10n { |
13 | 13 |
14 CaseInsensitiveCompare::CaseInsensitiveCompare() | 14 CaseInsensitiveCompare::CaseInsensitiveCompare() |
15 : CaseInsensitiveCompare(icu::Locale::getDefault()) {} | 15 : CaseInsensitiveCompare(icu::Locale::getDefault()) {} |
16 | 16 |
17 CaseInsensitiveCompare::CaseInsensitiveCompare(const icu::Locale& locale) { | 17 CaseInsensitiveCompare::CaseInsensitiveCompare(const icu::Locale& locale) { |
18 UErrorCode error = U_ZERO_ERROR; | 18 UErrorCode error = U_ZERO_ERROR; |
19 collator_.reset(icu::Collator::createInstance(locale, error)); | 19 collator_.reset(icu::Collator::createInstance(locale, error)); |
20 if (!collator_) { | 20 if (!collator_) { |
21 // On some systems, the default locale is invalid to the eyes of the ICU | 21 // On some systems, the default locale is invalid to the eyes of the ICU |
22 // library. This could be due to a device-specific issue (has been seen in | 22 // library. This could be due to a device-specific issue (has been seen in |
23 // the wild on Android devices). In the failure case, |collator_| will be | 23 // the wild on Android devices). In the failure case, |collator_| will be |
24 // null. See http://crbug.com/558625. | 24 // null. See http://crbug.com/558625. |
25 icu_54::UnicodeString name; | 25 icu::UnicodeString name; |
26 std::string locale_name; | 26 std::string locale_name; |
27 locale.getDisplayName(name).toUTF8String(locale_name); | 27 locale.getDisplayName(name).toUTF8String(locale_name); |
28 LOG(ERROR) << "Failed to initialize the ICU Collator for " | 28 LOG(ERROR) << "Failed to initialize the ICU Collator for " |
29 << "CaseInsensitiveCompare with locale" << locale_name; | 29 << "CaseInsensitiveCompare with locale" << locale_name; |
30 // Attempt to load the English locale. | 30 // Attempt to load the English locale. |
31 collator_.reset(icu::Collator::createInstance(icu::Locale::getEnglish(), | 31 collator_.reset(icu::Collator::createInstance(icu::Locale::getEnglish(), |
32 error)); | 32 error)); |
33 } | 33 } |
34 | 34 |
35 if (collator_) { | 35 if (collator_) { |
(...skipping 12 matching lines...) Expand all Loading... |
48 const base::string16& rhs) const { | 48 const base::string16& rhs) const { |
49 if (collator_) { | 49 if (collator_) { |
50 return base::i18n::CompareString16WithCollator(*collator_, lhs, rhs) == | 50 return base::i18n::CompareString16WithCollator(*collator_, lhs, rhs) == |
51 UCOL_EQUAL; | 51 UCOL_EQUAL; |
52 } | 52 } |
53 return lhs == rhs; | 53 return lhs == rhs; |
54 } | 54 } |
55 | 55 |
56 } // namespace l10n | 56 } // namespace l10n |
57 } // namespace autofill | 57 } // namespace autofill |
OLD | NEW |