Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(103)

Side by Side Diff: components/autofill/core/browser/phone_number_i18n.cc

Issue 355823007: Adjust autofill phone number format. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use "git cl format". Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 if (formatted_number) 68 std::string region_code;
69 *formatted_number = base::UTF8ToUTF16(processed_number); 69 phone_util->GetRegionCodeForNumber(number, &region_code);
70
71 if (formatted_number) {
72 // Drop the leading '+' for US numbers as some US sites can't handle
73 // the "+" and in the US dialing "+1..." is the same as dialing "1...".
74 if (processed_number[0] == '+' && region_code == "US") {
75 *formatted_number = base::UTF8ToUTF16(
76 processed_number.substr(1, processed_number.length()));
Ilya Sherman 2014/07/16 17:50:17 nit: foo.substr(1, foo.length()) is equivalent to
77 } else {
78 *formatted_number = base::UTF8ToUTF16(processed_number);
79 }
80 }
70 81
71 if (normalized_number) { 82 if (normalized_number) {
72 phone_util->NormalizeDigitsOnly(&processed_number); 83 // Keep the leading '+' while normalising numbers, excluding US numbers.
Ilya Sherman 2014/07/16 17:50:17 nit: "normalising" -> "normalizing"
84 if (processed_number[0] == '+' && region_code != "US") {
85 processed_number = processed_number.substr(1, processed_number.length());
Ilya Sherman 2014/07/16 17:50:17 (here too)
Evan Stade 2014/07/17 00:54:48 why do you have to remove the '+' then re-add it?
ziran.sun 2014/07/17 12:35:36 NormalizeDigitsOnly () will remove the '+' sign. F
Evan Stade 2014/07/17 17:28:50 If NormalizeDigitsOnly () will remove the '+' sign
Ilya Sherman 2014/07/17 18:44:33 Evan, the code is structured differently now. Do
Evan Stade 2014/07/17 18:53:49 nope
86 phone_util->NormalizeDigitsOnly(&processed_number);
87 processed_number.insert(processed_number.begin(), '+');
88 } else {
89 phone_util->NormalizeDigitsOnly(&processed_number);
90 }
73 *normalized_number = base::UTF8ToUTF16(processed_number); 91 *normalized_number = base::UTF8ToUTF16(processed_number);
74 } 92 }
Ilya Sherman 2014/07/16 17:50:17 It might be cleaner to factor out the code that sp
75 } 93 }
76 94
77 } // namespace 95 } // namespace
78 96
79 namespace i18n { 97 namespace i18n {
80 98
81 // Parses the number stored in |value| as it should be interpreted in the given 99 // 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. 100 // |default_region|, and stores the results into the remaining arguments.
83 // The |default_region| should be sanitized prior to calling this function. 101 // The |default_region| should be sanitized prior to calling this function.
84 bool ParsePhoneNumber(const base::string16& value, 102 bool ParsePhoneNumber(const base::string16& value,
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 number_ = other.number_; 311 number_ = other.number_;
294 312
295 formatted_number_ = other.formatted_number_; 313 formatted_number_ = other.formatted_number_;
296 whole_number_ = other.whole_number_; 314 whole_number_ = other.whole_number_;
297 315
298 return *this; 316 return *this;
299 } 317 }
300 318
301 } // namespace i18n 319 } // namespace i18n
302 } // namespace autofill 320 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698