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 // Author: David Yonge-Mallo 20 // 21 // This is a direct port from ShortNumberUtil.java. 22 // Changes to this class should also happen to the Java version, whenever it 23 // makes sense. 24 25 #ifndef I18N_PHONENUMBERS_SHORTNUMBERUTIL_H_ 26 #define I18N_PHONENUMBERS_SHORTNUMBERUTIL_H_ 27 28 #include <string> 29 30 #include "phonenumbers/base/basictypes.h" 31 32 namespace i18n { 33 namespace phonenumbers { 34 35 using std::string; 36 37 class PhoneNumberUtil; 38 39 class ShortNumberUtil { 40 public: 41 ShortNumberUtil(); 42 43 // Returns true if the number might be used to connect to an emergency service 44 // in the given region. 45 // 46 // This method takes into account cases where the number might contain 47 // formatting, or might have additional digits appended (when it is okay to do 48 // that in the region specified). 49 bool ConnectsToEmergencyNumber(const string& number, 50 const string& region_code) const; 51 52 // Returns true if the number exactly matches an emergency service number in 53 // the given region. 54 // 55 // This method takes into account cases where the number might contain 56 // formatting, but doesn't allow additional digits to be appended. 57 bool IsEmergencyNumber(const string& number, 58 const string& region_code) const; 59 60 private: 61 const PhoneNumberUtil& phone_util_; 62 63 bool MatchesEmergencyNumberHelper(const string& number, 64 const string& region_code, 65 bool allow_prefix_match) const; 66 67 DISALLOW_COPY_AND_ASSIGN(ShortNumberUtil); 68 }; 69 70 } // namespace phonenumbers 71 } // namespace i18n 72 73 #endif // I18N_PHONENUMBERS_SHORTNUMBERUTIL_H_ 74