Chromium Code Reviews| Index: components/autofill/core/browser/autofill_field.cc |
| diff --git a/components/autofill/core/browser/autofill_field.cc b/components/autofill/core/browser/autofill_field.cc |
| index c5b696e933c2721bda73b265aeddc2e89b5d1a89..421195f9dbf9c974ac2b33742f41a6e4127c17fe 100644 |
| --- a/components/autofill/core/browser/autofill_field.cc |
| +++ b/components/autofill/core/browser/autofill_field.cc |
| @@ -280,23 +280,8 @@ bool FillCreditCardTypeSelectControl(const base::string16& value, |
| void FillPhoneNumberField(const AutofillField& field, |
| const base::string16& number, |
| FormFieldData* field_data) { |
| - // Check to see if the size field matches the "prefix" or "suffix" sizes and |
| - // fill accordingly. |
| - base::string16 value = number; |
| - if (number.length() == |
| - PhoneNumber::kPrefixLength + PhoneNumber::kSuffixLength) { |
| - if (field.phone_part() == AutofillField::PHONE_PREFIX || |
| - field_data->max_length == PhoneNumber::kPrefixLength) { |
| - value = number.substr(PhoneNumber::kPrefixOffset, |
| - PhoneNumber::kPrefixLength); |
| - } else if (field.phone_part() == AutofillField::PHONE_SUFFIX || |
| - field_data->max_length == PhoneNumber::kSuffixLength) { |
| - value = number.substr(PhoneNumber::kSuffixOffset, |
| - PhoneNumber::kSuffixLength); |
| - } |
| - } |
| - |
| - field_data->value = value; |
| + field_data->value = |
| + AutofillField::GetPhoneNumberValue(field, number, *field_data); |
| } |
| // Fills in the select control |field| with |value|. If an exact match is not |
| @@ -493,4 +478,33 @@ bool AutofillField::FillFormField(const AutofillField& field, |
| return true; |
| } |
| +// Returns the phone number value for the given |field|. The returned value |
| +// might be |number|, or could possibly be a prefix or suffix of |number| |
| +// if that's appropriate for the field. |
|
Ilya Sherman
2014/09/22 21:24:02
nit: No need to duplicate the comment from the hea
|
| +base::string16 AutofillField::GetPhoneNumberValue( |
| + const AutofillField& field, |
| + const base::string16& number, |
| + const FormFieldData& field_data) { |
| + // Check to see if the size field matches the "prefix" or "suffix" size. |
| + // If so, return the appropriate substring. |
| + if (number.length() != |
| + PhoneNumber::kPrefixLength + PhoneNumber::kSuffixLength) { |
| + return number; |
| + } |
| + |
| + if (field.phone_part() == AutofillField::PHONE_PREFIX || |
| + field_data.max_length == PhoneNumber::kPrefixLength) { |
| + return |
| + number.substr(PhoneNumber::kPrefixOffset, PhoneNumber::kPrefixLength); |
| + } |
| + |
| + if (field.phone_part() == AutofillField::PHONE_SUFFIX || |
| + field_data.max_length == PhoneNumber::kSuffixLength) { |
| + return |
| + number.substr(PhoneNumber::kSuffixOffset, PhoneNumber::kSuffixLength); |
| + } |
| + |
| + return number; |
| +} |
| + |
| } // namespace autofill |