Browse Source

Area code information lost for all MX numbers in v8.13.38 metadata update (#3535)

* Area code information lost for all MX numbers in v8.13.38 metadata update.

* add mexico to new variable

* C++ changes for Mexico to show area code
pull/3536/head
mandlil 2 years ago
committed by GitHub
parent
commit
3b7ad7eb37
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
4 changed files with 40 additions and 6 deletions
  1. +16
    -3
      cpp/src/phonenumbers/phonenumberutil.cc
  2. +6
    -0
      cpp/test/phonenumbers/phonenumberutil_test.cc
  3. +15
    -3
      java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java
  4. +3
    -0
      java/libphonenumber/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java

+ 16
- 3
cpp/src/phonenumbers/phonenumberutil.cc View File

@ -619,6 +619,7 @@ class PhoneNumberRegExpsAndMappings {
}
mobile_token_mappings_.insert(std::make_pair(54, '9'));
countries_without_national_prefix_with_area_codes_.insert(52); // Mexico
geo_mobile_countries_without_mobile_area_codes_.insert(86); // China
geo_mobile_countries_.insert(52); // Mexico
geo_mobile_countries_.insert(54); // Argentina
@ -696,6 +697,10 @@ class PhoneNumberRegExpsAndMappings {
// to be an area code.
std::set<int> geo_mobile_countries_without_mobile_area_codes_;
// Set of country codes that doesn't have national prefix, but it has area
// codes.
std::set<int> countries_without_national_prefix_with_area_codes_;
// Set of country calling codes that have geographically assigned mobile
// numbers. This may not be complete; we add calling codes case by case, as we
// find geographical mobile numbers or hear from user reports.
@ -795,6 +800,7 @@ class PhoneNumberRegExpsAndMappings {
alpha_phone_mappings_(),
all_plus_number_grouping_symbols_(),
mobile_token_mappings_(),
countries_without_national_prefix_with_area_codes_(),
geo_mobile_countries_without_mobile_area_codes_(),
geo_mobile_countries_(),
single_international_prefix_(regexp_factory_->CreateRegExp(
@ -2676,15 +2682,22 @@ int PhoneNumberUtil::GetLengthOfGeographicalAreaCode(
if (!metadata) {
return 0;
}
PhoneNumberType type = GetNumberType(number);
int country_calling_code = number.country_code();
// If a country doesn't use a national prefix, and this number doesn't have an
// Italian leading zero, we assume it is a closed dialling plan with no area
// codes.
if (!metadata->has_national_prefix() && !number.italian_leading_zero()) {
// Note:this is our general assumption, but there are exceptions which are
// tracked in COUNTRIES_WITHOUT_NATIONAL_PREFIX_WITH_AREA_CODES.
if (!metadata->has_national_prefix() && !number.italian_leading_zero() &&
reg_exps_->countries_without_national_prefix_with_area_codes_.find(
country_calling_code) ==
reg_exps_->countries_without_national_prefix_with_area_codes_.end()) {
return 0;
}
PhoneNumberType type = GetNumberType(number);
int country_calling_code = number.country_code();
if (type == PhoneNumberUtil::MOBILE &&
reg_exps_->geo_mobile_countries_without_mobile_area_codes_.find(
country_calling_code) !=


+ 6
- 0
cpp/test/phonenumbers/phonenumberutil_test.cc View File

@ -1465,6 +1465,12 @@ TEST_F(PhoneNumberUtilTest, GetLengthOfGeographicalAreaCode) {
number.set_national_number(uint64{293744000});
EXPECT_EQ(1, phone_util_.GetLengthOfGeographicalAreaCode(number));
// Mexico numbers - there is no national prefix, but it still has an area
// code.
number.set_country_code(52);
number.set_national_number(uint64_t{3312345678});
EXPECT_EQ(2, phone_util_.GetLengthOfGeographicalAreaCode(number));
// Italian numbers - there is no national prefix, but it still has an area
// code.
number.set_country_code(39);


+ 15
- 3
java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java View File

@ -85,6 +85,9 @@ public class PhoneNumberUtil {
// considered to be an area code.
private static final Set<Integer> GEO_MOBILE_COUNTRIES_WITHOUT_MOBILE_AREA_CODES;
// Set of country codes that doesn't have national prefix, but it has area codes.
private static final Set<Integer> COUNTRIES_WITHOUT_NATIONAL_PREFIX_WITH_AREA_CODES;
// Set of country calling codes that have geographically assigned mobile numbers. This may not be
// complete; we add calling codes case by case, as we find geographical mobile numbers or hear
// from user reports. Note that countries like the US, where we can't distinguish between
@ -127,6 +130,11 @@ public class PhoneNumberUtil {
GEO_MOBILE_COUNTRIES_WITHOUT_MOBILE_AREA_CODES =
Collections.unmodifiableSet(geoMobileCountriesWithoutMobileAreaCodes);
HashSet<Integer> countriesWithoutNationalPrefixWithAreaCodes = new HashSet<>();
countriesWithoutNationalPrefixWithAreaCodes.add(52); // Mexico
COUNTRIES_WITHOUT_NATIONAL_PREFIX_WITH_AREA_CODES =
Collections.unmodifiableSet(countriesWithoutNationalPrefixWithAreaCodes);
HashSet<Integer> geoMobileCountries = new HashSet<>();
geoMobileCountries.add(52); // Mexico
geoMobileCountries.add(54); // Argentina
@ -893,14 +901,18 @@ public class PhoneNumberUtil {
if (metadata == null) {
return 0;
}
PhoneNumberType type = getNumberType(number);
int countryCallingCode = number.getCountryCode();
// If a country doesn't use a national prefix, and this number doesn't have an Italian leading
// zero, we assume it is a closed dialling plan with no area codes.
if (!metadata.hasNationalPrefix() && !number.isItalianLeadingZero()) {
// Note:this is our general assumption, but there are exceptions which are tracked in
// COUNTRIES_WITHOUT_NATIONAL_PREFIX_WITH_AREA_CODES.
if (!metadata.hasNationalPrefix() && !number.isItalianLeadingZero()
&& !COUNTRIES_WITHOUT_NATIONAL_PREFIX_WITH_AREA_CODES.contains(countryCallingCode)) {
return 0;
}
PhoneNumberType type = getNumberType(number);
int countryCallingCode = number.getCountryCode();
if (type == PhoneNumberType.MOBILE
// Note this is a rough heuristic; it doesn't cover Indonesia well, for example, where area
// codes are present for some mobile phones but not for others. We have no better way of


+ 3
- 0
java/libphonenumber/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java View File

@ -309,6 +309,9 @@ public class PhoneNumberUtilTest extends TestMetadataTestCase {
// Italian numbers - there is no national prefix, but it still has an area code.
assertEquals(2, phoneUtil.getLengthOfGeographicalAreaCode(IT_NUMBER));
// Mexico numbers - there is no national prefix, but it still has an area code.
assertEquals(2, phoneUtil.getLengthOfGeographicalAreaCode(MX_NUMBER1));
// Google Singapore. Singapore has no area code and no national prefix.
assertEquals(0, phoneUtil.getLengthOfGeographicalAreaCode(SG_NUMBER));


Loading…
Cancel
Save