OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/credit_card.h" | 5 #include "chrome/browser/autofill/credit_card.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "base/string_number_conversions.h" |
12 #include "base/string16.h" | 13 #include "base/string16.h" |
13 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
14 #include "chrome/browser/autofill/autofill_type.h" | 15 #include "chrome/browser/autofill/autofill_type.h" |
15 #include "chrome/browser/autofill/field_types.h" | 16 #include "chrome/browser/autofill/field_types.h" |
16 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
20 const string16::value_type kCreditCardSeparators[] = {' ','-',0}; | 21 const string16::value_type kCreditCardSeparators[] = {' ','-',0}; |
21 const char* kCreditCardObfuscationString = "************"; | 22 const char* kCreditCardObfuscationString = "************"; |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 FieldTypeSet types; | 432 FieldTypeSet types; |
432 GetAvailableFieldTypes(&types); | 433 GetAvailableFieldTypes(&types); |
433 return types.empty() && billing_address().empty(); | 434 return types.empty() && billing_address().empty(); |
434 } | 435 } |
435 | 436 |
436 | 437 |
437 string16 CreditCard::ExpirationMonthAsString() const { | 438 string16 CreditCard::ExpirationMonthAsString() const { |
438 if (expiration_month_ == 0) | 439 if (expiration_month_ == 0) |
439 return string16(); | 440 return string16(); |
440 | 441 |
441 string16 month = IntToString16(expiration_month_); | 442 string16 month = base::IntToString16(expiration_month_); |
442 if (expiration_month_ >= 10) | 443 if (expiration_month_ >= 10) |
443 return month; | 444 return month; |
444 | 445 |
445 string16 zero = ASCIIToUTF16("0"); | 446 string16 zero = ASCIIToUTF16("0"); |
446 zero.append(month); | 447 zero.append(month); |
447 return zero; | 448 return zero; |
448 } | 449 } |
449 | 450 |
450 string16 CreditCard::Expiration4DigitYearAsString() const { | 451 string16 CreditCard::Expiration4DigitYearAsString() const { |
451 if (expiration_year_ == 0) | 452 if (expiration_year_ == 0) |
452 return string16(); | 453 return string16(); |
453 | 454 |
454 return IntToString16(Expiration4DigitYear()); | 455 return base::IntToString16(Expiration4DigitYear()); |
455 } | 456 } |
456 | 457 |
457 string16 CreditCard::Expiration2DigitYearAsString() const { | 458 string16 CreditCard::Expiration2DigitYearAsString() const { |
458 if (expiration_year_ == 0) | 459 if (expiration_year_ == 0) |
459 return string16(); | 460 return string16(); |
460 | 461 |
461 return IntToString16(Expiration2DigitYear()); | 462 return base::IntToString16(Expiration2DigitYear()); |
462 } | 463 } |
463 | 464 |
464 void CreditCard::SetExpirationMonthFromString(const string16& text) { | 465 void CreditCard::SetExpirationMonthFromString(const string16& text) { |
465 int month; | 466 int month; |
466 if (!ConvertDate(text, &month)) | 467 if (!ConvertDate(text, &month)) |
467 return; | 468 return; |
468 | 469 |
469 set_expiration_month(month); | 470 set_expiration_month(month); |
470 } | 471 } |
471 | 472 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 } | 557 } |
557 return !match->empty(); | 558 return !match->empty(); |
558 } | 559 } |
559 | 560 |
560 bool CreditCard::IsNameOnCard(const string16& text) const { | 561 bool CreditCard::IsNameOnCard(const string16& text) const { |
561 return StringToLowerASCII(text) == StringToLowerASCII(name_on_card_); | 562 return StringToLowerASCII(text) == StringToLowerASCII(name_on_card_); |
562 } | 563 } |
563 | 564 |
564 bool CreditCard::IsExpirationMonth(const string16& text) const { | 565 bool CreditCard::IsExpirationMonth(const string16& text) const { |
565 int month; | 566 int month; |
566 if (!StringToInt(text, &month)) | 567 if (!base::StringToInt(text, &month)) |
567 return false; | 568 return false; |
568 | 569 |
569 return expiration_month_ == month; | 570 return expiration_month_ == month; |
570 } | 571 } |
571 | 572 |
572 bool CreditCard::Is2DigitExpirationYear(const string16& text) const { | 573 bool CreditCard::Is2DigitExpirationYear(const string16& text) const { |
573 int year; | 574 int year; |
574 if (!StringToInt(text, &year)) | 575 if (!base::StringToInt(text, &year)) |
575 return false; | 576 return false; |
576 | 577 |
577 return year < 100 && (expiration_year_ % 100) == year; | 578 return year < 100 && (expiration_year_ % 100) == year; |
578 } | 579 } |
579 | 580 |
580 bool CreditCard::Is4DigitExpirationYear(const string16& text) const { | 581 bool CreditCard::Is4DigitExpirationYear(const string16& text) const { |
581 int year; | 582 int year; |
582 if (!StringToInt(text, &year)) | 583 if (!base::StringToInt(text, &year)) |
583 return false; | 584 return false; |
584 | 585 |
585 return expiration_year_ == year; | 586 return expiration_year_ == year; |
586 } | 587 } |
587 | 588 |
588 bool CreditCard::ConvertDate(const string16& date, int* num) const { | 589 bool CreditCard::ConvertDate(const string16& date, int* num) const { |
589 if (!date.empty()) { | 590 if (!date.empty()) { |
590 bool converted = StringToInt(date, num); | 591 bool converted = base::StringToInt(date, num); |
591 DCHECK(converted); | 592 DCHECK(converted); |
592 if (!converted) | 593 if (!converted) |
593 return false; | 594 return false; |
594 } else { | 595 } else { |
595 // Clear the value. | 596 // Clear the value. |
596 *num = 0; | 597 *num = 0; |
597 } | 598 } |
598 | 599 |
599 return true; | 600 return true; |
600 } | 601 } |
(...skipping 12 matching lines...) Expand all Loading... |
613 << UTF16ToUTF8(creditcard.GetFieldText(AutoFillType(CREDIT_CARD_TYPE))) | 614 << UTF16ToUTF8(creditcard.GetFieldText(AutoFillType(CREDIT_CARD_TYPE))) |
614 << " " | 615 << " " |
615 << UTF16ToUTF8(creditcard.GetFieldText(AutoFillType(CREDIT_CARD_NUMBER))) | 616 << UTF16ToUTF8(creditcard.GetFieldText(AutoFillType(CREDIT_CARD_NUMBER))) |
616 << " " | 617 << " " |
617 << UTF16ToUTF8(creditcard.GetFieldText( | 618 << UTF16ToUTF8(creditcard.GetFieldText( |
618 AutoFillType(CREDIT_CARD_EXP_MONTH))) | 619 AutoFillType(CREDIT_CARD_EXP_MONTH))) |
619 << " " | 620 << " " |
620 << UTF16ToUTF8(creditcard.GetFieldText( | 621 << UTF16ToUTF8(creditcard.GetFieldText( |
621 AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR))); | 622 AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR))); |
622 } | 623 } |
OLD | NEW |