Browse Source

Colombia: update formatForMobileDialling() API to not include carrier selection code 03 (#2786)

pull/2787/head
penmetsaa 4 years ago
committed by GitHub
parent
commit
99a44a6ab5
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 747 additions and 682 deletions
  1. +1
    -9
      cpp/src/phonenumbers/phonenumberutil.cc
  2. +671
    -645
      cpp/src/phonenumbers/test_metadata.cc
  3. +6
    -0
      cpp/test/phonenumbers/phonenumberutil_test.cc
  4. +4
    -0
      cpp/test/phonenumbers/test_util.h
  5. +1
    -8
      java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java
  6. +6
    -2
      java/libphonenumber/test/com/google/i18n/phonenumbers/CountryCodeToRegionCodeMapForTesting.java
  7. +4
    -0
      java/libphonenumber/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java
  8. +1
    -0
      java/libphonenumber/test/com/google/i18n/phonenumbers/RegionCode.java
  9. BIN
      java/libphonenumber/test/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProtoForTesting_CO
  10. +1
    -18
      javascript/i18n/phonenumbers/phonenumberutil.js
  11. +7
    -0
      javascript/i18n/phonenumbers/phonenumberutil_test.js
  12. +1
    -0
      javascript/i18n/phonenumbers/regioncodefortesting.js
  13. +44
    -0
      resources/PhoneNumberMetadataForTesting.xml

+ 1
- 9
cpp/src/phonenumbers/phonenumberutil.cc View File

@ -88,10 +88,6 @@ const char PhoneNumberUtil::kRegionCodeForNonGeoEntity[] = "001";
namespace {
// The prefix that needs to be inserted in front of a Colombian landline
// number when dialed from a mobile phone in Colombia.
const char kColombiaMobileToFixedLinePrefix[] = "3";
// The kPlusSign signifies the international prefix.
const char kPlusSign[] = "+";
@ -1269,11 +1265,7 @@ void PhoneNumberUtil::FormatNumberForMobileDialing(
(number_type == FIXED_LINE) || (number_type == MOBILE) ||
(number_type == FIXED_LINE_OR_MOBILE);
// Carrier codes may be needed in some countries. We handle this here.
if ((region_code == "CO") && (number_type == FIXED_LINE)) {
FormatNationalNumberWithCarrierCode(
number_no_extension, kColombiaMobileToFixedLinePrefix,
formatted_number);
} else if ((region_code == "BR") && (is_fixed_line_or_mobile)) {
if ((region_code == "BR") && (is_fixed_line_or_mobile)) {
// Historically, we set this to an empty string when parsing with raw
// input if none was found in the input string. However, this doesn't
// result in a number we can dial. For this reason, we treat the empty


+ 671
- 645
cpp/src/phonenumbers/test_metadata.cc
File diff suppressed because it is too large
View File


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

@ -1102,6 +1102,12 @@ TEST_F(PhoneNumberUtilTest, FormatNumberForMobileDialing) {
// Numbers are normally dialed in national format in-country, and
// international format from outside the country.
test_number.set_country_code(57);
test_number.set_national_number(uint64{6012345678});
phone_util_.FormatNumberForMobileDialing(
test_number, RegionCode::CO(), false, /* remove formatting */
&formatted_number);
EXPECT_EQ("6012345678", formatted_number);
test_number.set_country_code(49);
test_number.set_national_number(uint64{30123456});
phone_util_.FormatNumberForMobileDialing(


+ 4
- 0
cpp/test/phonenumbers/test_util.h View File

@ -109,6 +109,10 @@ class RegionCode {
return "CN";
}
static const char* CO() {
return "CO";
}
static const char* CS() {
return "CS";
}


+ 1
- 8
java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java View File

@ -74,10 +74,6 @@ public class PhoneNumberUtil {
private static final int NANPA_COUNTRY_CODE = 1;
// The prefix that needs to be inserted in front of a Colombian landline number when dialed from
// a mobile phone in Colombia.
private static final String COLOMBIA_MOBILE_TO_FIXED_LINE_PREFIX = "3";
// Map of country calling codes that use a mobile token before the area code. One example of when
// this is relevant is when determining the length of the national destination code, which should
// be the length of the area code plus the length of the mobile token.
@ -1471,10 +1467,7 @@ public class PhoneNumberUtil {
(numberType == PhoneNumberType.FIXED_LINE) || (numberType == PhoneNumberType.MOBILE)
|| (numberType == PhoneNumberType.FIXED_LINE_OR_MOBILE);
// Carrier codes may be needed in some countries. We handle this here.
if (regionCode.equals("CO") && numberType == PhoneNumberType.FIXED_LINE) {
formattedNumber =
formatNationalNumberWithCarrierCode(numberNoExt, COLOMBIA_MOBILE_TO_FIXED_LINE_PREFIX);
} else if (regionCode.equals("BR") && isFixedLineOrMobile) {
if (regionCode.equals("BR") && isFixedLineOrMobile) {
// Historically, we set this to an empty string when parsing with raw input if none was
// found in the input string. However, this doesn't result in a number we can dial. For this
// reason, we treat the empty string the same as if it isn't set at all.


+ 6
- 2
java/libphonenumber/test/com/google/i18n/phonenumbers/CountryCodeToRegionCodeMapForTesting.java View File

@ -31,10 +31,10 @@ public class CountryCodeToRegionCodeMapForTesting {
// countries sharing a calling code, such as the NANPA countries, the one
// indicated with "isMainCountryForCode" in the metadata should be first.
public static Map<Integer, List<String>> getCountryCodeToRegionCodeMap() {
// The capacity is set to 37 as there are 28 different entries,
// The capacity is set to 38 as there are 29 different entries,
// and this offers a load factor of roughly 0.75.
Map<Integer, List<String>> countryCodeToRegionCodeMap =
new HashMap<Integer, List<String>>(37);
new HashMap<Integer, List<String>>(38);
ArrayList<String> listWithRegionCode;
@ -86,6 +86,10 @@ public class CountryCodeToRegionCodeMapForTesting {
listWithRegionCode.add("BR");
countryCodeToRegionCodeMap.put(55, listWithRegionCode);
listWithRegionCode = new ArrayList<String>(1);
listWithRegionCode.add("CO");
countryCodeToRegionCodeMap.put(57, listWithRegionCode);
listWithRegionCode = new ArrayList<String>(3);
listWithRegionCode.add("AU");
listWithRegionCode.add("CC");


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

@ -61,6 +61,8 @@ public class PhoneNumberUtilTest extends TestMetadataTestCase {
new PhoneNumber().setCountryCode(1).setNationalNumber(2423570000L);
private static final PhoneNumber BS_NUMBER =
new PhoneNumber().setCountryCode(1).setNationalNumber(2423651234L);
private static final PhoneNumber CO_FIXED_LINE =
new PhoneNumber().setCountryCode(57).setNationalNumber(6012345678L);
// Note that this is the same as the example number for DE in the metadata.
private static final PhoneNumber DE_NUMBER =
new PhoneNumber().setCountryCode(49).setNationalNumber(30123456L);
@ -810,6 +812,8 @@ public class PhoneNumberUtilTest extends TestMetadataTestCase {
public void testFormatNumberForMobileDialing() {
// Numbers are normally dialed in national format in-country, and international format from
// outside the country.
assertEquals("6012345678",
phoneUtil.formatNumberForMobileDialing(CO_FIXED_LINE, RegionCode.CO, false));
assertEquals("030123456",
phoneUtil.formatNumberForMobileDialing(DE_NUMBER, RegionCode.DE, false));
assertEquals("+4930123456",


+ 1
- 0
java/libphonenumber/test/com/google/i18n/phonenumbers/RegionCode.java View File

@ -37,6 +37,7 @@ final class RegionCode {
static final String CH = "CH";
static final String CL = "CL";
static final String CN = "CN";
static final String CO = "CO";
static final String CS = "CS";
static final String CX = "CX";
static final String DE = "DE";


BIN
java/libphonenumber/test/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProtoForTesting_CO View File


+ 1
- 18
javascript/i18n/phonenumbers/phonenumberutil.js View File

@ -144,17 +144,6 @@ i18n.phonenumbers.PhoneNumberUtil.MAX_INPUT_STRING_LENGTH_ = 250;
i18n.phonenumbers.PhoneNumberUtil.UNKNOWN_REGION_ = 'ZZ';
/**
* The prefix that needs to be inserted in front of a Colombian landline number
* when dialed from a mobile phone in Colombia.
*
* @const
* @type {string}
* @private
*/
i18n.phonenumbers.PhoneNumberUtil.COLOMBIA_MOBILE_TO_FIXED_LINE_PREFIX_ = '3';
/**
* Map of country calling codes that use a mobile token before the area code.
* One example of when this is relevant is when determining the length of the
@ -1985,13 +1974,7 @@ i18n.phonenumbers.PhoneNumberUtil.prototype.formatNumberForMobileDialing =
(numberType == i18n.phonenumbers.PhoneNumberType.MOBILE) ||
(numberType == i18n.phonenumbers.PhoneNumberType.FIXED_LINE_OR_MOBILE);
// Carrier codes may be needed in some countries. We handle this here.
if (regionCode == 'CO' &&
numberType == i18n.phonenumbers.PhoneNumberType.FIXED_LINE) {
formattedNumber = this.formatNationalNumberWithCarrierCode(
numberNoExt,
i18n.phonenumbers.PhoneNumberUtil
.COLOMBIA_MOBILE_TO_FIXED_LINE_PREFIX_);
} else if (regionCode == 'BR' && isFixedLineOrMobile) {
if (regionCode == 'BR' && isFixedLineOrMobile) {
formattedNumber =
// Historically, we set this to an empty string when parsing with raw
// input if none was found in the input string. However, this doesn't


+ 7
- 0
javascript/i18n/phonenumbers/phonenumberutil_test.js View File

@ -89,6 +89,10 @@ var BS_NUMBER = new i18n.phonenumbers.PhoneNumber();
BS_NUMBER.setCountryCode(1);
BS_NUMBER.setNationalNumber(2423651234);
/** @type {!i18n.phonenumbers.PhoneNumber} */
var CO_FIXED_LINE = new i18n.phonenumbers.PhoneNumber();
CO_FIXED_LINE.setCountryCode(57);
CO_FIXED_LINE.setNationalNumber(6012345678);
// Note that this is the same as the example number for DE in the metadata.
/** @type {!i18n.phonenumbers.PhoneNumber} */
@ -1103,6 +1107,9 @@ function testFormatWithPreferredCarrierCode() {
function testFormatNumberForMobileDialing() {
// Numbers are normally dialed in national format in-country, and
// international format from outside the country.
assertEquals(
'6012345678',
phoneUtil.formatNumberForMobileDialing(CO_FIXED_LINE, RegionCode.CO, false));
assertEquals(
'030123456',
phoneUtil.formatNumberForMobileDialing(DE_NUMBER, RegionCode.DE, false));


+ 1
- 0
javascript/i18n/phonenumbers/regioncodefortesting.js View File

@ -46,6 +46,7 @@ i18n.phonenumbers.RegionCode = {
CH: 'CH',
CL: 'CL',
CN: 'CN',
CO: 'CO',
CS: 'CS',
CX: 'CX',
DE: 'DE',


+ 44
- 0
resources/PhoneNumberMetadataForTesting.xml View File

@ -375,6 +375,50 @@
</mobile>
</territory>
<!-- Colombia (CO) -->
<!-- Data is here to check formatForMobileDialling() API is no more considering CO as special
i.e it returns regular E.164 format rather than using the 03 carrier code. -->
<territory id="CO" countryCode="57" nationalPrefix="0"
nationalPrefixForParsing="0(4(?:[14]4|56)|[579])?" mobileNumberPortableRegion="true">
<availableFormats>
<numberFormat pattern="(\d{3})(\d{7})" nationalPrefixFormattingRule="($FG)"
carrierCodeFormattingRule="$NP$CC $FG">
<leadingDigits>6</leadingDigits>
<format>$1 $2</format>
</numberFormat>
<numberFormat pattern="(\d{3})(\d{7})" carrierCodeFormattingRule="$NP$CC $FG">
<leadingDigits>3</leadingDigits>
<format>$1 $2</format>
</numberFormat>
</availableFormats>
<generalDesc>
<nationalNumberPattern>
(?:
60|
3\d
)\d{8}
</nationalNumberPattern>
</generalDesc>
<fixedLine>
<possibleLengths national="10"/>
<exampleNumber>6012345678</exampleNumber>
<nationalNumberPattern>60\d{8}</nationalNumberPattern>
</fixedLine>
<mobile>
<possibleLengths national="10"/>
<exampleNumber>3211234567</exampleNumber>
<nationalNumberPattern>
3(?:
0[0-5]|
1\d|
2[0-3]|
5[01]|
70
)\d{7}
</nationalNumberPattern>
</mobile>
</territory>
<!-- Christmas Islands -->
<!-- Country calling code shared with Australia. -->
<!-- This country is used to test ShortNumberInfo, so at least the country calling code must be


Loading…
Cancel
Save