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
24namespace i18n {
25namespace phonenumbers {
26
27using std::string;
28
29struct 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.
35class 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. language is a two-letter lowercase ISO language
50  // codes as defined by ISO 639-1. script is a four-letter titlecase (the first
51  // letter is uppercase and the rest of the letters are lowercase) ISO script
52  // codes as defined in ISO 15924. region is a two-letter uppercase ISO country
53  // codes as defined by ISO 3166-1.
54  const string& GetFileName(int country_calling_code, const string& language,
55                            const string& script, const string& region, string*
56                            filename) const;
57
58 private:
59  void FindBestMatchingLanguageCode(const CountryLanguages* languages,
60                                    const string& language,
61                                    const string& script,
62                                    const string& region,
63                                    string* best_match) const;
64
65  const int* const country_calling_codes_;
66  const int country_calling_codes_size_;
67  const country_languages_getter get_country_languages_;
68
69  DISALLOW_COPY_AND_ASSIGN(MappingFileProvider);
70};
71
72}  // namespace phonenumbers
73}  // namespace i18n
74
75#endif  // I18N_PHONENUMBERS_GEOCODING_MAPPING_FILE_PROVIDER_H_
76