From e4e52ec2d278eaf74cac2380ccbe203acff19dd0 Mon Sep 17 00:00:00 2001 From: Shaopeng Jia Date: Mon, 3 May 2010 11:24:47 +0000 Subject: [PATCH] Update library to v2.1 --- .../phonenumbers/src/PhoneNumberMetaData.xml | 690 ++++++++++++++---- .../generated_files/PhoneNumberMetadataProto | Bin 79839 -> 82444 bytes .../test/PhoneNumberMetaDataForTesting.xml | 49 +- .../PhoneNumberMetadataProtoForTesting | Bin 4840 -> 5854 bytes .../BuildMetadataProtoFromXml.java | 44 +- .../i18n/phonenumbers/PhoneNumberUtil.java | 34 +- .../i18n/phonenumbers/phonemetadata.proto | 39 +- .../phonenumbers/AsYouTypeFormatterTest.java | 92 ++- .../phonenumbers/PhoneNumberUtilTest.java | 105 +-- 9 files changed, 795 insertions(+), 258 deletions(-) diff --git a/java/resources/com/google/i18n/phonenumbers/src/PhoneNumberMetaData.xml b/java/resources/com/google/i18n/phonenumbers/src/PhoneNumberMetaData.xml index 0e72c87b8..862dd9a33 100644 --- a/java/resources/com/google/i18n/phonenumbers/src/PhoneNumberMetaData.xml +++ b/java/resources/com/google/i18n/phonenumbers/src/PhoneNumberMetaData.xml @@ -479,12 +479,16 @@ + nationalPrefix="0"> $1 $2 $3 - $1 $2 $3 + $1 $2 $3 $1 $2 $3 $1 $2 $3 @@ -542,10 +546,10 @@ - $1 $2 + $1 $2 - [57-9]\d{6} + [5-9]\d{6} \d{7} @@ -553,7 +557,10 @@ 5212345 - (?:5[69]\d|9(?:6\d|9[02-9])|7[34]\d)\d{4} + + (?:5[69]\d|660|9(?:6\d|9[02-9])|7[34]\d)\d{4} 5601234 @@ -702,7 +709,9 @@ 20491234 - 7(?:[0168]\d|2[0-4]|4[01]|5[01346-9])\d{5} + + 7(?:[01568]\d|2[0-4]|4[01]|5[01346-9])\d{5} 70123456 @@ -769,10 +778,10 @@ - - (?:2955|7(?:9(?:5[6-9]|[19]\d)|(?:6[269]|77|8\d)\d))\d{4} + (?:29\d|7(?:1[1-3]|[4-9]\d))\d{5} 79561234 @@ -785,7 +794,7 @@ - [289]\d{7}|7\d{3} + [2689]\d{7}|7\d{3} \d{4,8} @@ -798,8 +807,11 @@ - 9(?:0[069]|[35][0-2457-9]|7[014-9])\d{5} + of these prefixes can be found. 9[68] and 97[23] prefixes have also been + added because of online numbers following these patterns and numbers + where SMSs were successfully delivered. + 66 has been also added, as it seems to be a prefix for Mobile MTN. --> + 66\d{6}|9(?:0[069]|[35][0-2457-9]|[6-8]\d)\d{5} \d{8} 90011234 @@ -892,7 +904,7 @@ ($1) $2-$3 - $1-$2 + $1-$2 $1 $2 $3 @@ -901,7 +913,7 @@ \d{8,10} - 400\d{5}|(?:[14689][1-9]|2[12478]|3[1-578]|5[13-5]|7[13-579])[2-5]\d{7} + (?:[14689][1-9]|2[12478]|3[1-578]|5[13-5]|7[13-579])[2-5]\d{7} 1123456789 @@ -917,6 +929,10 @@ [359]00\d{6,7} 300123456 + + (?:400\d|3003)\d{4} + 40041234 + @@ -1048,7 +1064,29 @@ - + + + + $1 $2 $3 + $1 $2 + + + [89]\d{8}|[1-6]\d{6} + \d{7,9} + + + [1-6]\d{6} + \d{7} + 1234567 + + + (?:8[0149]|9[7-9])\d{7} + \d{9} + 991234567 + @@ -1158,7 +1196,8 @@ 21234567 - (?:0[1-9]|4[4-9]|50|6[067])\d{6} + + (?:0[1-9]|4[04-9]|50|6[067])\d{6} 01234567 @@ -1357,7 +1396,10 @@ 2211234 - 9[189]\d{5} + + 9[157-9]\d{5} 9911234 @@ -1532,7 +1574,7 @@ - + $1 $2 $3 $4 @@ -1546,7 +1588,9 @@ 32123456 - (?:2[0-9]|3[01]|4[0-2]|5[0-3]|6[01])\d{6} + + (?:2[0-9]|3[0-2]|4[0-2]|5[0-3]|6[01]|72|99)\d{6} 20123456 @@ -1616,8 +1660,56 @@ + + + nationalPrefix="0" nationalPrefixFormattingRule="$NP$FG"> + + + $1 $2 $3 $4 + $1 $2 $3 $4 + $1 $2 $3 $4 + + + (?:[1-4]|[5-9]\d)\d{7} + \d{8,9} + + + + (?:1\d|2[014-79]|3[0-8]|4[0135689])\d{6}|9619\d{5} + 12345678 + + + (?:5[56]|6[69]|7[79])\d{7} + \d{9} + 551234567 + + + 800\d{6} + \d{9} + 800123456 + + + + 80[12]1\d{5} + \d{9} + 801123456 + + + 80[3-689]1\d{5} + \d{9} + 808123456 + + + 98[23]\d{6} + \d{9} + 983123456 + @@ -2132,8 +2224,26 @@ - + + + + $1 $2 $3 $4 + + + [367]\d{7} + \d{8} + + + 30(?:24|3[12]|4[1-35-7]|5[13]|6[189]|[78]1|9[1478])\d{4} + 30241234 + + + + 6(?:0(?:2\d|3[3467]|5[2457-9])|[2457]\d{2}|3(?:[14]0|35))\d{4} + 60201234 + @@ -2298,6 +2408,10 @@ \d{11} 90012345678 + + 8[1-3]\d{6} + \d{8} + @@ -2434,9 +2548,10 @@ - 2[124]\d{7,8}|(?:2(?:[35][1-4]|6[0-8]|7[1-6]|8\d|9[1-8])|3(?:1|2[1-578]|3[1-68]|4[1-3]|5[1-8]|6[1-3568]|7[0-46]|8\d)|4(?:0[1-589]|1[01347-9]|2[0-36-8]|3[0-24-68]|5[1-378]|6[1-5]|7[134]|8[1245])|5(?:1[1-35-9]|2[25-8]|3[1246-9]|4[1-3589]|5[1-46]|6[1-8])|6(?:19?|[25]\d|3[1-469]|4[1-6])|7(?:1[1-46-9]|2[14-9]|[36]\d|4[1-8]|5[1-9]|7[1-36-9])|9(?:0[12]|1[0134-8]|2[0-479]|5[125-8]|6[23679]|7[159]|8[01346]))\d{5,8} + http://www.telkom.co.id/customer-services/area-and-country-code/?type=area. + We also added 0770 after user feedback because it seems to be used on + Bintan island. --> + 2[124]\d{7,8}|(?:2(?:[35][1-4]|6[0-8]|7[1-6]|8\d|9[1-8])|3(?:1|2[1-578]|3[1-68]|4[1-3]|5[1-8]|6[1-3568]|7[0-46]|8\d)|4(?:0[1-589]|1[01347-9]|2[0-36-8]|3[0-24-68]|5[1-378]|6[1-5]|7[134]|8[1245])|5(?:1[1-35-9]|2[25-8]|3[1246-9]|4[1-3589]|5[1-46]|6[1-8])|6(?:19?|[25]\d|3[1-469]|4[1-6])|7(?:1[1-46-9]|2[14-9]|[36]\d|4[1-8]|5[1-9]|7[0-36-9])|9(?:0[12]|1[0134-8]|2[0-479]|5[125-8]|6[23679]|7[159]|8[01346]))\d{5,8} \d{5,10} 612345678 @@ -2607,38 +2722,40 @@ - $1 $2 $3 - - $1 $2 $3 - - $1 $2 $3 - $1 $2 $3 - $1 $2 $3 - $1 $2 $3 - $1 $2 $3 - $1 $2 $3 - $1 $2 $3 - $1 $2 $3 - - - $1 $2 $3 - $1 $2 $3 - $1 $2 $3 + + $1 $2 $3 + + $1 $2 $3 + + $1 $2 $3 + $1 $2 $3 + $1 $2 $3 + $1 $2 $3 + $1 $2 $3 + $1 $2 $3 + $1 $2 $3 + $1 $2 $3 + + + $1 $2 $3 + $1 $2 $3 + $1 $2 $3 [1-9]\d{9,10} @@ -2648,16 +2765,20 @@ - (?:11|2[02]|33|4[04]|79|80)[2-6]\d{7}|(?:1(?:2[0-249]|3[0-25]|4[145]|5[14]|6[014]|7[1257]|8[01346]|9[14])|2(?:1[257]|3[013]|4[01]|5[0137]|6[0158]|78|8[1568]|9[14])|3(?:26|4[1-3]|5[34]|6[01489]|7[02-46]|8[159])|4(?:1[36]|2[1-47]|3[15]|5[12]|6[126-9]|7[0-24-9]|8[013-57]|9[014-7])|5(?:1[25]|22|3[25]|4[28]|5[12]|6[25]|[78]1|9[15])|6(?:12|[2345]1|57|6[13]|7[14]|80)|7(?:12|2[14]|3[134]|4[47]|5[15]|[67]1|88)|8(?:16|2[014]|3[126]|6[136]|7[078]|8[34]|91))[2-6]\d{6}|(?:1(?:2[35-8]|3[346-9]|4[236-9]|5[0235-9]|6[235-9]|7[34689]|8[257-9]|9[0235-9])|2(?:1[134689]|3[24-8]|4[2-8]|5[25689]|6[2-4679]|7[13-79]|8[2-479]|9[235-9])|3(?:01|1[79]|2[1-5]|4[25-8]|5[125689]|6[235-7]|7[157-9]|8[2-467])|4(?:1[14578]|2[5689]|3[2-467]|5[4-7]|6[35]|73|8[2689]|9[2389])|5(?:1[146-9]|2[14-8]|3[1346]|4[14-69]|5[46]|6[146-9]|7[2-4]|8[2-8]|9[246])|6(?:1[1358]|2[2457]|3[2-4]|4[235-7]|5[2-689]|6[24-58]|7[23-689]|8[1-6])|7(?:1[013-9]|2[0235-9]|3[2679]|4[1-35689]|5[2-46-9]|[67][02-9]|8[0-8]|9\d)|8(?:1[1357-9]|2[235-8]|3[03-57-9]|4[0-24-9]|5\d|6[2457-9]|7[1-6]|8[1256]|9[2-4]))\d[2-6]\d{5} + wikipedia, with the addition of 5 (HFCL Infotel). Area codes starting + with a 7 are listed separately, since the prefixes need to be more + detailed as they would otherwise clash with mobile phone prefixes. --> + (?:11|2[02]|33|4[04]|79|80)[2-6]\d{7}|(?:1(?:2[0-249]|3[0-25]|4[145]|5[14]|6[014]|7[1257]|8[01346]|9[14])|2(?:1[257]|3[013]|4[01]|5[0137]|6[0158]|78|8[1568]|9[14])|3(?:26|4[1-3]|5[34]|6[01489]|7[02-46]|8[159])|4(?:1[36]|2[1-47]|3[15]|5[12]|6[126-9]|7[0-24-9]|8[013-57]|9[014-7])|5(?:1[25]|22|3[25]|4[28]|5[12]|6[25]|[78]1|9[15])|6(?:12|[2345]1|57|6[13]|7[14]|80)|7(?:12|2[14]|3[134]|4[47]|5[15]|[67]1|88)|8(?:16|2[014]|3[126]|6[136]|7[078]|8[34]|91))[2-6]\d{6}|(?:(?:1(?:2[35-8]|3[346-9]|4[236-9]|5[0235-9]|6[235-9]|7[34689]|8[257-9]|9[0235-9])|2(?:1[134689]|3[24-8]|4[2-8]|5[25689]|6[2-4679]|7[13-79]|8[2-479]|9[235-9])|3(?:01|1[79]|2[1-5]|4[25-8]|5[125689]|6[235-7]|7[157-9]|8[2-467])|4(?:1[14578]|2[5689]|3[2-467]|5[4-7]|6[35]|73|8[2689]|9[2389])|5(?:1[146-9]|2[14-8]|3[1346]|4[14-69]|5[46]|6[146-9]|7[2-4]|8[2-8]|9[246])|6(?:1[1358]|2[2457]|3[2-4]|4[235-7]|5[2-689]|6[24-58]|7[23-689]|8[1-6])|8(?:1[1357-9]|2[235-8]|3[03-57-9]|4[0-24-9]|5\d|6[2457-9]|7[1-6]|8[1256]|9[2-4]))\d|7(?:(?:1[013-9]|2[0235-9]|3[2679]|4[1-35689]|5[2-46-9]|[67][02-9]|9\d)\d|8(?:2[0-6]|[013-8]\d)))[2-6]\d{5} \d{6,10} 1123456789 - - (?:9\d(?:0(?:0[1-9]|9[0-8]|[1-8]\d)|[1-9]\d{2})|8(?:0[01589]|1[024]|80)\d{2})\d{5} + (?:7(?:39[89]|5(?:50|6[6-8]|79|[89][7-9])|6(?:0[027]|20|3[19]|54|65|7[67]|9[6-9])|7(?:0[89]|3[589]|42|60|9[5-9])|8(?:[03][07-9]|14|2[7-9]|4[25]|6[09]))\d|9\d{4}|8(?:0[01589]\d|1[024]\d|8(?:[079]\d|44)|9[057-9]\d)\d)\d{5} \d{10} 9123456789 @@ -2822,7 +2943,8 @@ 8765123456 - 876(?:(?:21|3[02-9]|[48]\d|5[78]|77)\d|7(?:0[07]|8[1-47-9]|9[0-36-9])|9(?:[01]9|9[0579]))\d{4} + + 876(?:(?:21|[348]\d|5[78]|77)\d|7(?:0[07]|8[1-47-9]|9[0-36-9])|9(?:[01]9|9[0579]))\d{4} \d{10} 8762101234 @@ -2840,12 +2962,15 @@ + + $1 $2 $3 - $1 $2 $3 + $1 $2 $3 $4 $5 $1 $2 $1 $2 @@ -2860,7 +2985,9 @@ 62345678 - 7(?:4[5-7]|7[569]|8[5-8]|9[05-7])\d{6} + + 7(?:4[5-7]|7[5-79]|8[5-8]|9[05-9])\d{6} \d{9} 790123456 @@ -2952,8 +3079,7 @@ - - + @@ -2969,10 +3095,11 @@ (?:20|4[0-6]|5\d|6[0-24-9])\d{4,7} \d{4,9} - 201234 + 202012345 - 7(?:1[0-5]|2\d|3[2-8]|5[0-2]|7[023])\d{6} + + 7(?:1[0-6]|2\d|3[2-8]|5[0-2]|7[023])\d{6} \d{9} 712123456 @@ -3009,7 +3136,9 @@ 312123456 - 5[124-7]\d{7}|7(?:00|7\d)\d{6} + + 5[124-7]\d{7}|7(?:0[05]|7\d)\d{6} \d{9} 700123456 @@ -3026,13 +3155,13 @@ - $1 $2 $3 $1 $2 $3 - [1-79]\d{7,9} + [1-9]\d{7,9} \d{6,10} @@ -3041,7 +3170,9 @@ 23456789 - (?:1[0-25689]|9[1-49])[2-9]\d{5} + + (?:(?:1[0-35-9]|9[1-49])[1-9]|85[2-689])\d{5} \d{8} 91234567 @@ -3121,35 +3252,56 @@ - + + + + - $1-$2-$3 - $1-$2-$3 - $1-$2 - $1-$2-$3 - $1-$2-$3 - $1-$2-$3 + $1-$2-$3 + $1-$2-$3 + $1-$2-$3 + $1-$2-$3 + $1-$2-$3 + $1-$2-$3-$4 + $1-$2-$3 + $1-$2-$3 + $1-$2 + $1-$2 + $1-$2 + $1-$2 [1-79]\d{3,9}|8\d{8} \d{4,10} - - 2(?:1\d{2,3}|[2367]\d{6,7}|[4589]\d{6})|(?:[34][1-3]|5[13-5]|6[124])\d{7}|(?:52|63)\d{7,8} + (?:2|[34][1-3]|5[1-5]|6[1-4])(?:1\d{2,3}|[2-9]\d{6,7}) \d{4,10} 22123456 - 1[0-26-9]\d{5,7} - \d{7,9} - 12345678 + 1[0-25-9]\d{7,8} + \d{9,10} + 1023456789 80\d{7} @@ -3157,19 +3309,19 @@ 801234567 - 60\d{7,8} - \d{9,10} - 601234567 + 60[2-9]\d{6} + \d{9} + 602345678 - 50\d{7,8} - \d{9,10} - 501234567 + 50\d{8} + \d{10} + 5012345678 - 70\d{7,8} - \d{9,10} - 701234567 + 70\d{8} + \d{10} + 7012345678 @@ -3268,7 +3420,7 @@ nationalPrefix="0" nationalPrefixFormattingRule="$NP$FG"> $1 $2 $3 $4 + pattern="(20)([2357-9])(\d{3})(\d{3})">$1 $2 $3 $4 $1 $2 $3 @@ -3282,7 +3434,9 @@ 21212862 - 20[2579]\d{6} + + 20[2357-9]\d{6} \d{9} 202345678 @@ -3290,8 +3444,44 @@ + + + nationalPrefix="0" nationalPrefixFormattingRule="$NP$FG"> + + $1 $2 $3 + $1 $2 $3 + $1 $2 $3 + + + [13-9]\d{6,7} + \d{7,8} + + + (?:[14-6]\d|[7-9][2-9])\d{5} + \d{7} + 1123456 + + + + (3\d|7(?:0\d|1[167]))\d{5} + \d{7,8} + 71123456 + + + 8[01]\d{6} + \d{8} + 80123456 + + + 9[01]\d{6} + \d{8} + 90123456 + @@ -3307,7 +3497,9 @@ 7582345678 - 758(?:28[4-7]|384|4(?:6[01]|8[4-9])|5(?:1[89]|20|84)|7(?:1[2-9]|2[034]))\d{4} + + 758(?:28[4-7]|384|4(?:6[01]|8[4-9])|5(?:1[89]|20|84)|7(?:1[2-9]|2[0-4]))\d{4} \d{10} 7582845678 @@ -3407,8 +3599,28 @@ - + + + + + $1 $2 + + + [2568]\d{7} + \d{8} + + + 2\d{7} + 22123456 + + + [56]\d{7} + 50123456 + + + 800[256]\d{4} + 80021234 + @@ -3513,7 +3725,9 @@ 22212345 - (?:6(?:50|7[12]|8[0-7]|9\d)|7(?:80|9\d))\d{5} + + (?:6(?:50|7[12]|[89]\d)|7(?:80|9\d))\d{5} 65012345 @@ -3619,11 +3833,11 @@ - (?:2(?:0(?:2[0-589]|7[027-9])|1(?:2[5-7]|[3-9]\d))|442\d)\d{4} + (?:2(?:0(?:2[0-589]|7[027-9])|1(?:2[5-7]|[3-689]\d))|442\d)\d{4} 20212345 - (?:6(?:[569]\d)|7(?:[359][0-4]|4[014-7]|6\d|8[1-9]))\d{5} + (?:6(?:[569]\d)|7(?:[3579][0-4]|4[014-7]|6\d|8[1-9]))\d{5} 65012345 @@ -3715,7 +3929,9 @@ 28212345 - 66\d{6} + + 6[26]\d{6} 66123456 @@ -3818,10 +4034,10 @@ happen August 2010, and 7 digit numbers will be phased out by 1 November 2010. --> - $1 $2 + $1 $2 - [2-8]\d{6} + [2-9]\d{6} \d{7} @@ -3831,7 +4047,8 @@ 2012345 - (?:25\d|4(?:2[12389]|9\d)|7\d{2}|87[15-7]|9[13-8]\d)\d{4} + + (?:25\d|4(?:2[12389]|9\d)|7\d{2}|87[15-7]|9[1-8]\d)\d{4} 2512345 @@ -4046,6 +4263,7 @@ + @@ -4075,7 +4293,9 @@ 612012345 - 8(?:1(?:1[0-2]|[23]\d|50)|5\d{2})\d{5} + + 8(?:1(?:1[0-24]|[2-4]\d|50|6[0-2])|5\d{2})\d{5} \d{9} 811012345 @@ -4092,8 +4312,38 @@ - + + + + + $1 $2 $3 $4 + $1 $2 $3 + + + + [029]\d{7} + \d{8} + + + + 2(?:0(?:20|3[1-7]|4[134]|5[14]|6[14578]|7[1-578])|1(?:4[145]|5[14]|6[14-68]|7[169]|88))\d{4} + 20201234 + + + + 9[03467]\d{6} + 93123456 + + + 08\d{6} + 08123456 + + + 09\d{6} + 09123456 + @@ -4101,7 +4351,7 @@ - + @@ -4111,7 +4361,7 @@ pattern="(9)(\d{3})(\d{4})">$1 $2 $3 $1 $2 $3 - $1 $2 $3 $1 $2 $3 @@ -4134,7 +4384,8 @@ 12345678 - (?:70[3-9]|8(?:0[2-9]|12))\d{7}|(?:702[1-9]|819[01])\d{6} + + (?:70[3-9]|8(?:0[2-9]|1[23]))\d{7}|(?:702[1-9]|819[01])\d{6} \d{10} 8021234567 @@ -4353,7 +4604,7 @@ $1 $2 - (?:2[3-6]|5|9[25-9])\d{6}|800\d{5,6} + (?:2[3-6]|5|9[235-9])\d{6}|800\d{5,6} \d{7,9} @@ -4362,7 +4613,9 @@ 23123456 - 9[25-9]\d{6} + + 9[235-9]\d{6} \d{8} 92123456 @@ -4471,7 +4724,7 @@ 21234567 - 9(?:0[5-9]|1[025-9]|2[0-36-9]|3[235-8]|7[349])\d{7} + 9(?:0[5-9]|1[025-9]|2[0-36-9]|3[0235-9]|7[349]|[89]9)\d{7} \d{10} 9051234567 @@ -4529,14 +4782,12 @@ - + - $1 $2 $3 $4 - $1 $2 $3 $4 - $1 $2 $3 + $1 $2 $3 [1-9]\d{8} @@ -4547,7 +4798,7 @@ 123456789 - (?:5[01]|6[069]|7[289]|88)\d{7} + (?:5[013]|6[069]|7[289]|88)\d{7} 512345678 @@ -4663,7 +4914,7 @@ 4123456 - (?:3[0-5]|[5-7]\d)\d{5} + [35-7]\d{6} 3123456 @@ -4787,8 +5038,8 @@ - + @@ -4897,8 +5148,38 @@ - + + + + + $1 $2 + + + [2-8]\d{5} + \d{6} + + + + (?:2(?:1[78]|2[14-69]|3[2-4]|4[1-36-8]|6[167]|[89]\d)|3(?:2[1-6]|4[4-6]|55|6[016]|7\d|8[0-589]|9[0-5])|5(?:5\d|6[0-2])|6(?:0[0-27-9]|1[0-478]|2[145]|3[02-4]|4[124]|6[015]|7\d|8[1-3])|78[0138])\d{3} + 217123 + + + (?:5(?:[1247-9]\d|6[3-9])|7(?:[14679]\d|2[1-9]|8[24-79]))\d{3} + 510123 + + + 8000\d{2} + 800000 + + + 4[1-37]\d{4} + 410123 + @@ -5008,7 +5289,7 @@ $1 $2 $3 $4 - $1 $2 $3 $1 $2 @@ -5022,7 +5303,7 @@ 1123456 - (?:[347][01]|51|64)\d{6} + (?:[37][01]|4[019]|51|64)\d{6} \d{8} 31234567 @@ -5083,8 +5364,29 @@ + + nationalPrefix="0" nationalPrefixFormattingRule="($NP$FG)"> + + + $1 $2 + + + [2-578]\d{7} + \d{6,8} + + + [235]2[2-4][2-9]\d{4} + 22221234 + + + + (?:25|3[03]|44|5[056]|7[6-8]|88)[1-9]\d{5} + 25123456 + @@ -5109,7 +5411,9 @@ 301012345 - 7(?:0[1256]0|6(?:1[23]|2[89]|3[3489]|4[6-9]|5[1-389]|6[6-9]|7[45]|8[3-8])|7(?:1[014-8]|2[0-7]|3[0-35-8]|4[0-6]|[56]\d|7[0-389]|[89][01]))\d{5} + + 7(?:0[1256]0|6(?:1[23]|2[89]|3[3489]|4[6-9]|5[1-389]|6[6-9]|7[45]|8[3-8])|7(?:1[014-8]|2[0-7]|3[0-35-8]|4[0-6]|[56]\d|7[0-589]|8[01]|9[0-6]))\d{5} 701012345 @@ -5119,7 +5423,38 @@ + + + + + $1 $2 + + $1 $2 + + + [13-59]\d{6,7} + \d{7,8} + + + (?:5[57-9]|[134]\d)\d{5} + \d{7} + + 5522010 + + + (?:9[01]|15)\d{6} + \d{8} + 90792024 + @@ -5171,7 +5506,10 @@ 112345678 - 9(?:3[23]|4[47]|55|66|88|99)\d{6} + + 9(?:3[23]|4[457]|55|6[67]|88|9[19])\d{6} \d{9} 944567890 @@ -5249,21 +5587,22 @@ internationalPrefix="00|16"> $1 $2 $3 + pattern="(\d{2})(\d{2})(\d{2})(\d{2})">$1 $2 $3 $4 - [2369]\d{6} - \d{7} + [2679]\d{7} + \d{8} - 2(?:5[0-4]|6[89])\d{4} - 2511234 + 22(?:[3789]0|5[0-5]|6[89])\d{4} + 22501234 - - (?:3[0-7]|6[27]|9\d)\d{5} - 6201234 + + (?:6(?:3[0-7]|6\d)|77\d|9(?:5[0-4]|9\d))\d{5} + 63012345 @@ -5318,7 +5657,9 @@ 21234567 - 8[13-9]\d{7} + + 8\d{8} \d{9} 812345678 @@ -5349,9 +5690,9 @@ pattern="([349]\d{2})(\d{2})(\d{4})">$1 $2 $3 $1 $2 $3 $1 $2 $3 - $1 $2 $3 - $1 $2 $3 @@ -5363,7 +5704,9 @@ 372123456 - 9[1-35-9]\d{7} + + 9[0-35-9]\d{7} \d{9} 917123456 @@ -5381,18 +5724,27 @@ + nationalPrefix="8" nationalPrefixFormattingRule="$NP $FG"> - $1 $2 $3 $4 + $1 $2 $3 $4 - (?:12\d|243|[3-5]22)\d{5} + [1-6]\d{7} \d{8} - 12345678 + + (?:12\d|243|[3-5]22)\d{5} + 12345678 + + + + 6[6-8]\d{6} + 66123456 + @@ -5565,7 +5917,7 @@ is useful but not error-free. Have used local yellow pages guidelines, Google searches and regression tests to reverse-engineer these rules. --> - $1 $2 $3 \d{7,9} - (?:6[125679]|7[1-69])\d{7} + + (?:6[125679]|7[0-69])\d{7} 612345678 - 9[0-37-9]\d{7} + + 9[0-57-9]\d{7} 912345678 @@ -5824,7 +6180,9 @@ 2101234567 - (?:9[0-8]|1(?:2\d|6[46-9]|99))\d{7} + + (?:9[0-8]|1(?:2\d|6[3-9]|99))\d{7} \d{9,10} 912345678 @@ -5990,10 +6348,13 @@ - $1 $2 + $1 $2 + $1 $2 $3 - [29]\d{8} + [289]\d{8} \d{9} @@ -6001,9 +6362,16 @@ 211234567 - 9(?:55|66|7[7-9])\d{6} + + 9(?:55|6[4-9]|7[4-9])\d{6} 955123456 + + 800\d{6} + 800123456 + diff --git a/java/resources/com/google/i18n/phonenumbers/src/generated_files/PhoneNumberMetadataProto b/java/resources/com/google/i18n/phonenumbers/src/generated_files/PhoneNumberMetadataProto index 2cad06486d846dd6786f1a86be1861dc1e3b906d..27aeaa299c7d6fe65da2c3e1c5b7c0e446f9dbf7 100644 GIT binary patch delta 6999 zcmZ`;378etmG)M@US4%KP2X;Mc}?#P^lN!gRj;aEy#{H7C_6OGh@U(foeUXF{LmOR zGF@;#C@>jEd2W#swy>QQS~Q(LjuY631o!bE{rABr|?O)vG#n z?zw0A&wnoO?vGq`ap8l-jJ+vK*q@lD?-qNt59KQb3pF+*+l#hpnm%8!#%|FV<>K^Z zQ^l##x7c%Xu0FR|4ptU2wob0)cNA#)7jj@+&e_#o?oh%G8gn#IA|XQH~V=~Z0MIO4^+MU_1~(b?1OWZZQB@|9WFHAKArx@ePL z)tPY;>3;FvQPuLz`qvmEqo#;Y8!F}Z4J`OMU(-L6eT}PO@*45`=2J_j@gq~vmN866 z^t7yFJLLy0eVVxbS5rsLnBDtg@iNUYu3=37NL<`L)3kXjgsn8zrLWA4nMn3$Gd7l8 zzA_$PzVbXL7c0cY%ULCPE%1J)%CBT44ihX`6FcxRhd(iYdY)QX?Q&mT8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ZuP8k^HDd5 zzUS^2EdGCx9(&$BP_b`GZ`1Pf1eY>CL3O)oGnKlkEJ zfNnbf-%mT6zf1ZKAEq`Nc2CGZ5QiUOY zo*sESD)579c3uQ(JO5Uh01m zFTR%FdU5QdU#-aGiubpdj^S;nE+bkQf#Y!qH1?>dH1@$n$heTfT_-)yR2LThRE#%c zD0XzO@Kbe&f4^n;1GIU+n{^4a<->mgETLx(Ec%(~j)Rsc*R{B{E%wwe?RYzleD`T7 z9s98&l-WtMRS?gYYEfGi6%QljArGr$(I+h#l~Oi)-2cf*jAHeXfy8sf!eJ|pMxrkK z(m_`qxfb9<;ypIYHCzgk`;S%Ss6k%6bR<%2mNy-X2poq`(^H>5;dB+>kY%6E6@yYG zo{cS^Lh3*7&T+}NV|&Lkr3)@Km*&C%zpub9HdsB?23GZXTVV5nCYJjn*sUvZtbl#I zJ|QC8D*?QY1f!kn%6bdI=(#j8hID)}ilKz;{o;GuwEQnEfcE{e8xV8MTIp-cpRbX+ zua*3ORD^nB{buEWmuhTh8ec6Uw|qSV9;JuA_Br85QsG5E&x^*7j(zuwmPtHmws~Mw+T$So z)m-j@IoUzh2N?LpRFHFF3Av{4!1VEBVn2X+V;KxJ&-8{faF2P~3xBN8q-u6mLsVd; z4jHI;0Vi?1c$^Pmsl)iBdR0h^L}~eUBz&Lr%K93oHHt6Y9?PVhMA6&Pnv^# za1$tIw+~LkMdq4PsDw)ME&P{V)3AV;`cF!c&Ji!9H7%s4DKZEX3 C4__Vt diff --git a/java/resources/com/google/i18n/phonenumbers/test/PhoneNumberMetaDataForTesting.xml b/java/resources/com/google/i18n/phonenumbers/test/PhoneNumberMetaDataForTesting.xml index 21d2da387..524507bbf 100644 --- a/java/resources/com/google/i18n/phonenumbers/test/PhoneNumberMetaDataForTesting.xml +++ b/java/resources/com/google/i18n/phonenumbers/test/PhoneNumberMetaDataForTesting.xml @@ -16,7 +16,8 @@ MetaData on Phone Number Plan and formatting rules. This file is used solely for the purpose of unittesting, so data in this file is not - necessarily consistent with that of PhoneNumberMetaData.xml + necessarily consistent with that of + ../src/PhoneNumberMetaData.xml --> @@ -233,6 +234,52 @@ + + + + + + + + + + $1-$2-$3 + $1-$2-$3 + $1-$2-$3 + $1-$2-$3 + $1-$2-$3 + $1-$2-$3-$4 + $1-$2-$3 + $1-$2-$3 + $1-$2 + $1-$2 + $1-$2 + $1-$2 + + + [1-79]\d{3,9}|8\d{8} + \d{4,10} + + + 8S%5XZH?MDgv3fJ_jPfdryEaYk8bKm7qn2NDzkfl!JRET$l-c>uE3^{EoM zi$G8yA*hI4!V~ZcAZl8k0A_qPxe!na@2+=e{{P?1?vKHDw!20?9o+lud32|m@AOEu zJadPTx7F6{0QO#2dvk9{m324C_@z%T2MboPB+H*{ZL8I+a49U(BJ^R>tAZE7i4oz6 z5i5S+J-i*lckRzg`oZ4vrCaycAFV%Lo)P}yJf5WhsbdC* zshJ#&b_v-h56Yk23pZI`vc3uj0wTE+R%9R&XL;rf>}c&w=F%u~)+9M!>F~bTC!6%# z5S7Z0!NRx^xPbyzK&F-GWfK@s0^C*Zv^8;#G62bel0lrnLBi0;Ml?WKRYWl1x2=mP z@cW{%m=Q|ICRR)kAhr&KdXL9InKs*}oJ{!&XjC)BjFrWY~2QE8?LN6pY{8CYM3 zo@)EBQ3JQm#{q=I`emFu1q&{mU{;&lNh=bdaw>D$#WqfImsk!Bi=w8y=e2Tq5S(p^ z*HEjLu^f8_SH+o%aV2pFO<)I_9>Zi(*iWFta364W@CU8e23=c=jP`)IhKEXn*}BAV zN!ItsnbZ@+F+MF66%w@CWObN~chn>=*2#dO3~~X8Vg}1I3oU*V3K-Ry{ql)988 oB_%mCL6VF3G?-aeF*0zi-+V@J6(h`$hm$LW?|{q*5b0wA0Qj37tpET3 diff --git a/java/src/com/google/i18n/phonenumbers/BuildMetadataProtoFromXml.java b/java/src/com/google/i18n/phonenumbers/BuildMetadataProtoFromXml.java index b850cd5a4..81cb10d97 100644 --- a/java/src/com/google/i18n/phonenumbers/BuildMetadataProtoFromXml.java +++ b/java/src/com/google/i18n/phonenumbers/BuildMetadataProtoFromXml.java @@ -30,6 +30,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.regex.Pattern; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -84,24 +85,32 @@ public class BuildMetadataProtoFromXml { } } + private static String validateRE(String regex) { + Pattern regexPattern = Pattern.compile(regex); + // return regex itself if it is of correct regex syntax + return regex; + } + private static PhoneMetadata loadCountryMetadata(String regionCode, Element element) { PhoneMetadata.Builder metadata = PhoneMetadata.newBuilder(); metadata.setId(regionCode); metadata.setCountryCode(Integer.parseInt(element.getAttribute("countryCode"))); - metadata.setInternationalPrefix(element.getAttribute("internationalPrefix")); + metadata.setInternationalPrefix(validateRE(element.getAttribute("internationalPrefix"))); if (element.hasAttribute("preferredInternationalPrefix")) { String preferredInternationalPrefix = element.getAttribute("preferredInternationalPrefix"); metadata.setPreferredInternationalPrefix(preferredInternationalPrefix); } String nationalPrefix = ""; + String nationalPrefixFormattingRule = ""; if (element.hasAttribute("nationalPrefix")) { nationalPrefix = element.getAttribute("nationalPrefix"); metadata.setNationalPrefix(nationalPrefix); - metadata.setNationalPrefixFormattingRule( - getNationalPrefixFormattingRuleFromElement(element, nationalPrefix)); + nationalPrefixFormattingRule = + validateRE(getNationalPrefixFormattingRuleFromElement(element, nationalPrefix)); if (element.hasAttribute("nationalPrefixForParsing")) { - metadata.setNationalPrefixForParsing(element.getAttribute("nationalPrefixForParsing")); + metadata.setNationalPrefixForParsing( + validateRE(element.getAttribute("nationalPrefixForParsing"))); if (element.hasAttribute("nationalPrefixTransformRule")) { metadata.setNationalPrefixTransformRule( element.getAttribute("nationalPrefixTransformRule")); @@ -122,17 +131,16 @@ public class BuildMetadataProtoFromXml { Element numberFormatElement = (Element) numberFormatElements.item(i); NumberFormat.Builder format = NumberFormat.newBuilder(); if (numberFormatElement.hasAttribute("nationalPrefixFormattingRule")) { - format.setNationalPrefixFormattingRule( - getNationalPrefixFormattingRuleFromElement(numberFormatElement, nationalPrefix)); + format.setNationalPrefixFormattingRule(validateRE( + getNationalPrefixFormattingRuleFromElement(numberFormatElement, nationalPrefix))); } else { - format.setNationalPrefixFormattingRule(metadata.getNationalPrefixFormattingRule()); + format.setNationalPrefixFormattingRule(nationalPrefixFormattingRule); } if (numberFormatElement.hasAttribute("leadingDigits")) { - format.setLeadingDigits(numberFormatElement.getAttribute("leadingDigits")); + format.setLeadingDigits(validateRE(numberFormatElement.getAttribute("leadingDigits"))); } - format.setPattern(numberFormatElement.getAttribute("pattern")); - String formatValue = numberFormatElement.getFirstChild().getNodeValue(); - format.setFormat(formatValue); + format.setPattern(validateRE(numberFormatElement.getAttribute("pattern"))); + format.setFormat(validateRE(numberFormatElement.getFirstChild().getNodeValue())); metadata.addNumberFormat(format.build()); } } @@ -144,10 +152,10 @@ public class BuildMetadataProtoFromXml { Element numberFormatElement = (Element) intlNumberFormatElements.item(i); NumberFormat.Builder format = NumberFormat.newBuilder(); if (numberFormatElement.hasAttribute("leadingDigits")) { - format.setLeadingDigits(numberFormatElement.getAttribute("leadingDigits")); + format.setLeadingDigits(validateRE(numberFormatElement.getAttribute("leadingDigits"))); } - format.setPattern(numberFormatElement.getAttribute("pattern")); - format.setFormat(numberFormatElement.getFirstChild().getNodeValue()); + format.setPattern(validateRE(numberFormatElement.getAttribute("pattern"))); + format.setFormat(validateRE(numberFormatElement.getFirstChild().getNodeValue())); metadata.addIntlNumberFormat(format.build()); } } @@ -215,14 +223,14 @@ public class BuildMetadataProtoFromXml { Element element = (Element) phoneNumberDescList.item(0); NodeList possiblePattern = element.getElementsByTagName("possibleNumberPattern"); if (possiblePattern.getLength() > 0) { - numberDesc.setPossibleNumberPattern(possiblePattern. - item(0).getFirstChild().getNodeValue()); + numberDesc.setPossibleNumberPattern( + validateRE(possiblePattern.item(0).getFirstChild().getNodeValue())); } NodeList validPattern = element.getElementsByTagName("nationalNumberPattern"); if (validPattern.getLength() > 0) { - numberDesc.setNationalNumberPattern(validPattern. - item(0).getFirstChild().getNodeValue()); + numberDesc.setNationalNumberPattern( + validateRE(validPattern.item(0).getFirstChild().getNodeValue())); } if (!liteBuild) { diff --git a/java/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java b/java/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java index dc5fae4d0..bac6434e4 100644 --- a/java/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java +++ b/java/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java @@ -161,6 +161,7 @@ public class PhoneNumberUtil { new ImmutableSet.Builder() .add(39) // Italy .add(225) // C™te d'Ivoire + .add(227) // Niger .add(228) // Togo .add(240) // Equatorial Guinea .add(241) // Gabon @@ -562,7 +563,7 @@ public class PhoneNumberUtil { * supplied is used only for the resultant log message. */ private boolean isValidRegionCode(String regionCode, int countryCode, String number) { - if (regionCode == null || regionCode.equals("ZZ")) { + if (regionCode == null || regionCode.equalsIgnoreCase("ZZ")) { LOGGER.log(Level.WARNING, "Number " + number + "has invalid or missing country code (" + countryCode + ")"); return false; @@ -674,11 +675,12 @@ public class PhoneNumberUtil { */ public String formatOutOfCountryCallingNumber(PhoneNumber number, String countryCallingFrom) { - if (countryCallingFrom == null || countryCallingFrom.equals("ZZ")) { + if (countryCallingFrom == null || countryCallingFrom.equalsIgnoreCase("ZZ")) { LOGGER.log(Level.WARNING, "Trying to format number from invalid region. International formatting applied."); return format(number, PhoneNumberFormat.INTERNATIONAL); } + countryCallingFrom = countryCallingFrom.toUpperCase(); int countryCode = number.getCountryCode(); if (countryCode == NANPA_COUNTRY_CODE && isNANPACountry(countryCallingFrom)) { // For NANPA countries, return the national format for these countries but prefix it with the @@ -837,6 +839,7 @@ public class PhoneNumberUtil { * does not contain such information. */ public PhoneNumber getExampleNumber(String regionCode) { + regionCode = regionCode.toUpperCase(); return getExampleNumberForType(regionCode, PhoneNumberType.FIXED_LINE); } @@ -850,6 +853,7 @@ public class PhoneNumberUtil { * does not contain such information. */ public PhoneNumber getExampleNumberForType(String regionCode, PhoneNumberType type) { + regionCode = regionCode.toUpperCase(); PhoneNumberDesc desc = getNumberDescByType(getMetadataForRegion(regionCode), type); try { if (desc.hasExampleNumber()) { @@ -1021,6 +1025,7 @@ public class PhoneNumberUtil { * @return a boolean that indicates whether the number is of a valid pattern */ public boolean isValidNumberForRegion(PhoneNumber number, String regionCode) { + regionCode = regionCode.toUpperCase(); if (number.getCountryCode() != getCountryCodeForRegion(regionCode)) { return false; } @@ -1098,11 +1103,11 @@ public class PhoneNumberUtil { * @return the country calling code for the country/region denoted by regionCode */ public int getCountryCodeForRegion(String regionCode) { - if (regionCode == null || regionCode.equals("ZZ")) { + if (regionCode == null || regionCode.equalsIgnoreCase("ZZ")) { LOGGER.log(Level.SEVERE, "Invalid or missing country code provided."); return 0; } - PhoneMetadata metadata = getMetadataForRegion(regionCode); + PhoneMetadata metadata = getMetadataForRegion(regionCode.toUpperCase()); if (metadata == null) { LOGGER.log(Level.SEVERE, "Unsupported country code provided."); return 0; @@ -1117,6 +1122,7 @@ public class PhoneNumberUtil { * @return true if regionCode is one of the countries under NANPA */ public boolean isNANPACountry(String regionCode) { + regionCode = regionCode.toUpperCase(); return nanpaCountries.contains(regionCode); } @@ -1202,6 +1208,7 @@ public class PhoneNumberUtil { * @return true if the number is possible */ public boolean isPossibleNumber(String number, String countryDialingFrom) { + countryDialingFrom = countryDialingFrom.toUpperCase(); try { return isPossibleNumber(parse(number, countryDialingFrom)); } catch (NumberParseException e) { @@ -1225,6 +1232,7 @@ public class PhoneNumberUtil { * specific country "as you type" */ public AsYouTypeFormatter getAsYouTypeFormatter(String regionCode) { + regionCode = regionCode.toUpperCase(); return new AsYouTypeFormatter(regionCode); } @@ -1472,11 +1480,11 @@ public class PhoneNumberUtil { */ public PhoneNumber parse(String numberToParse, String defaultCountry) throws NumberParseException { - if (defaultCountry == null || defaultCountry.equals("ZZ")) { + if (defaultCountry == null || defaultCountry.equalsIgnoreCase("ZZ")) { throw new NumberParseException(NumberParseException.ErrorType.INVALID_COUNTRY_CODE, "No default country was supplied."); } - return parseHelper(numberToParse, defaultCountry, false); + return parseHelper(numberToParse, defaultCountry.toUpperCase(), false); } /** @@ -1496,11 +1504,11 @@ public class PhoneNumberUtil { */ public PhoneNumber parseAndKeepRawInput(String numberToParse, String defaultCountry) throws NumberParseException { - if (defaultCountry == null || defaultCountry.equals("ZZ")) { + if (defaultCountry == null || defaultCountry.equalsIgnoreCase("ZZ")) { throw new NumberParseException(NumberParseException.ErrorType.INVALID_COUNTRY_CODE, "No default country was supplied."); } - return parseHelper(numberToParse, defaultCountry, true); + return parseHelper(numberToParse, defaultCountry.toUpperCase(), true); } /** @@ -1588,11 +1596,6 @@ public class PhoneNumberUtil { countryMetadata.getNationalPrefixTransformRule(), validNumberPattern); } - phoneNumber.setCountryCode(countryCode); - if (isLeadingZeroCountry(countryCode) && - normalizedNationalNumber.charAt(0) == '0') { - phoneNumber.setItalianLeadingZero(true); - } int lengthOfNationalNumber = normalizedNationalNumber.length(); if (lengthOfNationalNumber < MIN_LENGTH_FOR_NSN) { throw new NumberParseException(NumberParseException.ErrorType.TOO_SHORT_NSN, @@ -1604,6 +1607,11 @@ public class PhoneNumberUtil { "The string supplied is too long to be a " + "phone number."); } + phoneNumber.setCountryCode(countryCode); + if (isLeadingZeroCountry(countryCode) && + normalizedNationalNumber.charAt(0) == '0') { + phoneNumber.setItalianLeadingZero(true); + } phoneNumber.setNationalNumber(Long.parseLong(normalizedNationalNumber.toString())); return phoneNumber.build(); } diff --git a/java/src/com/google/i18n/phonenumbers/phonemetadata.proto b/java/src/com/google/i18n/phonenumbers/phonemetadata.proto index 3e744e3c1..e42bca156 100644 --- a/java/src/com/google/i18n/phonenumbers/phonemetadata.proto +++ b/java/src/com/google/i18n/phonenumbers/phonemetadata.proto @@ -20,8 +20,11 @@ syntax = "proto2"; +option cc_api_version = 1; +option java_api_version = 1; +option py_api_version = 1; + option java_package = "com.google.i18n.phonenumbers"; -option optimize_for = LITE_RUNTIME; package i18n.phonenumbers; message NumberFormat { @@ -51,9 +54,18 @@ message NumberFormat { // This field specifies how the national prefix ($NP) together with the first // group ($FG) in the national significant number should be formatted in // the NATIONAL format when a national prefix exists for a certain country. - // When present, it overrides the national_prefix_formatting_rule specified - // in PhoneNumberDesc. See the comment in PhoneNumberDesc for more information - // on how this rule is specified. + // For example, when this field contains "($NP$FG)", a number from Beijing, + // China (whose $NP = 0), which would by default be formatted without + // national prefix as 10 1234 5678 in NATIONAL format, will instead be + // formatted as (010) 1234 5678; to format it as (0)10 1234 5678, the field + // would contain "($NP)$FG". Note $FG should always be present in this field, + // but $NP can be omitted. For example, having "$FG" could indicate the + // number should be formatted in NATIONAL format without the national prefix. + // This is commonly used to override the rule from generalDesc. + // + // When this field is missing, a number will be formatted without national + // prefix in NATIONAL format. This field does not affect how a number + // is formatted in other formats, such as INTERNATIONAL. optional string national_prefix_formatting_rule = 4; } @@ -184,24 +196,7 @@ message PhoneMetadata { // 15 (inserted after the area code of 343) is used. repeated NumberFormat intl_number_format = 20; - // This field specifies how the national prefix ($NP) together with the first - // group ($FG) in the national significant number should be formatted in - // the NATIONAL format when a national prefix exists for a certain country. - // For example, when this field contains "($NP$FG)", a number from Beijing, - // China (whose $NP = 0), which would by default be formatted without - // national prefix as 10 1234 5678 in NATIONAL format, will instead be - // formatted as (010) 1234 5678; to format it as (0)10 1234 5678, the field - // would contain "($NP)$FG". Note $FG should always be present in this field, - // but $NP can be omitted. For example, having "$FG" could indicate the - // number should be formatted in NATIONAL format without the national prefix. - // This is commonly used to override the rule from generalDesc. - // - // When this field is missing, a number will be formatted without national - // prefix in NATIONAL format. This field does not affect how a number - // is formatted in other formats, such as INTERNATIONAL. - // - // This field applies to all numberFormats unless overridden by the - // national_prefix_formatting_rule in a specific numberFormat. + // Deprecated. optional string national_prefix_formatting_rule = 21; } diff --git a/java/test/com/google/i18n/phonenumbers/AsYouTypeFormatterTest.java b/java/test/com/google/i18n/phonenumbers/AsYouTypeFormatterTest.java index d464cd265..f8758bc00 100644 --- a/java/test/com/google/i18n/phonenumbers/AsYouTypeFormatterTest.java +++ b/java/test/com/google/i18n/phonenumbers/AsYouTypeFormatterTest.java @@ -196,7 +196,7 @@ public class AsYouTypeFormatterTest extends TestCase { } public void testAsYouTypeFormatterGBTollFree() { - AsYouTypeFormatter formatter = phoneUtil.getAsYouTypeFormatter("GB"); + AsYouTypeFormatter formatter = phoneUtil.getAsYouTypeFormatter("gb"); assertEquals("0", formatter.inputDigit('0')); assertEquals("08", formatter.inputDigit('8')); assertEquals("080", formatter.inputDigit('0')); @@ -282,4 +282,94 @@ public class AsYouTypeFormatterTest extends TestCase { assertEquals("+54 9 11 2312 123\u2008", formatter.inputDigit('3')); assertEquals("+54 9 11 2312 1234", formatter.inputDigit('4')); } + + public void testAsYouTypeFormatterKR() { + // +82 51 234 5678 + AsYouTypeFormatter formatter = phoneUtil.getAsYouTypeFormatter("KR"); + assertEquals("+", formatter.inputDigit('+')); + assertEquals("+8", formatter.inputDigit('8')); + assertEquals("+82", formatter.inputDigit('2')); + assertEquals("+825", formatter.inputDigit('5')); + assertEquals("+8251", formatter.inputDigit('1')); + assertEquals("+82 512", formatter.inputDigit('2')); + assertEquals("+82 51-23\u2008-\u2008\u2008\u2008\u2008", formatter.inputDigit('3')); + assertEquals("+82 51-234-\u2008\u2008\u2008\u2008", formatter.inputDigit('4')); + assertEquals("+82 51-234-5\u2008\u2008\u2008", formatter.inputDigit('5')); + assertEquals("+82 51-234-56\u2008\u2008", formatter.inputDigit('6')); + assertEquals("+82 51-234-567\u2008", formatter.inputDigit('7')); + assertEquals("+82 51-234-5678", formatter.inputDigit('8')); + + // +82 2 531 5678 + formatter.clear(); + assertEquals("+", formatter.inputDigit('+')); + assertEquals("+8", formatter.inputDigit('8')); + assertEquals("+82", formatter.inputDigit('2')); + assertEquals("+822", formatter.inputDigit('2')); + assertEquals("+8225", formatter.inputDigit('5')); + assertEquals("+82 253", formatter.inputDigit('3')); + assertEquals("+82 2-531-\u2008\u2008\u2008\u2008", formatter.inputDigit('1')); + assertEquals("+82 2-531-5\u2008\u2008\u2008", formatter.inputDigit('5')); + assertEquals("+82 2-531-56\u2008\u2008", formatter.inputDigit('6')); + assertEquals("+82 2-531-567\u2008", formatter.inputDigit('7')); + assertEquals("+82 2-531-5678", formatter.inputDigit('8')); + + // +82 2 3665 5678 + formatter.clear(); + assertEquals("+", formatter.inputDigit('+')); + assertEquals("+8", formatter.inputDigit('8')); + assertEquals("+82", formatter.inputDigit('2')); + assertEquals("+822", formatter.inputDigit('2')); + assertEquals("+8223", formatter.inputDigit('3')); + assertEquals("+82 236", formatter.inputDigit('6')); + assertEquals("+82 2-366\u2008-\u2008\u2008\u2008\u2008", formatter.inputDigit('6')); + assertEquals("+82 2-3665-\u2008\u2008\u2008\u2008", formatter.inputDigit('5')); + assertEquals("+82 2-3665-5\u2008\u2008\u2008", formatter.inputDigit('5')); + assertEquals("+82 2-3665-56\u2008\u2008", formatter.inputDigit('6')); + assertEquals("+82 2-3665-567\u2008", formatter.inputDigit('7')); + assertEquals("+82 2-3665-5678", formatter.inputDigit('8')); + + // 02-114 : This is too short to format. Checking that there are no side-effects. + formatter.clear(); + assertEquals("0", formatter.inputDigit('0')); + assertEquals("02", formatter.inputDigit('2')); + assertEquals("021", formatter.inputDigit('1')); + assertEquals("0211", formatter.inputDigit('1')); + assertEquals("02114", formatter.inputDigit('4')); + + // 02-1300 + formatter.clear(); + assertEquals("0", formatter.inputDigit('0')); + assertEquals("02", formatter.inputDigit('2')); + assertEquals("021", formatter.inputDigit('1')); + assertEquals("0213", formatter.inputDigit('3')); + assertEquals("02130", formatter.inputDigit('0')); + assertEquals("02-1300", formatter.inputDigit('0')); + + // 011-456-7890 + formatter.clear(); + assertEquals("0", formatter.inputDigit('0')); + assertEquals("01", formatter.inputDigit('1')); + assertEquals("011", formatter.inputDigit('1')); + assertEquals("0114", formatter.inputDigit('4')); + assertEquals("01145", formatter.inputDigit('5')); + assertEquals("011-456-\u2008\u2008\u2008\u2008", formatter.inputDigit('6')); + assertEquals("011-456-7\u2008\u2008\u2008", formatter.inputDigit('7')); + assertEquals("011-456-78\u2008\u2008", formatter.inputDigit('8')); + assertEquals("011-456-789\u2008", formatter.inputDigit('9')); + assertEquals("011-456-7890", formatter.inputDigit('0')); + + // 011-9876-7890 + formatter.clear(); + assertEquals("0", formatter.inputDigit('0')); + assertEquals("01", formatter.inputDigit('1')); + assertEquals("011", formatter.inputDigit('1')); + assertEquals("0119", formatter.inputDigit('9')); + assertEquals("01198", formatter.inputDigit('8')); + assertEquals("011-987\u2008-\u2008\u2008\u2008\u2008", formatter.inputDigit('7')); + assertEquals("011-9876-\u2008\u2008\u2008\u2008", formatter.inputDigit('6')); + assertEquals("011-9876-7\u2008\u2008\u2008", formatter.inputDigit('7')); + assertEquals("011-9876-78\u2008\u2008", formatter.inputDigit('8')); + assertEquals("011-9876-789\u2008", formatter.inputDigit('9')); + assertEquals("011-9876-7890", formatter.inputDigit('0')); + } } diff --git a/java/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java b/java/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java index 746a3ed94..43ded0fa3 100644 --- a/java/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java +++ b/java/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java @@ -123,6 +123,7 @@ public class PhoneNumberUtilTest extends TestCase { PhoneNumber deNumber = PhoneNumber.newBuilder().setCountryCode(49).setNationalNumber(30123456).build(); assertEquals(deNumber, phoneUtil.getExampleNumber("DE")); + assertEquals(deNumber, phoneUtil.getExampleNumber("de")); assertEquals(deNumber, phoneUtil.getExampleNumberForType("DE", @@ -415,6 +416,8 @@ public class PhoneNumberUtilTest extends TestCase { phoneUtil.formatOutOfCountryCallingNumber(arNumber2, "AU")); assertEquals("011 15 8765-4321 ext. 1234", phoneUtil.formatOutOfCountryCallingNumber(arNumber2, "AR")); + assertEquals("011 15 8765-4321 ext. 1234", + phoneUtil.formatOutOfCountryCallingNumber(arNumber2, "ar")); } public void testFormatOutOfCountryWithPreferredIntlPrefix() { @@ -687,6 +690,7 @@ public class PhoneNumberUtilTest extends TestCase { PhoneNumber.newBuilder().setCountryCode(1).setNationalNumber(2423232345L).build(); assertTrue(phoneUtil.isValidNumber(bsNumber1)); assertTrue(phoneUtil.isValidNumberForRegion(bsNumber1, "BS")); + assertTrue(phoneUtil.isValidNumberForRegion(bsNumber1, "bs")); assertFalse(phoneUtil.isValidNumberForRegion(bsNumber1, "US")); PhoneNumber bsNumber2 = PhoneNumber.newBuilder(bsNumber1).setNationalNumber(2421232345L).build(); @@ -739,6 +743,7 @@ public class PhoneNumberUtilTest extends TestCase { public void testGetCountryCodeForRegion() { assertEquals(1, phoneUtil.getCountryCodeForRegion("US")); assertEquals(64, phoneUtil.getCountryCodeForRegion("NZ")); + assertEquals(64, phoneUtil.getCountryCodeForRegion("nz")); assertEquals(0, phoneUtil.getCountryCodeForRegion(null)); assertEquals(0, phoneUtil.getCountryCodeForRegion("ZZ")); // CS is already deprecated so the library doesn't support it. @@ -748,6 +753,7 @@ public class PhoneNumberUtilTest extends TestCase { public void testIsNANPACountry() { assertTrue(phoneUtil.isNANPACountry("US")); assertTrue(phoneUtil.isNANPACountry("BS")); + assertTrue(phoneUtil.isNANPACountry("bs")); } public void testIsPossibleNumber() { @@ -771,6 +777,7 @@ public class PhoneNumberUtilTest extends TestCase { assertTrue(phoneUtil.isPossibleNumber("(020) 7031 3000", "GB")); assertTrue(phoneUtil.isPossibleNumber("7031 3000", "GB")); assertTrue(phoneUtil.isPossibleNumber("3331 6005", "NZ")); + assertTrue(phoneUtil.isPossibleNumber("3331 6005", "nz")); } public void testIsPossibleNumberWithReason() { @@ -1032,22 +1039,11 @@ public class PhoneNumberUtilTest extends TestCase { // National prefix attached. assertEquals(nzNumber, phoneUtil.parse("033316005", "NZ")); + assertEquals(nzNumber, phoneUtil.parse("033316005", "nz")); assertEquals(nzNumber, phoneUtil.parse("33316005", "NZ")); // National prefix attached and some formatting present. assertEquals(nzNumber, phoneUtil.parse("03-331 6005", "NZ")); assertEquals(nzNumber, phoneUtil.parse("03 331 6005", "NZ")); - // Test case with alpha characters. - PhoneNumber tollfreeNumber = - PhoneNumber.newBuilder().setCountryCode(64).setNationalNumber(800332005L).build(); - assertEquals(tollfreeNumber, phoneUtil.parse("0800 DDA 005", "NZ")); - PhoneNumber premiumNumber = - PhoneNumber.newBuilder().setCountryCode(64).setNationalNumber(9003326005L).build(); - assertEquals(premiumNumber, phoneUtil.parse("0900 DDA 6005", "NZ")); - // Not enough alpha characters for them to be considered intentional, so they are stripped. - assertEquals(premiumNumber, phoneUtil.parse("0900 332 6005a", "NZ")); - assertEquals(premiumNumber, phoneUtil.parse("0900 332 600a5", "NZ")); - assertEquals(premiumNumber, phoneUtil.parse("0900 332 600A5", "NZ")); - assertEquals(premiumNumber, phoneUtil.parse("0900 a332 600A5", "NZ")); // Testing international prefixes. // Should strip country code. @@ -1057,11 +1053,38 @@ public class PhoneNumberUtilTest extends TestCase { assertEquals(nzNumber, phoneUtil.parse("01164 3 331 6005", "US")); assertEquals(nzNumber, phoneUtil.parse("+64 3 331 6005", "US")); - // Test for http://b/issue?id=2247493 PhoneNumber nzNumber2 = PhoneNumber.newBuilder().setCountryCode(64).setNationalNumber(64123456L).build(); assertEquals(nzNumber2, phoneUtil.parse("64(0)64123456", "NZ")); + // Check that using a "/" is fine in a phone number. + PhoneNumber deNumber = + PhoneNumber.newBuilder().setCountryCode(49).setNationalNumber(12345678L).build(); + assertEquals(deNumber, phoneUtil.parse("123/45678", "DE")); + // Check it doesn't use the '1' as a country code when parsing if the phone number was already + // possible. + PhoneNumber usNumber = + PhoneNumber.newBuilder().setCountryCode(1).setNationalNumber(1234567890L).build(); + assertEquals(usNumber, phoneUtil.parse("123-456-7890", "US")); + + } + + public void testParseNumberWithAlphaCharacters() throws Exception { + // Test case with alpha characters. + PhoneNumber tollfreeNumber = + PhoneNumber.newBuilder().setCountryCode(64).setNationalNumber(800332005L).build(); + assertEquals(tollfreeNumber, phoneUtil.parse("0800 DDA 005", "NZ")); + PhoneNumber premiumNumber = + PhoneNumber.newBuilder().setCountryCode(64).setNationalNumber(9003326005L).build(); + assertEquals(premiumNumber, phoneUtil.parse("0900 DDA 6005", "NZ")); + // Not enough alpha characters for them to be considered intentional, so they are stripped. + assertEquals(premiumNumber, phoneUtil.parse("0900 332 6005a", "NZ")); + assertEquals(premiumNumber, phoneUtil.parse("0900 332 600a5", "NZ")); + assertEquals(premiumNumber, phoneUtil.parse("0900 332 600A5", "NZ")); + assertEquals(premiumNumber, phoneUtil.parse("0900 a332 600A5", "NZ")); + } + + public void testParseWithInternationalPrefixes() throws Exception { PhoneNumber usNumber = PhoneNumber.newBuilder().setCountryCode(1).setNationalNumber(6503336000L).build(); assertEquals(usNumber, phoneUtil.parse("+1 (650) 333-6000", "NZ")); @@ -1075,12 +1098,9 @@ public class PhoneNumberUtilTest extends TestCase { assertEquals(usNumber, phoneUtil.parse("0191-650-333-6000", "SG")); // Calling the US number from Poland assertEquals(usNumber, phoneUtil.parse("0~01-650-333-6000", "PL")); - // Check it doesn't use the '1' as a country code when parsing if the phone number was already - // possible. - PhoneNumber usNumber2 = - PhoneNumber.newBuilder().setCountryCode(1).setNationalNumber(1234567890L).build(); - assertEquals(usNumber2, phoneUtil.parse("123-456-7890", "US")); + } + public void testParseWithLeadingZero() throws Exception { PhoneNumber itNumber = PhoneNumber.newBuilder().setCountryCode(39).setNationalNumber(236618300L) .setItalianLeadingZero(true).build(); @@ -1090,12 +1110,9 @@ public class PhoneNumberUtilTest extends TestCase { PhoneNumber itNumber2 = PhoneNumber.newBuilder().setCountryCode(39).setNationalNumber(312345678L).build(); assertEquals(itNumber2, phoneUtil.parse("312 345 678", "IT")); + } - // Check that using a "/" is fine in a phone number. - PhoneNumber deNumber = - PhoneNumber.newBuilder().setCountryCode(49).setNationalNumber(12345678L).build(); - assertEquals(deNumber, phoneUtil.parse("123/45678", "DE")); - + public void testParseNationalNumberArgentina() throws Exception { // Test parsing mobile numbers of Argentina. PhoneNumber arNumber = PhoneNumber.newBuilder().setCountryCode(54).setNationalNumber(93435551212L).build(); @@ -1122,7 +1139,9 @@ public class PhoneNumberUtilTest extends TestCase { PhoneNumber.newBuilder().setCountryCode(54).setNationalNumber(2312340000L).build(); assertEquals(arNumber5, phoneUtil.parse("+54 23 1234 0000", "AR")); assertEquals(arNumber5, phoneUtil.parse("023 1234 0000", "AR")); + } + public void testParseWithXInNumber() throws Exception { // Test that having an 'x' in the phone number at the start is ok and that it just gets removed. PhoneNumber arNumber6 = PhoneNumber.newBuilder().setCountryCode(54).setNationalNumber(123456789L).build(); @@ -1137,7 +1156,9 @@ public class PhoneNumberUtilTest extends TestCase { // to 7 digits. This assumption is okay for now as all the countries where a carrier selection // code is written in the form of xx have a national significant number of length larger than 7. assertEquals(arFromUs, phoneUtil.parse("011xx5481429712", "US")); + } + public void testParseNumbersMexico() throws Exception { // Test parsing fixed-line numbers of Mexico. PhoneNumber mxNumber = PhoneNumber.newBuilder().setCountryCode(52).setNationalNumber(4499780001L).build(); @@ -1151,24 +1172,6 @@ public class PhoneNumberUtilTest extends TestCase { assertEquals(mxNumber2, phoneUtil.parse("+52 1 33 1234-5678", "MX")); assertEquals(mxNumber2, phoneUtil.parse("044 (33) 1234-5678", "MX")); assertEquals(mxNumber2, phoneUtil.parse("045 33 1234-5678", "MX")); - - // Test that if a number has two extensions specified, we ignore the second. - PhoneNumber usWithTwoExtensionsNumber = - PhoneNumber.newBuilder().setCountryCode(1).setNationalNumber(2121231234L) - .setExtension("508").build(); - assertEquals(usWithTwoExtensionsNumber, phoneUtil.parse("(212)123-1234 x508/x1234", - "US")); - assertEquals(usWithTwoExtensionsNumber, phoneUtil.parse("(212)123-1234 x508/ x1234", - "US")); - assertEquals(usWithTwoExtensionsNumber, phoneUtil.parse("(212)123-1234 x508\\x1234", - "US")); - - // Test parsing numbers in the form (645) 123-1234-910# works, where the last 3 digits before - // the # are an extension. - PhoneNumber usWithExtension = - PhoneNumber.newBuilder().setCountryCode(1).setNationalNumber(6451231234L) - .setExtension("910").build(); - assertEquals(usWithExtension, phoneUtil.parse("+1 (645) 123 1234-910#", "US")); } public void testFailedParseOnInvalidNumbers() { @@ -1317,6 +1320,24 @@ public class PhoneNumberUtilTest extends TestCase { phoneUtil.parse("(800) 901-3355 ,extension 7246433", "US")); assertEquals(usWithExtension, phoneUtil.parse("(800) 901-3355 , 7246433", "US")); assertEquals(usWithExtension, phoneUtil.parse("(800) 901-3355 ext: 7246433", "US")); + + // Test that if a number has two extensions specified, we ignore the second. + PhoneNumber usWithTwoExtensionsNumber = + PhoneNumber.newBuilder().setCountryCode(1).setNationalNumber(2121231234L) + .setExtension("508").build(); + assertEquals(usWithTwoExtensionsNumber, phoneUtil.parse("(212)123-1234 x508/x1234", + "US")); + assertEquals(usWithTwoExtensionsNumber, phoneUtil.parse("(212)123-1234 x508/ x1234", + "US")); + assertEquals(usWithTwoExtensionsNumber, phoneUtil.parse("(212)123-1234 x508\\x1234", + "US")); + + // Test parsing numbers in the form (645) 123-1234-910# works, where the last 3 digits before + // the # are an extension. + PhoneNumber usWithExtension2 = + PhoneNumber.newBuilder().setCountryCode(1).setNationalNumber(6451231234L) + .setExtension("910").build(); + assertEquals(usWithExtension2, phoneUtil.parse("+1 (645) 123 1234-910#", "US")); } public void testParseAndKeepRaw() throws Exception { @@ -1334,7 +1355,7 @@ public class PhoneNumberUtilTest extends TestCase { assertEquals("+376 12345", phoneUtil.format(adNumber, PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL)); assertEquals("+37612345", phoneUtil.format(adNumber, - PhoneNumberUtil.PhoneNumberFormat.E164)); + PhoneNumberUtil.PhoneNumberFormat.E164)); assertEquals("12345", phoneUtil.format(adNumber, PhoneNumberUtil.PhoneNumberFormat.NATIONAL)); assertEquals(PhoneNumberUtil.PhoneNumberType.UNKNOWN,