Chromium Code Reviews| Index: components/autofill/core/browser/credit_card.cc |
| diff --git a/components/autofill/core/browser/credit_card.cc b/components/autofill/core/browser/credit_card.cc |
| index 85bad41ffd98eca579d1f5e42657e5b029d2f539..fe6b492e69677f5cf1e48ea247f3a5859d44d238 100644 |
| --- a/components/autofill/core/browser/credit_card.cc |
| +++ b/components/autofill/core/browser/credit_card.cc |
| @@ -23,6 +23,7 @@ |
| #include "components/autofill/core/browser/autofill_regexes.h" |
| #include "components/autofill/core/browser/autofill_type.h" |
| #include "components/autofill/core/browser/validation.h" |
| +#include "components/autofill/core/common/autofill_l10n_util.h" |
| #include "components/autofill/core/common/form_field_data.h" |
| #include "grit/components_scaled_resources.h" |
| #include "grit/components_strings.h" |
| @@ -51,58 +52,6 @@ bool ConvertYear(const base::string16& year, int* num) { |
| return false; |
| } |
| -bool ConvertMonth(const base::string16& month, |
| - const std::string& app_locale, |
| - int* num) { |
| - // If the |month| is empty, clear the stored value. |
| - if (month.empty()) { |
| - *num = 0; |
| - return true; |
| - } |
| - |
| - // Try parsing the |month| as a number. |
| - if (base::StringToInt(month, num)) |
| - return true; |
| - |
| - // If the locale is unknown, give up. |
| - if (app_locale.empty()) |
| - return false; |
| - |
| - // Otherwise, try parsing the |month| as a named month, e.g. "January" or |
| - // "Jan". |
| - base::string16 lowercased_month = base::StringToLowerASCII(month); |
| - |
| - UErrorCode status = U_ZERO_ERROR; |
| - icu::Locale locale(app_locale.c_str()); |
| - icu::DateFormatSymbols date_format_symbols(locale, status); |
| - DCHECK(status == U_ZERO_ERROR || status == U_USING_FALLBACK_WARNING || |
| - status == U_USING_DEFAULT_WARNING); |
| - |
| - int32_t num_months; |
| - const icu::UnicodeString* months = date_format_symbols.getMonths(num_months); |
| - for (int32_t i = 0; i < num_months; ++i) { |
| - const base::string16 icu_month = base::string16(months[i].getBuffer(), |
| - months[i].length()); |
| - if (lowercased_month == base::StringToLowerASCII(icu_month)) { |
| - *num = i + 1; // Adjust from 0-indexed to 1-indexed. |
| - return true; |
| - } |
| - } |
| - |
| - months = date_format_symbols.getShortMonths(num_months); |
| - for (int32_t i = 0; i < num_months; ++i) { |
| - const base::string16 icu_month = base::string16(months[i].getBuffer(), |
| - months[i].length()); |
| - if (lowercased_month == base::StringToLowerASCII(icu_month)) { |
| - *num = i + 1; // Adjust from 0-indexed to 1-indexed. |
| - return true; |
| - } |
| - } |
| - |
| - *num = 0; |
| - return false; |
| -} |
| - |
| base::string16 TypeForFill(const std::string& type) { |
| if (type == kAmericanExpressCard) |
| return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_AMEX); |
| @@ -757,6 +706,61 @@ void CreditCard::SetNumber(const base::string16& number) { |
| type_ = GetCreditCardType(StripSeparators(number_)); |
| } |
| +// static |
| +bool CreditCard::ConvertMonth(const base::string16& month, |
| + const std::string& app_locale, |
| + int* num) { |
| + // If the |month| is empty, clear the stored value. |
| + if (month.empty()) { |
| + *num = 0; |
| + return true; |
|
Lei Zhang
2015/04/13 19:59:13
I wonder if this should return false. It's not a s
Evan Stade
2015/04/13 21:34:13
good point. It makes more sense if this check is m
|
| + } |
| + |
| + // Try parsing the |month| as a number. |
| + if (base::StringToInt(month, num)) |
| + return true; |
| + |
| + // If the locale is unknown, give up. |
| + if (app_locale.empty()) |
| + return false; |
| + |
| + // Otherwise, try parsing the |month| as a named month, e.g. "January" or |
| + // "Jan". |
| + l10n::CaseInsensitiveCompare compare; |
| + UErrorCode status = U_ZERO_ERROR; |
| + icu::Locale locale(app_locale.c_str()); |
| + icu::DateFormatSymbols date_format_symbols(locale, status); |
| + DCHECK(status == U_ZERO_ERROR || status == U_USING_FALLBACK_WARNING || |
| + status == U_USING_DEFAULT_WARNING); |
| + |
| + int32_t num_months; |
| + const icu::UnicodeString* months = date_format_symbols.getMonths(num_months); |
| + for (int32_t i = 0; i < num_months; ++i) { |
| + const base::string16 icu_month(months[i].getBuffer(), months[i].length()); |
| + if (compare.StringsEqual(icu_month, month)) { |
| + *num = i + 1; // Adjust from 0-indexed to 1-indexed. |
| + return true; |
| + } |
| + } |
| + |
| + months = date_format_symbols.getShortMonths(num_months); |
| + // Some abbreviations have . at the end (e.g., "janv." in French). We don't |
| + // care about matching that. |
| + base::string16 trimmed_month; |
| + base::TrimString(month, base::ASCIIToUTF16("."), &trimmed_month); |
| + for (int32_t i = 0; i < num_months; ++i) { |
| + base::string16 icu_month(months[i].getBuffer(), months[i].length()); |
| + base::TrimString(icu_month, base::ASCIIToUTF16("."), &icu_month); |
| + if (compare.StringsEqual(icu_month, trimmed_month)) { |
| + *num = i + 1; // Adjust from 0-indexed to 1-indexed. |
| + return true; |
| + } |
| + } |
| + |
| + *num = 0; |
| + return false; |
| +} |
| + |
| // So we can compare CreditCards with EXPECT_EQ(). |
| std::ostream& operator<<(std::ostream& os, const CreditCard& credit_card) { |
| return os |