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.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 Loading... |
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 if either | 137 // Store a formatted (i.e., pretty printed) version of the number. |
138 // the number doesn't contain formatting marks. | |
139 UpdateCacheIfNeeded(app_locale); | 138 UpdateCacheIfNeeded(app_locale); |
140 if (base::ContainsOnlyChars(number_, base::ASCIIToUTF16("+0123456789"))) { | 139 number_ = cached_parsed_phone_.GetFormattedNumber(); |
141 number_ = cached_parsed_phone_.GetFormattedNumber(); | |
142 } else if (i18n::NormalizePhoneNumber( | |
143 number_, GetRegion(*profile_, app_locale)).empty()) { | |
144 // The number doesn't make sense for this region; clear it. | |
145 number_.clear(); | |
146 } | |
147 return !number_.empty(); | 140 return !number_.empty(); |
148 } | 141 } |
149 | 142 |
150 void PhoneNumber::GetMatchingTypes(const base::string16& text, | 143 void PhoneNumber::GetMatchingTypes(const base::string16& text, |
151 const std::string& app_locale, | 144 const std::string& app_locale, |
152 ServerFieldTypeSet* matching_types) const { | 145 ServerFieldTypeSet* matching_types) const { |
153 base::string16 stripped_text = text; | 146 base::string16 stripped_text = text; |
154 base::RemoveChars(stripped_text, base::ASCIIToUTF16(" .()-"), &stripped_text); | 147 base::RemoveChars(stripped_text, base::ASCIIToUTF16(" .()-"), &stripped_text); |
155 FormGroup::GetMatchingTypes(stripped_text, app_locale, matching_types); | 148 FormGroup::GetMatchingTypes(stripped_text, app_locale, matching_types); |
156 | 149 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 | 225 |
233 return i18n::ConstructPhoneNumber( | 226 return i18n::ConstructPhoneNumber( |
234 country_, city_, phone_, GetRegion(profile, app_locale), value); | 227 country_, city_, phone_, GetRegion(profile, app_locale), value); |
235 } | 228 } |
236 | 229 |
237 bool PhoneNumber::PhoneCombineHelper::IsEmpty() const { | 230 bool PhoneNumber::PhoneCombineHelper::IsEmpty() const { |
238 return phone_.empty() && whole_number_.empty(); | 231 return phone_.empty() && whole_number_.empty(); |
239 } | 232 } |
240 | 233 |
241 } // namespace autofill | 234 } // namespace autofill |
OLD | NEW |