pico_phone 0.6.2-aarch64-linux
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE.txt +21 -0
- data/THIRD_PARTY_LICENSES.txt +353 -0
- data/ext/pico_phone/carrier_data.cc +68763 -0
- data/ext/pico_phone/carrier_mapper.cc +127 -0
- data/ext/pico_phone/carrier_mapper.h +88 -0
- data/ext/pico_phone/extconf.rb +129 -0
- data/ext/pico_phone/pico_phone.cpp +1059 -0
- data/ext/pico_phone/timezone_data.cc +6648 -0
- data/ext/pico_phone/timezone_data.h +25 -0
- data/ext/pico_phone/timezone_mapper.cc +54 -0
- data/ext/pico_phone/timezone_mapper.h +49 -0
- data/ext/pico_phone/vendor_headers/phonenumbers/geocoding/area_code_map.h +92 -0
- data/ext/pico_phone/vendor_headers/phonenumbers/geocoding/carrier_data.h +52 -0
- data/ext/pico_phone/vendor_headers/phonenumbers/geocoding/geocoding_data.h +93 -0
- data/ext/pico_phone/vendor_headers/phonenumbers/geocoding/mapping_file_provider.h +89 -0
- data/lib/pico_phone/3.1/pico_phone.so +0 -0
- data/lib/pico_phone/3.2/pico_phone.so +0 -0
- data/lib/pico_phone/3.3/pico_phone.so +0 -0
- data/lib/pico_phone/3.4/pico_phone.so +0 -0
- data/lib/pico_phone/4.0/pico_phone.so +0 -0
- data/lib/pico_phone/phone_number.rb +294 -0
- data/lib/pico_phone/version.rb +5 -0
- data/lib/pico_phone.rb +29 -0
- metadata +128 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// First-party pico_phone file, not vendored. Declares the accessor for
|
|
2
|
+
// timezone_data.cc (generated by generate_timezone_data.rb). Unlike
|
|
3
|
+
// carrier_data.h, this doesn't need to live under phonenumbers/geocoding/
|
|
4
|
+
// -- that constraint only applies to files generated by libphonenumber's
|
|
5
|
+
// own generate_geocoding_data tool, which hardcodes that include path.
|
|
6
|
+
// This generator is first-party too, so it just includes this header
|
|
7
|
+
// directly by relative name.
|
|
8
|
+
|
|
9
|
+
#ifndef PICO_PHONE_TIMEZONE_DATA_H_
|
|
10
|
+
#define PICO_PHONE_TIMEZONE_DATA_H_
|
|
11
|
+
|
|
12
|
+
#include "phonenumbers/geocoding/geocoding_data.h"
|
|
13
|
+
|
|
14
|
+
namespace i18n {
|
|
15
|
+
namespace phonenumbers {
|
|
16
|
+
|
|
17
|
+
// A single flat prefix -> raw '&'-joined time zone names table. No
|
|
18
|
+
// per-language dimension (unlike geocoding/carrier) since time zone
|
|
19
|
+
// identifiers aren't translated.
|
|
20
|
+
const PrefixDescriptions* get_timezone_descriptions();
|
|
21
|
+
|
|
22
|
+
} // namespace phonenumbers
|
|
23
|
+
} // namespace i18n
|
|
24
|
+
|
|
25
|
+
#endif // PICO_PHONE_TIMEZONE_DATA_H_
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// First-party pico_phone file. See timezone_mapper.h.
|
|
2
|
+
|
|
3
|
+
#include "timezone_mapper.h"
|
|
4
|
+
|
|
5
|
+
#include <sstream>
|
|
6
|
+
#include <string>
|
|
7
|
+
#include <vector>
|
|
8
|
+
|
|
9
|
+
#include "phonenumbers/geocoding/area_code_map.h"
|
|
10
|
+
#include "phonenumbers/phonenumber.pb.h"
|
|
11
|
+
#include "timezone_data.h"
|
|
12
|
+
|
|
13
|
+
namespace i18n {
|
|
14
|
+
namespace phonenumbers {
|
|
15
|
+
|
|
16
|
+
using std::string;
|
|
17
|
+
using std::vector;
|
|
18
|
+
|
|
19
|
+
namespace {
|
|
20
|
+
|
|
21
|
+
// Time zones are joined with '&' in the raw description string, matching
|
|
22
|
+
// libphonenumber's own PrefixTimeZonesMap.RAW_STRING_TIMEZONES_SEPARATOR.
|
|
23
|
+
vector<string> SplitTimeZones(const string& raw) {
|
|
24
|
+
vector<string> result;
|
|
25
|
+
std::stringstream stream(raw);
|
|
26
|
+
string token;
|
|
27
|
+
while (std::getline(stream, token, '&')) {
|
|
28
|
+
if (!token.empty()) {
|
|
29
|
+
result.push_back(token);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
} // namespace
|
|
36
|
+
|
|
37
|
+
PhoneNumberTimeZonesMapper::PhoneNumberTimeZonesMapper() {
|
|
38
|
+
area_code_map_.reset(new AreaCodeMap());
|
|
39
|
+
area_code_map_->ReadAreaCodeMap(get_timezone_descriptions());
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
PhoneNumberTimeZonesMapper::~PhoneNumberTimeZonesMapper() {}
|
|
43
|
+
|
|
44
|
+
vector<string> PhoneNumberTimeZonesMapper::GetTimeZonesForNumber(
|
|
45
|
+
const PhoneNumber& number) const {
|
|
46
|
+
const char* description = area_code_map_->Lookup(number);
|
|
47
|
+
if (!description || *description == '\0') {
|
|
48
|
+
return vector<string>();
|
|
49
|
+
}
|
|
50
|
+
return SplitTimeZones(description);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
} // namespace phonenumbers
|
|
54
|
+
} // namespace i18n
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// First-party pico_phone file. Unlike carrier_mapper.h, this doesn't need
|
|
2
|
+
// its own AreaCodeMap-alike class: timezone data is a single flat prefix
|
|
3
|
+
// table (no per-language dimension, no multiple files to lazily choose
|
|
4
|
+
// between), so it's a thin wrapper directly around the vendored
|
|
5
|
+
// AreaCodeMap -- same longest-prefix-match lookup logic already reused by
|
|
6
|
+
// the geocoder and carrier mapper, just with one eagerly-loaded table
|
|
7
|
+
// (the whole thing is ~86KB source data, small enough that lazy loading
|
|
8
|
+
// isn't worth the complexity here).
|
|
9
|
+
|
|
10
|
+
#ifndef PICO_PHONE_TIMEZONE_MAPPER_H_
|
|
11
|
+
#define PICO_PHONE_TIMEZONE_MAPPER_H_
|
|
12
|
+
|
|
13
|
+
#include <string>
|
|
14
|
+
#include <vector>
|
|
15
|
+
|
|
16
|
+
#include "phonenumbers/base/memory/scoped_ptr.h"
|
|
17
|
+
|
|
18
|
+
namespace i18n {
|
|
19
|
+
namespace phonenumbers {
|
|
20
|
+
|
|
21
|
+
class AreaCodeMap;
|
|
22
|
+
class PhoneNumber;
|
|
23
|
+
|
|
24
|
+
class PhoneNumberTimeZonesMapper {
|
|
25
|
+
public:
|
|
26
|
+
PhoneNumberTimeZonesMapper();
|
|
27
|
+
|
|
28
|
+
PhoneNumberTimeZonesMapper(const PhoneNumberTimeZonesMapper&) = delete;
|
|
29
|
+
PhoneNumberTimeZonesMapper& operator=(const PhoneNumberTimeZonesMapper&) = delete;
|
|
30
|
+
|
|
31
|
+
~PhoneNumberTimeZonesMapper();
|
|
32
|
+
|
|
33
|
+
// Returns the time zones the given phone number's prefix belongs to, or
|
|
34
|
+
// an empty vector if no mapping is available. A single prefix can map to
|
|
35
|
+
// several time zones (e.g. NANPA numbers span many), hence the plural --
|
|
36
|
+
// matching libphonenumber's own Java PhoneNumberToTimeZonesMapper shape,
|
|
37
|
+
// though this returns an empty vector for "not found" rather than Java's
|
|
38
|
+
// single-element ["Etc/Unknown"] sentinel, to match this codebase's own
|
|
39
|
+
// convention (see carrier_mapper.h) of empty over sentinel values.
|
|
40
|
+
std::vector<std::string> GetTimeZonesForNumber(const PhoneNumber& number) const;
|
|
41
|
+
|
|
42
|
+
private:
|
|
43
|
+
scoped_ptr<AreaCodeMap> area_code_map_;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
} // namespace phonenumbers
|
|
47
|
+
} // namespace i18n
|
|
48
|
+
|
|
49
|
+
#endif // PICO_PHONE_TIMEZONE_MAPPER_H_
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// Vendored verbatim from libphonenumber's
|
|
2
|
+
// cpp/src/phonenumbers/geocoding/area_code_map.h (pinned version 9.0.34,
|
|
3
|
+
// see ext/pico_phone/build_deps.sh). Upstream's CMake install step only
|
|
4
|
+
// installs phonenumber_offline_geocoder.h from this directory, not this
|
|
5
|
+
// file, even though AreaCodeMap's implementation (area_code_map.cc) is
|
|
6
|
+
// already compiled into libgeocoding.a/libgeocoding.dylib in both pico_phone
|
|
7
|
+
// build paths (static-vendored and dynamic/Homebrew). This header is needed
|
|
8
|
+
// at compile time only, to declare the interface for carrier_mapper.cc; no
|
|
9
|
+
// implementation is duplicated here. Copied under the same Apache License,
|
|
10
|
+
// Version 2.0 as the rest of the vendored libphonenumber source. If the
|
|
11
|
+
// vendored libphonenumber version is ever bumped, diff this against the new
|
|
12
|
+
// version's copy to confirm the interface hasn't changed.
|
|
13
|
+
|
|
14
|
+
// Copyright (C) 2012 The Libphonenumber Authors
|
|
15
|
+
//
|
|
16
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
17
|
+
// you may not use this file except in compliance with the License.
|
|
18
|
+
// You may obtain a copy of the License at
|
|
19
|
+
//
|
|
20
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
21
|
+
//
|
|
22
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
23
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
24
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
25
|
+
// See the License for the specific language governing permissions and
|
|
26
|
+
// limitations under the License.
|
|
27
|
+
//
|
|
28
|
+
// Author: Patrick Mezard
|
|
29
|
+
|
|
30
|
+
#ifndef I18N_PHONENUMBERS_AREA_CODE_MAP_H_
|
|
31
|
+
#define I18N_PHONENUMBERS_AREA_CODE_MAP_H_
|
|
32
|
+
|
|
33
|
+
#include <cstdint>
|
|
34
|
+
#include <map>
|
|
35
|
+
#include <string>
|
|
36
|
+
|
|
37
|
+
#include "phonenumbers/base/basictypes.h"
|
|
38
|
+
#include "phonenumbers/base/memory/scoped_ptr.h"
|
|
39
|
+
|
|
40
|
+
namespace i18n {
|
|
41
|
+
namespace phonenumbers {
|
|
42
|
+
|
|
43
|
+
using std::map;
|
|
44
|
+
using std::string;
|
|
45
|
+
|
|
46
|
+
class DefaultMapStorage;
|
|
47
|
+
class PhoneNumber;
|
|
48
|
+
class PhoneNumberUtil;
|
|
49
|
+
struct PrefixDescriptions;
|
|
50
|
+
|
|
51
|
+
// A utility that maps phone number prefixes to a string describing the
|
|
52
|
+
// geographical area the prefix covers.
|
|
53
|
+
class AreaCodeMap {
|
|
54
|
+
public:
|
|
55
|
+
AreaCodeMap();
|
|
56
|
+
|
|
57
|
+
// This type is neither copyable nor movable.
|
|
58
|
+
AreaCodeMap(const AreaCodeMap&) = delete;
|
|
59
|
+
AreaCodeMap& operator=(const AreaCodeMap&) = delete;
|
|
60
|
+
|
|
61
|
+
~AreaCodeMap();
|
|
62
|
+
|
|
63
|
+
// Returns the description of the geographical area the number corresponds
|
|
64
|
+
// to. This method distinguishes the case of an invalid prefix and a prefix
|
|
65
|
+
// for which the name is not available in the current language. If the
|
|
66
|
+
// description is not available in the current language an empty string is
|
|
67
|
+
// returned. If no description was found for the provided number, null is
|
|
68
|
+
// returned.
|
|
69
|
+
const char* Lookup(const PhoneNumber& number) const;
|
|
70
|
+
|
|
71
|
+
// Creates an AreaCodeMap initialized with area_codes. Note that the
|
|
72
|
+
// underlying implementation of this method is expensive thus should
|
|
73
|
+
// not be called by time-critical applications.
|
|
74
|
+
//
|
|
75
|
+
// area_codes maps phone number prefixes to geographical area description.
|
|
76
|
+
void ReadAreaCodeMap(const PrefixDescriptions* descriptions);
|
|
77
|
+
|
|
78
|
+
private:
|
|
79
|
+
// Does a binary search for value in the provided array from start to end
|
|
80
|
+
// (inclusive). Returns the position if {@code value} is found; otherwise,
|
|
81
|
+
// returns the position which has the largest value that is less than value.
|
|
82
|
+
// This means if value is the smallest, -1 will be returned.
|
|
83
|
+
int BinarySearch(int start, int end, int64_t value) const;
|
|
84
|
+
|
|
85
|
+
const PhoneNumberUtil& phone_util_;
|
|
86
|
+
scoped_ptr<const DefaultMapStorage> storage_;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
} // namespace phonenumbers
|
|
90
|
+
} // namespace i18n
|
|
91
|
+
|
|
92
|
+
#endif /* I18N_PHONENUMBERS_AREA_CODE_MAP_H_ */
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// First-party pico_phone file, NOT vendored/copied from libphonenumber
|
|
2
|
+
// (unlike its siblings in this directory). Declares the accessors for
|
|
3
|
+
// carrier_data.cc, which is generated at build time by running
|
|
4
|
+
// libphonenumber's own (unmodified) generate_geocoding_data tool against
|
|
5
|
+
// resources/carrier/ with accessor prefix "_carrier" -- see
|
|
6
|
+
// ext/pico_phone/build_deps.sh. Mirrors the shape of libphonenumber's own
|
|
7
|
+
// test/phonenumbers/geocoding/geocoding_test_data.h, which does the same
|
|
8
|
+
// thing for its "_test" prefix: reuse the CountryLanguages/
|
|
9
|
+
// PrefixDescriptions struct layouts from geocoding_data.h, declare
|
|
10
|
+
// prefix-renamed accessor functions.
|
|
11
|
+
//
|
|
12
|
+
// This file must live at exactly this path (phonenumbers/geocoding/
|
|
13
|
+
// carrier_data.h, relative to an include root) because the generator
|
|
14
|
+
// tool hardcodes `#include "phonenumbers/geocoding/<base_name>.h"` in
|
|
15
|
+
// every file it emits, where base_name is derived from the output .cc
|
|
16
|
+
// filename -- not configurable.
|
|
17
|
+
|
|
18
|
+
#ifndef PICO_PHONE_CARRIER_DATA_H_
|
|
19
|
+
#define PICO_PHONE_CARRIER_DATA_H_
|
|
20
|
+
|
|
21
|
+
#include "phonenumbers/geocoding/geocoding_data.h"
|
|
22
|
+
|
|
23
|
+
namespace i18n {
|
|
24
|
+
namespace phonenumbers {
|
|
25
|
+
|
|
26
|
+
// Returns a sorted array of country calling codes with carrier data.
|
|
27
|
+
const int* get_carrier_country_calling_codes();
|
|
28
|
+
|
|
29
|
+
// Returns the number of country calling codes in
|
|
30
|
+
// get_carrier_country_calling_codes() array.
|
|
31
|
+
int get_carrier_country_calling_codes_size();
|
|
32
|
+
|
|
33
|
+
// Returns the CountryLanguages record for country at index, index
|
|
34
|
+
// being in [0, get_carrier_country_calling_codes_size()).
|
|
35
|
+
const CountryLanguages* get_carrier_country_languages(int index);
|
|
36
|
+
|
|
37
|
+
// Returns a sorted array of prefix language code pairs like
|
|
38
|
+
// "1_de" or "82_ko".
|
|
39
|
+
const char** get_carrier_prefix_language_code_pairs();
|
|
40
|
+
|
|
41
|
+
// Returns the number of elements in
|
|
42
|
+
// get_carrier_prefix_language_code_pairs()
|
|
43
|
+
int get_carrier_prefix_language_code_pairs_size();
|
|
44
|
+
|
|
45
|
+
// Returns the PrefixDescriptions for language/code pair at index,
|
|
46
|
+
// index being in [0, get_carrier_prefix_language_code_pairs_size()).
|
|
47
|
+
const PrefixDescriptions* get_carrier_prefix_descriptions(int index);
|
|
48
|
+
|
|
49
|
+
} // namespace phonenumbers
|
|
50
|
+
} // namespace i18n
|
|
51
|
+
|
|
52
|
+
#endif // PICO_PHONE_CARRIER_DATA_H_
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// Vendored verbatim from libphonenumber's
|
|
2
|
+
// cpp/src/phonenumbers/geocoding/geocoding_data.h (pinned version 9.0.34,
|
|
3
|
+
// see ext/pico_phone/build_deps.sh). Same rationale as area_code_map.h and
|
|
4
|
+
// mapping_file_provider.h in this directory: upstream doesn't install this
|
|
5
|
+
// header. Needed here for the CountryLanguages/PrefixDescriptions struct
|
|
6
|
+
// layouts, which carrier_data.h (first-party, not vendored -- see that
|
|
7
|
+
// file) reuses for its own get_carrier_* accessors. The unsuffixed
|
|
8
|
+
// get_*() declarations below are also harmless to have in scope: they're
|
|
9
|
+
// declarations only (no bodies), resolved at link time to the real
|
|
10
|
+
// geocoding_data.cc's implementations already compiled into
|
|
11
|
+
// libgeocoding.a/libgeocoding.dylib, exactly as libphonenumber's own
|
|
12
|
+
// phonenumber_offline_geocoder.cc and test/.../geocoding_test_data.h
|
|
13
|
+
// already do elsewhere in this same codebase. Copied under the same
|
|
14
|
+
// Apache License, Version 2.0 as the rest of the vendored libphonenumber
|
|
15
|
+
// source.
|
|
16
|
+
|
|
17
|
+
// Copyright (C) 2012 The Libphonenumber Authors
|
|
18
|
+
//
|
|
19
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
20
|
+
// you may not use this file except in compliance with the License.
|
|
21
|
+
// You may obtain a copy of the License at
|
|
22
|
+
//
|
|
23
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
24
|
+
//
|
|
25
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
26
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
27
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
28
|
+
// See the License for the specific language governing permissions and
|
|
29
|
+
// limitations under the License.
|
|
30
|
+
//
|
|
31
|
+
// This file is generated automatically, do not edit it manually.
|
|
32
|
+
|
|
33
|
+
#ifndef I18N_PHONENUMBERS_GEOCODING_DATA
|
|
34
|
+
#define I18N_PHONENUMBERS_GEOCODING_DATA
|
|
35
|
+
|
|
36
|
+
#include <cstdint>
|
|
37
|
+
|
|
38
|
+
namespace i18n {
|
|
39
|
+
namespace phonenumbers {
|
|
40
|
+
|
|
41
|
+
struct CountryLanguages {
|
|
42
|
+
// Sorted array of language codes.
|
|
43
|
+
const char** available_languages;
|
|
44
|
+
|
|
45
|
+
// Number of elements in available_languages.
|
|
46
|
+
const int available_languages_size;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
struct PrefixDescriptions {
|
|
50
|
+
// Sorted array of phone number prefixes.
|
|
51
|
+
const int32_t* prefixes;
|
|
52
|
+
|
|
53
|
+
// Number of elements in prefixes.
|
|
54
|
+
const int prefixes_size;
|
|
55
|
+
|
|
56
|
+
// Array of phone number prefix descriptions, mapped one to one
|
|
57
|
+
// to prefixes.
|
|
58
|
+
const char** descriptions;
|
|
59
|
+
|
|
60
|
+
// Sorted array of unique prefix lengths in base 10.
|
|
61
|
+
const int32_t* possible_lengths;
|
|
62
|
+
|
|
63
|
+
// Number of elements in possible_lengths.
|
|
64
|
+
const int possible_lengths_size;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// Returns a sorted array of country calling codes.
|
|
68
|
+
const int* get_country_calling_codes();
|
|
69
|
+
|
|
70
|
+
// Returns the number of country calling codes in
|
|
71
|
+
// get_country_calling_codes() array.
|
|
72
|
+
int get_country_calling_codes_size();
|
|
73
|
+
|
|
74
|
+
// Returns the CountryLanguages record for country at index, index
|
|
75
|
+
// being in [0, get_country_calling_codes_size()).
|
|
76
|
+
const CountryLanguages* get_country_languages(int index);
|
|
77
|
+
|
|
78
|
+
// Returns a sorted array of prefix language code pairs like
|
|
79
|
+
// "1_de" or "82_ko".
|
|
80
|
+
const char** get_prefix_language_code_pairs();
|
|
81
|
+
|
|
82
|
+
// Returns the number of elements in
|
|
83
|
+
// get_prefix_language_code_pairs()
|
|
84
|
+
int get_prefix_language_code_pairs_size();
|
|
85
|
+
|
|
86
|
+
// Returns the PrefixDescriptions for language/code pair at index,
|
|
87
|
+
// index being in [0, get_prefix_language_code_pairs_size()).
|
|
88
|
+
const PrefixDescriptions* get_prefix_descriptions(int index);
|
|
89
|
+
|
|
90
|
+
} // namespace phonenumbers
|
|
91
|
+
} // namespace i18n
|
|
92
|
+
|
|
93
|
+
#endif // I18N_PHONENUMBERS_GEOCODING_DATA
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// Vendored verbatim from libphonenumber's
|
|
2
|
+
// cpp/src/phonenumbers/geocoding/mapping_file_provider.h (pinned version
|
|
3
|
+
// 9.0.34, see ext/pico_phone/build_deps.sh). Same rationale as
|
|
4
|
+
// area_code_map.h in this directory: upstream doesn't install this header,
|
|
5
|
+
// even though mapping_file_provider.cc is already compiled into
|
|
6
|
+
// libgeocoding.a/libgeocoding.dylib in both pico_phone build paths. Header
|
|
7
|
+
// only, no implementation duplicated. Copied under the same Apache License,
|
|
8
|
+
// Version 2.0 as the rest of the vendored libphonenumber source.
|
|
9
|
+
|
|
10
|
+
// Copyright (C) 2012 The Libphonenumber Authors
|
|
11
|
+
//
|
|
12
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
13
|
+
// you may not use this file except in compliance with the License.
|
|
14
|
+
// You may obtain a copy of the License at
|
|
15
|
+
//
|
|
16
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
17
|
+
//
|
|
18
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
19
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
20
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
21
|
+
// See the License for the specific language governing permissions and
|
|
22
|
+
// limitations under the License.
|
|
23
|
+
|
|
24
|
+
// Author: Patrick Mezard
|
|
25
|
+
|
|
26
|
+
#ifndef I18N_PHONENUMBERS_GEOCODING_MAPPING_FILE_PROVIDER_H_
|
|
27
|
+
#define I18N_PHONENUMBERS_GEOCODING_MAPPING_FILE_PROVIDER_H_
|
|
28
|
+
|
|
29
|
+
#include <string>
|
|
30
|
+
|
|
31
|
+
#include "phonenumbers/base/basictypes.h"
|
|
32
|
+
|
|
33
|
+
namespace i18n {
|
|
34
|
+
namespace phonenumbers {
|
|
35
|
+
|
|
36
|
+
using std::string;
|
|
37
|
+
|
|
38
|
+
struct CountryLanguages;
|
|
39
|
+
|
|
40
|
+
// A utility which knows the data files that are available for the geocoder to
|
|
41
|
+
// use. The data files contain mappings from phone number prefixes to text
|
|
42
|
+
// descriptions, and are organized by country calling code and language that the
|
|
43
|
+
// text descriptions are in.
|
|
44
|
+
class MappingFileProvider {
|
|
45
|
+
public:
|
|
46
|
+
typedef const CountryLanguages* (*country_languages_getter)(int index);
|
|
47
|
+
|
|
48
|
+
// Initializes a MappingFileProvider with country_calling_codes, a sorted
|
|
49
|
+
// list of country_calling_code_size calling codes, and a function
|
|
50
|
+
// get_country_languages(int index) returning the CountryLanguage information
|
|
51
|
+
// related to the country code at index in country_calling_codes.
|
|
52
|
+
MappingFileProvider(const int* country_calling_codes,
|
|
53
|
+
int country_calling_code_size,
|
|
54
|
+
country_languages_getter get_country_languages);
|
|
55
|
+
|
|
56
|
+
// This type is neither copyable nor movable.
|
|
57
|
+
MappingFileProvider(const MappingFileProvider&) = delete;
|
|
58
|
+
MappingFileProvider& operator=(const MappingFileProvider&) = delete;
|
|
59
|
+
|
|
60
|
+
// Returns the name of the file that contains the mapping data for the
|
|
61
|
+
// country_calling_code in the language specified, or an empty string if no
|
|
62
|
+
// such file can be found.
|
|
63
|
+
// language is a two or three-letter lowercase language code as defined by ISO
|
|
64
|
+
// 639. Note that where two different language codes exist (e.g. 'he' and 'iw'
|
|
65
|
+
// for Hebrew) we use the one that Java/Android canonicalized on ('iw' in this
|
|
66
|
+
// case).
|
|
67
|
+
// script is a four-letter titlecase (the first letter is uppercase and the
|
|
68
|
+
// rest of the letters are lowercase) ISO script code as defined in ISO 15924.
|
|
69
|
+
// region is a two-letter uppercase ISO country code as defined by ISO 3166-1.
|
|
70
|
+
const string& GetFileName(int country_calling_code, const string& language,
|
|
71
|
+
const string& script, const string& region, string*
|
|
72
|
+
filename) const;
|
|
73
|
+
|
|
74
|
+
private:
|
|
75
|
+
void FindBestMatchingLanguageCode(const CountryLanguages* languages,
|
|
76
|
+
const string& language,
|
|
77
|
+
const string& script,
|
|
78
|
+
const string& region,
|
|
79
|
+
string* best_match) const;
|
|
80
|
+
|
|
81
|
+
const int* const country_calling_codes_;
|
|
82
|
+
const int country_calling_codes_size_;
|
|
83
|
+
const country_languages_getter get_country_languages_;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
} // namespace phonenumbers
|
|
87
|
+
} // namespace i18n
|
|
88
|
+
|
|
89
|
+
#endif // I18N_PHONENUMBERS_GEOCODING_MAPPING_FILE_PROVIDER_H_
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|