summaryrefslogtreecommitdiff
path: root/geocoding/mapping_file_provider.h
blob: 1234a5e5736b1bcf792e73581f9e83d2230067c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright (C) 2012 The Libphonenumber Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Author: Patrick Mezard

#ifndef I18N_PHONENUMBERS_GEOCODING_MAPPING_FILE_PROVIDER_H_
#define I18N_PHONENUMBERS_GEOCODING_MAPPING_FILE_PROVIDER_H_

#include <string>

#include "base/basictypes.h"

namespace i18n {
namespace phonenumbers {

using std::string;

struct CountryLanguages;

// A utility which knows the data files that are available for the geocoder to
// use. The data files contain mappings from phone number prefixes to text
// descriptions, and are organized by country calling code and language that the
// text descriptions are in.
class MappingFileProvider {
 public:
  typedef const CountryLanguages* (*country_languages_getter)(int index);

  // Initializes a MappingFileProvider with country_calling_codes, a sorted
  // list of country_calling_code_size calling codes, and a function
  // get_country_languages(int index) returning the CountryLanguage information
  // related to the country code at index in country_calling_codes.
  MappingFileProvider(const int* country_calling_codes,
                      int country_calling_code_size,
                      country_languages_getter get_country_languages);

  // Returns the name of the file that contains the mapping data for the
  // country_calling_code in the language specified, or an empty string if no
  // such file can be found. language is a two-letter lowercase ISO language
  // codes as defined by ISO 639-1. script is a four-letter titlecase (the first
  // letter is uppercase and the rest of the letters are lowercase) ISO script
  // codes as defined in ISO 15924. region is a two-letter uppercase ISO country
  // codes as defined by ISO 3166-1.
  const string& GetFileName(int country_calling_code, const string& language,
                            const string& script, const string& region, string*
                            filename) const;

 private:
  void FindBestMatchingLanguageCode(const CountryLanguages* languages,
                                    const string& language,
                                    const string& script,
                                    const string& region,
                                    string* best_match) const;

  const int* const country_calling_codes_;
  const int country_calling_codes_size_;
  const country_languages_getter get_country_languages_;

  DISALLOW_COPY_AND_ASSIGN(MappingFileProvider);
};

}  // namespace phonenumbers
}  // namespace i18n

#endif  // I18N_PHONENUMBERS_GEOCODING_MAPPING_FILE_PROVIDER_H_