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

Side by Side Diff: chrome/browser/autofill/credit_card.cc

Issue 3013043: AutoFill: Remove a static string16. (Closed)
Patch Set: One line. Created 10 years, 4 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/autofill/autofill_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/string16.h"
10 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/autofill/autofill_type.h" 12 #include "chrome/browser/autofill/autofill_type.h"
12 #include "chrome/browser/autofill/field_types.h" 13 #include "chrome/browser/autofill/field_types.h"
13 #include "grit/generated_resources.h" 14 #include "grit/generated_resources.h"
14 15
15 static const string16 kCreditCardSeparators = ASCIIToUTF16(" -"); 16 namespace {
16 static const char* kCreditCardObfuscationString = "************";
17 17
18 static const AutoFillFieldType kAutoFillCreditCardTypes[] = { 18 const string16::value_type kCreditCardSeparators[] = {' ','-',0};
19 const char* kCreditCardObfuscationString = "************";
20
21 const AutoFillFieldType kAutoFillCreditCardTypes[] = {
19 CREDIT_CARD_NAME, 22 CREDIT_CARD_NAME,
20 CREDIT_CARD_NUMBER, 23 CREDIT_CARD_NUMBER,
21 CREDIT_CARD_TYPE, 24 CREDIT_CARD_TYPE,
22 CREDIT_CARD_EXP_MONTH, 25 CREDIT_CARD_EXP_MONTH,
23 CREDIT_CARD_EXP_4_DIGIT_YEAR, 26 CREDIT_CARD_EXP_4_DIGIT_YEAR,
24 }; 27 };
25 28
26 static const int kAutoFillCreditCardLength = 29 const int kAutoFillCreditCardLength = arraysize(kAutoFillCreditCardTypes);
27 arraysize(kAutoFillCreditCardTypes); 30
31 } // namespace
28 32
29 CreditCard::CreditCard(const string16& label, int unique_id) 33 CreditCard::CreditCard(const string16& label, int unique_id)
30 : expiration_month_(0), 34 : expiration_month_(0),
31 expiration_year_(0), 35 expiration_year_(0),
32 label_(label), 36 label_(label),
33 unique_id_(unique_id) { 37 unique_id_(unique_id) {
34 } 38 }
35 39
36 CreditCard::CreditCard(const CreditCard& card) : FormGroup() { 40 CreditCard::CreditCard(const CreditCard& card) : FormGroup() {
37 operator=(card); 41 operator=(card);
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 } 306 }
303 307
304 bool CreditCard::operator!=(const CreditCard& creditcard) const { 308 bool CreditCard::operator!=(const CreditCard& creditcard) const {
305 return !operator==(creditcard); 309 return !operator==(creditcard);
306 } 310 }
307 311
308 // Use the Luhn formula to validate the number. 312 // Use the Luhn formula to validate the number.
309 // static 313 // static
310 bool CreditCard::IsCreditCardNumber(const string16& text) { 314 bool CreditCard::IsCreditCardNumber(const string16& text) {
311 string16 number; 315 string16 number;
312 RemoveChars(text, kCreditCardSeparators.c_str(), &number); 316 RemoveChars(text, kCreditCardSeparators, &number);
313 317
314 int sum = 0; 318 int sum = 0;
315 bool odd = false; 319 bool odd = false;
316 string16::reverse_iterator iter; 320 string16::reverse_iterator iter;
317 for (iter = number.rbegin(); iter != number.rend(); ++iter) { 321 for (iter = number.rbegin(); iter != number.rend(); ++iter) {
318 if (!IsAsciiDigit(*iter)) 322 if (!IsAsciiDigit(*iter))
319 return false; 323 return false;
320 324
321 int digit = *iter - '0'; 325 int digit = *iter - '0';
322 if (odd) { 326 if (odd) {
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 << UTF16ToUTF8(creditcard.GetFieldText(AutoFillType(CREDIT_CARD_TYPE))) 522 << UTF16ToUTF8(creditcard.GetFieldText(AutoFillType(CREDIT_CARD_TYPE)))
519 << " " 523 << " "
520 << UTF16ToUTF8(creditcard.GetFieldText(AutoFillType(CREDIT_CARD_NUMBER))) 524 << UTF16ToUTF8(creditcard.GetFieldText(AutoFillType(CREDIT_CARD_NUMBER)))
521 << " " 525 << " "
522 << UTF16ToUTF8(creditcard.GetFieldText( 526 << UTF16ToUTF8(creditcard.GetFieldText(
523 AutoFillType(CREDIT_CARD_EXP_MONTH))) 527 AutoFillType(CREDIT_CARD_EXP_MONTH)))
524 << " " 528 << " "
525 << UTF16ToUTF8(creditcard.GetFieldText( 529 << UTF16ToUTF8(creditcard.GetFieldText(
526 AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR))); 530 AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR)));
527 } 531 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698