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 0bedb8649657d135c8c0facf1b864a834951caf0..8822bd883098f5510d60cc48209e481d71518a1b 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); |
} |
// Set |field_data|'s value to |number|, or possibly an appropriate substring |
@@ -515,4 +500,30 @@ bool AutofillField::FillFormField(const AutofillField& field, |
return true; |
} |
+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 |