1 // Copyright (C) 2012 The Libphonenumber Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // Author: Patrick Mezard 16 17 #ifndef I18N_PHONENUMBERS_GEOCODING_MAPPING_FILE_PROVIDER_H_ 18 #define I18N_PHONENUMBERS_GEOCODING_MAPPING_FILE_PROVIDER_H_ 19 20 #include <string> 21 22 #include "phonenumbers/base/basictypes.h" 23 24 namespace i18n { 25 namespace phonenumbers { 26 27 using std::string; 28 29 struct CountryLanguages; 30 31 // A utility which knows the data files that are available for the geocoder to 32 // use. The data files contain mappings from phone number prefixes to text 33 // descriptions, and are organized by country calling code and language that the 34 // text descriptions are in. 35 class MappingFileProvider { 36 public: 37 typedef const CountryLanguages* (*country_languages_getter)(int index); 38 39 // Initializes a MappingFileProvider with country_calling_codes, a sorted 40 // list of country_calling_code_size calling codes, and a function 41 // get_country_languages(int index) returning the CountryLanguage information 42 // related to the country code at index in country_calling_codes. 43 MappingFileProvider(const int* country_calling_codes, 44 int country_calling_code_size, 45 country_languages_getter get_country_languages); 46 47 // This type is neither copyable nor movable. 48 MappingFileProvider(const MappingFileProvider&) = delete; 49 MappingFileProvider& operator=(const MappingFileProvider&) = delete; 50 51 // Returns the name of the file that contains the mapping data for the 52 // country_calling_code in the language specified, or an empty string if no 53 // such file can be found. 54 // language is a two or three-letter lowercase language code as defined by ISO 55 // 639. Note that where two different language codes exist (e.g. 'he' and 'iw' 56 // for Hebrew) we use the one that Java/Android canonicalized on ('iw' in this 57 // case). 58 // script is a four-letter titlecase (the first letter is uppercase and the 59 // rest of the letters are lowercase) ISO script code as defined in ISO 15924. 60 // region is a two-letter uppercase ISO country code as defined by ISO 3166-1. 61 const string& GetFileName(int country_calling_code, const string& language, 62 const string& script, const string& region, string* 63 filename) const; 64 65 private: 66 void FindBestMatchingLanguageCode(const CountryLanguages* languages, 67 const string& language, 68 const string& script, 69 const string& region, 70 string* best_match) const; 71 72 const int* const country_calling_codes_; 73 const int country_calling_codes_size_; 74 const country_languages_getter get_country_languages_; 75 }; 76 77 } // namespace phonenumbers 78 } // namespace i18n 79 80 #endif // I18N_PHONENUMBERS_GEOCODING_MAPPING_FILE_PROVIDER_H_ 81