Browse Source

Merge branch 'master' into b-335892662

b-335892662
Tijana Vislavski Gradina 12 months ago
committed by GitHub
parent
commit
1e23b3077c
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
6 changed files with 37 additions and 6 deletions
  1. +11
    -0
      cpp/src/phonenumbers/phonenumberutil.cc
  2. +10
    -0
      cpp/test/phonenumbers/phonenumberutil_test.cc
  3. +5
    -2
      java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java
  4. +8
    -1
      java/libphonenumber/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java
  5. +1
    -2
      javascript/i18n/phonenumbers/phonenumberutil.js
  6. +2
    -1
      pending_code_changes.txt

+ 11
- 0
cpp/src/phonenumbers/phonenumberutil.cc View File

@ -1710,6 +1710,17 @@ void PhoneNumberUtil::FormatOutOfCountryKeepingAlphaChars(
PrefixNumberWithCountryCallingCode(country_code, INTERNATIONAL,
formatted_number);
}
std::string region_code;
GetRegionCodeForCountryCode(country_code, &region_code);
// Metadata cannot be null because the country code is valid.
const PhoneMetadata* metadata_for_region =
GetMetadataForRegionOrCallingCode(country_code, region_code);
// Strip any extension
std::string extension;
MaybeStripExtension(formatted_number, &extension);
// Append the formatted extension
MaybeAppendFormattedExtension(number, *metadata_for_region, INTERNATIONAL,
formatted_number);
}
const NumberFormat* PhoneNumberUtil::ChooseFormattingPatternForNumber(


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

@ -935,6 +935,16 @@ TEST_F(PhoneNumberUtilTest, FormatOutOfCountryKeepingAlphaChars) {
&formatted_number);
EXPECT_EQ("1 800 SIX-FLAG", formatted_number);
// Testing a number with extension.
formatted_number.clear();
PhoneNumber alpha_numeric_number_with_extn;
phone_util_.ParseAndKeepRawInput("800 SIX-flag ext. 1234", RegionCode::US(),
&alpha_numeric_number_with_extn);
// preferredExtnPrefix for US is " extn. " (in test metadata)
phone_util_.FormatOutOfCountryKeepingAlphaChars(
alpha_numeric_number_with_extn, RegionCode::AU(), &formatted_number);
EXPECT_EQ("0011 1 800 SIX-FLAG extn. 1234", formatted_number);
// Testing that if the raw input doesn't exist, it is formatted using
// FormatOutOfCountryCallingNumber.
alpha_numeric_number.clear_raw_input();


+ 5
- 2
java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java View File

@ -1878,8 +1878,11 @@ public class PhoneNumberUtil {
String regionCode = getRegionCodeForCountryCode(countryCode);
// Metadata cannot be null because the country calling code is valid.
PhoneMetadata metadataForRegion = getMetadataForRegionOrCallingCode(countryCode, regionCode);
maybeAppendFormattedExtension(number, metadataForRegion,
PhoneNumberFormat.INTERNATIONAL, formattedNumber);
// Strip any extension
maybeStripExtension(formattedNumber);
// Append the formatted extension
maybeAppendFormattedExtension(
number, metadataForRegion, PhoneNumberFormat.INTERNATIONAL, formattedNumber);
if (internationalPrefixForFormatting.length() > 0) {
formattedNumber.insert(0, " ").insert(0, countryCode).insert(0, " ")
.insert(0, internationalPrefixForFormatting);


+ 8
- 1
java/libphonenumber/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java View File

@ -675,7 +675,7 @@ public class PhoneNumberUtilTest extends TestMetadataTestCase {
phoneUtil.formatOutOfCountryCallingNumber(IT_NUMBER, RegionCode.UZ));
}
public void testFormatOutOfCountryKeepingAlphaChars() {
public void testFormatOutOfCountryKeepingAlphaChars() throws Exception {
PhoneNumber alphaNumericNumber = new PhoneNumber();
alphaNumericNumber.setCountryCode(1).setNationalNumber(8007493524L)
.setRawInput("1800 six-flag");
@ -701,6 +701,13 @@ public class PhoneNumberUtilTest extends TestMetadataTestCase {
assertEquals("1 800 SIX-FLAG",
phoneUtil.formatOutOfCountryKeepingAlphaChars(alphaNumericNumber, RegionCode.BS));
// Testing a number with extension.
PhoneNumber alphaNumericNumberWithExtn =
phoneUtil.parseAndKeepRawInput("800 SIX-flag ext. 1234", RegionCode.US);
assertEquals(
"0011 1 800 SIX-FLAG extn. 1234",
phoneUtil.formatOutOfCountryKeepingAlphaChars(alphaNumericNumberWithExtn, RegionCode.AU));
// Testing that if the raw input doesn't exist, it is formatted using
// formatOutOfCountryCallingNumber.
alphaNumericNumber.clearRawInput();


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

@ -4771,8 +4771,7 @@ i18n.phonenumbers.PhoneNumberUtil.prototype.canBeInternationallyDialled =
*/
i18n.phonenumbers.PhoneNumberUtil.matchesEntirely = function(regex, str) {
/** @type {Array.<string>} */
var matchedGroups = (typeof regex == 'string') ?
str.match('^(?:' + regex + ')$') : str.match(regex);
var matchedGroups = str.match(new RegExp('^(?:' + (typeof regex == 'string' ? regex : regex.source) + ')$', 'i'));
if (matchedGroups && matchedGroups[0].length == str.length) {
return true;
}


+ 2
- 1
pending_code_changes.txt View File

@ -1 +1,2 @@
Code changes:
- Fixed a bug where the extension was appended twice in formatOutOfCountryKeepingAlphaChars in the Java version and updated FormatOutOfCountryKeepingAlphaChars in the C++ version to format the extension.

Loading…
Cancel
Save