Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/autofill/autofill_country.h" | 5 #include "chrome/browser/autofill/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 11 matching lines...) Expand all Loading... | |
| 22 #include "unicode/locid.h" | 22 #include "unicode/locid.h" |
| 23 #include "unicode/ucol.h" | 23 #include "unicode/ucol.h" |
| 24 #include "unicode/uloc.h" | 24 #include "unicode/uloc.h" |
| 25 #include "unicode/unistr.h" | 25 #include "unicode/unistr.h" |
| 26 #include "unicode/urename.h" | 26 #include "unicode/urename.h" |
| 27 #include "unicode/utypes.h" | 27 #include "unicode/utypes.h" |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 struct CountryData { | 31 struct CountryData { |
| 32 std::string country_code; | |
| 33 int postal_code_label_id; | 32 int postal_code_label_id; |
| 34 int state_label_id; | 33 int state_label_id; |
| 35 }; | 34 }; |
| 36 | 35 |
| 37 // The maximum capacity needed to store a locale up to the country code. | 36 // The maximum capacity needed to store a locale up to the country code. |
| 38 const size_t kLocaleCapacity = | 37 const size_t kLocaleCapacity = |
| 39 ULOC_LANG_CAPACITY + ULOC_SCRIPT_CAPACITY + ULOC_COUNTRY_CAPACITY + 1; | 38 ULOC_LANG_CAPACITY + ULOC_SCRIPT_CAPACITY + ULOC_COUNTRY_CAPACITY + 1; |
| 40 | 39 |
| 40 struct StaticCountryData { | |
| 41 char country_code[3]; | |
| 42 int postal_code_label_id; | |
|
Peter Kasting
2011/08/30 22:55:52
Nit: If we nested the structs:
struct CountryData
tony
2011/08/30 23:11:28
Good idea! Done.
| |
| 43 int state_label_id; | |
| 44 }; | |
| 45 | |
| 41 // Maps country codes to localized label string identifiers. | 46 // Maps country codes to localized label string identifiers. |
| 42 const CountryData kCountryData[] = { | 47 const StaticCountryData kCountryData[] = { |
| 43 {"AD", IDS_AUTOFILL_DIALOG_POSTAL_CODE, IDS_AUTOFILL_DIALOG_PARISH}, | 48 {"AD", IDS_AUTOFILL_DIALOG_POSTAL_CODE, IDS_AUTOFILL_DIALOG_PARISH}, |
| 44 {"AE", IDS_AUTOFILL_DIALOG_POSTAL_CODE, IDS_AUTOFILL_DIALOG_EMIRATE}, | 49 {"AE", IDS_AUTOFILL_DIALOG_POSTAL_CODE, IDS_AUTOFILL_DIALOG_EMIRATE}, |
| 45 {"AF", IDS_AUTOFILL_DIALOG_POSTAL_CODE, IDS_AUTOFILL_DIALOG_PROVINCE}, | 50 {"AF", IDS_AUTOFILL_DIALOG_POSTAL_CODE, IDS_AUTOFILL_DIALOG_PROVINCE}, |
| 46 {"AG", IDS_AUTOFILL_DIALOG_POSTAL_CODE, IDS_AUTOFILL_DIALOG_PROVINCE}, | 51 {"AG", IDS_AUTOFILL_DIALOG_POSTAL_CODE, IDS_AUTOFILL_DIALOG_PROVINCE}, |
| 47 {"AI", IDS_AUTOFILL_DIALOG_POSTAL_CODE, IDS_AUTOFILL_DIALOG_PROVINCE}, | 52 {"AI", IDS_AUTOFILL_DIALOG_POSTAL_CODE, IDS_AUTOFILL_DIALOG_PROVINCE}, |
| 48 {"AL", IDS_AUTOFILL_DIALOG_POSTAL_CODE, IDS_AUTOFILL_DIALOG_PROVINCE}, | 53 {"AL", IDS_AUTOFILL_DIALOG_POSTAL_CODE, IDS_AUTOFILL_DIALOG_PROVINCE}, |
| 49 {"AM", IDS_AUTOFILL_DIALOG_POSTAL_CODE, IDS_AUTOFILL_DIALOG_PROVINCE}, | 54 {"AM", IDS_AUTOFILL_DIALOG_POSTAL_CODE, IDS_AUTOFILL_DIALOG_PROVINCE}, |
| 50 {"AN", IDS_AUTOFILL_DIALOG_POSTAL_CODE, IDS_AUTOFILL_DIALOG_PROVINCE}, | 55 {"AN", IDS_AUTOFILL_DIALOG_POSTAL_CODE, IDS_AUTOFILL_DIALOG_PROVINCE}, |
| 51 {"AO", IDS_AUTOFILL_DIALOG_POSTAL_CODE, IDS_AUTOFILL_DIALOG_PROVINCE}, | 56 {"AO", IDS_AUTOFILL_DIALOG_POSTAL_CODE, IDS_AUTOFILL_DIALOG_PROVINCE}, |
| 52 {"AQ", IDS_AUTOFILL_DIALOG_POSTAL_CODE, IDS_AUTOFILL_DIALOG_PROVINCE}, | 57 {"AQ", IDS_AUTOFILL_DIALOG_POSTAL_CODE, IDS_AUTOFILL_DIALOG_PROVINCE}, |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 304 }; | 309 }; |
| 305 | 310 |
| 306 // static | 311 // static |
| 307 CountryDataMap* CountryDataMap::GetInstance() { | 312 CountryDataMap* CountryDataMap::GetInstance() { |
| 308 return Singleton<CountryDataMap>::get(); | 313 return Singleton<CountryDataMap>::get(); |
| 309 } | 314 } |
| 310 | 315 |
| 311 CountryDataMap::CountryDataMap() { | 316 CountryDataMap::CountryDataMap() { |
| 312 // Add all the countries we have explicit data for. | 317 // Add all the countries we have explicit data for. |
| 313 for (size_t i = 0; i < arraysize(kCountryData); ++i) { | 318 for (size_t i = 0; i < arraysize(kCountryData); ++i) { |
| 314 const CountryData& data = kCountryData[i]; | 319 const StaticCountryData& static_data = kCountryData[i]; |
| 315 country_data_.insert(std::make_pair(data.country_code, data)); | 320 CountryData data = { |
| 321 static_data.postal_code_label_id, | |
| 322 static_data.state_label_id | |
| 323 }; | |
| 324 country_data_.insert(std::make_pair(static_data.country_code, data)); | |
| 316 } | 325 } |
| 317 | 326 |
| 318 // Add any other countries that ICU knows about, falling back to default data | 327 // Add any other countries that ICU knows about, falling back to default data |
| 319 // values. | 328 // values. |
| 320 for (const char* const* country_pointer = icu::Locale::getISOCountries(); | 329 for (const char* const* country_pointer = icu::Locale::getISOCountries(); |
| 321 *country_pointer; | 330 *country_pointer; |
| 322 ++country_pointer) { | 331 ++country_pointer) { |
| 323 std::string country_code = *country_pointer; | 332 std::string country_code = *country_pointer; |
| 324 if (!country_data_.count(country_code)) { | 333 if (!country_data_.count(country_code)) { |
| 325 CountryData data = { | 334 CountryData data = { |
| 326 country_code, | |
| 327 IDS_AUTOFILL_DIALOG_POSTAL_CODE, | 335 IDS_AUTOFILL_DIALOG_POSTAL_CODE, |
| 328 IDS_AUTOFILL_DIALOG_PROVINCE | 336 IDS_AUTOFILL_DIALOG_PROVINCE |
| 329 }; | 337 }; |
| 330 country_data_.insert(std::make_pair(country_code, data)); | 338 country_data_.insert(std::make_pair(country_code, data)); |
| 331 } | 339 } |
| 332 } | 340 } |
| 333 } | 341 } |
| 334 | 342 |
| 335 const CountryDataMap::Iterator CountryDataMap::Begin() { | 343 const CountryDataMap::Iterator CountryDataMap::Begin() { |
| 336 return GetInstance()->country_data_.begin(); | 344 return GetInstance()->country_data_.begin(); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 408 return Singleton<CountryNames>::get(); | 416 return Singleton<CountryNames>::get(); |
| 409 } | 417 } |
| 410 | 418 |
| 411 CountryNames::CountryNames() { | 419 CountryNames::CountryNames() { |
| 412 // Add 2- and 3-letter ISO country codes. | 420 // Add 2- and 3-letter ISO country codes. |
| 413 for (CountryDataMap::Iterator it = CountryDataMap::Begin(); | 421 for (CountryDataMap::Iterator it = CountryDataMap::Begin(); |
| 414 it != CountryDataMap::End(); | 422 it != CountryDataMap::End(); |
| 415 ++it) { | 423 ++it) { |
| 416 const std::string& country_code = it->first; | 424 const std::string& country_code = it->first; |
| 417 std::string iso3_country_code = | 425 std::string iso3_country_code = |
| 418 icu::Locale(NULL, country_code.c_str()).getISO3Country(); | 426 icu::Locale(NULL, country_code.c_str()).getISO3Country(); |
| 419 | 427 |
| 420 common_names_.insert(std::make_pair(country_code, country_code)); | 428 common_names_.insert(std::make_pair(country_code, country_code)); |
| 421 common_names_.insert(std::make_pair(iso3_country_code, country_code)); | 429 common_names_.insert(std::make_pair(iso3_country_code, country_code)); |
| 422 } | 430 } |
| 423 | 431 |
| 424 // Add a few other common synonyms. | 432 // Add a few other common synonyms. |
| 425 common_names_.insert(std::make_pair("UNITED STATES OF AMERICA", "US")); | 433 common_names_.insert(std::make_pair("UNITED STATES OF AMERICA", "US")); |
| 426 common_names_.insert(std::make_pair("GREAT BRITAIN", "GB")); | 434 common_names_.insert(std::make_pair("GREAT BRITAIN", "GB")); |
| 427 common_names_.insert(std::make_pair("UK", "GB")); | 435 common_names_.insert(std::make_pair("UK", "GB")); |
| 428 common_names_.insert(std::make_pair("BRASIL", "BR")); | 436 common_names_.insert(std::make_pair("BRASIL", "BR")); |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 628 | 636 |
| 629 AutofillCountry::AutofillCountry(const std::string& country_code, | 637 AutofillCountry::AutofillCountry(const std::string& country_code, |
| 630 const string16& name, | 638 const string16& name, |
| 631 const string16& postal_code_label, | 639 const string16& postal_code_label, |
| 632 const string16& state_label) | 640 const string16& state_label) |
| 633 : country_code_(country_code), | 641 : country_code_(country_code), |
| 634 name_(name), | 642 name_(name), |
| 635 postal_code_label_(postal_code_label), | 643 postal_code_label_(postal_code_label), |
| 636 state_label_(state_label) { | 644 state_label_(state_label) { |
| 637 } | 645 } |
| OLD | NEW |