OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_AUTOFILL_PHONE_NUMBER_I18N_H_ | 5 #ifndef CHROME_BROWSER_AUTOFILL_PHONE_NUMBER_I18N_H_ |
6 #define CHROME_BROWSER_AUTOFILL_PHONE_NUMBER_I18N_H_ | 6 #define CHROME_BROWSER_AUTOFILL_PHONE_NUMBER_I18N_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/memory/scoped_ptr.h" | |
13 #include "base/string16.h" | 14 #include "base/string16.h" |
14 | 15 |
16 namespace i18n { | |
17 namespace phonenumbers { | |
18 class PhoneNumber; | |
19 } | |
20 } | |
21 | |
15 // Utilities to process, normalize and compare international phone numbers. | 22 // Utilities to process, normalize and compare international phone numbers. |
16 | |
17 namespace autofill_i18n { | 23 namespace autofill_i18n { |
18 | 24 |
19 // Most of the following functions require |locale| to operate. The |locale| is | 25 // Most of the following functions require |locale| to operate. The |locale| is |
20 // a ISO 3166 standard code ("US" for USA, "CZ" for Czech Republic, etc.). | 26 // a ISO 3166 standard code ("US" for USA, "CZ" for Czech Republic, etc.). |
21 | 27 |
22 // Normalizes phone number, by changing digits in the extended fonts | 28 // Normalizes phone number, by changing digits in the extended fonts |
23 // (such as \xFF1x) into '0'-'9'. Also strips out non-digit characters. | 29 // (such as \xFF1x) into '0'-'9'. Also strips out non-digit characters. |
24 string16 NormalizePhoneNumber(const string16& value, | 30 string16 NormalizePhoneNumber(const string16& value, |
25 const std::string& locale); | 31 const std::string& locale); |
26 | 32 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 | 87 |
82 // Compares two phones, normalizing them before comparision. | 88 // Compares two phones, normalizing them before comparision. |
83 PhoneMatch ComparePhones(const string16& phone1, | 89 PhoneMatch ComparePhones(const string16& phone1, |
84 const string16& phone2, | 90 const string16& phone2, |
85 const std::string& locale); | 91 const std::string& locale); |
86 | 92 |
87 bool PhoneNumbersMatch(const string16& number_a, | 93 bool PhoneNumbersMatch(const string16& number_a, |
88 const string16& number_b, | 94 const string16& number_b, |
89 const std::string& country_code); | 95 const std::string& country_code); |
90 | 96 |
97 // The cached phone number, does parsing only once, improves performance. | |
98 class PhoneObject { | |
99 public: | |
100 PhoneObject(const string16& number, const std::string& locale); | |
101 PhoneObject(const PhoneObject&); | |
102 PhoneObject(); | |
103 ~PhoneObject(); | |
104 | |
105 string16 GetCountryCode() const; | |
106 string16 GetCityCode() const; | |
107 string16 GetNumber() const; | |
108 std::string GetLocale() const { return locale_; } | |
Ilya Sherman
2011/06/21 23:46:12
nit: Why did you inline just one of these four? ;)
GeorgeY
2011/06/22 23:43:45
Initially I had lazy initialization of the other m
| |
109 | |
110 string16 GetWholeNumber() const; | |
111 | |
112 PhoneMatch ComparePhones(const string16& phone) const; | |
113 | |
114 PhoneObject& operator=(const PhoneObject& other); | |
115 | |
116 bool ValidNumber() const { return i18n_number_ != NULL; } | |
Ilya Sherman
2011/06/21 23:46:12
nit: Perhaps "IsValidNumber" rather than "ValidNum
GeorgeY
2011/06/22 23:43:45
Sure
| |
117 | |
118 private: | |
119 string16 city_code_; | |
120 string16 country_code_; | |
121 string16 number_; | |
122 mutable string16 whole_number_; // Set on first request. | |
123 std::string locale_; | |
124 scoped_ptr<i18n::phonenumbers::PhoneNumber> i18n_number_; | |
125 }; | |
126 | |
91 } // namespace autofill_i18n | 127 } // namespace autofill_i18n |
92 | 128 |
93 #endif // CHROME_BROWSER_AUTOFILL_PHONE_NUMBER_I18N_H_ | 129 #endif // CHROME_BROWSER_AUTOFILL_PHONE_NUMBER_I18N_H_ |
OLD | NEW |