Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Unified Diff: chrome/browser/autofill/credit_card.cc

Issue 7125004: Support named months for Autofill implicit learning (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/autofill/credit_card_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/autofill/credit_card.cc
diff --git a/chrome/browser/autofill/credit_card.cc b/chrome/browser/autofill/credit_card.cc
index 8abf7fa7b13a82699391a58798178c8d787712c8..39221fbc52f112d145ee14fad2e088153dbbae0a 100644
--- a/chrome/browser/autofill/credit_card.cc
+++ b/chrome/browser/autofill/credit_card.cc
@@ -14,12 +14,15 @@
#include "base/string_split.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/autofill/autofill_country.h"
#include "chrome/browser/autofill/autofill_regexes.h"
#include "chrome/browser/autofill/autofill_type.h"
#include "chrome/browser/autofill/field_types.h"
#include "chrome/common/guid.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
+#include "unicode/dtfmtsym.h"
+#include "unicode/uloc.h"
namespace {
@@ -119,18 +122,55 @@ std::string GetCreditCardType(const string16& number) {
return kGenericCard;
}
-bool ConvertDate(const string16& date, int* num) {
- if (!date.empty()) {
- bool converted = base::StringToInt(date, num);
- DCHECK(converted);
- if (!converted)
- return false;
- } else {
- // Clear the value.
+bool ConvertDate(const string16& date, bool is_month, int* num) {
dhollowa 2011/06/07 16:33:00 This feels like it is really two separate function
Ilya Sherman 2011/06/08 00:10:12 Done.
+ // If the |date| is empty, clear the value.
+ if (date.empty()) {
*num = 0;
+ return true;
+ }
+
+ // Try parsing the |date| as a number.
+ if (base::StringToInt(date, num))
+ return true;
+
+ // Try parsing the |date| as a named month, e.g. "January" or "Jan".
+ if (is_month) {
+ string16 lowercased_date = StringToLowerASCII(date);
+
+ UErrorCode status = U_ZERO_ERROR;
+ icu::Locale locale(AutofillCountry::ApplicationLocale().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 string16 month = string16(months[i].getBuffer(),
+ months[i].length());
+ if (lowercased_date == StringToLowerASCII(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 string16 month = string16(months[i].getBuffer(),
+ months[i].length());
+ if (lowercased_date == StringToLowerASCII(month)) {
+ *num = i + 1; // Adjust from 0-indexed to 1-indexed.
+ return true;
+ }
+ }
}
- return true;
+
dhollowa 2011/06/07 16:33:00 nit: extra space.
Ilya Sherman 2011/06/08 00:10:12 Done.
+
+ NOTREACHED();
+ *num = 0;
+ return false;
}
} // namespace
@@ -482,7 +522,7 @@ string16 CreditCard::Expiration2DigitYearAsString() const {
void CreditCard::SetExpirationMonthFromString(const string16& text) {
int month;
- if (!ConvertDate(text, &month))
+ if (!ConvertDate(text, true, &month))
return;
SetExpirationMonth(month);
@@ -490,7 +530,7 @@ void CreditCard::SetExpirationMonthFromString(const string16& text) {
void CreditCard::SetExpirationYearFromString(const string16& text) {
int year;
- if (!ConvertDate(text, &year))
+ if (!ConvertDate(text, false, &year))
return;
SetExpirationYear(year);
« no previous file with comments | « no previous file | chrome/browser/autofill/credit_card_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698