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/credit_card_field.h" | 5 #include "components/autofill/core/browser/credit_card_field.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
367 static int kMinimum2YearCcExpLength = strlen("12/14"); | 367 static int kMinimum2YearCcExpLength = strlen("12/14"); |
368 int current_field_max_length = scanner->Cursor()->max_length; | 368 int current_field_max_length = scanner->Cursor()->max_length; |
369 if (current_field_max_length > 0 && | 369 if (current_field_max_length > 0 && |
370 current_field_max_length < kMinimum2YearCcExpLength) { | 370 current_field_max_length < kMinimum2YearCcExpLength) { |
371 return false; | 371 return false; |
372 } | 372 } |
373 | 373 |
374 if (ParseFieldSpecifics(scanner, | 374 if (ParseFieldSpecifics(scanner, |
375 base::UTF8ToUTF16(kExpirationDate2DigitYearRe), | 375 base::UTF8ToUTF16(kExpirationDate2DigitYearRe), |
376 kMatchTelAndSelect, | 376 kMatchTelAndSelect, |
377 &expiration_date_) || | |
378 ParseFieldSpecifics(scanner, | |
379 base::ASCIIToUTF16("^mm\\s*[-/]\\syy$"), | |
Evan Stade
2015/04/01 23:11:29
can you add comment explaining why this isn't just
Lei Zhang
2015/04/03 02:02:01
Sure.
| |
380 kMatchTelAndSelect, | |
377 &expiration_date_)) { | 381 &expiration_date_)) { |
378 exp_year_type_ = CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR; | 382 exp_year_type_ = CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR; |
379 expiration_month_ = nullptr; | 383 expiration_month_ = nullptr; |
380 return true; | 384 return true; |
381 } | 385 } |
382 | 386 |
383 | 387 |
384 if (ParseFieldSpecifics(scanner, | 388 if (ParseFieldSpecifics(scanner, |
385 base::UTF8ToUTF16(kExpirationDateRe), | 389 base::UTF8ToUTF16(kExpirationDateRe), |
386 kMatchTelAndSelect, | 390 kMatchTelAndSelect, |
387 &expiration_date_)) { | 391 &expiration_date_)) { |
388 if (current_field_max_length > 0 && | 392 if (current_field_max_length > 0 && |
389 current_field_max_length < kMinimum4YearCcExpLength) { | 393 current_field_max_length < kMinimum4YearCcExpLength) { |
390 exp_year_type_ = CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR; | 394 exp_year_type_ = CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR; |
391 } | 395 } |
392 expiration_month_ = nullptr; | 396 expiration_month_ = nullptr; |
393 return true; | 397 return true; |
394 } | 398 } |
395 | 399 |
400 if (current_field_max_length > 0 && | |
401 current_field_max_length < kMinimum4YearCcExpLength) { | |
402 return false; | |
403 } | |
404 | |
405 | |
406 if (ParseFieldSpecifics(scanner, | |
407 base::ASCIIToUTF16("^mm\\s*[-/]\\syyyy$"), | |
Evan Stade
2015/04/01 23:11:30
ditto. Why isn't this part of the other regex, and
Lei Zhang
2015/04/03 02:02:01
I reworked the code a little and added more commen
| |
408 kMatchTelAndSelect, | |
409 &expiration_date_)) { | |
410 expiration_month_ = nullptr; | |
411 return true; | |
412 } | |
413 | |
396 return false; | 414 return false; |
397 } | 415 } |
398 | 416 |
399 ServerFieldType CreditCardField::GetExpirationYearType() const { | 417 ServerFieldType CreditCardField::GetExpirationYearType() const { |
400 return (expiration_date_ | 418 return (expiration_date_ |
401 ? exp_year_type_ | 419 ? exp_year_type_ |
402 : ((expiration_year_ && expiration_year_->max_length == 2) | 420 : ((expiration_year_ && expiration_year_->max_length == 2) |
403 ? CREDIT_CARD_EXP_2_DIGIT_YEAR | 421 ? CREDIT_CARD_EXP_2_DIGIT_YEAR |
404 : CREDIT_CARD_EXP_4_DIGIT_YEAR)); | 422 : CREDIT_CARD_EXP_4_DIGIT_YEAR)); |
405 } | 423 } |
406 | 424 |
407 } // namespace autofill | 425 } // namespace autofill |
OLD | NEW |