• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // Utility for international short phone numbers, such as short codes and
16 // emergency numbers. Note most commercial short numbers are not handled here,
17 // but by the phonenumberutil.
18 
19 #ifndef I18N_PHONENUMBERS_SHORTNUMBERINFO_H_
20 #define I18N_PHONENUMBERS_SHORTNUMBERINFO_H_
21 
22 #include <map>
23 #include <string>
24 
25 #include "phonenumbers/base/basictypes.h"
26 #include "phonenumbers/base/memory/scoped_ptr.h"
27 #include "phonenumbers/phonemetadata.pb.h"
28 
29 namespace i18n {
30 namespace phonenumbers {
31 
32 using std::map;
33 using std::string;
34 
35 class PhoneNumberUtil;
36 
37 class ShortNumberInfo {
38  public:
39   ShortNumberInfo();
40 
41   // Returns true if the number might be used to connect to an emergency service
42   // in the given region.
43   //
44   // This method takes into account cases where the number might contain
45   // formatting, or might have additional digits appended (when it is okay to do
46   // that in the region specified).
47   bool ConnectsToEmergencyNumber(const string& number,
48                                  const string& region_code) const;
49 
50   // Returns true if the number exactly matches an emergency service number in
51   // the given region.
52   //
53   // This method takes into account cases where the number might contain
54   // formatting, but doesn't allow additional digits to be appended.
55   bool IsEmergencyNumber(const string& number,
56                          const string& region_code) const;
57 
58  private:
59   const PhoneNumberUtil& phone_util_;
60 
61   // A mapping from a RegionCode to the PhoneMetadata for that region.
62   scoped_ptr<map<string, PhoneMetadata> >
63       region_to_short_metadata_map_;
64 
65   const i18n::phonenumbers::PhoneMetadata* GetMetadataForRegion(
66       const string& region_code) const;
67 
68   bool MatchesEmergencyNumberHelper(const string& number,
69                                     const string& region_code,
70                                     bool allow_prefix_match) const;
71 
72   DISALLOW_COPY_AND_ASSIGN(ShortNumberInfo);
73 };
74 
75 }  // namespace phonenumbers
76 }  // namespace i18n
77 
78 #endif  // I18N_PHONENUMBERS_SHORTNUMBERINFO_H_
79