Skip to content

Commit

Permalink
v8.10.17
Browse files Browse the repository at this point in the history
  • Loading branch information
twcclegg committed Aug 16, 2019
1 parent 83206bf commit 805f8bc
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 23 deletions.
19 changes: 19 additions & 0 deletions csharp/PhoneNumbers.Test/TestPhoneNumberUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,25 @@ public void TestGetLengthOfNationalDestinationCode()
// A number containing an invalid country calling code, which shouldn't have any NDC.
var number = new PhoneNumber.Builder().SetCountryCode(123).SetNationalNumber(6502530000L).Build();
Assert.Equal(0, phoneUtil.GetLengthOfNationalDestinationCode(number));

// An international toll free number, which has NDC "1234".
Assert.Equal(4, phoneUtil.GetLengthOfNationalDestinationCode(InternationalTollFree));

// A mobile number from China is geographical, but does not have an area code: however it still
// can be considered to have a national destination code.
var cnMobile = new PhoneNumber.Builder().SetCountryCode(86).SetNationalNumber(18912341234L).Build();
Assert.Equal(3, phoneUtil.GetLengthOfNationalDestinationCode(cnMobile));
}

[Fact]
public void TestGetCountryMobileToken()
{
Assert.Equal("9", PhoneNumberUtil.GetCountryMobileToken(phoneUtil.GetCountryCodeForRegion(
RegionCode.AR)));

// Country calling code for Sweden, which has no mobile token.
Assert.Equal("", PhoneNumberUtil.GetCountryMobileToken(phoneUtil.GetCountryCodeForRegion(
RegionCode.SE)));
}

[Fact]
Expand Down
19 changes: 18 additions & 1 deletion csharp/PhoneNumbers/AsYouTypeFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,10 @@ private bool IsDigitOrLeadingPlusSign(char nextChar)
PhoneNumberUtil.PlusCharsPattern.MatchAll(char.ToString(nextChar)).Success;
}

/// <summary>
/// Checks to see if there is an exact pattern match for these digits. If so, we should use this
///instead of any other formatting template whose leadingDigitsPattern also matches the input.
/// </summary>
private string AttemptToFormatAccruedDigits()
{
foreach (var numFormat in possibleFormats)
Expand All @@ -457,7 +461,20 @@ private string AttemptToFormatAccruedDigits()
shouldAddSpaceAfterNationalPrefix =
NationalPrefixSeparatorsPattern.Match(numFormat.NationalPrefixFormattingRule).Success;
var formattedNumber = m.Replace(nationalNumber.ToString(), numFormat.Format);
return AppendNationalNumber(formattedNumber);
// Check that we did not remove nor add any extra digits when we matched
// this formatting pattern. This usually happens after we entered the last
// digit during AYTF. Eg: In case of MX, we swallow mobile token (1) when
// formatted but AYTF should retain all the number entered and not change
// in order to match a format (of same leading digits and length) display
// in that way.
var fullOutput = AppendNationalNumber(formattedNumber);
var formattedNumberDigitsOnly = PhoneNumberUtil.NormalizeDiallableCharsOnly(fullOutput);
if (formattedNumberDigitsOnly.Equals(accruedInputWithoutFormatting.ToString()))
{
// If it's the same (i.e entered number and format is same), then it's
// safe to return this in formatted number as nothing is lost / added.
return fullOutput;
}
}
}
return "";
Expand Down
18 changes: 18 additions & 0 deletions csharp/PhoneNumbers/PhoneNumberUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,17 @@ internal static StringBuilder NormalizeDigits(string number, bool keepNonDigits)
return normalizedDigits;
}

/// <summary>
/// Normalizes a string of characters representing a phone number. This strips all characters which
/// are not diallable on a mobile phone keypad (including all non-ASCII digits).
/// </summary>
/// <param name="number"> a string of characters representing a phone number</param>
/// <returns> the normalized string version of the phone number</returns>
public static string NormalizeDiallableCharsOnly(string number)
{
return NormalizeHelper(number, DiallableCharMappings, true /* remove non matches */);
}

/// <summary>
/// Converts all alpha characters in a number to their respective digits on a keypad, but retains
/// existing formatting.
Expand Down Expand Up @@ -883,6 +894,13 @@ private static string NormalizeHelper(string number, Dictionary<char, char> norm
return normalizedNumber.ToString();
}

/// <summary>
/// Gets a {@link PhoneNumberUtil} instance to carry out international phone number formatting,
/// parsing, or validation. The instance is loaded with all phone number metadata.
/// The <see cref="PhoneNumberUtil" /> is implemented as a singleton.Therefore, calling getInstance
/// multiple times will only result in one instance being created.
/// </summary>
/// <returns> a PhoneNumberUtil instance</returns>
public static PhoneNumberUtil GetInstance(string baseFileLocation,
Dictionary<int, List<string>> countryCallingCodeToRegionCodeMap)
{
Expand Down
48 changes: 27 additions & 21 deletions resources/PhoneNumberMetaData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,10 @@
<format>$1 $2 $3</format>
</numberFormat>
<numberFormat pattern="(\d{3})(\d{5})" nationalPrefixFormattingRule="($NP$FG)">
<leadingDigits>[23]</leadingDigits>
<leadingDigits>
2|
3[12]
</leadingDigits>
<format>$1 $2</format>
</numberFormat>
<numberFormat pattern="(\d{2})(\d{6})" nationalPrefixFormattingRule="($NP$FG)">
Expand All @@ -615,7 +618,7 @@
<format>$1 $2</format>
</numberFormat>
<numberFormat pattern="(\d{2})(\d{6})" nationalPrefixFormattingRule="$NP$FG">
<leadingDigits>[4-9]</leadingDigits>
<leadingDigits>[3-9]</leadingDigits>
<format>$1 $2</format>
</numberFormat>
</availableFormats>
Expand Down Expand Up @@ -658,6 +661,7 @@
<exampleNumber>77123456</exampleNumber>
<nationalNumberPattern>
(?:
33|
4[1349]|
55|
77|
Expand Down Expand Up @@ -18636,14 +18640,15 @@
[0-36]|
4\d
)|
(?:
6[7-9]|
89
)\d|
6[7-9]\d|
7(?:
3|
5[0-2]|
[6-9]\d
)|
8(?:
8[7-9]|
9\d
)
)\d|
4(?:
Expand Down Expand Up @@ -19508,8 +19513,7 @@
national format (leading 044/045), will be parsed into the same form. -->
<territory id="MX" countryCode="52" preferredInternationalPrefix="00"
internationalPrefix="0[09]" nationalPrefix="01"
nationalPrefixForParsing="0[12]|04[45]([2-9]\d{9})$"
nationalPrefixTransformRule="1$1" mobileNumberPortableRegion="true">
nationalPrefixForParsing="0(?:[12]|4[45])|1" mobileNumberPortableRegion="true">
<availableFormats>
<!-- 5-digit shortcodes (very rare). -->
<numberFormat pattern="(\d{5})">
Expand All @@ -19518,8 +19522,7 @@
<intlFormat>NA</intlFormat>
</numberFormat>
<!-- Fixed line (2-digit area codes). -->
<numberFormat pattern="(\d{2})(\d{4})(\d{4})" nationalPrefixFormattingRule="$NP $FG"
nationalPrefixOptionalWhenFormatting="true">
<numberFormat pattern="(\d{2})(\d{4})(\d{4})" nationalPrefixOptionalWhenFormatting="true">
<leadingDigits>
33|
5[56]|
Expand All @@ -19528,13 +19531,13 @@
<format>$1 $2 $3</format>
</numberFormat>
<!-- Fixed line (3-digit area codes) and other non-mobile numbers. -->
<numberFormat pattern="(\d{3})(\d{3})(\d{4})" nationalPrefixFormattingRule="$NP $FG"
nationalPrefixOptionalWhenFormatting="true">
<numberFormat pattern="(\d{3})(\d{3})(\d{4})" nationalPrefixOptionalWhenFormatting="true">
<leadingDigits>[2-9]</leadingDigits>
<format>$1 $2 $3</format>
</numberFormat>
<!-- Mobile version of fixed line 2-digit area codes (prepends mobile token). -->
<numberFormat pattern="(\d)(\d{2})(\d{4})(\d{4})" nationalPrefixFormattingRule="044 $FG">
<!-- Mobile version of fixed line 2-digit area codes and removing former mobile token 1. -->
<numberFormat pattern="(\d)(\d{2})(\d{4})(\d{4})"
nationalPrefixOptionalWhenFormatting="true">
<leadingDigits>
1(?:
33|
Expand All @@ -19543,21 +19546,24 @@
)
</leadingDigits>
<format>$2 $3 $4</format>
<intlFormat>$1 $2 $3 $4</intlFormat>
</numberFormat>
<!-- Mobile version of fixed line 3-digit area codes (prepends mobile token). -->
<numberFormat pattern="(\d)(\d{3})(\d{3})(\d{4})" nationalPrefixFormattingRule="044 $FG">
<!-- Mobile version of fixed line 3-digit area codes and removing former mobile token 1. -->
<numberFormat pattern="(\d)(\d{3})(\d{3})(\d{4})"
nationalPrefixOptionalWhenFormatting="true">
<leadingDigits>1</leadingDigits>
<format>$2 $3 $4</format>
<intlFormat>$1 $2 $3 $4</intlFormat>
</numberFormat>
</availableFormats>
<generalDesc>
<nationalNumberPattern>
(?:
1\d|
[2-9]
)\d{9}
1(?:
[01467]\d|
[2359][1-9]|
8[1-79]
)|
[2-9]\d
)\d{8}
</nationalNumberPattern>
</generalDesc>
<!-- http://en.wikipedia.org/wiki/Area_codes_in_Mexico_by_code -->
Expand Down
4 changes: 3 additions & 1 deletion resources/ShortNumberMetadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11970,7 +11970,8 @@
)|
2(?:
22|
3[89]
3[89]|
66
)|
3(?:
18|
Expand Down Expand Up @@ -12066,6 +12067,7 @@
)|
1(?:
1[68]|
26|
3[1-35]|
5[689]|
60|
Expand Down
1 change: 1 addition & 0 deletions resources/carrier/en/374.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# Data from Wikipedia:
# http://en.wikipedia.org/wiki/Telephone_numbers_in_Armenia#Mobile_network_codes

37433|Beeline
37441|Ucom
37443|Beeline
37444|Ucom
Expand Down
1 change: 1 addition & 0 deletions resources/carrier/en/86.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
86155|China Unicom
86156|China Unicom
86166|China Unicom
86167|China Unicom
861700|China Telecom
861701|China Telecom
861702|China Telecom
Expand Down
3 changes: 3 additions & 0 deletions resources/carrier/en/95.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
95985|MPT
95986|MPT
95987|MPT
959887|MPT
959888|MPT
959889|MPT
95989|MPT
95991|MPT
95995|Ooredoo
Expand Down
1 change: 1 addition & 0 deletions resources/carrier/ru/374.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

# Translated manually from en/374.txt.

37433|Билайн
37441|Юком
37443|Билайн
37444|Юком
Expand Down
1 change: 1 addition & 0 deletions resources/carrier/zh/86.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
86155|中国联通
86156|中国联通
86166|中国联通
86167|中国联通
861700|中国电信
861701|中国电信
861702|中国电信
Expand Down
1 change: 1 addition & 0 deletions resources/carrier/zh_Hant/86.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
86155|中國聯通
86156|中國聯通
86166|中國聯通
86167|中國聯通
861700|中國電信
861701|中國電信
861702|中國電信
Expand Down

0 comments on commit 805f8bc

Please sign in to comment.