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