diff --git a/src/PhoneNumbers/Formatters/PhoneNumberFormatter.cs b/src/PhoneNumbers/Formatters/PhoneNumberFormatter.cs index 66656a8a..7a538500 100644 --- a/src/PhoneNumbers/Formatters/PhoneNumberFormatter.cs +++ b/src/PhoneNumbers/Formatters/PhoneNumberFormatter.cs @@ -36,7 +36,7 @@ protected static string FormatInternational( bool wrapNdc = false, char nonDigitSubstitute = Chars.Null) { - var shouldWrapNdc = wrapNdc && phoneNumber.Country.HasNationalDestinationCodes; + var shouldWrapNdc = wrapNdc && phoneNumber.HasNationalDestinationCode; var nsnMask = phoneNumber.Country.FormatProvider.GetFormat(phoneNumber, international: true); var arSize = @@ -44,7 +44,7 @@ protected static string FormatInternational( + 1 // add one for the + appended to the calling code + phoneNumber.Country.CallingCode.Length + (charBetweenCallingCodeAndNsn != Chars.Null ? 1 : 0) - + (wrapNdc ? 2 : 0) // add 2 for the parenthesis if wrapping the NDC + + (shouldWrapNdc ? 2 : 0) // add 2 for the parenthesis if wrapping the NDC + nsnMask.Length; Span ar = stackalloc char[arSize]; diff --git a/test/PhoneNumbers.Tests/PhoneNumber_ToString_Africa_Tests.cs b/test/PhoneNumbers.Tests/PhoneNumber_ToString_Africa_Tests.cs index fc9b2bfa..c3a323a3 100644 --- a/test/PhoneNumbers.Tests/PhoneNumber_ToString_Africa_Tests.cs +++ b/test/PhoneNumbers.Tests/PhoneNumber_ToString_Africa_Tests.cs @@ -6,6 +6,7 @@ public class PhoneNumber_ToString_Africa_Tests [InlineData("+20235344239", "E.123", "+20 2 3534 4239")] [InlineData("+20235344239", "N", "02 3534 4239")] [InlineData("+20235344239", "RFC3966", "tel:+20-2-3534-4239")] + [InlineData("+20235344239", "TAPI", "+20 (2) 3534 4239")] [InlineData("+20235344239", "U", "0235344239")] public void Egypt_Numbers(string input, string format, string expected) => Assert.Equal(expected, PhoneNumber.Parse(input).ToString(format)); @@ -17,6 +18,8 @@ public void Egypt_Numbers(string input, string format, string expected) => [InlineData("+254703042000", "N", "0703 042000")] [InlineData("+25420424200", "RFC3966", "tel:+254-20-424200")] [InlineData("+254703042000", "RFC3966", "tel:+254-703-042000")] + [InlineData("+25420424200", "TAPI", "+254 (20) 424200")] + [InlineData("+254703042000", "TAPI", "+254 (703) 042000")] [InlineData("+25420424200", "U", "020424200")] [InlineData("+254703042000", "U", "0703042000")] public void Kenya_Numbers(string input, string format, string expected) => @@ -26,6 +29,7 @@ public void Kenya_Numbers(string input, string format, string expected) => [InlineData("+2342094617000", "E.123", "+234 209 461 7000")] [InlineData("+2342094617000", "N", "(0209) 461 7000")] [InlineData("+2342094617000", "RFC3966", "tel:+234-209-461-7000")] + [InlineData("+2342094617000", "TAPI", "+234 (209) 461 7000")] [InlineData("+2342094617000", "U", "02094617000")] public void Nigeria_Numbers(string input, string format, string expected) => Assert.Equal(expected, PhoneNumber.Parse(input).ToString(format)); @@ -34,6 +38,7 @@ public void Nigeria_Numbers(string input, string format, string expected) => [InlineData("+27215616800", "E.123", "+27 21 561 6800")] [InlineData("+27215616800", "N", "021 561 6800")] [InlineData("+27215616800", "RFC3966", "tel:+27-21-561-6800")] + [InlineData("+27215616800", "TAPI", "+27 (21) 561 6800")] [InlineData("+27215616800", "U", "0215616800")] public void SouthAfrica_Numbers(string input, string format, string expected) => Assert.Equal(expected, PhoneNumber.Parse(input).ToString(format)); @@ -42,6 +47,7 @@ public void SouthAfrica_Numbers(string input, string format, string expected) => [InlineData("+255222199760", "E.123", "+255 22 219 9760")] [InlineData("+255222199760", "N", "022 219 9760")] [InlineData("+255222199760", "RFC3966", "tel:+255-22-219-9760")] + [InlineData("+255222199760", "TAPI", "+255 (22) 219 9760")] [InlineData("+255222199760", "U", "0222199760")] public void Tanzania_Numbers(string input, string format, string expected) => Assert.Equal(expected, PhoneNumber.Parse(input).ToString(format)); diff --git a/test/PhoneNumbers.Tests/PhoneNumber_ToString_Asia_Tests.cs b/test/PhoneNumbers.Tests/PhoneNumber_ToString_Asia_Tests.cs index 894b4f0e..66ba1b5a 100644 --- a/test/PhoneNumbers.Tests/PhoneNumber_ToString_Asia_Tests.cs +++ b/test/PhoneNumbers.Tests/PhoneNumber_ToString_Asia_Tests.cs @@ -6,6 +6,7 @@ public class PhoneNumber_ToString_Asia_Tests [InlineData("+85229616333", "E.123", "+852 2961 6333")] [InlineData("+85229616333", "N", "2961 6333")] [InlineData("+85229616333", "RFC3966", "tel:+852-2961-6333")] + [InlineData("+85229616333", "TAPI", "+852 2961 6333")] [InlineData("+85229616333", "U", "29616333")] public void HongKong_Numbers(string input, string format, string expected) => Assert.Equal(expected, PhoneNumber.Parse(input).ToString(format)); @@ -14,6 +15,7 @@ public void HongKong_Numbers(string input, string format, string expected) => [InlineData("+85328000000", "E.123", "+853 2800 0000")] [InlineData("+85328000000", "N", "2800 0000")] [InlineData("+85328000000", "RFC3966", "tel:+853-2800-0000")] + [InlineData("+85328000000", "TAPI", "+853 2800 0000")] [InlineData("+85328000000", "U", "28000000")] public void Macau_Numbers(string input, string format, string expected) => Assert.Equal(expected, PhoneNumber.Parse(input).ToString(format)); @@ -22,6 +24,7 @@ public void Macau_Numbers(string input, string format, string expected) => [InlineData("+6563773800", "E.123", "+65 6377 3800")] [InlineData("+6563773800", "N", "6377 3800")] [InlineData("+6563773800", "RFC3966", "tel:+65-6377-3800")] + [InlineData("+6563773800", "TAPI", "+65 6377 3800")] [InlineData("+6563773800", "U", "63773800")] public void Singapore_Numbers(string input, string format, string expected) => Assert.Equal(expected, PhoneNumber.Parse(input).ToString(format)); @@ -33,6 +36,8 @@ public void Singapore_Numbers(string input, string format, string expected) => [InlineData("+903122947200", "N", "(0312) 294 72 00")] [InlineData("+904441234", "RFC3966", "tel:+90-444-12-34")] [InlineData("+903122947200", "RFC3966", "tel:+90-312-294-72-00")] + [InlineData("+904441234", "TAPI", "+90 444 12 34")] + [InlineData("+903122947200", "TAPI", "+90 (312) 294 72 00")] [InlineData("+904441234", "U", "04441234")] [InlineData("+903122947200", "U", "03122947200")] public void Turkey_Numbers(string input, string format, string expected) => diff --git a/test/PhoneNumbers.Tests/PhoneNumber_ToString_SouthAmerica_Tests.cs b/test/PhoneNumbers.Tests/PhoneNumber_ToString_SouthAmerica_Tests.cs index a092be54..c5a3ad4a 100644 --- a/test/PhoneNumbers.Tests/PhoneNumber_ToString_SouthAmerica_Tests.cs +++ b/test/PhoneNumbers.Tests/PhoneNumber_ToString_SouthAmerica_Tests.cs @@ -9,6 +9,8 @@ public class PhoneNumber_ToString_SouthAmerica_Tests [InlineData("+5541732649808", "N", "(041) 73264-9808")] [InlineData("+556123122026", "RFC3966", "tel:+55-61-2312-2026")] [InlineData("+5541732649808", "RFC3966", "tel:+55-41-73264-9808")] + [InlineData("+556123122026", "TAPI", "+55 (61) 2312-2026")] + [InlineData("+5541732649808", "TAPI", "+55 (41) 73264-9808")] [InlineData("+556123122026", "U", "06123122026")] [InlineData("+5541732649808", "U", "041732649808")] public void Brazil_Numbers(string input, string format, string expected) => @@ -18,6 +20,7 @@ public void Brazil_Numbers(string input, string format, string expected) => [InlineData("+576013198300", "E.123", "+57 601 3198300")] [InlineData("+576013198300", "N", "601 3198300")] [InlineData("+576013198300", "RFC3966", "tel:+57-601-3198300")] + [InlineData("+576013198300", "TAPI", "+57 (601) 3198300")] public void Colombia_Numbers(string input, string format, string expected) => Assert.Equal(expected, PhoneNumber.Parse(input).ToString(format)); }