| OLD | NEW | 
|    1 // Copyright 2017 The Chromium Authors. All rights reserved. |    1 // Copyright 2017 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/payments/core/payment_request_data_util.h" |    5 #include "components/payments/core/payment_request_data_util.h" | 
|    6  |    6  | 
|    7 #include "base/strings/string16.h" |    7 #include "base/strings/string16.h" | 
|    8 #include "base/strings/string_split.h" |    8 #include "base/strings/string_split.h" | 
 |    9 #include "base/strings/string_util.h" | 
|    9 #include "base/strings/utf_string_conversions.h" |   10 #include "base/strings/utf_string_conversions.h" | 
|   10 #include "components/autofill/core/browser/autofill_country.h" |   11 #include "components/autofill/core/browser/autofill_country.h" | 
|   11 #include "components/autofill/core/browser/autofill_data_util.h" |   12 #include "components/autofill/core/browser/autofill_data_util.h" | 
|   12 #include "components/autofill/core/browser/autofill_profile.h" |   13 #include "components/autofill/core/browser/autofill_profile.h" | 
|   13 #include "components/autofill/core/browser/credit_card.h" |   14 #include "components/autofill/core/browser/credit_card.h" | 
|   14 #include "components/autofill/core/browser/field_types.h" |   15 #include "components/autofill/core/browser/field_types.h" | 
|   15 #include "components/autofill/core/browser/personal_data_manager.h" |   16 #include "components/autofill/core/browser/personal_data_manager.h" | 
|   16 #include "components/autofill/core/browser/validation.h" |   17 #include "components/autofill/core/browser/validation.h" | 
|   17 #include "components/payments/core/basic_card_response.h" |   18 #include "components/payments/core/basic_card_response.h" | 
|   18 #include "components/payments/core/payment_address.h" |   19 #include "components/payments/core/payment_address.h" | 
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  184   return FormatPhoneNumber(phone_number, country_code, |  185   return FormatPhoneNumber(phone_number, country_code, | 
|  185                            PhoneNumberUtil::PhoneNumberFormat::INTERNATIONAL); |  186                            PhoneNumberUtil::PhoneNumberFormat::INTERNATIONAL); | 
|  186 } |  187 } | 
|  187  |  188  | 
|  188 std::string FormatPhoneForResponse(const std::string& phone_number, |  189 std::string FormatPhoneForResponse(const std::string& phone_number, | 
|  189                                    const std::string& country_code) { |  190                                    const std::string& country_code) { | 
|  190   return FormatPhoneNumber(phone_number, country_code, |  191   return FormatPhoneNumber(phone_number, country_code, | 
|  191                            PhoneNumberUtil::PhoneNumberFormat::E164); |  192                            PhoneNumberUtil::PhoneNumberFormat::E164); | 
|  192 } |  193 } | 
|  193  |  194  | 
 |  195 base::string16 FormatCardNumberForDisplay(const base::string16& card_number) { | 
 |  196   base::string16 number = autofill::CreditCard::StripSeparators(card_number); | 
 |  197   if (number.empty() || !base::IsAsciiDigit(number[0])) | 
 |  198     return card_number; | 
 |  199  | 
 |  200   std::vector<size_t> positions = {4U, 9U, 14U}; | 
 |  201   if (autofill::CreditCard::GetCardNetwork(number) == | 
 |  202       autofill::kAmericanExpressCard) { | 
 |  203     positions = {4U, 11U}; | 
 |  204   } | 
 |  205  | 
 |  206   static const base::char16 kSeparator = base::ASCIIToUTF16(" ")[0]; | 
 |  207   for (size_t i : positions) { | 
 |  208     if (number.size() > i) | 
 |  209       number.insert(i, 1U, kSeparator); | 
 |  210   } | 
 |  211  | 
 |  212   return number; | 
 |  213 } | 
 |  214  | 
|  194 std::string GetCountryCodeWithFallback(const autofill::AutofillProfile* profile, |  215 std::string GetCountryCodeWithFallback(const autofill::AutofillProfile* profile, | 
|  195                                        const std::string& app_locale) { |  216                                        const std::string& app_locale) { | 
|  196   std::string country_code = |  217   std::string country_code = | 
|  197       base::UTF16ToUTF8(profile->GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)); |  218       base::UTF16ToUTF8(profile->GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)); | 
|  198   if (!autofill::data_util::IsValidCountryCode(country_code)) |  219   if (!autofill::data_util::IsValidCountryCode(country_code)) | 
|  199     country_code = autofill::AutofillCountry::CountryCodeForLocale(app_locale); |  220     country_code = autofill::AutofillCountry::CountryCodeForLocale(app_locale); | 
|  200   return country_code; |  221   return country_code; | 
|  201 } |  222 } | 
|  202  |  223  | 
|  203 }  // namespace data_util |  224 }  // namespace data_util | 
|  204 }  // namespace payments |  225 }  // namespace payments | 
| OLD | NEW |