| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/browser/autofill_country.h" | 5 #include "components/autofill/core/browser/autofill_country.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 1070 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1081 } | 1081 } |
| 1082 | 1082 |
| 1083 // static | 1083 // static |
| 1084 const std::string AutofillCountry::CountryCodeForLocale( | 1084 const std::string AutofillCountry::CountryCodeForLocale( |
| 1085 const std::string& locale) { | 1085 const std::string& locale) { |
| 1086 // Add likely subtags to the locale. In particular, add any likely country | 1086 // Add likely subtags to the locale. In particular, add any likely country |
| 1087 // subtags -- e.g. for locales like "ru" that only include the language. | 1087 // subtags -- e.g. for locales like "ru" that only include the language. |
| 1088 std::string likely_locale; | 1088 std::string likely_locale; |
| 1089 UErrorCode error_ignored = U_ZERO_ERROR; | 1089 UErrorCode error_ignored = U_ZERO_ERROR; |
| 1090 uloc_addLikelySubtags(locale.c_str(), | 1090 uloc_addLikelySubtags(locale.c_str(), |
| 1091 WriteInto(&likely_locale, kLocaleCapacity), | 1091 base::WriteInto(&likely_locale, kLocaleCapacity), |
| 1092 kLocaleCapacity, | 1092 kLocaleCapacity, |
| 1093 &error_ignored); | 1093 &error_ignored); |
| 1094 | 1094 |
| 1095 // Extract the country code. | 1095 // Extract the country code. |
| 1096 std::string country_code = icu::Locale(likely_locale.c_str()).getCountry(); | 1096 std::string country_code = icu::Locale(likely_locale.c_str()).getCountry(); |
| 1097 | 1097 |
| 1098 // Default to the United States if we have no better guess. | 1098 // Default to the United States if we have no better guess. |
| 1099 if (CountryDataMap::Find(country_code) == CountryDataMap::End()) | 1099 if (CountryDataMap::Find(country_code) == CountryDataMap::End()) |
| 1100 return "US"; | 1100 return "US"; |
| 1101 | 1101 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1112 const base::string16& name, | 1112 const base::string16& name, |
| 1113 const base::string16& postal_code_label, | 1113 const base::string16& postal_code_label, |
| 1114 const base::string16& state_label) | 1114 const base::string16& state_label) |
| 1115 : country_code_(country_code), | 1115 : country_code_(country_code), |
| 1116 name_(name), | 1116 name_(name), |
| 1117 postal_code_label_(postal_code_label), | 1117 postal_code_label_(postal_code_label), |
| 1118 state_label_(state_label) { | 1118 state_label_(state_label) { |
| 1119 } | 1119 } |
| 1120 | 1120 |
| 1121 } // namespace autofill | 1121 } // namespace autofill |
| OLD | NEW |