| 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 22 matching lines...) Expand all Loading... |
| 33 // consecutive section of |haystack| matches |regex_needles|. | 33 // consecutive section of |haystack| matches |regex_needles|. |
| 34 bool FindConsecutiveStrings(const std::vector<base::string16>& regex_needles, | 34 bool FindConsecutiveStrings(const std::vector<base::string16>& regex_needles, |
| 35 const std::vector<base::string16>& haystack) { | 35 const std::vector<base::string16>& haystack) { |
| 36 if (regex_needles.empty() || | 36 if (regex_needles.empty() || |
| 37 haystack.empty() || | 37 haystack.empty() || |
| 38 (haystack.size() < regex_needles.size())) | 38 (haystack.size() < regex_needles.size())) |
| 39 return false; | 39 return false; |
| 40 | 40 |
| 41 for (size_t i = 0; i < haystack.size() - regex_needles.size() + 1; ++i) { | 41 for (size_t i = 0; i < haystack.size() - regex_needles.size() + 1; ++i) { |
| 42 for (size_t j = 0; j < regex_needles.size(); ++j) { | 42 for (size_t j = 0; j < regex_needles.size(); ++j) { |
| 43 if (!MatchesPattern(haystack[i + j], regex_needles[j])) | 43 if (!MatchesPattern(haystack[i + j], |
| 44 base::UTF16ToASCII(regex_needles[j]))) |
| 44 break; | 45 break; |
| 45 | 46 |
| 46 if (j == regex_needles.size() - 1) | 47 if (j == regex_needles.size() - 1) |
| 47 return true; | 48 return true; |
| 48 } | 49 } |
| 49 } | 50 } |
| 50 return false; | 51 return false; |
| 51 } | 52 } |
| 52 | 53 |
| 53 // Returns true if a field that has |max_length| can fit the data for a field of | 54 // Returns true if a field that has |max_length| can fit the data for a field of |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 return false; | 208 return false; |
| 208 | 209 |
| 209 AutofillField* field = scanner->Cursor(); | 210 AutofillField* field = scanner->Cursor(); |
| 210 if (!MatchesFormControlType(field->form_control_type, MATCH_SELECT)) | 211 if (!MatchesFormControlType(field->form_control_type, MATCH_SELECT)) |
| 211 return false; | 212 return false; |
| 212 | 213 |
| 213 if (field->option_values.size() < 12 || field->option_values.size() > 13) | 214 if (field->option_values.size() < 12 || field->option_values.size() > 13) |
| 214 return false; | 215 return false; |
| 215 | 216 |
| 216 // Filter out years. | 217 // Filter out years. |
| 217 const base::string16 kNumericalYearRe = | 218 const char kNumericalYearRe[] = "[1-9][0-9][0-9][0-9]"; |
| 218 base::ASCIIToUTF16("[1-9][0-9][0-9][0-9]"); | |
| 219 for (const auto& value : field->option_values) { | 219 for (const auto& value : field->option_values) { |
| 220 if (MatchesPattern(value, kNumericalYearRe)) | 220 if (MatchesPattern(value, kNumericalYearRe)) |
| 221 return false; | 221 return false; |
| 222 } | 222 } |
| 223 for (const auto& value : field->option_contents) { | 223 for (const auto& value : field->option_contents) { |
| 224 if (MatchesPattern(value, kNumericalYearRe)) | 224 if (MatchesPattern(value, kNumericalYearRe)) |
| 225 return false; | 225 return false; |
| 226 } | 226 } |
| 227 | 227 |
| 228 // Look for numerical months. | 228 // Look for numerical months. |
| 229 const base::string16 kNumericalMonthRe = base::ASCIIToUTF16("12"); | 229 const char kNumericalMonthRe[] = "12"; |
| 230 if (MatchesPattern(field->option_values.back(), kNumericalMonthRe) || | 230 if (MatchesPattern(field->option_values.back(), kNumericalMonthRe) || |
| 231 MatchesPattern(field->option_contents.back(), kNumericalMonthRe)) { | 231 MatchesPattern(field->option_contents.back(), kNumericalMonthRe)) { |
| 232 return true; | 232 return true; |
| 233 } | 233 } |
| 234 | 234 |
| 235 // Maybe do more matches here. e.g. look for (translated) December. | 235 // Maybe do more matches here. e.g. look for (translated) December. |
| 236 | 236 |
| 237 // Unsure? Return false. | 237 // Unsure? Return false. |
| 238 return false; | 238 return false; |
| 239 } | 239 } |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 | 452 |
| 453 ServerFieldType CreditCardField::GetExpirationYearType() const { | 453 ServerFieldType CreditCardField::GetExpirationYearType() const { |
| 454 return (expiration_date_ | 454 return (expiration_date_ |
| 455 ? exp_year_type_ | 455 ? exp_year_type_ |
| 456 : ((expiration_year_ && expiration_year_->max_length == 2) | 456 : ((expiration_year_ && expiration_year_->max_length == 2) |
| 457 ? CREDIT_CARD_EXP_2_DIGIT_YEAR | 457 ? CREDIT_CARD_EXP_2_DIGIT_YEAR |
| 458 : CREDIT_CARD_EXP_4_DIGIT_YEAR)); | 458 : CREDIT_CARD_EXP_4_DIGIT_YEAR)); |
| 459 } | 459 } |
| 460 | 460 |
| 461 } // namespace autofill | 461 } // namespace autofill |
| OLD | NEW |