Commit c8d5787e authored by Caitlin Fischer's avatar Caitlin Fischer Committed by Commit Bot

[Autofill] Added function to get nationally formatted phone numbers.

Change-Id: Ieea938de39081ef958fc82d0c971ededd8214b63
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1504117Reviewed-by: default avatarTommy Martino <tmartino@chromium.org>
Auto-Submit: Caitlin Fischer <caitlinfischer@google.com>
Commit-Queue: Caitlin Fischer <caitlinfischer@google.com>
Cr-Commit-Position: refs/heads/master@{#637825}
parent ea568d28
...@@ -329,6 +329,15 @@ base::string16 GetFormattedPhoneNumberForDisplay(const AutofillProfile& profile, ...@@ -329,6 +329,15 @@ base::string16 GetFormattedPhoneNumberForDisplay(const AutofillProfile& profile,
return base::UTF8ToUTF16(phone); return base::UTF8ToUTF16(phone);
} }
std::string FormatPhoneNationallyForDisplay(const std::string& phone_number,
const std::string& country_code) {
if (IsValidPhoneNumber(phone_number, country_code)) {
return FormatPhoneNumber(phone_number, country_code,
PhoneNumberUtil::PhoneNumberFormat::NATIONAL);
}
return phone_number;
}
std::string FormatPhoneForDisplay(const std::string& phone_number, std::string FormatPhoneForDisplay(const std::string& phone_number,
const std::string& country_code) { const std::string& country_code) {
if (IsValidPhoneNumber(phone_number, country_code)) { if (IsValidPhoneNumber(phone_number, country_code)) {
......
...@@ -90,12 +90,18 @@ bool PhoneNumbersMatch(const base::string16& number_a, ...@@ -90,12 +90,18 @@ bool PhoneNumbersMatch(const base::string16& number_a,
const std::string& app_locale); const std::string& app_locale);
// Returns the phone number from the given |profile| formatted for display. // Returns the phone number from the given |profile| formatted for display.
// If it's valid number for the country of profile, or for the |locale| given // If it's a valid number for the profile's country or for the |locale| given
// as a fall back, return the number in internaional format; otherwise return // as a fallback, returns the number in international format; otherwise returns
// the raw number string from profile. // the raw number string from profile.
base::string16 GetFormattedPhoneNumberForDisplay(const AutofillProfile& profile, base::string16 GetFormattedPhoneNumberForDisplay(const AutofillProfile& profile,
const std::string& locale); const std::string& locale);
// Returns |phone_number| in i18n::phonenumbers::PhoneNumberUtil::
// PhoneNumberFormat::NATIONAL format if the number is valid for
// |country_code|. Otherwise, returns the given |phone_number|.
std::string FormatPhoneNationallyForDisplay(const std::string& phone_number,
const std::string& country_code);
// Formats the given number |phone_number| to // Formats the given number |phone_number| to
// i18n::phonenumbers::PhoneNumberUtil::PhoneNumberFormat::INTERNATIONAL format // i18n::phonenumbers::PhoneNumberUtil::PhoneNumberFormat::INTERNATIONAL format
// by using i18n::phonenumbers::PhoneNumberUtil::Format. // by using i18n::phonenumbers::PhoneNumberUtil::Format.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment