| 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 COMPONENTS_AUTOFILL_BROWSER_PHONE_NUMBER_I18N_H_ | 5 #ifndef COMPONENTS_AUTOFILL_BROWSER_PHONE_NUMBER_I18N_H_ |
| 6 #define COMPONENTS_AUTOFILL_BROWSER_PHONE_NUMBER_I18N_H_ | 6 #define COMPONENTS_AUTOFILL_BROWSER_PHONE_NUMBER_I18N_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 namespace autofill_i18n { | 22 namespace autofill_i18n { |
| 23 | 23 |
| 24 // Most of the following functions require |region| to operate. The |region| is | 24 // Most of the following functions require |region| to operate. The |region| is |
| 25 // a ISO 3166 standard code ("US" for USA, "CZ" for Czech Republic, etc.). | 25 // a ISO 3166 standard code ("US" for USA, "CZ" for Czech Republic, etc.). |
| 26 | 26 |
| 27 // Parses the number stored in |value| as a phone number interpreted in the | 27 // Parses the number stored in |value| as a phone number interpreted in the |
| 28 // given |region|, and stores the results into the remaining arguments. The | 28 // given |region|, and stores the results into the remaining arguments. The |
| 29 // |region| should be a 2-letter country code. This is an internal function, | 29 // |region| should be a 2-letter country code. This is an internal function, |
| 30 // exposed in the header file so that it can be tested. | 30 // exposed in the header file so that it can be tested. |
| 31 bool ParsePhoneNumber( | 31 bool ParsePhoneNumber( |
| 32 const string16& value, | 32 const base::string16& value, |
| 33 const std::string& region, | 33 const std::string& region, |
| 34 string16* country_code, | 34 base::string16* country_code, |
| 35 string16* city_code, | 35 base::string16* city_code, |
| 36 string16* number, | 36 base::string16* number, |
| 37 i18n::phonenumbers::PhoneNumber* i18n_number) WARN_UNUSED_RESULT; | 37 i18n::phonenumbers::PhoneNumber* i18n_number) WARN_UNUSED_RESULT; |
| 38 | 38 |
| 39 // Normalizes phone number, by changing digits in the extended fonts | 39 // Normalizes phone number, by changing digits in the extended fonts |
| 40 // (such as \xFF1x) into '0'-'9'. Also strips out non-digit characters. | 40 // (such as \xFF1x) into '0'-'9'. Also strips out non-digit characters. |
| 41 string16 NormalizePhoneNumber(const string16& value, | 41 base::string16 NormalizePhoneNumber(const base::string16& value, |
| 42 const std::string& region); | 42 const std::string& region); |
| 43 | 43 |
| 44 // Constructs whole phone number from parts. | 44 // Constructs whole phone number from parts. |
| 45 // |city_code| - area code, could be empty. | 45 // |city_code| - area code, could be empty. |
| 46 // |country_code| - country code, could be empty. | 46 // |country_code| - country code, could be empty. |
| 47 // |number| - local number, should not be empty. | 47 // |number| - local number, should not be empty. |
| 48 // |region| - current region, the parsing is based on. | 48 // |region| - current region, the parsing is based on. |
| 49 // |whole_number| - constructed whole number. | 49 // |whole_number| - constructed whole number. |
| 50 // Separator characters are stripped before parsing the digits. | 50 // Separator characters are stripped before parsing the digits. |
| 51 // Returns true if parsing was successful, false otherwise. | 51 // Returns true if parsing was successful, false otherwise. |
| 52 bool ConstructPhoneNumber(const string16& country_code, | 52 bool ConstructPhoneNumber(const base::string16& country_code, |
| 53 const string16& city_code, | 53 const base::string16& city_code, |
| 54 const string16& number, | 54 const base::string16& number, |
| 55 const std::string& region, | 55 const std::string& region, |
| 56 string16* whole_number) WARN_UNUSED_RESULT; | 56 base::string16* whole_number) WARN_UNUSED_RESULT; |
| 57 | 57 |
| 58 // Returns true if |number_a| and |number_b| parse to the same phone number in | 58 // Returns true if |number_a| and |number_b| parse to the same phone number in |
| 59 // the given |region|. | 59 // the given |region|. |
| 60 bool PhoneNumbersMatch(const string16& number_a, | 60 bool PhoneNumbersMatch(const base::string16& number_a, |
| 61 const string16& number_b, | 61 const base::string16& number_b, |
| 62 const std::string& region, | 62 const std::string& region, |
| 63 const std::string& app_locale); | 63 const std::string& app_locale); |
| 64 | 64 |
| 65 // The cached phone number, does parsing only once, improves performance. | 65 // The cached phone number, does parsing only once, improves performance. |
| 66 class PhoneObject { | 66 class PhoneObject { |
| 67 public: | 67 public: |
| 68 PhoneObject(const string16& number, | 68 PhoneObject(const base::string16& number, |
| 69 const std::string& region); | 69 const std::string& region); |
| 70 PhoneObject(const PhoneObject&); | 70 PhoneObject(const PhoneObject&); |
| 71 PhoneObject(); | 71 PhoneObject(); |
| 72 ~PhoneObject(); | 72 ~PhoneObject(); |
| 73 | 73 |
| 74 std::string region() const { return region_; } | 74 std::string region() const { return region_; } |
| 75 | 75 |
| 76 string16 country_code() const { return country_code_; } | 76 base::string16 country_code() const { return country_code_; } |
| 77 string16 city_code() const { return city_code_; } | 77 base::string16 city_code() const { return city_code_; } |
| 78 string16 number() const { return number_; } | 78 base::string16 number() const { return number_; } |
| 79 | 79 |
| 80 string16 GetFormattedNumber() const; | 80 base::string16 GetFormattedNumber() const; |
| 81 string16 GetWholeNumber() const; | 81 base::string16 GetWholeNumber() const; |
| 82 | 82 |
| 83 PhoneObject& operator=(const PhoneObject& other); | 83 PhoneObject& operator=(const PhoneObject& other); |
| 84 | 84 |
| 85 bool IsValidNumber() const { return i18n_number_ != NULL; } | 85 bool IsValidNumber() const { return i18n_number_ != NULL; } |
| 86 | 86 |
| 87 private: | 87 private: |
| 88 // The region code used to parse this number. | 88 // The region code used to parse this number. |
| 89 std::string region_; | 89 std::string region_; |
| 90 | 90 |
| 91 // The parsed number and its components. | 91 // The parsed number and its components. |
| 92 scoped_ptr<i18n::phonenumbers::PhoneNumber> i18n_number_; | 92 scoped_ptr<i18n::phonenumbers::PhoneNumber> i18n_number_; |
| 93 string16 city_code_; | 93 base::string16 city_code_; |
| 94 string16 country_code_; | 94 base::string16 country_code_; |
| 95 string16 number_; | 95 base::string16 number_; |
| 96 | 96 |
| 97 // Pretty printed version of the whole number, or empty if parsing failed. | 97 // Pretty printed version of the whole number, or empty if parsing failed. |
| 98 // Set on first request. | 98 // Set on first request. |
| 99 mutable string16 formatted_number_; | 99 mutable base::string16 formatted_number_; |
| 100 | 100 |
| 101 // The whole number, normalized to contain only digits if possible. | 101 // The whole number, normalized to contain only digits if possible. |
| 102 // Set on first request. | 102 // Set on first request. |
| 103 mutable string16 whole_number_; | 103 mutable base::string16 whole_number_; |
| 104 }; | 104 }; |
| 105 | 105 |
| 106 } // namespace autofill_i18n | 106 } // namespace autofill_i18n |
| 107 | 107 |
| 108 #endif // COMPONENTS_AUTOFILL_BROWSER_PHONE_NUMBER_I18N_H_ | 108 #endif // COMPONENTS_AUTOFILL_BROWSER_PHONE_NUMBER_I18N_H_ |
| OLD | NEW |