diff options
| author | Tristan Van Berkom <tristanvb@openismus.com> | 2013-11-23 22:08:58 +0900 |
|---|---|---|
| committer | Tristan Van Berkom <tristanvb@openismus.com> | 2013-11-29 22:08:02 +0900 |
| commit | 3c6d57c5275140fd93c1025180ba71a3d6928a80 (patch) | |
| tree | fbbf5908519a816472694d4521ba89d8c2a3fccc /addressbook | |
| parent | 96876cd1942e7e855f167e48bbf4e4613c2a394f (diff) | |
| download | evolution-data-server-3c6d57c5275140fd93c1025180ba71a3d6928a80.tar.gz | |
EPhoneNumber: Fixed phone number matching semantics.
Only use the default region code for the purpose of parsing
phone numbers, but disregard the default country code in comparisons.
Also, work around a bug in libphonenumber's C++ implementation
and make sure to properly promote SHORT number matches to NATIONAL
number match strength.
Based on a patch by Patrick Ohly
Diffstat (limited to 'addressbook')
| -rw-r--r-- | addressbook/libebook-contacts/e-phone-number-private.cpp | 50 |
1 files changed, 37 insertions, 13 deletions
diff --git a/addressbook/libebook-contacts/e-phone-number-private.cpp b/addressbook/libebook-contacts/e-phone-number-private.cpp index f0acc2ba9..e5ee7c9c5 100644 --- a/addressbook/libebook-contacts/e-phone-number-private.cpp +++ b/addressbook/libebook-contacts/e-phone-number-private.cpp @@ -285,24 +285,48 @@ e_phone_number_match (PhoneNumberUtil::MatchType match_type) } static EPhoneNumberMatch -_e_phone_number_cxx_compare (const PhoneNumber &first_number, - const PhoneNumber &second_number) +_e_phone_number_cxx_compare (const PhoneNumber &first_number_in, + const PhoneNumber &second_number_in) { + PhoneNumber first_number(first_number_in); + PhoneNumber second_number(second_number_in); + const EPhoneNumberCountrySource cs1 = + _e_phone_number_cxx_get_country_source (first_number); + const EPhoneNumberCountrySource cs2 = + _e_phone_number_cxx_get_country_source (second_number); + + /* Must clear guessed country codes, otherwise libphonenumber + * includes them in the comparison, leading to false + * negatives. */ + if (cs1 == E_PHONE_NUMBER_COUNTRY_FROM_DEFAULT) + first_number.clear_country_code(); + if (cs2 == E_PHONE_NUMBER_COUNTRY_FROM_DEFAULT) + second_number.clear_country_code(); + PhoneNumberUtil::MatchType match_type = e_phone_number_util_get_instance ()->IsNumberMatch ( first_number, second_number); - /* Downgrade exact matches to national number matches - * if one of the numbers had a guessed country code. */ - if (match_type == PhoneNumberUtil::EXACT_MATCH) { - const EPhoneNumberCountrySource cs1 = - _e_phone_number_cxx_get_country_source (first_number); - const EPhoneNumberCountrySource cs2 = - _e_phone_number_cxx_get_country_source (second_number); - - if (cs1 == E_PHONE_NUMBER_COUNTRY_FROM_DEFAULT - || cs2 == E_PHONE_NUMBER_COUNTRY_FROM_DEFAULT) - match_type = PhoneNumberUtil::NSN_MATCH; + /* XXX Work around a bug in libphonenumber's C++ implementation + * + * If we got a short match and either of the numbers is missing + * the country code, then make sure both of them have an arbitrary + * country code specified... if that matches exactly, then we promote + * the short number match to a national match. + */ + if (match_type == PhoneNumberUtil::SHORT_NSN_MATCH && + (first_number.country_code() == 0 || + second_number.country_code() == 0)) { + + second_number.set_country_code (1); + first_number.set_country_code (1); + + PhoneNumberUtil::MatchType second_match = + e_phone_number_util_get_instance ()->IsNumberMatch ( + first_number, second_number); + + if (second_match == PhoneNumberUtil::EXACT_MATCH) + match_type = PhoneNumberUtil::NSN_MATCH; } g_warn_if_fail (match_type != PhoneNumberUtil::INVALID_NUMBER); |
