From: lararennie@google.com Date: Thu, 20 Jan 2011 14:26:34 +0000 (+0000) Subject: Metadata changes, new countries, small code changes. X-Git-Tag: upstream/5.3.2~434 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=11acf58629b8039038af4d5bda7e5911911193bf;p=platform%2Fupstream%2Flibphonenumber.git Metadata changes, new countries, small code changes. git-svn-id: http://libphonenumber.googlecode.com/svn/trunk@66 ee073f10-1060-11df-b6a4-87a95322a99c --- diff --git a/java/release_notes.txt b/java/release_notes.txt index 860189c..4206e3a 100644 --- a/java/release_notes.txt +++ b/java/release_notes.txt @@ -1,3 +1,23 @@ +Jan 20th, 2011 +* Code improvements: + - Handle null phone-numbers when parsing by throwing a NumberParseException. + - Handle extension written with an accented "o", as per Spanish, when parsing. + - Handle U+30FC dashes as phone-number punctuation. + - Allow "ZZ" or null regions to be specified for numbers starting with a full-width "+" symbol, or + with other characters (such as whitespace) before the leading +. + - new getLengthOfNationalDestinationCode function +* Metadata changes: + - New types of numbers introduced: UAN (universal or "company" numbers) and short codes. Note that + "generalDesc" patterns do not encompass short-codes. No code-support for these has been + introduced as of yet. We are also now enabling the collection of data for information such as + area-code-optional, and no-international-dialling ranges. + - Data updates as per ITU notifications/bug fixes for the following countries: AM, BH, CD, CG, CR, + DE, DJ, EE, GB, GN, HU, IE, JO, JP, LB, LR, MA, MK, MN, MR, NA, PG, SC, SG, SO, SZ, VN, ZA, ZW + - Data added for the following countries: BZ, CU, EC, FO, GI, HN, HT, LK, MT, MV, NU, PS, SD + - Indentation fixes in reg-exes for the following countries: BG, GB + - Allow nationalPrefixForParsing to be specified for countries with no national prefix, to handle + possible carrier prefixes + Jan 3rd, 2011 * Metadata changes: - Updates to JE diff --git a/java/resources/com/google/i18n/phonenumbers/BuildMetadataFromXml.java b/java/resources/com/google/i18n/phonenumbers/BuildMetadataFromXml.java index 1f2b77b..5c2ef7a 100644 --- a/java/resources/com/google/i18n/phonenumbers/BuildMetadataFromXml.java +++ b/java/resources/com/google/i18n/phonenumbers/BuildMetadataFromXml.java @@ -126,20 +126,21 @@ public class BuildMetadataFromXml { String nationalPrefix = ""; String nationalPrefixFormattingRule = ""; String carrierCodeFormattingRule = ""; + if (element.hasAttribute("nationalPrefixForParsing")) { + metadata.setNationalPrefixForParsing( + validateRE(element.getAttribute("nationalPrefixForParsing"))); + if (element.hasAttribute("nationalPrefixTransformRule")) { + metadata.setNationalPrefixTransformRule( + validateRE(element.getAttribute("nationalPrefixTransformRule"))); + } + } if (element.hasAttribute("nationalPrefix")) { nationalPrefix = element.getAttribute("nationalPrefix"); metadata.setNationalPrefix(nationalPrefix); nationalPrefixFormattingRule = validateRE(getNationalPrefixFormattingRuleFromElement(element, nationalPrefix)); - if (element.hasAttribute("nationalPrefixForParsing")) { - metadata.setNationalPrefixForParsing( - validateRE(element.getAttribute("nationalPrefixForParsing"))); - if (element.hasAttribute("nationalPrefixTransformRule")) { - metadata.setNationalPrefixTransformRule( - validateRE(element.getAttribute("nationalPrefixTransformRule"))); - } - } else { + if (!metadata.hasNationalPrefixForParsing()) { metadata.setNationalPrefixForParsing(nationalPrefix); } } diff --git a/java/resources/com/google/i18n/phonenumbers/src/PhoneNumberMetaData.xml b/java/resources/com/google/i18n/phonenumbers/src/PhoneNumberMetaData.xml index abf008a..fb011b2 100644 --- a/java/resources/com/google/i18n/phonenumbers/src/PhoneNumberMetaData.xml +++ b/java/resources/com/google/i18n/phonenumbers/src/PhoneNumberMetaData.xml @@ -16,28 +16,33 @@ @author: Lara Rennie MetaData on Phone Number Plan and formatting rules - Note: Territories are in alphabetical order by their IDs, which are - based on ISO 3166-1 two-letter country codes. The country names - in the comments are the official short names in English according - to ISO 3166-1. + Note: Territories are in alphabetical order by their IDs, which are based on ISO 3166-1 + two-letter country codes. The country names in the comments are the official short names + in English according to ISO 3166-1. For more information on what each element represents, see java/com/google/i18n/phonenumbers/phonemetadata.proto - Note that if you want to add validation metadata, the generalDesc - nationalNumberPattern and possibleNumberPattern must be provided. - If this is missing, then the country will be considered to have no more - specific phone-number type metadata (fixedLine, mobile etc) and hence only - basic validation rules (numbers should be between 3 and 15 digits long) - will be applied. + Note that if you want to add validation metadata, the generalDesc nationalNumberPattern and + possibleNumberPattern must be provided. If this is missing, then the country will be + considered to have no more specific phone-number type metadata (fixedLine, mobile etc) and + hence only basic validation rules (numbers should be between 3 and 15 digits long) will be + applied. + + Country code, international and national prefix information main source: + http://www.itu.int/publ/T-SP-E.164C-2010/en --> - + + + @@ -46,6 +51,8 @@ + + @@ -72,7 +79,7 @@ - ]> +]> @@ -448,7 +455,7 @@ [17]| - 9[1-49] + 9[1-469] $1 $2 @@ -490,7 +497,7 @@ (?: 77| - 9[1-49] + 9[1-469] )\d{6} \d{8} @@ -511,6 +518,14 @@ \d{8} 80112345 + + + 8[1-7]\d{2}| + 1\d{2} + + \d{3,4} + 8711 + @@ -1785,8 +1800,23 @@ - (?:2\d|[36]\d|5[1-9]|8[1-6]|9[1-7])\d{5,6}| - (?:4(?:[124-7]\d|3[1-6])|7(?:0[1-9]|[1-9]\d))\d{4,5} + (?: + 2\d| + [36]\d| + 5[1-9]| + 8[1-6]| + 9[1-7] + )\d{5,6}| + (?: + 4(?: + [124-7]\d| + 3[1-6] + )| + 7(?: + 0[1-9]| + [1-9]\d + ) + )\d{4,5} \d{7,8} 2123456 @@ -1823,6 +1853,7 @@ + @@ -1830,7 +1861,7 @@ - [1367]\d{7} + [136-9]\d{7} \d{8} + + + (?: + 87| + 9[014578] + )\d{6} + + 90123456 + + + 84\d{6} + 84123456 + @@ -2527,8 +2577,51 @@ - + + + + + + [2-8] + + $1-$2 + + + 0 + $1-$2-$3-$4 + + + + + [2-8]\d{6}| + 0\d{10} + + \d{7}(?:\d{4})? + + + [234578][02]\d{5} + \d{7} + 2221234 + + + + 6(?: + [01]\d| + 2[0-5]| + [67][01])\d{4} + + \d{7} + 6221234 + + + + 0800\d{7} + \d{11} + 08001234123 + @@ -2695,7 +2788,7 @@ (?: - 8[0149]| + 8[0-2489]| 9[7-9] )\d{7} @@ -2734,29 +2827,32 @@ - - $1 $2 + + [02] + $1 $2 $3 + + + 8 + $1 $2 $3 - [24-68]\d{6} - \d{7} + [028]\d{8} + \d{9} - - - (?: - 2[1-589]| - 8\d - )\d{5} - - 2123456 + 222[1-589]\d{5} + 222123456 - [4-6]\d{6} - 5012345 + 0[14-6]\d{7} + 061234567 + + + 800\d{6} + 800123456 + @@ -3453,27 +3549,87 @@ - + + + 2| + 8[389] + $1 $2 + + [89]0 + $1-$2-$3 + - [28]\d{7} - \d{8} + [289]\d{7,9} + \d{8,10} 2[24-7]\d{6} + \d{8} 22123456 - 8[38]\d{6} + 8[389]\d{6} + \d{8} 83123456 + + 800\d{7} + \d{10} + 8001234567 + + + + 90[059]\d{7} + \d{10} + 9001234567 + + + nationalPrefix="0" nationalPrefixFormattingRule="($NP$FG)"> + + + 7 + $1 $2 + + + [2-4] + $1 $2 + + + 5 + $1 $2 + + + + [2-57]\d{5,7} + \d{4,8} + + + + (?: + 2[1-4]\d{5,6}| + 3(?: + 1\d{6}| + [23]\d{4,6})| + 4(?: + [125]\d{5,6}| + [36]\d{6}| + [78]\d{4,6})| + 7\d{6,7}) + + 71234567 + + + 5\d{7} + \d{8} + 51234567 + @@ -3610,7 +3766,7 @@ - + @@ -3771,32 +3927,43 @@ stricter for numbers starting with 49, to try and remove the country code if the number begins with 49 whenever possible. --> - (?: - 4[0-8]| - [1-35-9]\d - )\d{4,12}| - 49(?: - 4[1-8]| - [0-35-7]\d - )\d{2,7} + [1-35-9]\d{3,13}| + 4(?: + [0-8]\d{4,12}| + 9(?: + 4[1-8]| + [0-35-7]\d + )\d{2,7} + ) \d{2,14} + - (?: - [246]\d{2}| - 3[02-9]\d| - 5(?: - 0[2-8]| - [38][0-8]| - [124-6]\d| - [79][0-7] - )| - [789](?: - [1-9]\d| - 0[2-9] - ) + [246]\d{5,13}| + 3(?: + [03-9]\d{4,11}| + 2\d{9} + )| + 5(?: + 0[2-8]| + [38][0-8]| + [124-6]\d| + [79][0-7] + )\d{3,10}| + 7(?: + 0[2-8]| + [1-9]\d + )\d{3,10}| + 8(?: + 0[2-9]| + [1-9]\d + )\d{3,10}| + 9(?: + 0[6-9]| + [1-9]\d )\d{3,10} 30123456 @@ -3812,13 +3979,25 @@ [0-57-9]| 6\d )\d{7}| - 6[02]\d{7,8}| - 63\d{7} + 6(?: + [02]\d{7,8}| + 3\d{7} + ) ) \d{10,11} 15123456789 + + + 16(?: + 4\d{1,10}| + [89]\d{1,11} + ) + + \d{4,14} + 16412345 + 800\d{7,9} \d{10,12} @@ -3854,35 +4033,26 @@ - + $1 $2 $3 - [2-8]\d{5} + [1-8]\d{5} \d{6} - + (?: - 25| - 3[0-6]| - 42 + 1[05]| + [2-5]\d )\d{4} 251234 - - - (?: - [5-7]\d| - 8[0-7] - )\d{4} - + [6-8]\d{5} 601234 @@ -4117,17 +4287,72 @@ + + + + + nationalPrefix="0" nationalPrefixFormattingRule="($NP$FG)"> + + + [2-7] + $1 $2-$3 + + + [2-7] + $1-$2-$3 + + + [89] + $1 $2 $3 + + + [89] + $1 $2 $3 + + + 1 + $1 $2 $3 + + + 1 + $1 $2 $3 + + + + [2-9]\d{7}|1\d{9,10} + \d{7,11} + + + [2-7][2-7]\d{6} + \d{7,8} + 22123456 + + + [89]\d{7} + \d{8} + 99123456 + + + 1800\d{6,7} + \d{10,11} + 18001234567 + + + - [34679]| + [3679]| + 4[3-8]| 5(?: [0-2]| 5[0-478]| @@ -4135,7 +4360,8 @@ ) - [34679]| + [3679]| + 4[3-8]| 5(?: [02]| 1(?: @@ -4151,13 +4377,18 @@ $1 $2 + + 70 + $1 $2 $3 + 800 8000 $1 $2 $3 - + + 40| 5| 8(?: 00| @@ -4165,6 +4396,7 @@ ) + 40| 5| 8(?: 00[1-9]| @@ -4181,17 +4413,26 @@ \d{6,10} + + 800[2-9]\d{3} + \d{7} + 8002123 + + (?: 3[23589]| - 4[3-8]| + 4(?: + 0\d| + [3-8] + )| 6\d| 7[1-9]| 88 )\d{5} - \d{7} + \d{7,8} 3212345 @@ -4233,10 +4474,17 @@ 9001234 - 70\d{5} - \d{7} - 7012345 + + 70[0-2]?\d{5} + \d{7,8} + 70012345 + + 1[1-9]\d + \d{3} + 112 + @@ -4673,7 +4921,69 @@ - + + + + [2-9]\d{5} + \d{6} + + + + (?: + 20| + [3-4]\d| + 8[19] + )\d{4} + + 201234 + + + + (?: + 2[1-9]| + 5\d| + 7[1-79] + )\d{4} + + 211234 + + + 80[257-9]\d{3} + 802123 + + + + 90(?: + [1345][15-7]| + 2[125-7]| + 99 + )\d{2} + + 901123 + + + + (?: + 6[0-36]| + 88 + )\d{4} + + 601234 + + + + + 1(?: + 1[248]| + 4[124]\d| + 71\d| + 8[7-9]\d + ) + + \d{3,4} + 211234 + @@ -4940,31 +5250,324 @@ \d{7,10} \d{4,10} - + + + + 2\d[2-9]\d{7}| + 1(?: + 1\d| + \d1 + )[2-9]\d{6}| + 1(?: + [248][02-9]\d[2-9]\d{4,5}| + (?: + 3(?: + [02-79]\d| + 8[0-69] + )| + 5(?: + [04-9]\d| + 2[0-35-9]| + 3[0-8] + )| + 6(?: + [02-8]\d| + 9[0-689] + )| + 7(?: + [02-5789]\d| + 6[0-79] + )| + 9(?: + [0235-9]\d| + 4[0-5789] + ) + )[2-9]\d{4,5}| + (?: + 387(?: + 3[2-9]| + [24-9]\d + )| + 5(?: + 24(?: + 2[2-9]| + [3-9]\d + )| + 39(?: + [4-6][2-9]| + [237-9]\d + ) + )| + 697(?: + [347][2-9]| + [25689]\d + )| + 768(?: + [347][2-9]| + [25679]\d + )| + 946(?: + 7[2-9]| + [2-689]\d + ) + )\d{3,4} + ) + + \d{9,10} + 1332456789 + + - - 1(?:1[3-8]|[2-69]1)\d{7}| - 1(?:2(?:0[024-9]|2[3-9]|3[3-79]|4[1-689]|[58][02-9]|6[0-4789]|7[013-9]|9\d)| - 3(?:0\d|[25][02-9]|3[02-579]|[468][0-46-9]|7[1235679]|9[24578])| - 4(?:0[03-9]|2[02-5789]|[37]\d|4[02-69]|5[0-8]|[69][0-79]|8[02-5789])| - 5(?:0[1235-9]|2[024-9]|3[015689]|4[02-9]|5[03-9]|6\d|7[0-35-9]|8[0-468]|9[0-5789])| - 6(?:0[034689]|2[0-35689]|3[013-9]|4[1-467]|5[0-69]|6[13-9]|7[0-8]|8[013-9]|9[0124578])| - 7(?:0[0246-9]|2\d|3[023678]|4[03-9]|5[0-46-9]|6[013-9]|7[0-35-9]|8[024-9]|9[02-9])| - 8(?:0[35-9]|2[1-5789]|3[02-578]|4[0-578]|5[124-9]|6[2-69]|7\d|8[02-9]|9[02569])| - 9(?:0[02-589]|2[02-689]|3[1-5789]|4[2-9]|5[0-579]|6[234789]|7[0124578]|8\d|9[2-57]))\d{6}| - 1(?:2(?:0(?:46[1-4]|87[2-9])|545[1-79]|76(?:2\d|3[1-8]|6[1-6])|9(?:7(?:2[0-4]|3[2-5])|8(?:2[2-8]|7[0-4789]|8[345])))| - 3(?:638[2-5]|647[23]|8(?:47[04-9]|64[015789]))| - 4(?:044[1-7]|20(?:2[23]|8\d)|6(?:0(?:30|5[2-57]|6[1-8]|7[2-8])|140)|8(?:052|87[123]))| - 5(?:24(?:3[2-79]|6\d)|276\d|6(?:26[06-9]|686))| - 6(?:06(?:4\d|7[4-79])|295[567]|35[34]\d|47(?:24|61)|59(?:5[08]|6[67]|74)|955[0-4])| - 7(?:26(?:6[13-9]|7[0-7])|442\d|50(?:2[0-3]|[3-68]2|76))| - 8(?:27[56]\d|37(?:5[2-5]|8[239])|84(?:3[2-58]))| - 9(?:0(?:0(?:6[1-8]|85)|52\d)|3583|4(?:66[1-8]|9(?:2[01]|81))|63(?:23|3[1-4])|9561))\d{3}| + + + 2(?: + 0[01378]| + 3[0189]| + 4[017]| + 8[0-46-9]| + 9[012] + )\d{7}| + 1(?: + (?:1 + (?:3[0-48]| + [46][0-4]| + 5[012789]| + 7[0-39]| + 8[01349] + )| + 21[0-7]| + 31[0-8]| + [459]1\d| + 61[01246-9] + ) + )\d{6}| + 1(?: + 2(?: + 0[024-9]| + 2[3-9]| + 3[3-79]| + 4[1-689]| + [58][02-9]| + 6[0-4789]| + 7[013-9]| + 9\d + )| + 3(?: + 0\d| + [25][02-9]| + 3[02-579]| + [468][0-46-9]| + 7[1235679]| + 9[24578] + )| + 4(?: + 0[03-9]| + [28][02-5789]| + [37]\d| + 4[02-69]| + 5[0-8]| + [69][0-79] + )| + 5(?: + 0[1235-9]| + 2[024-9]| + 3[015689]| + 4[02-9]| + 5[03-9]| + 6\d| + 7[0-35-9]| + 8[0-468]| + 9[0-5789] + )| + 6(?: + 0[034689]| + 2[0-35689]| + [38][013-9]| + 4[1-467]| + 5[0-69]| + 6[13-9]| + 7[0-8]| + 9[0124578] + )| + 7(?: + 0[0246-9]| + 2\d| + 3[023678]| + 4[03-9]| + 5[0-46-9]| + 6[013-9]| + 7[0-35-9]| + 8[024-9]| + 9[02-9] + )| + 8(?: + 0[35-9]| + 2[1-5789]| + 3[02-578]| + 4[0-578]| + 5[124-9]| + 6[2-69]| + 7\d| + 8[02-9]| + 9[02569] + )| + 9(?: + 0[02-589]| + 2[02-689]| + 3[1-5789]| + 4[2-9]| + 5[0-579]| + 6[234789]| + 7[0124578]| + 8\d| + 9[2-57] + ) + )\d{6}| + 1(?: + 2(?: + 0(?: + 46[1-4]| + 87[2-9] + )| + 545[1-79]| + 76(?: + 2\d| + 3[1-8]| + 6[1-6] + )| + 9(?: + 7(?: + 2[0-4]| + 3[2-5] + )| + 8(?: + 2[2-8]| + 7[0-4789]| + 8[345] + ) + ) + )| + 3(?: + 638[2-5]| + 647[23]| + 8(?: + 47[04-9]| + 64[015789] + ) + )| + 4(?: + 044[1-7]| + 20(?: + 2[23]| + 8\d + )| + 6(?: + 0(?: + 30| + 5[2-57]| + 6[1-8]| + 7[2-8] + )| + 140 + )| + 8(?: + 052| + 87[123] + ) + )| + 5(?: + 24(?: + 3[2-79]| + 6\d + )| + 276\d| + 6(?: + 26[06-9]| + 686 + ) + )| + 6(?: + 06(?: + 4\d| + 7[4-79] + )| + 295[567]| + 35[34]\d| + 47(?: + 24| + 61 + )| + 59(?: + 5[08]| + 6[67]| + 74 + )| + 955[0-4] + )| + 7(?: + 26(?: + 6[13-9]| + 7[0-7] + )| + 442\d| + 50(?: + 2[0-3]| + [3-68]2| + 76 + ) + )| + 8(?: + 27[56]\d| + 37(?: + 5[2-5]| + 8[239] + )| + 84(?: + 3[2-58] + ) + )| + 9(?: + 0(?: + 0(?: + 6[1-8]| + 85 + )| + 52\d + )| + 3583| + 4(?: + 66[1-8]| + 9(?: + 2[01]| + 81 + ) + )| + 63(?: + 23| + 3[1-4] + )| + 9561 + ) + )\d{3}| 176888[234678]\d{2}| 16977[23]\d{3}| - 2(?:0[01378]|3[0189]|4[017]|8[0-46-9]|9[012])\d{7}| - (?:3[0347]|55)\d{8} + (?: + 3[0347]| + 55 + )\d{8} + 1212345678 @@ -5075,6 +5678,16 @@ \d{10} 5612345678 + + + (?: + 3[0347]| + 55 + )\d{8} + + \d{10} + 5512345678 + @@ -5407,6 +6020,71 @@ + + + [2568]\d{7} + \d{8} + + + + 2(?: + 00\d| + 16[0-7]| + 22[2457] + )\d{4} + + 20012345 + + + + (?: + 5[4-8]| + 60 + )\d{6} + + 57123456 + + + 80\d{6} + 80123456 + + + 8[1-689]\d{6} + 88123456 + + + 87\d{6} + 87123456 + + + + 1(?: + 00| + 1(?: + 2| + 6(?: + 00[06]| + 11[17] + )| + 8\d{2} + )| + 23| + 4(?: + 1| + 7[014] + )| + 5[015]| + 9[0349] + )| + 8(?: + 00| + 4[0-2]| + 8\d + ) + + \d{3,6} + 116123 + @@ -5530,7 +6208,7 @@ 3[3467]| 5[2457-9] )| - [2457]\d{2}| + [24578]\d{2}| 3(?: [14]0| 35 @@ -5922,8 +6600,67 @@ - + + + + + + $1-$2 + + + + [237-9]\d{7} + \d{8} + + + + 2(?: + 2(?: + 0[019]| + 1[1-36]| + [23]\d| + 4[056]| + 5[57]| + 9[01] + )| + 4(?: + 2|3-59]| + 3[13-689]| + 4[0-68]| + 5[1-35] + )| + 5(?: + 4[3-5]| + 5\d| + 6[56]| + 74 + )| + 6(?: + 4[0-378]| + [56]\d| + [78][0-8]| + 9[01] + )| + 7(?: + 6[46-9]| + 7[02-9]| + 8[34] + )| + 8(?: + 79| + 8[0-35789]| + 9[1-57-9] + ) + )\d{4} + + 22123456 + + + [37-9]\d{7} + 91234567 + @@ -6028,8 +6765,58 @@ - + + + + + + $1 $2 $3 + + + + [2-489]\d{7} + \d{8} + + + + + 2(?: + [24]\d| + 5[1-5]| + 94 + )\d{5} + + 22453300 + + + + (?: + 3[4-9]| + 4\d + )\d{6} + + 34101234 + + + + 8\d{7} + \d{8} + 80012345 + + + + 98[89]\d{5} + \d{8} + 98901234 + + + 1\d{2} + \d{3} + 114 + @@ -6079,8 +6866,8 @@ (?: - [237]0| - 31 + [27]0| + 3[01] )\d{7} \d{9} @@ -6285,7 +7072,7 @@ $1 $2 $3 + pattern="([78]\d)(\d{3,4})(\d{4})"> 76| 8[35-9] @@ -6330,46 +7117,51 @@ technically they are numbers for the UK. --> 1\d{7,8}| - (?: - 2[24-9]| - 4(?: - 0[24]| - 7 - )| - 5(?: - 0[45]| - 8 - )| - 6[237-9]| - 9[3-9] - )\d{5}| - (?: - 45| - [569]1| - 818 - )\d{6}| - (?: - 4[12469]| - 5[3679]| - 6[56]| - 7[14]| - 9[04] - )\d{7}| - 21\d{6,7}| - (?: - 23| - 4[34]| - 52| - 64 - )\d{5,7}| - 48\d{8} + 2(?: + 1\d{6,7}| + [24-9]\d{5}| + 3\d{5,7} + )| + 4(?: + 0[24]\d{5}| + [1269]\d{7}| + [34]\d{5,7}| + 5\d{6}| + 7\d{5}| + 8[0-46-9]\d{7} + )| + 5(?: + 0[45]\d{5}| + 1\d{6}| + 2\d{5,7}| + [3679]\d{7}| + 8\d{5} + )| + 6(?: + 1\d{6}| + 4\d{5,7}| + [237-9]\d{5}| + [56]\d{7} + )| + 7[14]\d{7}| + 818\d{6}| + 9(?: + 1\d{6}| + [04]\d{7}| + [3-9]\d{5} + ) \d{5,10} 2212345 - 8[35-9]\d{7} - \d{9} + + 8(?: + 22\d{6}| + [35-9]\d{7,8} + ) + + \d{9,10} 850123456 @@ -7559,15 +8351,17 @@ - + - [2356] + pattern="(\d)(\d{3})(\d{4})"> + + [2356] + $1 $2 $3 @@ -7584,23 +8378,20 @@ [235-9]\d{7,8} - \d{7,9} + \d{8,9} + [2356][2-8]\d{6} \d{7,8} - 62345678 + 62001234 - 7(?: - 4[5-7]| - 55| - 7[5-79]| - 8[5-8]| - 9[05-9] + [1-8]\d| + 9[02-9] )\d{6} \d{9} @@ -7612,16 +8403,21 @@ 80012345 - 90\d{6} + 900\d{5} \d{8} 90012345 - (?: - 8[57]\d| - 810 - )\d{5} + 8(?: + 10\d| + 5\d{2}| + 7(?: + [02]0| + 7[08]| + 9[09] + ) + )\d{4} \d{8} 85012345 @@ -7635,6 +8431,7 @@ + @@ -8411,15 +9208,43 @@ (?: - 1[1-9][1-9]| - 9(?: - [3-9][1-9]| - 2\d + 1(?: + 2[3-6]| + 3[3-9]| + 4[2-6]| + [58][2-8]| + 6[2-7]| + 7[2-9]| + 9[1-578] )| - (?: - [36][1-9]| - [24578][2-9] - )\d + 2[2-9]\d| + [36][1-9]\d| + 4(?: + 6[0235-8]| + [2-578]\d| + 9[2-59] + )| + 5(?: + 6[1-9]| + 7[2-8]| + [2-589]\d + )| + 7(?: + 3[4-9]| + 4[02-9]| + [25-9]\d + )| + 8(?: + 3[2-9]| + 4[5-9]| + 5[1-9]| + 8[03-9]| + [2679]\d + )| + 9(?: + [679][1-9]| + [2-58]\d + ) )\d{6} \d{9} @@ -9376,16 +10201,23 @@ - - [13-6] - $1 $2 $3 - - - [7-9][01] + + + [13-6]| + 7(?: + [2-57-9]| + 62)| + [89][2-9] + $1 $2 $3 - - [7-9][2-9] + + + [89][01]| + 7(?: + [01]| + 66) + $1 $2 $3 @@ -9396,22 +10228,23 @@ (?: - [14-6]\d| - [7-9][2-9] - )\d{5} + [14-6]\d{2}| + 7(?: + [2-57-9]\d| + 62)| + [89][2-9]\d + )\d{4} \d{7} 1123456 - (?: 3\d| 7(?: - 0\d| - 1[167] + [01]\d| + 66 ) )\d{5} @@ -9625,8 +10458,42 @@ + + + nationalPrefix="0" nationalPrefixFormattingRule="$NP$FG"> + + + [1-689] + $1 $2 $3 + + + 7 + $1 $2 $3 + + + + [1-9]\d{8} + \d{7,9} + + + + (?: + [189]1| + 2[13-7]| + 3[1-8]| + 4[157]| + 5[12457]| + 6[35-7] + )[2-57]\d{6} + + 112345678 + + + 7[12578]\d{7} + \d{9} + 712345678 + @@ -9636,8 +10503,8 @@ - - [27] + + [279] $1 $2 $3 @@ -9648,7 +10515,7 @@ (?: - [27]\d| + [279]\d| [4-6] )\d{6} @@ -9665,12 +10532,18 @@ (?: 4[67]| 5\d| - 7\d{2}| - 6[4-8] + 6[4-8]| + 7\d{2} )\d{5} 4612345 + + + 90\d{6} + \d{8} + 90123456 + @@ -9878,11 +10751,12 @@ 5(?: 2(?: - [015-7]\d{2}| (?: - [28][2-9]| - 3[2-7]| - 4[2-8] + [015-7]\d| + 2[2-9]| + 3[2-57]| + 4[2-8]| + 8[235-9]| )\d| 9(?: 0\d| @@ -9890,10 +10764,10 @@ ) )| 3(?: - [0-4]\d{2}| (?: + [0-4]\d| [57][2-9]| - 6[2-8]| + 6[235-8]| 9[3-9] )\d| 8(?: @@ -9908,10 +10782,10 @@ 6(?: - 00| + 0[06]| + [14-7]\d| + 2[236]| 33| - [15-7]\d| - 4[0-8]| 99 )\d{6} @@ -10124,16 +10998,32 @@ (?: - 2\d| - 3[1-4]| - 4[2-8] - )\d{6} + 2(?: + [23]\d| + 5[125]| + 61 + )| + 3(?: + 1[3-6]| + 2[2-6]| + 3[2-5]| + 4[235] + )| + 4(?: + [23][2-6]| + 4[3-6]| + 5[25]| + 6[25-8]| + 7[24-6]| + 8[4-6] + ) + )\d{5} \d{6,8} 22212345 - 7\d{7} + 7[0-25-8]\d{6} 72345678 @@ -10286,18 +11176,15 @@ - - - [12]1| - [7-9] - + + [12]1 $1 $2 $3 - + [12]2[1-3] $1 $2 - + [12](?: 27| @@ -10312,7 +11199,14 @@ $1 $2 - + + + [57-9] + $1 $2 + + [12](?: 27| @@ -10329,37 +11223,54 @@ - [127-9]\d{7} - \d{8} + + [12]\d{7,9}| + [57-9]\d{7} + + \d{8,10} + code, and could be 1 to 4 digits long. We also cover wireless local loop numbers here + as well, even though we are not certain whether they are in fact fixed or mobile in + this country. 5-digit subscriber numbers for 4-digit area codes have been added due to + online numbers being found. --> - (?: - [12](?: - 1\d| - 2[1-37]| - 3[2-8]| - 4[2-68]| - 5[1-4689] + [12](?: + 1\d| + 2(?: + [1-3]\d?| + 7\d )| + 3[2-8]\d{1,2}| + 4[2-68]\d{1,2}| + 5[1-4689]\d{1,2} + )\d{5}| + (?: + 5[0568]| 70 )\d{6} 70123456 + (?: - 88| - 9[1569] + 8[89]| + 9[15689] )\d{6} + \d{8} 88123456 + + 7[569]\d{6} + \d{8} + 75123456 + @@ -10470,15 +11381,26 @@ + + + [2-48] + $1 $2 $3 $4 + + [2-7] $1 $2 $3 - [2-7]\d{6} - \d{7} + + [2-4]\d{6,7}| + [5-7]\d{6}| + 8\d{7} + + \d{7,8} @@ -10490,9 +11412,10 @@ 5[02-467]| 6[39]| 7[4-69] - )\d{4} + )\d{4}| + [2-4]5\d{6} - 5131234 + 35123456 @@ -10501,10 +11424,20 @@ 4[3-5]| 6\d| 7[0-7] - )\d{5} + )\d{5}| + (?: + 2[27]| + 3[367]| + 4[467] + )\d{6} - 3123456 + 22123456 + + 800\d{5} + \d{8} + 80012345 + @@ -10546,8 +11479,68 @@ - + + + + + + $1 $2 + + + + [2579]\d{7} + \d{8} + + + + 2(?: + 0(?: + 1[0-6]| + [69]\d + )| + [1-357]\d{2} + )\d{4} + + 21001234 + + + + (?: + 7(?: + 210| + [79]\d{2}| + )| + 9(?: + 2[13]\d| + 696| + 8(?: + 1[1-3]| + 89| + 97 + )| + 9\d{2} + ) + )\d{4} + + 96961234 + + + 7117\d{4} + 71171234 + + + + 50(?: + 0(?: + 3[1679]| + 4\d + )| + [169]\d{2}| + 7[06]\d + )\d{3} + + 50031234 + @@ -10619,8 +11612,62 @@ - + + + + + + $1-$2 + + + + [3679]\d{6} + \d{7} + + + + + (?: + 3(?: + 00| + 3[0-59]| + )| + 6(?: + [567][02468]| + 8[024689] + ) + )\d{4} + + 6701234 + + + + (?: + 7(?: + [679]\d| + 8[02-9] + )| + 9[6-9]\d + )\d{4} + + 7712345 + + + 781\d{4} + 7812345 + + + + 1(?: + [19]0| + 23 + ) + + \d{3} + 123 + @@ -11074,130 +12121,159 @@ - - - - 8[15] - $1 $2 $3 - - - - 632 - 6325 - 63253 - 632532 - $1 $2 - - - - 6(?: - 1| - [245][1-7]| - 3[125-7]| - 6[1256]| - 7[1236] - ) - - $1 $2 $3 - - - - - 6(?: - 3[12567]| - 5[3-5]| - 6[1256]| - 7[1236] - ) - - $1 $2 - - - 6[2356]8 - $1 $2 + + + + 8[125] + $1 $2 $3 - - - 6(?: - 34| - 6[34]| - 75 - ) - - - 6(?: - 342| - 6[34]| - 751 - ) - - $1 $2 + + 6 + $1 $2 $3 88 $1 $2 $3 + + 870 + $1 $2 $3 + - [68]\d{5,9} - \d{4,10} + [68]\d{7,8} + \d{8,9} + 6(?: 1(?: - [136]| - 2\d? - )\d| + 17| + 2(?: + [0189]\d| + [23-6]| + 7\d? + )| + 3(?: + 2\d| + 3[378] + )| + 4[01]| + 69| + 7[014] + )| 2(?: - [25]\d? | - [134678] - )\d| + 17| + 25| + 5(?: + [0-36-8]| + 4\d? + )| + 69| + 70 + )| 3(?: - 2\d{0,3}| - 4\d{1,2}| - [135-8]\d? + 17| + 2(?: + [0237]\d?| + [14-689] + )| + 34| + 6[29]| + 7[01]| + 81 )| 4(?: - [13-8]\d| - 2\d{1,2} - )| - (?: + 17| + 2(?: + [012]| + 7? + )| + 4(?: + [06]| + 1\d + )| 5(?: - [16-7]\d| - [3-58]\d? | - 2\d{1,2} - ) + [01357]| + [25]\d? + )| + 69| + 7[01] + )| + 5(?: + 17| + 2(?: + [0459]| + [23678]\d? + )| + 69| + 7[01] )| - 6\d{0,4}| - 7\d{0,3} + 6(?: + 17| + 2(?: + 5| + 6\d? + )| + 38| + 42| + 69| + 7[01] + )| + 7(?: + 17| + 2(?: + [569]| + [234]\d? + )| + 3(?: + 0\d?| + [13] + )| + 69| + 7[01] + ) )\d{4} 612012345 - + - 8(?: - 1(?: - 1[0-24]| - [2-4]\d| - 50| - 6[0-2] - )| - 5\d{2} - )\d{5} + (?: + 60| + 8[125] + )\d{7} \d{9} - 811012345 + 811234567 + + 8701\d{5} + \d{9} + 870123456 + - 88\d{6} + 886\d{5} \d{8} - 88123456 + 88612345 + + + 1(?: + 0111| + \d{3} + )| + 9(?: + 3111| + \d{2} + ) + + \d{3,5} + 93111 + @@ -11609,8 +12685,22 @@ - + + + + + [1-5]\d{3} + \d{4} + + + + [34]\d{3} + 4002 + + + [125]\d{3} + 1234 + @@ -11872,7 +12962,7 @@ 68| 7(?: [126]\d| - 3[34689] + 3[1-9] ) )\d{5} @@ -11885,6 +12975,7 @@ 1801234 + 275\d{4} \d{7} 2751234 @@ -12485,8 +13576,80 @@ + + + + + nationalPrefix="0" nationalPrefixFormattingRule="$NP$FG"> + + + [2489] + $1 $2 $3 + + + 5 + $1 $2 $3 + + + 1[78] + $1 $2 $3 + + + + + + (?: + [24589]\d{7,9}| + 1(?: + [78]\d{8}| + [49]\d{2,3} + ) + ) + + \d{4,10} + + + + (?: + 22[2379]| + 42[45]| + 82[01458]| + 92[369] + )\d{5} + + \d{7,8} + 22234567 + + + 5[69]\d{7} + \d{9} + 599123456 + + + 1800\d{6} + \d{10} + 1800123456 + + + + + 1(?: + 4| + 9\d + )\d{2} + + \d{4,5} + 19123 + + + 1700\d{6} + \d{10} + 1700123456 + @@ -12966,12 +14129,20 @@ preferredInternationalPrefix="00"> + + [23578]| + [46][0-35-9] + $1 $2 + + [46]4 + $1 $2 $3 + - [2-8]\d{5} - \d{6} + [2-8]\d{5,6} + \d{6,7} + + (?: + 4?4[1-3]| + 6?47 + )\d{4} + + 4410123 + + nationalPrefix="0" nationalPrefixFormattingRule="$NP$FG"> + + + $1 $2 $3 + + + + [19]\d{8} + \d{9} + + + + + 1(?: + [25]\d| + 8[3567] + )\d{6} + + 121231234 + + + 9[1259]\d{7} + 911231234 + @@ -13264,22 +14468,40 @@ 1[89] $1 $2 $3 + + 70 + $1 $2 $3 + 80 $1 $2 $3 - [13689]\d{7,10} + + + [36]\d{7}| + [17-9]\d{7,10} + \d{8,11} - [36]\d{7} - \d{8} - 31234567 + + + 6[1-8]\d{6}| + 7000\d{7} + + \d{8,11} + 61234567 - [89]\d{7} + + (?: + 8[1-5]| + 9[0-8] + )\d{6} + \d{8} 81234567 @@ -13293,6 +14515,34 @@ \d{11} 19001234567 + + 3[0-2]\d{6} + \d{8} + 31234567 + + + + 7000\d{7} + \d{11} + 70001234567 + + + + 1(?: + [0136]\d{2}| + 41\d| + [89](?: + [1-9]\d| + 0[1-9] + )| + [57]\d{2,3})| + 99\d + + \d{3,5} + 1312 + @@ -13583,7 +14833,7 @@ - [19] + 15|9 $1 $2 @@ -13712,14 +14962,19 @@ $1 $2 - 7 + [027] $1 $2 - [2-7]\d{6,7} + [02-7]\d{6,7} \d{7,8} + + 0800\d{4} + \d{8} + 08001234 + @@ -13759,11 +15014,16 @@ (?: 6| - 7[67] + 7[6-8] )\d{6} 76123456 + + 0800\d{4} + \d{8} + 08001234 + @@ -15260,10 +16520,11 @@ 9 $1 $2 $3 $4 - + 1(?: [26]| + 88| 99 ) @@ -15271,12 +16532,7 @@ - - 1(?: - 8| - 90 - ) - + 1[89]0 $1 $2 @@ -15320,14 +16576,13 @@ 2101234567 - (?: 9\d| 1(?: - 2[1-35-9]| + 2\d| 6[3-9]| + 88| 99 ) )\d{7} @@ -15489,7 +16744,18 @@ + + 860 + $1 $2 $3 + + + [1-57]| + 8(?: + [0-57-9]| + 6[1-9] + ) + $1 $2 $3 @@ -15526,10 +16792,15 @@ 801234567 - 86\d{7} + 86[1-9]\d{6} \d{9} 861234567 + + 860\d{6} + \d{9} + 860123456 + 87\d{7} \d{9} @@ -15804,18 +17075,12 @@ 9[2-8] )\d{4,7} - \d{3,10} 1312345 - - (?: - [19]1| - 7[13] - )\d{6,7} - - \d{8,9} - 911234567 + 7[137]\d{7} + \d{9} + 711234567 diff --git a/java/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java b/java/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java index 4a176ce..5aae184 100644 --- a/java/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java +++ b/java/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java @@ -169,7 +169,10 @@ public class PhoneNumberUtil { aSet.add(227); // Niger aSet.add(228); // Togo aSet.add(241); // Gabon + aSet.add(242); // Congo (Rep. of the) + aSet.add(268); // Swaziland aSet.add(379); // Vatican City + aSet.add(501); // Belize LEADING_ZERO_COUNTRIES = Collections.unmodifiableSet(aSet); } @@ -187,7 +190,7 @@ public class PhoneNumberUtil { // This consists of dash characters, white space characters, full stops, slashes, // square brackets, parentheses and tildes. It also includes the letter 'x' as that is found as a // placeholder for carrier information in some phone numbers. - private static final String VALID_PUNCTUATION = "-x\u2010-\u2015\u2212\uFF0D-\uFF0F " + + private static final String VALID_PUNCTUATION = "-x\u2010-\u2015\u2212\u30FC\uFF0D-\uFF0F " + "\u00A0\u200B\u2060\u3000()\uFF08\uFF09\uFF3B\uFF3D.\\[\\]/~\u2053\u223C\uFF5E"; // Digits accepted in phone numbers @@ -255,7 +258,7 @@ public class PhoneNumberUtil { // the extension is written with a hash at the end, such as "- 503#". // Note that the only capturing groups should be around the digits that you want to capture as // part of the extension, or else parsing will fail! - private static final String KNOWN_EXTN_PATTERNS = "[ \u00A0\\t,]*(?:ext(?:ensio)?n?|" + + private static final String KNOWN_EXTN_PATTERNS = "[ \u00A0\\t,]*(?:ext(?:ensi[o\u00F3])?n?|" + "\uFF45\uFF58\uFF54\uFF4E?|[,x\uFF58#\uFF03~\uFF5E]|int|anexo|\uFF49\uFF4E\uFF54)" + "[:\\.\uFF0E]?[ \u00A0\\t,-]*([" + VALID_DIGITS + "]{1,7})#?|[- ]+([" + VALID_DIGITS + "]{1,5})#"; @@ -264,13 +267,13 @@ public class PhoneNumberUtil { // digits, for use when parsing. private static final Pattern EXTN_PATTERN = Pattern.compile("(?:" + KNOWN_EXTN_PATTERNS + ")$", - Pattern.UNICODE_CASE | Pattern.CASE_INSENSITIVE); + Pattern.CANON_EQ | Pattern.UNICODE_CASE | Pattern.CASE_INSENSITIVE); // We append optionally the extension pattern to the end here, as a valid phone number may // have an extension prefix appended, followed by 1 or more digits. private static final Pattern VALID_PHONE_NUMBER_PATTERN = Pattern.compile(VALID_PHONE_NUMBER + "(?:" + KNOWN_EXTN_PATTERNS + ")?", - Pattern.UNICODE_CASE | Pattern.CASE_INSENSITIVE); + Pattern.CANON_EQ | Pattern.UNICODE_CASE | Pattern.CASE_INSENSITIVE); private static final Pattern NON_DIGITS_PATTERN = Pattern.compile("(\\D+)"); private static final Pattern FIRST_GROUP_PATTERN = Pattern.compile("(\\$1)"); @@ -533,9 +536,7 @@ public class PhoneNumberUtil { return 0; } PhoneMetadata metadata = getMetadataForRegion(regionCode); - // For NANPA countries, national prefix is the same as country code, but it is not stored in - // the metadata. - if (!metadata.hasNationalPrefix() && !isNANPACountry(regionCode)) { + if (!metadata.hasNationalPrefix()) { return 0; } @@ -546,6 +547,39 @@ public class PhoneNumberUtil { return 0; } + return getLengthOfNationalDestinationCode(number); + } + + /** + * Gets the length of the national destination code (NDC) from the PhoneNumber object passed in, + * so that clients could use it to split a national significant number into NDC and subscriber + * number. The NDC of a phone number is normally the first group of digit(s) right after the + * country code when the number is formatted in the international format, if there is a subscriber + * number part that follows. An example of how this could be used: + * + * PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance(); + * PhoneNumber number = phoneUtil.parse("18002530000", "US"); + * String nationalSignificantNumber = PhoneNumberUtil.getNationalSignificantNumber(number); + * String nationalDestinationCode; + * String subscriberNumber; + * + * int nationalDestinationCodeLength = phoneUtil.getLengthOfNationalDestinationCode(number); + * if (nationalDestinationCodeLength > 0) { + * nationalDestinationCode = nationalSignificantNumber.substring(0, + * nationalDestinationCodeLength); + * subscriberNumber = nationalSignificantNumber.substring(nationalDestinationCodeLength); + * } else { + * nationalDestinationCode = ""; + * subscriberNumber = nationalSignificantNumber; + * } + * + * Refer to the unittests to see the difference between this function and + * getLengthOfGeographicalAreaCode(). + * + * @param number the PhoneNumber object for which clients want to know the length of the NDC. + * @return the length of NDC of the PhoneNumber object passed in. + */ + public int getLengthOfNationalDestinationCode(PhoneNumber number) { PhoneNumber copiedProto; if (number.hasExtension()) { // We don't want to alter the proto given to us, but we don't want to include the extension @@ -566,6 +600,17 @@ public class PhoneNumberUtil { if (numberGroups.length <= 3) { return 0; } + + if (getRegionCodeForNumber(number).equals("AR") && + getNumberType(number) == PhoneNumberType.MOBILE) { + // Argentinian mobile numbers, when formatted in the international format, are in the form of + // +54 9 NDC XXXX.... As a result, we take the length of the third group (NDC) and add 1 for + // the digit 9, which also forms part of the national significant number. + // + // TODO: Investigate the possibility of better modeling the metadata to make it + // easier to obtain the NDC. + return numberGroups[3].length() + 1; + } return numberGroups[2].length(); } @@ -1165,8 +1210,7 @@ public class PhoneNumberUtil { */ public boolean isValidNumber(PhoneNumber number) { String regionCode = getRegionCodeForNumber(number); - return isValidRegionCode(regionCode) - && isValidNumberForRegion(number, regionCode); + return (isValidRegionCode(regionCode) && isValidNumberForRegion(number, regionCode)); } /** @@ -1604,12 +1648,12 @@ public class PhoneNumberUtil { * the resulting number, and indicates if an international prefix was present. * * @param number the non-normalized telephone number that we wish to strip any international - * dialing prefix from + * dialing prefix from. * @param possibleIddPrefix the international direct dialing prefix from the country we * think this number may be dialed in * @return the corresponding CountryCodeSource if an international dialing prefix could be * removed from the number, otherwise CountryCodeSource.FROM_DEFAULT_COUNTRY if the - * number did not seem to be in international format + * number did not seem to be in international format. */ CountryCodeSource maybeStripInternationalPrefixAndNormalize( StringBuffer number, @@ -1713,6 +1757,21 @@ public class PhoneNumberUtil { } /** + * Checks to see that the region code used is valid, or if it is not valid, that the number to + * parse starts with a + symbol so that we can attempt to infer the country from the number. + * Returns false if it cannot use the region provided and the region cannot be inferred. + */ + private boolean checkRegionForParsing(String numberToParse, String defaultCountry) { + if (!isValidRegionCode(defaultCountry)) { + if (numberToParse != null && !numberToParse.isEmpty() && + !PLUS_CHARS_PATTERN.matcher(numberToParse).lookingAt()) { + return false; + } + } + return true; + } + + /** * Parses a string and returns it in proto buffer format. This method will throw a * NumberParseException exception if the number is not considered to be a possible number. Note * that validation of whether the number is actually a valid number for a particular @@ -1743,13 +1802,7 @@ public class PhoneNumberUtil { // decrease object creation when invoked many times. public void parse(String numberToParse, String defaultCountry, PhoneNumber phoneNumber) throws NumberParseException { - if (!isValidRegionCode(defaultCountry)) { - if (numberToParse.length() > 0 && numberToParse.charAt(0) != PLUS_SIGN) { - throw new NumberParseException(NumberParseException.ErrorType.INVALID_COUNTRY_CODE, - "Missing or invalid default country."); - } - } - parseHelper(numberToParse, defaultCountry, false, phoneNumber); + parseHelper(numberToParse, defaultCountry, false, true, phoneNumber); } /** @@ -1780,23 +1833,22 @@ public class PhoneNumberUtil { public void parseAndKeepRawInput(String numberToParse, String defaultCountry, PhoneNumber phoneNumber) throws NumberParseException { - if (!isValidRegionCode(defaultCountry)) { - if (numberToParse.length() > 0 && numberToParse.charAt(0) != PLUS_SIGN) { - throw new NumberParseException(NumberParseException.ErrorType.INVALID_COUNTRY_CODE, - "Missing or invalid default country."); - } - } - parseHelper(numberToParse, defaultCountry, true, phoneNumber); + parseHelper(numberToParse, defaultCountry, true, true, phoneNumber); } /** * Parses a string and fills up the phoneNumber. This method is the same as the public * parse() method, with the exception that it allows the default country to be null, for use by - * isNumberMatch(). + * isNumberMatch(). checkRegion should be set to false if it is permitted for the default country + * to be null or unknown ("ZZ"). */ - private void parseHelper(String numberToParse, String defaultCountry, - boolean keepRawInput, PhoneNumber phoneNumber) + private void parseHelper(String numberToParse, String defaultCountry, boolean keepRawInput, + boolean checkRegion, PhoneNumber phoneNumber) throws NumberParseException { + if (numberToParse == null) { + throw new NumberParseException(NumberParseException.ErrorType.NOT_A_NUMBER, + "The phone number supplied was null."); + } // Extract a possible number from the string passed in (this strips leading characters that // could not be the start of a phone number.) String number = extractPossibleNumber(numberToParse); @@ -1805,6 +1857,13 @@ public class PhoneNumberUtil { "The string supplied did not seem to be a phone number."); } + // Check the country supplied is valid, or that the extracted number starts with some sort of + + // sign so the number's region can be determined. + if (checkRegion && !checkRegionForParsing(number, defaultCountry)) { + throw new NumberParseException(NumberParseException.ErrorType.INVALID_COUNTRY_CODE, + "Missing or invalid default country."); + } + if (keepRawInput) { phoneNumber.setRawInput(numberToParse); } @@ -1969,9 +2028,9 @@ public class PhoneNumberUtil { public MatchType isNumberMatch(String firstNumber, String secondNumber) throws NumberParseException { PhoneNumber number1 = new PhoneNumber(); - parseHelper(firstNumber, null, false, number1); + parseHelper(firstNumber, null, false, false, number1); PhoneNumber number2 = new PhoneNumber(); - parseHelper(secondNumber, null, false, number2); + parseHelper(secondNumber, null, false, false, number2); return isNumberMatch(number1, number2); } @@ -1990,7 +2049,7 @@ public class PhoneNumberUtil { public MatchType isNumberMatch(PhoneNumber firstNumber, String secondNumber) throws NumberParseException { PhoneNumber number2 = new PhoneNumber(); - parseHelper(secondNumber, null, false, number2); + parseHelper(secondNumber, null, false, false, number2); return isNumberMatch(firstNumber, number2); } } diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AM b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AM index 0fc855a..aa722df 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AM and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AM differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BH b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BH index 6559332..abef816 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BH and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BH differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BZ b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BZ index a890dcc..f5a494a 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BZ and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BZ differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CD b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CD index bfdfe3b..b248f9c 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CD and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CD differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CG b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CG index 0ad281c..94f8cca 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CG and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CG differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CR b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CR index 699410d..5cb60ae 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CR and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CR differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CU b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CU index 6566563..ab458a3 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CU and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CU differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_DE b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_DE index a2fc820..5cec8ce 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_DE and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_DE differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_DJ b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_DJ index b9e8dc6..8df1bce 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_DJ and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_DJ differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_EC b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_EC index edb880d..1e125fc 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_EC and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_EC differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_EE b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_EE index dcb5b6c..8933370 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_EE and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_EE differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_FO b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_FO index b76288c..6f8ab3a 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_FO and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_FO differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GB b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GB index e3ab079..c6853de 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GB and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GB differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GI b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GI index b597b4b..89fad3e 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GI and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GI differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GN b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GN index 284d882..919cd8d 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GN and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GN differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_HN b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_HN index 305ac3f..c884ba6 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_HN and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_HN differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_HT b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_HT index 610a2d4..aac7351 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_HT and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_HT differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_HU b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_HU index e0b9d9b..14dcc1c 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_HU and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_HU differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_IE b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_IE index 2edbe88..bcaef59 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_IE and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_IE differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_JO b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_JO index 45e5454..8d6edad 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_JO and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_JO differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_JP b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_JP index ab74bd8..1a8acdb 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_JP and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_JP differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_LB b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_LB index d04c407..8ec8d9d 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_LB and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_LB differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_LK b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_LK index 528b89a..aa92d0e 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_LK and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_LK differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_LR b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_LR index a6d98d1..762883c 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_LR and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_LR differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MA b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MA index 7781aeb..673f6bb 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MA and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MA differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MK b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MK index 5401cbb..9bf3754 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MK and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MK differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MN b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MN index 9fe3e04..d3c52c6 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MN and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MN differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MR b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MR index e7c1c5d..ce173e4 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MR and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MR differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MT b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MT index 8bae5e4..8e06f3f 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MT and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MT differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MV b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MV index ef2343e..77a73cc 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MV and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MV differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_NA b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_NA index b87e997..1e44cb9 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_NA and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_NA differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_NU b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_NU index fb8ea16..099065c 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_NU and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_NU differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_PG b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_PG index 5350b0c..05e8556 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_PG and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_PG differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_PS b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_PS index dc8b00f..16b2bed 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_PS and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_PS differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SC b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SC index 6a0ef37..79ee4c0 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SC and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SC differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SD b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SD index 05dafe7..8d70a39 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SD and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SD differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SG b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SG index 399191b..5c92a37 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SG and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SG differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SO b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SO index c58bcf3..f23197b 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SO and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SO differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SZ b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SZ index 2d43434..a9184ca 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SZ and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SZ differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_VN b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_VN index 81fbb02..79206df 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_VN and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_VN differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_ZA b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_ZA index f4a82cc..54877d9 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_ZA and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_ZA differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_ZW b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_ZW index 99b27ec..0c3990e 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_ZW and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_ZW differ diff --git a/java/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java b/java/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java index 1e96cdb..723435e 100644 --- a/java/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java +++ b/java/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java @@ -169,6 +169,49 @@ public class PhoneNumberUtilTest extends TestCase { assertEquals(0, phoneUtil.getLengthOfGeographicalAreaCode(number)); } + public void testGetLengthOfNationalDestinationCode() { + PhoneNumber number = new PhoneNumber(); + // Google MTV, which has national destination code (NDC) "650". + number.setCountryCode(1).setNationalNumber(6502530000L); + assertEquals(3, phoneUtil.getLengthOfNationalDestinationCode(number)); + + // A North America toll-free number, which has NDC "800". + number.setCountryCode(1).setNationalNumber(8002530000L); + assertEquals(3, phoneUtil.getLengthOfNationalDestinationCode(number)); + + // Google London, which has NDC "20". + number.setCountryCode(44).setNationalNumber(2070313000L); + assertEquals(2, phoneUtil.getLengthOfNationalDestinationCode(number)); + + // A UK mobile phone, which has NDC "7123". + number.setCountryCode(44).setNationalNumber(7123456789L); + assertEquals(4, phoneUtil.getLengthOfNationalDestinationCode(number)); + + // Google Buenos Aires, which has NDC "11". + number.setCountryCode(54).setNationalNumber(1155303000L); + assertEquals(2, phoneUtil.getLengthOfNationalDestinationCode(number)); + + // An Argentinian mobile which has NDC "911". + number.setCountryCode(54).setNationalNumber(91155303001L); + assertEquals(3, phoneUtil.getLengthOfNationalDestinationCode(number)); + + // Google Sydney, which has NDC "2". + number.setCountryCode(61).setNationalNumber(293744000L); + assertEquals(1, phoneUtil.getLengthOfNationalDestinationCode(number)); + + // Google Singapore, which has NDC "6521". + number.setCountryCode(65).setNationalNumber(65218000L); + assertEquals(4, phoneUtil.getLengthOfNationalDestinationCode(number)); + + // An invalid US number (1 digit shorter), which has no NDC. + number.setCountryCode(1).setNationalNumber(650253000L); + assertEquals(0, phoneUtil.getLengthOfNationalDestinationCode(number)); + + // A number containing an invalid country code, which shouldn't have any NDC. + number.setCountryCode(123).setNationalNumber(6502530000L); + assertEquals(0, phoneUtil.getLengthOfNationalDestinationCode(number)); + } + public void testGetNationalSignificantNumber() { PhoneNumber number = new PhoneNumber(); number.setCountryCode(1).setNationalNumber(6502530000L); @@ -1273,6 +1316,10 @@ public class PhoneNumberUtilTest extends TestCase { assertEquals(usNumber, phoneUtil.parse("\uFF0B\uFF11\u3000\uFF08\uFF16\uFF15\uFF10\uFF09" + "\u3000\uFF13\uFF13\uFF13\uFF0D\uFF16\uFF10\uFF10\uFF10", "SG")); + // Using U+30FC dash instead. + assertEquals(usNumber, phoneUtil.parse("\uFF0B\uFF11\u3000\uFF08\uFF16\uFF15\uFF10\uFF09" + + "\u3000\uFF13\uFF13\uFF13\u30FC\uFF16\uFF10\uFF10\uFF10", + "SG")); } public void testParseWithLeadingZero() throws Exception { @@ -1481,6 +1528,31 @@ public class PhoneNumberUtilTest extends TestCase { NumberParseException.ErrorType.NOT_A_NUMBER, e.getErrorType()); } + try { + String nullNumber = null; + // Invalid region. + phoneUtil.parse(nullNumber, "ZZ"); + fail("Null string - should fail."); + } catch (NumberParseException e) { + // Expected this exception. + assertEquals("Wrong error type stored in exception.", + NumberParseException.ErrorType.NOT_A_NUMBER, + e.getErrorType()); + } catch (NullPointerException e) { + fail("Null string - but should not throw a null pointer exception."); + } + try { + String nullNumber = null; + phoneUtil.parse(nullNumber, "US"); + fail("Null string - should fail."); + } catch (NumberParseException e) { + // Expected this exception. + assertEquals("Wrong error type stored in exception.", + NumberParseException.ErrorType.NOT_A_NUMBER, + e.getErrorType()); + } catch (NullPointerException e) { + fail("Null string - but should not throw a null pointer exception."); + } } public void testParseNumbersWithPlusWithNoRegion() throws Exception { @@ -1489,6 +1561,10 @@ public class PhoneNumberUtilTest extends TestCase { // "ZZ" is allowed only if the number starts with a '+' - then the country code can be // calculated. assertEquals(nzNumber, phoneUtil.parse("+64 3 331 6005", "ZZ")); + // Test with full-width plus. + assertEquals(nzNumber, phoneUtil.parse("\uFF0B64 3 331 6005", "ZZ")); + // Test with normal plus but leading characters that need to be stripped. + assertEquals(nzNumber, phoneUtil.parse("Tel: +64 3 331 6005", "ZZ")); assertEquals(nzNumber, phoneUtil.parse("+64 3 331 6005", null)); nzNumber.setRawInput("+64 3 331 6005"). setCountryCodeSource(CountryCodeSource.FROM_NUMBER_WITH_PLUS_SIGN); @@ -1534,6 +1610,11 @@ public class PhoneNumberUtilTest extends TestCase { assertEquals(usWithExtension, phoneUtil.parse("(800) 901-3355 , ext 7246433", "US")); assertEquals(usWithExtension, phoneUtil.parse("(800) 901-3355 ,extension 7246433", "US")); + assertEquals(usWithExtension, + phoneUtil.parse("(800) 901-3355 ,extensi\u00F3n 7246433", "US")); + // Repeat with the small letter o with acute accent created by combining characters. + assertEquals(usWithExtension, + 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"));