| 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 | 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 // Normalizes phone number, by changing digits in the extended fonts | 27 // Normalizes phone number, by changing digits in the extended fonts |
| 28 // (such as \xFF1x) into '0'-'9'. Also strips out non-digit characters. | 28 // (such as \xFF1x) into '0'-'9'. Also strips out non-digit characters. |
| 29 string16 NormalizePhoneNumber(const string16& value, | 29 string16 NormalizePhoneNumber(const string16& value, |
| 30 const std::string& region); | 30 const std::string& region); |
| 31 | 31 |
| 32 // Parses |value| to extract the components of a phone number. |number| | 32 // Parses the number stored in |value| as a phone number interpreted in the |
| 33 // returns the local number, |city_code| returns the city code, and | 33 // given |region|, and stores the results into the remaining arguments. The |
| 34 // |country_code| returns country code. For some regions the |city_code| is | 34 // |region| should be a 2-letter country code. This is an internal function, |
| 35 // empty. | 35 // exposed in the header file so that it can be tested. |
| 36 // The parsing is based on current region - |region|. | |
| 37 // Separator characters are stripped before parsing the digits. | |
| 38 // Returns true if parsing was successful, false otherwise. | |
| 39 bool ParsePhoneNumber(const string16& value, | 36 bool ParsePhoneNumber(const string16& value, |
| 40 const std::string& region, | 37 const std::string& region, |
| 41 string16* country_code, | 38 string16* country_code, |
| 42 string16* city_code, | 39 string16* city_code, |
| 43 string16* number) WARN_UNUSED_RESULT; | 40 string16* number) WARN_UNUSED_RESULT; |
| 44 | 41 |
| 45 enum FullPhoneFormat { | 42 enum FullPhoneFormat { |
| 46 E164, // Example: +16502345678 | 43 E164, // Example: +16502345678 |
| 47 INTERNATIONAL, // Example: +1 650-234-5678 | 44 INTERNATIONAL, // Example: +1 650-234-5678 |
| 48 NATIONAL, // Example: (650) 234-5678 | 45 NATIONAL, // Example: (650) 234-5678 |
| 49 RFC3966 // Example: +1-650-234-5678 | 46 RFC3966 // Example: +1-650-234-5678 |
| 50 }; | 47 }; |
| 51 | 48 |
| 52 // Constructs whole phone number from parts. | 49 // Constructs whole phone number from parts. |
| 53 // |city_code| - area code, could be empty. | 50 // |city_code| - area code, could be empty. |
| 54 // |country_code| - country code, could be empty | 51 // |country_code| - country code, could be empty. |
| 55 // |number| - local number, should not be empty. | 52 // |number| - local number, should not be empty. |
| 56 // |region| - current region, the parsing is based on. | 53 // |region| - current region, the parsing is based on. |
| 57 // |phone_format| - whole number constructed in that format, | 54 // |phone_format| - whole number constructed in that format, |
| 58 // |whole_number| - constructed whole number. | 55 // |whole_number| - constructed whole number. |
| 59 // Separator characters are stripped before parsing the digits. | 56 // Separator characters are stripped before parsing the digits. |
| 60 // Returns true if parsing was successful, false otherwise. | 57 // Returns true if parsing was successful, false otherwise. |
| 61 bool ConstructPhoneNumber(const string16& country_code, | 58 bool ConstructPhoneNumber(const string16& country_code, |
| 62 const string16& city_code, | 59 const string16& city_code, |
| 63 const string16& number, | 60 const string16& number, |
| 64 const std::string& region, | 61 const std::string& region, |
| 65 FullPhoneFormat phone_format, | 62 FullPhoneFormat phone_format, |
| 66 string16* whole_number) WARN_UNUSED_RESULT; | 63 string16* whole_number) WARN_UNUSED_RESULT; |
| 67 | 64 |
| 65 // Returns true if |number_a| and |number_b| parse to the same phone number in |
| 66 // the given |region|. |
| 68 bool PhoneNumbersMatch(const string16& number_a, | 67 bool PhoneNumbersMatch(const string16& number_a, |
| 69 const string16& number_b, | 68 const string16& number_b, |
| 70 const std::string& region); | 69 const std::string& region); |
| 71 | 70 |
| 72 // The cached phone number, does parsing only once, improves performance. | 71 // The cached phone number, does parsing only once, improves performance. |
| 73 class PhoneObject { | 72 class PhoneObject { |
| 74 public: | 73 public: |
| 75 PhoneObject(const string16& number, const std::string& region); | 74 PhoneObject(const string16& number, const std::string& region); |
| 76 PhoneObject(const PhoneObject&); | 75 PhoneObject(const PhoneObject&); |
| 77 PhoneObject(); | 76 PhoneObject(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 93 string16 country_code_; | 92 string16 country_code_; |
| 94 string16 number_; | 93 string16 number_; |
| 95 mutable string16 whole_number_; // Set on first request. | 94 mutable string16 whole_number_; // Set on first request. |
| 96 std::string region_; | 95 std::string region_; |
| 97 scoped_ptr<i18n::phonenumbers::PhoneNumber> i18n_number_; | 96 scoped_ptr<i18n::phonenumbers::PhoneNumber> i18n_number_; |
| 98 }; | 97 }; |
| 99 | 98 |
| 100 } // namespace autofill_i18n | 99 } // namespace autofill_i18n |
| 101 | 100 |
| 102 #endif // CHROME_BROWSER_AUTOFILL_PHONE_NUMBER_I18N_H_ | 101 #endif // CHROME_BROWSER_AUTOFILL_PHONE_NUMBER_I18N_H_ |
| OLD | NEW |