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 // Returns the name of the file that contains the mapping data for the 48 // country_calling_code in the language specified, or an empty string if no 49 // such file can be found. 50 // language is a two or three-letter lowercase language code as defined by ISO 51 // 639. Note that where two different language codes exist (e.g. 'he' and 'iw' 52 // for Hebrew) we use the one that Java/Android canonicalized on ('iw' in this 53 // case). 54 // script is a four-letter titlecase (the first letter is uppercase and the 55 // rest of the letters are lowercase) ISO script code as defined in ISO 15924. 56 // region is a two-letter uppercase ISO country code as defined by ISO 3166-1. 57 const string& GetFileName(int country_calling_code, const string& language, 58 const string& script, const string& region, string* 59 filename) const; 60 61 private: 62 void FindBestMatchingLanguageCode(const CountryLanguages* languages, 63 const string& language, 64 const string& script, 65 const string& region, 66 string* best_match) const; 67 68 const int* const country_calling_codes_; 69 const int country_calling_codes_size_; 70 const country_languages_getter get_country_languages_; 71 72 DISALLOW_COPY_AND_ASSIGN(MappingFileProvider); 73 }; 74 75 } // namespace phonenumbers 76 } // namespace i18n 77 78 #endif // I18N_PHONENUMBERS_GEOCODING_MAPPING_FILE_PROVIDER_H_ 79