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

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

Issue 374053007: Change PhoneNumber::SetInfo to only apply formatting where there is none (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | components/autofill/core/browser/phone_number_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.h" 5 #include "components/autofill/core/browser/phone_number.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 } 127 }
128 128
129 bool PhoneNumber::SetInfo(const AutofillType& type, 129 bool PhoneNumber::SetInfo(const AutofillType& type,
130 const base::string16& value, 130 const base::string16& value,
131 const std::string& app_locale) { 131 const std::string& app_locale) {
132 SetRawInfo(type.GetStorableType(), value); 132 SetRawInfo(type.GetStorableType(), value);
133 133
134 if (number_.empty()) 134 if (number_.empty())
135 return true; 135 return true;
136 136
137 // Store a formatted (i.e., pretty printed) version of the number. 137 // Store a formatted (i.e., pretty printed) version of the number, but only if
138 // the number doesn't contain any other formatting. If there is formatting,
139 // assume the user provided it and wants to keep it.
138 UpdateCacheIfNeeded(app_locale); 140 UpdateCacheIfNeeded(app_locale);
139 number_ = cached_parsed_phone_.GetFormattedNumber(); 141 if (base::ContainsOnlyChars(number_,
142 base::ASCIIToUTF16("0123456789"))) {
Ilya Sherman 2014/07/08 23:53:54 The '+' sign should also be treated as an unformat
Evan Stade 2014/07/08 23:58:31 Done.
143 number_ = cached_parsed_phone_.GetFormattedNumber();
144 }
140 return !number_.empty(); 145 return !number_.empty();
141 } 146 }
142 147
143 void PhoneNumber::GetMatchingTypes(const base::string16& text, 148 void PhoneNumber::GetMatchingTypes(const base::string16& text,
144 const std::string& app_locale, 149 const std::string& app_locale,
145 ServerFieldTypeSet* matching_types) const { 150 ServerFieldTypeSet* matching_types) const {
146 base::string16 stripped_text = text; 151 base::string16 stripped_text = text;
147 base::RemoveChars(stripped_text, base::ASCIIToUTF16(" .()-"), &stripped_text); 152 base::RemoveChars(stripped_text, base::ASCIIToUTF16(" .()-"), &stripped_text);
148 FormGroup::GetMatchingTypes(stripped_text, app_locale, matching_types); 153 FormGroup::GetMatchingTypes(stripped_text, app_locale, matching_types);
149 154
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 230
226 return i18n::ConstructPhoneNumber( 231 return i18n::ConstructPhoneNumber(
227 country_, city_, phone_, GetRegion(profile, app_locale), value); 232 country_, city_, phone_, GetRegion(profile, app_locale), value);
228 } 233 }
229 234
230 bool PhoneNumber::PhoneCombineHelper::IsEmpty() const { 235 bool PhoneNumber::PhoneCombineHelper::IsEmpty() const {
231 return phone_.empty() && whole_number_.empty(); 236 return phone_.empty() && whole_number_.empty();
232 } 237 }
233 238
234 } // namespace autofill 239 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | components/autofill/core/browser/phone_number_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698