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 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
242 // The phone number was successfully parsed, so store the parsed version. | 242 // The phone number was successfully parsed, so store the parsed version. |
243 // The formatted and normalized versions will be set on the first call to | 243 // The formatted and normalized versions will be set on the first call to |
244 // the coresponding methods. | 244 // the coresponding methods. |
245 i18n_number_.reset(i18n_number.release()); | 245 i18n_number_.reset(i18n_number.release()); |
246 } else { | 246 } else { |
247 // Parsing failed. Store passed phone "as is" into |whole_number_|. | 247 // Parsing failed. Store passed phone "as is" into |whole_number_|. |
248 whole_number_ = number; | 248 whole_number_ = number; |
249 } | 249 } |
250 } | 250 } |
251 | 251 |
252 base::string16 FormatPhoneNumberForRegion(const base::string16& whole_number, | |
253 const std::string& region) { | |
254 PhoneNumber phone_number; | |
255 PhoneNumberUtil* phone_util = PhoneNumberUtil::GetInstance(); | |
256 if (phone_util->Parse(UTF16ToUTF8(whole_number), | |
257 region, | |
258 &phone_number) != PhoneNumberUtil::NO_PARSING_ERROR) { | |
259 return base::string16(); | |
260 } | |
261 | |
262 std::string formatted_number; | |
263 phone_util->Format(phone_number, | |
264 PhoneNumberUtil::PhoneNumberFormat::NATIONAL, | |
265 &formatted_number); | |
266 return UTF8ToUTF16(formatted_number); | |
267 } | |
Ilya Sherman
2013/09/26 22:01:06
Please still move this above the PhoneObject const
Evan Stade
2013/09/27 00:29:17
Done.
| |
268 | |
252 PhoneObject::PhoneObject(const PhoneObject& other) { *this = other; } | 269 PhoneObject::PhoneObject(const PhoneObject& other) { *this = other; } |
253 | 270 |
254 PhoneObject::PhoneObject() {} | 271 PhoneObject::PhoneObject() {} |
255 | 272 |
256 PhoneObject::~PhoneObject() { | 273 PhoneObject::~PhoneObject() { |
257 } | 274 } |
258 | 275 |
259 base::string16 PhoneObject::GetFormattedNumber() const { | 276 base::string16 PhoneObject::GetFormattedNumber() const { |
260 if (i18n_number_ && formatted_number_.empty()) { | 277 if (i18n_number_ && formatted_number_.empty()) { |
261 FormatValidatedNumber(*i18n_number_, country_code_, &formatted_number_, | 278 FormatValidatedNumber(*i18n_number_, country_code_, &formatted_number_, |
(...skipping 28 matching lines...) Expand all Loading... | |
290 number_ = other.number_; | 307 number_ = other.number_; |
291 | 308 |
292 formatted_number_ = other.formatted_number_; | 309 formatted_number_ = other.formatted_number_; |
293 whole_number_ = other.whole_number_; | 310 whole_number_ = other.whole_number_; |
294 | 311 |
295 return *this; | 312 return *this; |
296 } | 313 } |
297 | 314 |
298 } // namespace i18n | 315 } // namespace i18n |
299 } // namespace autofill | 316 } // namespace autofill |
OLD | NEW |