| 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/phone_number_i18n.h" | 5 #include "components/autofill/core/browser/phone_number_i18n.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 base::string16* normalized_number) { | 58 base::string16* normalized_number) { |
| 59 PhoneNumberUtil::PhoneNumberFormat format = | 59 PhoneNumberUtil::PhoneNumberFormat format = |
| 60 country_code.empty() ? | 60 country_code.empty() ? |
| 61 PhoneNumberUtil::NATIONAL : | 61 PhoneNumberUtil::NATIONAL : |
| 62 PhoneNumberUtil::INTERNATIONAL; | 62 PhoneNumberUtil::INTERNATIONAL; |
| 63 | 63 |
| 64 PhoneNumberUtil* phone_util = PhoneNumberUtil::GetInstance(); | 64 PhoneNumberUtil* phone_util = PhoneNumberUtil::GetInstance(); |
| 65 std::string processed_number; | 65 std::string processed_number; |
| 66 phone_util->Format(number, format, &processed_number); | 66 phone_util->Format(number, format, &processed_number); |
| 67 | 67 |
| 68 std::string region_code; |
| 69 phone_util->GetRegionCodeForNumber(number, ®ion_code); |
| 70 |
| 71 // Drop the leading '+' for US numbers as some US sites can't handle the "+", |
| 72 // and in the US dialing "+1..." is the same as dialing "1...". |
| 73 std::string prefix; |
| 74 if (processed_number[0] == '+') { |
| 75 processed_number = processed_number.substr(1); |
| 76 if (region_code != "US") |
| 77 prefix = "+"; |
| 78 } |
| 79 |
| 68 if (formatted_number) | 80 if (formatted_number) |
| 69 *formatted_number = base::UTF8ToUTF16(processed_number); | 81 *formatted_number = base::UTF8ToUTF16(prefix + processed_number); |
| 70 | 82 |
| 71 if (normalized_number) { | 83 if (normalized_number) { |
| 72 phone_util->NormalizeDigitsOnly(&processed_number); | 84 phone_util->NormalizeDigitsOnly(&processed_number); |
| 73 *normalized_number = base::UTF8ToUTF16(processed_number); | 85 *normalized_number = base::UTF8ToUTF16(prefix + processed_number); |
| 74 } | 86 } |
| 75 } | 87 } |
| 76 | 88 |
| 77 } // namespace | 89 } // namespace |
| 78 | 90 |
| 79 namespace i18n { | 91 namespace i18n { |
| 80 | 92 |
| 81 // Parses the number stored in |value| as it should be interpreted in the given | 93 // Parses the number stored in |value| as it should be interpreted in the given |
| 82 // |default_region|, and stores the results into the remaining arguments. | 94 // |default_region|, and stores the results into the remaining arguments. |
| 83 // The |default_region| should be sanitized prior to calling this function. | 95 // The |default_region| should be sanitized prior to calling this function. |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 number_ = other.number_; | 305 number_ = other.number_; |
| 294 | 306 |
| 295 formatted_number_ = other.formatted_number_; | 307 formatted_number_ = other.formatted_number_; |
| 296 whole_number_ = other.whole_number_; | 308 whole_number_ = other.whole_number_; |
| 297 | 309 |
| 298 return *this; | 310 return *this; |
| 299 } | 311 } |
| 300 | 312 |
| 301 } // namespace i18n | 313 } // namespace i18n |
| 302 } // namespace autofill | 314 } // namespace autofill |
| OLD | NEW |