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 <map> | 7 #include <map> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 379 std::string likely_locale; | 379 std::string likely_locale; |
| 380 UErrorCode error_ignored = U_ZERO_ERROR; | 380 UErrorCode error_ignored = U_ZERO_ERROR; |
| 381 uloc_addLikelySubtags(locale.c_str(), | 381 uloc_addLikelySubtags(locale.c_str(), |
| 382 WriteInto(&likely_locale, kLocaleCapacity), | 382 WriteInto(&likely_locale, kLocaleCapacity), |
| 383 kLocaleCapacity, | 383 kLocaleCapacity, |
| 384 &error_ignored); | 384 &error_ignored); |
| 385 | 385 |
| 386 // Extract the country code. | 386 // Extract the country code. |
| 387 std::string country_code = icu::Locale(likely_locale.c_str()).getCountry(); | 387 std::string country_code = icu::Locale(likely_locale.c_str()).getCountry(); |
| 388 | 388 |
| 389 // Default to the United States if we have no better guess. | 389 // Default to the United States if we have no better guess. Consider the |
| 390 return !country_code.empty() ? country_code : "US"; | 390 // country code invalid if it is empty or contains any character other |
| 391 // than A-Z. | |
| 392 if (country_code.empty() || | |
| 393 country_code.find_first_not_of("ABCDEFGHIJKLMNOPQRSTUVWXYZ") != | |
| 394 std::string::npos) | |
|
Ilya Sherman
2011/03/08 10:35:18
Probably the right check here is actually to see i
satorux1
2011/03/08 11:28:10
Done.
| |
| 395 return "US"; | |
| 396 return country_code; | |
| 391 } | 397 } |
| 392 | 398 |
| 393 // static | 399 // static |
| 394 const std::string AutofillCountry::GetCountryCode( | 400 const std::string AutofillCountry::GetCountryCode( |
| 395 const string16& country, const std::string& locale) { | 401 const string16& country, const std::string& locale) { |
| 396 // First, check for a few common synonyms. | 402 // First, check for a few common synonyms. |
| 397 if (country == ASCIIToUTF16("United States of America")) | 403 if (country == ASCIIToUTF16("United States of America")) |
| 398 return "US"; | 404 return "US"; |
| 399 if (country == ASCIIToUTF16("Great Britain") || | 405 if (country == ASCIIToUTF16("Great Britain") || |
| 400 country == ASCIIToUTF16("UK")) | 406 country == ASCIIToUTF16("UK")) |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 453 | 459 |
| 454 AutofillCountry::AutofillCountry(const std::string& country_code, | 460 AutofillCountry::AutofillCountry(const std::string& country_code, |
| 455 const string16& name, | 461 const string16& name, |
| 456 const string16& postal_code_label, | 462 const string16& postal_code_label, |
| 457 const string16& state_label) | 463 const string16& state_label) |
| 458 : country_code_(country_code), | 464 : country_code_(country_code), |
| 459 name_(name), | 465 name_(name), |
| 460 postal_code_label_(postal_code_label), | 466 postal_code_label_(postal_code_label), |
| 461 state_label_(state_label) { | 467 state_label_(state_label) { |
| 462 } | 468 } |
| OLD | NEW |