1 // Copyright (C) 2009 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 // Author: Philippe Liard 16 17 #include "phonenumbers/phonemetadata.pb.h" 18 #include "phonenumbers/phonenumber.pb.h" 19 20 namespace i18n { 21 namespace phonenumbers { 22 ExactlySameAs(const PhoneNumber & first_number,const PhoneNumber & second_number)23bool ExactlySameAs(const PhoneNumber& first_number, 24 const PhoneNumber& second_number) { 25 if (first_number.has_country_code() != second_number.has_country_code() || 26 first_number.country_code() != second_number.country_code()) { 27 return false; 28 } 29 if (first_number.has_national_number() != 30 second_number.has_national_number() || 31 first_number.national_number() != second_number.national_number()) { 32 return false; 33 } 34 if (first_number.has_extension() != second_number.has_extension() || 35 first_number.extension() != second_number.extension()) { 36 return false; 37 } 38 if (first_number.has_italian_leading_zero() != 39 second_number.has_italian_leading_zero() || 40 first_number.italian_leading_zero() != 41 second_number.italian_leading_zero()) { 42 return false; 43 } 44 if (first_number.has_number_of_leading_zeros() != 45 second_number.has_number_of_leading_zeros() || 46 first_number.number_of_leading_zeros() != 47 second_number.number_of_leading_zeros()) { 48 return false; 49 } 50 if (first_number.has_raw_input() != second_number.has_raw_input() || 51 first_number.raw_input() != second_number.raw_input()) { 52 return false; 53 } 54 if (first_number.has_country_code_source() != 55 second_number.has_country_code_source() || 56 first_number.country_code_source() != 57 second_number.country_code_source()) { 58 return false; 59 } 60 if (first_number.has_preferred_domestic_carrier_code() != 61 second_number.has_preferred_domestic_carrier_code() || 62 first_number.preferred_domestic_carrier_code() != 63 second_number.preferred_domestic_carrier_code()) { 64 return false; 65 } 66 return true; 67 } 68 ExactlySameAs(const PhoneNumberDesc & first_number_desc,const PhoneNumberDesc & second_number_desc)69bool ExactlySameAs(const PhoneNumberDesc& first_number_desc, 70 const PhoneNumberDesc& second_number_desc) { 71 if (first_number_desc.has_national_number_pattern() != 72 second_number_desc.has_national_number_pattern() || 73 first_number_desc.national_number_pattern() != 74 second_number_desc.national_number_pattern()) { 75 return false; 76 } 77 if (first_number_desc.has_example_number() != 78 second_number_desc.has_example_number() || 79 first_number_desc.example_number() != 80 second_number_desc.example_number()) { 81 return false; 82 } 83 if (first_number_desc.possible_length_size() != 84 second_number_desc.possible_length_size()) { 85 return false; 86 } else { 87 for (int i = 0; i < first_number_desc.possible_length_size(); ++i) { 88 if (first_number_desc.possible_length(i) != 89 second_number_desc.possible_length(i)) { 90 return false; 91 } 92 } 93 } 94 if (first_number_desc.possible_length_local_only_size() != 95 second_number_desc.possible_length_local_only_size()) { 96 return false; 97 } else { 98 for (int i = 0; i < first_number_desc.possible_length_local_only_size(); 99 ++i) { 100 if (first_number_desc.possible_length_local_only(i) != 101 second_number_desc.possible_length_local_only(i)) { 102 return false; 103 } 104 } 105 } 106 return true; 107 } 108 109 } // namespace phonenumbers 110 } // namespace i18n 111