OLD | NEW |
1 // Copyright (C) 2009 The Libphonenumber Authors | 1 // Copyright (C) 2009 The Libphonenumber Authors |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with 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 | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
13 // limitations under the License. | 13 // limitations under the License. |
14 | 14 |
15 // Author: Shaopeng Jia | 15 // Author: Shaopeng Jia |
16 // Open-sourced by: Philippe Liard | 16 // Open-sourced by: Philippe Liard |
17 | 17 |
18 #include "phonenumbers/phonenumberutil.h" | 18 #include "phonenumbers/phonenumberutil.h" |
19 | 19 |
20 #include <string.h> | |
21 #include <algorithm> | 20 #include <algorithm> |
22 #include <cctype> | 21 #include <cctype> |
23 #include <fstream> | 22 #include <cstring> |
24 #include <iostream> | |
25 #include <iterator> | 23 #include <iterator> |
26 #include <map> | 24 #include <map> |
27 #include <sstream> | |
28 #include <utility> | 25 #include <utility> |
29 #include <vector> | 26 #include <vector> |
30 | 27 |
31 #include <google/protobuf/message_lite.h> | 28 #include <google/protobuf/message_lite.h> |
32 #include <unicode/uchar.h> | 29 #include <unicode/uchar.h> |
33 #include <unicode/utf8.h> | 30 #include <unicode/utf8.h> |
34 | 31 |
35 #include "phonenumbers/asyoutypeformatter.h" | 32 #include "phonenumbers/asyoutypeformatter.h" |
36 #include "phonenumbers/base/basictypes.h" | 33 #include "phonenumbers/base/basictypes.h" |
37 #include "phonenumbers/base/logging.h" | 34 #include "phonenumbers/base/logging.h" |
(...skipping 10 matching lines...) Expand all Loading... |
48 #include "phonenumbers/regexp_factory.h" | 45 #include "phonenumbers/regexp_factory.h" |
49 #include "phonenumbers/region_code.h" | 46 #include "phonenumbers/region_code.h" |
50 #include "phonenumbers/stl_util.h" | 47 #include "phonenumbers/stl_util.h" |
51 #include "phonenumbers/stringutil.h" | 48 #include "phonenumbers/stringutil.h" |
52 #include "phonenumbers/utf/unicodetext.h" | 49 #include "phonenumbers/utf/unicodetext.h" |
53 #include "phonenumbers/utf/utf.h" | 50 #include "phonenumbers/utf/utf.h" |
54 | 51 |
55 namespace i18n { | 52 namespace i18n { |
56 namespace phonenumbers { | 53 namespace phonenumbers { |
57 | 54 |
58 using std::cerr; | |
59 using std::endl; | |
60 using std::ifstream; | |
61 using std::make_pair; | 55 using std::make_pair; |
62 using std::sort; | 56 using std::sort; |
63 using std::stringstream; | |
64 | 57 |
65 using google::protobuf::RepeatedPtrField; | 58 using google::protobuf::RepeatedPtrField; |
66 | 59 |
67 // static | 60 // static |
68 const char PhoneNumberUtil::kPlusChars[] = "+\xEF\xBC\x8B"; /* "++" */ | 61 const char PhoneNumberUtil::kPlusChars[] = "+\xEF\xBC\x8B"; /* "++" */ |
69 // To find out the unicode code-point of the characters below in vim, highlight | 62 // To find out the unicode code-point of the characters below in vim, highlight |
70 // the character and type 'ga'. Note that the - is used to express ranges of | 63 // the character and type 'ga'. Note that the - is used to express ranges of |
71 // full-width punctuation below, as well as being present in the expression | 64 // full-width punctuation below, as well as being present in the expression |
72 // itself. In emacs, you can use M-x unicode-what to query information about the | 65 // itself. In emacs, you can use M-x unicode-what to query information about the |
73 // unicode character. | 66 // unicode character. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 // extn: 3456", then you should specify " extn: " here as the default extension | 104 // extn: 3456", then you should specify " extn: " here as the default extension |
112 // prefix. This can be overridden by region-specific preferences. | 105 // prefix. This can be overridden by region-specific preferences. |
113 const char kDefaultExtnPrefix[] = " ext. "; | 106 const char kDefaultExtnPrefix[] = " ext. "; |
114 | 107 |
115 // One-character symbols that can be used to indicate an extension. | 108 // One-character symbols that can be used to indicate an extension. |
116 const char kSingleExtnSymbolsForMatching[] = | 109 const char kSingleExtnSymbolsForMatching[] = |
117 "x\xEF\xBD\x98#\xEF\xBC\x83~\xEF\xBD\x9E"; | 110 "x\xEF\xBD\x98#\xEF\xBC\x83~\xEF\xBD\x9E"; |
118 | 111 |
119 bool LoadCompiledInMetadata(PhoneMetadataCollection* metadata) { | 112 bool LoadCompiledInMetadata(PhoneMetadataCollection* metadata) { |
120 if (!metadata->ParseFromArray(metadata_get(), metadata_size())) { | 113 if (!metadata->ParseFromArray(metadata_get(), metadata_size())) { |
121 cerr << "Could not parse binary data." << endl; | 114 LOG(ERROR) << "Could not parse binary data."; |
122 return false; | 115 return false; |
123 } | 116 } |
124 return true; | 117 return true; |
125 } | 118 } |
126 | 119 |
127 // Returns a pointer to the description inside the metadata of the appropriate | 120 // Returns a pointer to the description inside the metadata of the appropriate |
128 // type. | 121 // type. |
129 const PhoneNumberDesc* GetNumberDescByType( | 122 const PhoneNumberDesc* GetNumberDescByType( |
130 const PhoneMetadata& metadata, | 123 const PhoneMetadata& metadata, |
131 PhoneNumberUtil::PhoneNumberType type) { | 124 PhoneNumberUtil::PhoneNumberType type) { |
(...skipping 2618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2750 } | 2743 } |
2751 string national_significant_number; | 2744 string national_significant_number; |
2752 GetNationalSignificantNumber(number, &national_significant_number); | 2745 GetNationalSignificantNumber(number, &national_significant_number); |
2753 return !IsNumberMatchingDesc( | 2746 return !IsNumberMatchingDesc( |
2754 national_significant_number, metadata->no_international_dialling(), | 2747 national_significant_number, metadata->no_international_dialling(), |
2755 reg_exps_->regexp_cache_.get()); | 2748 reg_exps_->regexp_cache_.get()); |
2756 } | 2749 } |
2757 | 2750 |
2758 } // namespace phonenumbers | 2751 } // namespace phonenumbers |
2759 } // namespace i18n | 2752 } // namespace i18n |
OLD | NEW |