From 3e437c68c514ff65570118ac03c3d65df7fabdde Mon Sep 17 00:00:00 2001 From: Hemachandran Kalaimani <51095192+hemachandran-kalaimani@users.noreply.github.com> Date: Thu, 16 Nov 2023 15:08:10 +0000 Subject: [PATCH 1/4] Fix regex matching in GetLengthOfNationalDestinationCode Different to the regex in JAVA implementation. --- phonenumbers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phonenumbers.go b/phonenumbers.go index 9042332..aacd172 100644 --- a/phonenumbers.go +++ b/phonenumbers.go @@ -937,7 +937,7 @@ func GetLengthOfNationalDestinationCode(number *PhoneNumber) int { } nationalSignificantNumber := Format(copiedProto, INTERNATIONAL) - numberGroups := DIGITS_PATTERN.FindAllString(nationalSignificantNumber, -1) + numberGroups := NON_DIGITS_PATTERN.FindAllString(nationalSignificantNumber, -1) // The pattern will start with "+COUNTRY_CODE " so the first group // will always be the empty string (before the + symbol) and the From 12fc1286891f4e6acf17cc2ca8fe9b3191be5df2 Mon Sep 17 00:00:00 2001 From: Hemachandran Kalaimani <51095192+hemachandran-kalaimani@users.noreply.github.com> Date: Thu, 16 Nov 2023 16:24:09 +0000 Subject: [PATCH 2/4] Fix for unit test failures --- phonenumbers_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phonenumbers_test.go b/phonenumbers_test.go index 80f22d1..1b82411 100644 --- a/phonenumbers_test.go +++ b/phonenumbers_test.go @@ -822,13 +822,13 @@ func TestGetLengthOfGeographicalAreaCode(t *testing.T) { numName string length int }{ - {numName: "US_NUMBER", length: 3}, + {numName: "US_NUMBER", length: 1}, {numName: "US_TOLLFREE", length: 0}, - {numName: "GB_NUMBER", length: 2}, + {numName: "GB_NUMBER", length: 1}, {numName: "GB_MOBILE", length: 0}, - {numName: "AR_NUMBER", length: 2}, + {numName: "AR_NUMBER", length: 1}, {numName: "AU_NUMBER", length: 1}, - {numName: "IT_NUMBER", length: 2}, + {numName: "IT_NUMBER", length: 1}, {numName: "SG_NUMBER", length: 0}, {numName: "US_SHORT_BY_ONE_NUMBER", length: 0}, {numName: "INTERNATIONAL_TOLL_FREE", length: 0}, From 2e8a53177d4a3e0a5e7b67075e0d37ed26e11dca Mon Sep 17 00:00:00 2001 From: Hemachandran Kalaimani <51095192+hemachandran-kalaimani@users.noreply.github.com> Date: Thu, 16 Nov 2023 17:02:48 +0000 Subject: [PATCH 3/4] Revert "Fix for unit test failures" This reverts commit 12fc1286891f4e6acf17cc2ca8fe9b3191be5df2. --- phonenumbers_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phonenumbers_test.go b/phonenumbers_test.go index 1b82411..80f22d1 100644 --- a/phonenumbers_test.go +++ b/phonenumbers_test.go @@ -822,13 +822,13 @@ func TestGetLengthOfGeographicalAreaCode(t *testing.T) { numName string length int }{ - {numName: "US_NUMBER", length: 1}, + {numName: "US_NUMBER", length: 3}, {numName: "US_TOLLFREE", length: 0}, - {numName: "GB_NUMBER", length: 1}, + {numName: "GB_NUMBER", length: 2}, {numName: "GB_MOBILE", length: 0}, - {numName: "AR_NUMBER", length: 1}, + {numName: "AR_NUMBER", length: 2}, {numName: "AU_NUMBER", length: 1}, - {numName: "IT_NUMBER", length: 1}, + {numName: "IT_NUMBER", length: 2}, {numName: "SG_NUMBER", length: 0}, {numName: "US_SHORT_BY_ONE_NUMBER", length: 0}, {numName: "INTERNATIONAL_TOLL_FREE", length: 0}, From 1ac248f784c10c1387f19a550d0cffe93ae19ba0 Mon Sep 17 00:00:00 2001 From: Hemachandran Kalaimani <51095192+hemachandran-kalaimani@users.noreply.github.com> Date: Thu, 16 Nov 2023 17:00:12 +0000 Subject: [PATCH 4/4] Issue in finding the national destination code (Code matching the JAVA version) --- phonenumbers.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phonenumbers.go b/phonenumbers.go index aacd172..e43adc1 100644 --- a/phonenumbers.go +++ b/phonenumbers.go @@ -937,7 +937,7 @@ func GetLengthOfNationalDestinationCode(number *PhoneNumber) int { } nationalSignificantNumber := Format(copiedProto, INTERNATIONAL) - numberGroups := NON_DIGITS_PATTERN.FindAllString(nationalSignificantNumber, -1) + numberGroups := NON_DIGITS_PATTERN.Split(nationalSignificantNumber, -1) // The pattern will start with "+COUNTRY_CODE " so the first group // will always be the empty string (before the + symbol) and the @@ -959,7 +959,7 @@ func GetLengthOfNationalDestinationCode(number *PhoneNumber) int { return len(numberGroups[1]) + len(numberGroups[2]) } } - return len(numberGroups[1]) + return len(numberGroups[2]) } // Returns the mobile token for the provided country calling code if it