From dd3c09db660e3e3da394913a0a1ff6bb268b0a3a Mon Sep 17 00:00:00 2001 From: "jia.shao.peng" Date: Thu, 24 Nov 2011 13:47:31 +0000 Subject: [PATCH] Update libphonenumber to v4.3 Review URL: http://codereview.appspot.com/5434054 git-svn-id: http://libphonenumber.googlecode.com/svn/trunk@395 ee073f10-1060-11df-b6a4-87a95322a99c --- .../geocoding/PhoneNumberOfflineGeocoder.java | 72 ++++++- .../geocoding/PhoneNumberOfflineGeocoderTest.java | 20 ++ .../i18n/phonenumbers/AsYouTypeFormatter.java | 7 +- .../i18n/phonenumbers/PhoneNumberMatcher.java | 10 +- .../google/i18n/phonenumbers/PhoneNumberUtil.java | 84 ++++++--- .../phonenumbers/data/PhoneNumberMetadataProto_CR | Bin 505 -> 541 bytes .../phonenumbers/data/PhoneNumberMetadataProto_GN | Bin 401 -> 425 bytes .../phonenumbers/data/PhoneNumberMetadataProto_JP | Bin 4967 -> 5034 bytes .../phonenumbers/data/PhoneNumberMetadataProto_KE | Bin 476 -> 549 bytes .../phonenumbers/data/PhoneNumberMetadataProto_PL | Bin 617 -> 864 bytes .../phonenumbers/data/PhoneNumberMetadataProto_SG | Bin 599 -> 588 bytes .../phonenumbers/data/PhoneNumberMetadataProto_SR | Bin 447 -> 446 bytes .../phonenumbers/data/PhoneNumberMetadataProto_SX | Bin 427 -> 439 bytes .../phonenumbers/data/PhoneNumberMetadataProto_TH | Bin 584 -> 626 bytes .../phonenumbers/data/PhoneNumberMetadataProto_TK | Bin 234 -> 224 bytes .../i18n/phonenumbers/AsYouTypeFormatterTest.java | 10 + .../i18n/phonenumbers/PhoneNumberMatcherTest.java | 7 + .../i18n/phonenumbers/PhoneNumberUtilTest.java | 26 ++- .../data/PhoneNumberMetadataProtoForTesting_JP | Bin 552 -> 573 bytes java/release_notes.txt | 13 ++ resources/PhoneNumberMetaData.xml | 209 ++++++++++++++------- resources/PhoneNumberMetaDataForTesting.xml | 12 +- 22 files changed, 358 insertions(+), 112 deletions(-) diff --git a/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/PhoneNumberOfflineGeocoder.java b/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/PhoneNumberOfflineGeocoder.java index 1d074b7..1a93cc1 100644 --- a/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/PhoneNumberOfflineGeocoder.java +++ b/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/PhoneNumberOfflineGeocoder.java @@ -135,10 +135,12 @@ public class PhoneNumberOfflineGeocoder { } /** - * Returns a text description for the given language code for the given phone number. The - * description might consist of the name of the country where the phone number is from and/or the - * name of the geographical area the phone number is from. This method assumes the validity of the - * number passed in has already been checked. + * Returns a text description for the given phone number, in the language provided. The + * description might consist of the name of the country where the phone number is from, or the + * name of the geographical area the phone number is from if more detailed information is + * available. + * + *

This method assumes the validity of the number passed in has already been checked. * * @param number a valid phone number for which we want to get a text description * @param languageCode the language code for which the description should be written @@ -156,10 +158,44 @@ public class PhoneNumberOfflineGeocoder { } /** - * Returns a text description for the given language code for the given phone number. The - * description might consist of the name of the country where the phone number is from and/or the - * name of the geographical area the phone number is from. This method explictly checkes the - * validity of the number passed in. + * As per {@link #getDescriptionForValidNumber(PhoneNumber, Locale)} but also considers the + * region of the user. If the phone number is from the same region as the user, only a lower-level + * description will be returned, if one exists. Otherwise, the phone number's region will be + * returned, with optionally some more detailed information. + * + *

For example, for a user from the region "US" (United States), we would show "Mountain View, + * CA" for a particular number, omitting the United States from the description. For a user from + * the United Kingdom (region "GB"), for the same number we may show "Mountain View, CA, United + * States" or even just "United States". + * + *

This method assumes the validity of the number passed in has already been checked. + * + * @param number the phone number for which we want to get a text description + * @param languageCode the language code for which the description should be written + * @param userRegion the region code for a given user. This region will be omitted from the + * description if the phone number comes from this region. It is a two-letter uppercase ISO + * country code as defined by ISO 3166-1. + * @return a text description for the given language code for the given phone number, or empty + * string if the number passed in is invalid + */ + public String getDescriptionForValidNumber(PhoneNumber number, Locale languageCode, + String userRegion) { + // If the user region matches the number's region, then we just show the lower-level + // description, if one exists - if no description exists, we will show the region(country) name + // for the number. + String regionCode = phoneUtil.getRegionCodeForNumber(number); + if (userRegion.equals(regionCode)) { + return getDescriptionForValidNumber(number, languageCode); + } + // Otherwise, we just show the region(country) name for now. + return getCountryNameForNumber(number, languageCode); + // TODO: Concatenate the lower-level and country-name information in an appropriate + // way for each language. + } + + /** + * As per {@link #getDescriptionForValidNumber(PhoneNumber, Locale)} but explicitly checks + * the validity of the number passed in. * * @param number the phone number for which we want to get a text description * @param languageCode the language code for which the description should be written @@ -174,6 +210,26 @@ public class PhoneNumberOfflineGeocoder { } /** + * As per {@link #getDescriptionForValidNumber(PhoneNumber, Locale, String)} but + * explicitly checks the validity of the number passed in. + * + * @param number the phone number for which we want to get a text description + * @param languageCode the language code for which the description should be written + * @param userRegion the region code for a given user. This region will be omitted from the + * description if the phone number comes from this region. It is a two-letter uppercase ISO + * country code as defined by ISO 3166-1. + * @return a text description for the given language code for the given phone number, or empty + * string if the number passed in is invalid + */ + public String getDescriptionForNumber(PhoneNumber number, Locale languageCode, + String userRegion) { + if (!phoneUtil.isValidNumber(number)) { + return ""; + } + return getDescriptionForValidNumber(number, languageCode, userRegion); + } + + /** * Returns an area-level text description in the given language for the given phone number. * * @param number the phone number for which we want to get a text description diff --git a/java/geocoder/test/com/google/i18n/phonenumbers/geocoding/PhoneNumberOfflineGeocoderTest.java b/java/geocoder/test/com/google/i18n/phonenumbers/geocoding/PhoneNumberOfflineGeocoderTest.java index e8488e4..96c9d3d 100644 --- a/java/geocoder/test/com/google/i18n/phonenumbers/geocoding/PhoneNumberOfflineGeocoderTest.java +++ b/java/geocoder/test/com/google/i18n/phonenumbers/geocoding/PhoneNumberOfflineGeocoderTest.java @@ -116,6 +116,26 @@ public class PhoneNumberOfflineGeocoderTest extends TestCase { geocoder.getDescriptionForNumber(KO_NUMBER3, Locale.KOREAN)); } + public void testGetDescriptionForNumberWithUserRegion() { + // User in Italy, American number. We should just show United States, in German, and not more + // detailed information. + assertEquals("Vereinigte Staaten von Amerika", + geocoder.getDescriptionForNumber(US_NUMBER1, Locale.GERMAN, "IT")); + // Unknown region - should just show country name. + assertEquals("Vereinigte Staaten von Amerika", + geocoder.getDescriptionForNumber(US_NUMBER1, Locale.GERMAN, "ZZ")); + // User in the States, language German, should show detailed data. + assertEquals("Kalifornien", + geocoder.getDescriptionForNumber(US_NUMBER1, Locale.GERMAN, "US")); + // User in the States, language French, no data for French, so we fallback to English detailed + // data. + assertEquals("CA", + geocoder.getDescriptionForNumber(US_NUMBER1, Locale.FRENCH, "US")); + // Invalid number - return an empty string. + assertEquals("", geocoder.getDescriptionForNumber(US_INVALID_NUMBER, Locale.ENGLISH, + "US")); + } + public void testGetDescriptionForInvalidNumber() { assertEquals("", geocoder.getDescriptionForNumber(KO_INVALID_NUMBER, Locale.ENGLISH)); assertEquals("", geocoder.getDescriptionForNumber(US_INVALID_NUMBER, Locale.ENGLISH)); diff --git a/java/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java b/java/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java index 80eae06..37aabb6 100644 --- a/java/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java +++ b/java/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java @@ -356,7 +356,7 @@ public class AsYouTypeFormatter { } return ableToFormat ? prefixBeforeNationalNumber + tempNationalNumber - : tempNationalNumber; + : accruedInput.toString(); } else { return attemptToChooseFormattingPattern(); } @@ -428,8 +428,7 @@ public class AsYouTypeFormatter { // number (excluding national prefix) have been entered. if (nationalNumber.length() >= MIN_LEADING_DIGITS_LENGTH) { getAvailableFormats(nationalNumber.substring(0, MIN_LEADING_DIGITS_LENGTH)); - maybeCreateNewTemplate(); - return inputAccruedNationalNumber(); + return maybeCreateNewTemplate() ? inputAccruedNationalNumber() : accruedInput.toString(); } else { return prefixBeforeNationalNumber + nationalNumber.toString(); } @@ -446,7 +445,7 @@ public class AsYouTypeFormatter { } return ableToFormat ? prefixBeforeNationalNumber + tempNationalNumber - : tempNationalNumber; + : accruedInput.toString(); } else { return prefixBeforeNationalNumber.toString(); } diff --git a/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberMatcher.java b/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberMatcher.java index 62586f1..e0892ba 100644 --- a/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberMatcher.java +++ b/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberMatcher.java @@ -294,8 +294,8 @@ final class PhoneNumberMatcher implements Iterator { block.equals(UnicodeBlock.COMBINING_DIACRITICAL_MARKS); } - private static boolean isCurrencySymbol(char character) { - return Character.getType(character) == Character.CURRENCY_SYMBOL; + private static boolean isInvalidPunctuationSymbol(char character) { + return character == '%' || Character.getType(character) == Character.CURRENCY_SYMBOL; } /** @@ -407,15 +407,15 @@ final class PhoneNumberMatcher implements Iterator { // punctuation, check the previous character. if (offset > 0 && !LEAD_CLASS.matcher(candidate).lookingAt()) { char previousChar = text.charAt(offset - 1); - // We return null if it is a latin letter or a currency symbol. - if (isCurrencySymbol(previousChar) || isLatinLetter(previousChar)) { + // We return null if it is a latin letter or an invalid punctuation symbol. + if (isInvalidPunctuationSymbol(previousChar) || isLatinLetter(previousChar)) { return null; } } int lastCharIndex = offset + candidate.length(); if (lastCharIndex < text.length()) { char nextChar = text.charAt(lastCharIndex); - if (isCurrencySymbol(nextChar) || isLatinLetter(nextChar)) { + if (isInvalidPunctuationSymbol(nextChar) || isLatinLetter(nextChar)) { return null; } } diff --git a/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java b/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java index a600334..b9307e7 100644 --- a/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java +++ b/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java @@ -97,6 +97,11 @@ public class PhoneNumberUtil { private static final String RFC3966_EXTN_PREFIX = ";ext="; + // A map that contains characters that are essential when dialling. That means any of the + // characters in this map must not be removed from a number when dialing, otherwise the call will + // not reach the intended destination. + private static final Map DIALLABLE_CHAR_MAPPINGS; + // Only upper-case variants of alpha characters are stored. private static final Map ALPHA_MAPPINGS; @@ -156,6 +161,12 @@ public class PhoneNumberUtil { combinedMap.putAll(asciiDigitMappings); ALPHA_PHONE_MAPPINGS = Collections.unmodifiableMap(combinedMap); + HashMap diallableCharMap = new HashMap(); + diallableCharMap.put('+', '+'); + diallableCharMap.put('*', '*'); + diallableCharMap.putAll(asciiDigitMappings); + DIALLABLE_CHAR_MAPPINGS = Collections.unmodifiableMap(diallableCharMap); + HashMap allPlusNumberGroupings = new HashMap(); // Put (lower letter -> upper letter) and (upper letter -> upper letter) mappings. for (char c : ALPHA_MAPPINGS.keySet()) { @@ -407,9 +418,8 @@ public class PhoneNumberUtil { */ public enum Leniency { /** - * Phone numbers accepted are - * {@linkplain PhoneNumberUtil#isPossibleNumber(Phonenumber.PhoneNumber) possible}, but not - * necessarily {@linkplain PhoneNumberUtil#isValidNumber(Phonenumber.PhoneNumber) valid}. + * Phone numbers accepted are {@linkplain PhoneNumberUtil#isPossibleNumber(PhoneNumber) + * possible}, but not necessarily {@linkplain PhoneNumberUtil#isValidNumber(PhoneNumber) valid}. */ POSSIBLE { @Override @@ -418,9 +428,8 @@ public class PhoneNumberUtil { } }, /** - * Phone numbers accepted are - * {@linkplain PhoneNumberUtil#isPossibleNumber(Phonenumber.PhoneNumber) possible} and - * {@linkplain PhoneNumberUtil#isValidNumber(Phonenumber.PhoneNumber) valid}. Numbers written + * Phone numbers accepted are {@linkplain PhoneNumberUtil#isPossibleNumber(PhoneNumber) + * possible} and {@linkplain PhoneNumberUtil#isValidNumber(PhoneNumber) valid}. Numbers written * in national format must have their national-prefix present if it is usually written for a * number of this type. */ @@ -1059,9 +1068,8 @@ public class PhoneNumberUtil { } /** - * Same as {@link #format(Phonenumber.PhoneNumber, PhoneNumberUtil.PhoneNumberFormat)}, but - * accepts a mutable StringBuilder as a parameter to decrease object creation when invoked many - * times. + * Same as {@link #format(PhoneNumber, PhoneNumberFormat)}, but accepts a mutable StringBuilder as + * a parameter to decrease object creation when invoked many times. */ public void format(PhoneNumber number, PhoneNumberFormat numberFormat, StringBuilder formattedNumber) { @@ -1222,7 +1230,7 @@ public class PhoneNumberUtil { */ public String formatNumberForMobileDialing(PhoneNumber number, String regionCallingFrom, boolean withFormatting) { - String regionCode = getRegionCodeForNumber(number); + String regionCode = getRegionCodeForCountryCode(number.getCountryCode()); if (!isValidRegionCode(regionCode)) { return number.hasRawInput() ? number.getRawInput() : ""; } @@ -1231,11 +1239,19 @@ public class PhoneNumberUtil { // Clear the extension, as that part cannot normally be dialed together with the main number. PhoneNumber numberNoExt = new PhoneNumber().mergeFrom(number).clearExtension(); PhoneNumberType numberType = getNumberType(numberNoExt); - if ((regionCode.equals("CO")) && (regionCallingFrom.equals("CO")) && - (numberType == PhoneNumberType.FIXED_LINE)) { - formattedNumber = - formatNationalNumberWithCarrierCode(numberNoExt, COLOMBIA_MOBILE_TO_FIXED_LINE_PREFIX); - } else if ((regionCode.equals("BR")) && (regionCallingFrom.equals("BR")) && + if (regionCode.equals("CO") && regionCallingFrom.equals("CO")) { + if (numberType == PhoneNumberType.FIXED_LINE) { + formattedNumber = + formatNationalNumberWithCarrierCode(numberNoExt, COLOMBIA_MOBILE_TO_FIXED_LINE_PREFIX); + } else { + // E164 doesn't work at all when dialing within Colombia. + formattedNumber = format(numberNoExt, PhoneNumberFormat.NATIONAL); + } + } else if (regionCode.equals("PE") && regionCallingFrom.equals("PE")) { + // In Peru, numbers cannot be dialled using E164 format from a mobile phone for Movistar. + // Instead they must be dialled in national format. + formattedNumber = format(numberNoExt, PhoneNumberFormat.NATIONAL); + } else if (regionCode.equals("BR") && regionCallingFrom.equals("BR") && ((numberType == PhoneNumberType.FIXED_LINE) || (numberType == PhoneNumberType.MOBILE) || (numberType == PhoneNumberType.FIXED_LINE_OR_MOBILE))) { formattedNumber = numberNoExt.hasPreferredDomesticCarrierCode() @@ -1251,7 +1267,9 @@ public class PhoneNumberUtil { formattedNumber = (regionCallingFrom.equals(regionCode)) ? format(numberNoExt, PhoneNumberFormat.NATIONAL) : ""; } - return withFormatting ? formattedNumber : normalizeDigitsOnly(formattedNumber); + return withFormatting ? formattedNumber + : normalizeHelper(formattedNumber, DIALLABLE_CHAR_MAPPINGS, + true /* remove non matches */); } /** @@ -1339,7 +1357,11 @@ public class PhoneNumberUtil { * @return the formatted phone number in its original number format */ public String formatInOriginalFormat(PhoneNumber number, String regionCallingFrom) { - if (number.hasRawInput() && !isValidNumber(number)) { + if (number.hasRawInput() && + (!hasFormattingPatternForNumber(number) || !isValidNumber(number))) { + // We check if we have the formatting pattern because without that, we might format the number + // as a group without national prefix. We also want to check the validity of the number + // because we don't want to risk formatting the number if we don't really understand it. return number.getRawInput(); } if (!number.hasCountryCodeSource()) { @@ -1358,6 +1380,18 @@ public class PhoneNumberUtil { } } + private boolean hasFormattingPatternForNumber(PhoneNumber number) { + String phoneNumberRegion = getRegionCodeForCountryCode(number.getCountryCode()); + PhoneMetadata metadata = getMetadataForRegion(phoneNumberRegion); + if (metadata == null) { + return false; + } + String nationalNumber = getNationalSignificantNumber(number); + NumberFormat formatRule = + chooseFormattingPatternForNumber(metadata.numberFormats(), nationalNumber); + return formatRule != null; + } + /** * Formats a phone number for out-of-country dialing purposes. * @@ -2028,10 +2062,10 @@ public class PhoneNumberUtil { /** * Check whether a phone number is a possible number given a number in the form of a string, and * the region where the number could be dialed from. It provides a more lenient check than - * {@link #isValidNumber}. See {@link #isPossibleNumber(Phonenumber.PhoneNumber)} for details. + * {@link #isValidNumber}. See {@link #isPossibleNumber(PhoneNumber)} for details. * - *

This method first parses the number, then invokes - * {@link #isPossibleNumber(Phonenumber.PhoneNumber)} with the resultant PhoneNumber object. + *

This method first parses the number, then invokes {@link #isPossibleNumber(PhoneNumber)} + * with the resultant PhoneNumber object. * * @param number the number that needs to be checked, in the form of a string * @param regionDialingFrom the region that we are expecting the number to be dialed from. @@ -2683,15 +2717,14 @@ public class PhoneNumberUtil { /** * Takes two phone numbers as strings and compares them for equality. This is a convenience - * wrapper for {@link #isNumberMatch(Phonenumber.PhoneNumber, Phonenumber.PhoneNumber)}. No - * default region is known. + * wrapper for {@link #isNumberMatch(PhoneNumber, PhoneNumber)}. No default region is known. * * @param firstNumber first number to compare. Can contain formatting, and can have country * calling code specified with + at the start. * @param secondNumber second number to compare. Can contain formatting, and can have country * calling code specified with + at the start. * @return NOT_A_NUMBER, NO_MATCH, SHORT_NSN_MATCH, NSN_MATCH, EXACT_MATCH. See - * {@link #isNumberMatch(Phonenumber.PhoneNumber, Phonenumber.PhoneNumber)} for more details. + * {@link #isNumberMatch(PhoneNumber, PhoneNumber)} for more details. */ public MatchType isNumberMatch(String firstNumber, String secondNumber) { try { @@ -2723,14 +2756,13 @@ public class PhoneNumberUtil { /** * Takes two phone numbers and compares them for equality. This is a convenience wrapper for - * {@link #isNumberMatch(Phonenumber.PhoneNumber, Phonenumber.PhoneNumber)}. No default region is - * known. + * {@link #isNumberMatch(PhoneNumber, PhoneNumber)}. No default region is known. * * @param firstNumber first number to compare in proto buffer format. * @param secondNumber second number to compare. Can contain formatting, and can have country * calling code specified with + at the start. * @return NOT_A_NUMBER, NO_MATCH, SHORT_NSN_MATCH, NSN_MATCH, EXACT_MATCH. See - * {@link #isNumberMatch(Phonenumber.PhoneNumber, Phonenumber.PhoneNumber)} for more details. + * {@link #isNumberMatch(PhoneNumber, PhoneNumber)} for more details. */ public MatchType isNumberMatch(PhoneNumber firstNumber, String secondNumber) { // First see if the second number has an implicit country calling code, by attempting to parse diff --git a/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CR b/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CR index cbc064bbe478989c43bd38c01b619aa705938667..a1d4d34f5e7c69ca37cb5e33ee8447980a3e0033 100644 GIT binary patch delta 102 zcmey#JeP%Y&07Z6Dh387k%^oh8hWN0_ErYb2D&D(F)7uiwKe9^28KW;gse8M)vU3I tHa63pm{rSYGVz5DTa775-DF|LWDyY!LrbV`qu3fl%NlcY&B-;4wE*zL9fAM= delta 66 zcmbQs@{^f!&07Z6Dh39|4-+{(B;`%bqYVsWV^SbwwQ+5YMYOS*xy8iFT1MT8-*qNy SF($FGX&71>7))NkSPKBH$P_XF diff --git a/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GN b/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GN index b0b7406586a9fe4f908141fbace9b9a8fdc9d9be..468f4d25dc4a16b391e583e794598afe18ce6447 100644 GIT binary patch delta 79 zcmbQpypox7&07Z6Dh39|1rs^*q(_XY@Q}?kqH2pi8}fK delta 174 zcmZ3b{#2BXb$xXh=c!^Pa@){;7Da{%S3!`X5BNNlun3QUh zT1`d&$25M`ocI(Y)K?BsAZWoAYO=E;04&a71o z3@i+r16lSmPo6IzFj<+y7%KFOcMIcYE-p@{$sX+Tlg)WlAmWp2+2uA@^2}$REXWJi M&Fr-~LBNX{0F#$38~^|S diff --git a/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_KE b/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_KE index 68de57a008b3b758771eafc1fb96b34ab74682e8..a87c7e87dc64441cedd8ff1804e620a8fa5e721a 100644 GIT binary patch delta 265 zcmYk0I}U(&QPA{R*7%xC9t?fLLSFrE~&S*@m z=J(#rJiJ?fet&|00O-vC01;uV<#u;8Y1uZF5w4~pPhB@%qv-bGps`gUTz3vPQdZjJ z!hVUOMF@y>sgjfqt(014CNF5^)WypM<03C@-6*x)CA^k6pB3gE@!jh*_h1xLPqzsN zej@=tQemX|KN!$WQPh_!#w#olJQ*pZ2}~HzzSb|KhUDNQhf((N`;~R|pT;V{8#oX+ A7ytkO delta 196 zcmZ3=a)()B&07Z6Dh39|%M3t*k&%HTCZ*a;$IxJ+nva5-xrV)!L9~IcX>3ijp^*apymP;iaHuPYLEu5kntgCxD5>@Ed_UA zB_PQ*`+NJOuiekR>$h*H9szc40e~?Ewdd#BhUMK8_BKUF1tpIrk2H-KOv}CA+#FeXJ~s8T(q*j_EHi_UYU%i633tC#n)LsWuDN#w@M;DE+lNTqRHvKv;7 zuk7LEs3lUQE~l*SplW#Ci2QN57(dv2oK5D>r_x332QEWIKPYq|8b1h2+4{i-mT`*X j?2*5^Kdb1ehy7x$8(G8?RR0&Vt&0q9J-?x**-h~SBeG8| delta 132 zcmaFB_L4@xbgDjNJgH?D;V7wnI?Z=ESS8NNmWlz|1nX#yr}< T$O1@PL>pMdG6L-Z+64sw;kY0( diff --git a/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SG b/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SG index e8dfd31d415054306d40bc893d1d5c3daa777e8e..cb7d0125ee03dbaa7d0643862fba88faebcadcf4 100644 GIT binary patch delta 31 mcmcc4a)yO-&07Z6Dh387=Z%~ujO=WdmeHn`v77xFIT!(rsRyzE delta 42 xcmX@Za-D^9&07Z6Dh387zm1$Gj6#BjhDJ4(8unI(hBcPark1gqn_U<=7y*Y)oR)^ oGVlReCbcya)qjYwL1Y;jSixe93@nC*1_qNg7*%meg)x2t04EY2l>h($ delta 68 zcmeywa)L#D&07Z6Dh387dj3eNwQ(&Y11pd=sRfFIg-uX}85vlN4Gax{l5D0Z l>VXobhL#`+CO=0o0WyK6YzC$fZw3aYO$ possibleOnlyContexts = new ArrayList(); + possibleOnlyContexts.add(new NumberContext("", "%")); + // Numbers followed by % should be dropped. + findMatchesInContexts(possibleOnlyContexts, false, true); + } + public void testPhoneNumberWithLeadingOrTrailingMoneyMatches() throws Exception { // Because of the space after the 20 (or before the 100) these dollar amounts should not stop // the actual number from being found. diff --git a/java/libphonenumber/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java b/java/libphonenumber/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java index e7038c6..97be058 100644 --- a/java/libphonenumber/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java +++ b/java/libphonenumber/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java @@ -71,6 +71,8 @@ public class PhoneNumberUtilTest extends TestCase { private static final PhoneNumber IT_NUMBER = new PhoneNumber().setCountryCode(39).setNationalNumber(236618300L). setItalianLeadingZero(true); + private static final PhoneNumber JP_STAR_NUMBER = + new PhoneNumber().setCountryCode(81).setNationalNumber(2345); // Numbers to test the formatting rules from Mexico. private static final PhoneNumber MX_MOBILE1 = new PhoneNumber().setCountryCode(52).setNationalNumber(12345678900L); @@ -614,7 +616,8 @@ public class PhoneNumberUtilTest extends TestCase { // US toll free numbers are marked as noInternationalDialling in the test metadata for testing // purposes. assertEquals("800 253 0000", - phoneUtil.formatNumberForMobileDialing(US_TOLLFREE, RegionCode.US, true)); + phoneUtil.formatNumberForMobileDialing(US_TOLLFREE, RegionCode.US, + true /* keep formatting */)); assertEquals("", phoneUtil.formatNumberForMobileDialing(US_TOLLFREE, RegionCode.CN, true)); assertEquals("+1 650 253 0000", phoneUtil.formatNumberForMobileDialing(US_NUMBER, RegionCode.US, true)); @@ -623,12 +626,26 @@ public class PhoneNumberUtilTest extends TestCase { phoneUtil.formatNumberForMobileDialing(usNumberWithExtn, RegionCode.US, true)); assertEquals("8002530000", - phoneUtil.formatNumberForMobileDialing(US_TOLLFREE, RegionCode.US, false)); + phoneUtil.formatNumberForMobileDialing(US_TOLLFREE, RegionCode.US, + false /* remove formatting */)); assertEquals("", phoneUtil.formatNumberForMobileDialing(US_TOLLFREE, RegionCode.CN, false)); assertEquals("+16502530000", phoneUtil.formatNumberForMobileDialing(US_NUMBER, RegionCode.US, false)); assertEquals("+16502530000", phoneUtil.formatNumberForMobileDialing(usNumberWithExtn, RegionCode.US, false)); + + // An invalid US number, which is one digit too long. + assertEquals("+165025300001", + phoneUtil.formatNumberForMobileDialing(US_LONG_NUMBER, RegionCode.US, false)); + assertEquals("+1 65025300001", + phoneUtil.formatNumberForMobileDialing(US_LONG_NUMBER, RegionCode.US, true)); + + // Star numbers. In real life they appear in Israel, but we have them in JP in our test + // metadata. + assertEquals("*2345", + phoneUtil.formatNumberForMobileDialing(JP_STAR_NUMBER, RegionCode.JP, false)); + assertEquals("*2345", + phoneUtil.formatNumberForMobileDialing(JP_STAR_NUMBER, RegionCode.JP, true)); } public void testFormatByPattern() { @@ -730,6 +747,11 @@ public class PhoneNumberUtilTest extends TestCase { // When the raw input is unavailable, format as usual. PhoneNumber number7 = phoneUtil.parse("7345678901", RegionCode.US); assertEquals("734 567 8901", phoneUtil.formatInOriginalFormat(number7, RegionCode.US)); + + // This number is valid, but we don't have a formatting pattern for it. Fall back to the raw + // input. + PhoneNumber number8 = phoneUtil.parseAndKeepRawInput("02-4567-8900", RegionCode.KR); + assertEquals("02-4567-8900", phoneUtil.formatInOriginalFormat(number8, RegionCode.KR)); } public void testIsPremiumRate() { diff --git a/java/libphonenumber/test/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProtoForTesting_JP b/java/libphonenumber/test/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProtoForTesting_JP index 1dbb2b1be39969b176b5136a34ffa43c61ad9d87..06f685abfa0fa598619e728bfb8ea90b709deeeb 100644 GIT binary patch delta 98 zcmZ3%vX_N(&07Z6Dh387lZl+gLY&b?#<4Le)yB1q46H!fq;_J>EaM(NCKW?Q1~>o!{QDL^ delta 66 zcmdnXvVw(k&07Z6Dh387`H7sx6CF4w_V1NuH!?D+F*Y`4;L)(Rg0eLY8F+!b$;FI& MCi60JvN3=G08Ld76#xJL diff --git a/java/release_notes.txt b/java/release_notes.txt index 0fb5dc6..d73b7d6 100644 --- a/java/release_notes.txt +++ b/java/release_notes.txt @@ -1,3 +1,16 @@ +November 24th, 2011: libphonenumber-4.3 +* Code changes + - Fix the problems with AYTF crashing for longer numbers entered with +CountryCode, and incorrectly + removing national prefix for some numbers. + - Improve PhoneNumberMatcher to not match numbers ending with '%'. + - Fix formatNumberForMobileDialing to handle Israeli star numbers, Peruvian and Colombian numbers. + - Modify formatInOriginalFormat to use the raw input if we don't have a formatting pattern for a + number. + - Simple offline geocoding function which takes into account the user's region. + +* Metadata changes + - Updates for CR, GN, JP, KE, PL, SG, SR, SX, TH, TK + November 10th, 2011: libphonenumber-4.2 * Code changes - Providing an "exact match" isEmergencyNumber method diff --git a/resources/PhoneNumberMetaData.xml b/resources/PhoneNumberMetaData.xml index 4b83e54..33282aa 100644 --- a/resources/PhoneNumberMetaData.xml +++ b/resources/PhoneNumberMetaData.xml @@ -4436,7 +4436,7 @@ + nationalPrefixForParsing="(19(?:0[0-2]|19|77))" carrierCodeFormattingRule="$CC $FG"> @@ -4463,8 +4463,11 @@ - 57[01]\d[01]\d{3}| - 8[36789]\d{6} + 5(?: + 0[0-4]\d{5}| + 7[01]\d[01]\d{3} + )| + 8[36-9]\d{6} \d{8} 83123456 @@ -4488,7 +4491,8 @@ 2(?: 00\d| 900 - )\d{2} + )\d{2}| + 5\d{5} ) \d{8} @@ -4512,14 +4516,17 @@ )| 2(?: 12| + 22| 34 )| + 333| 400| + 55[15]| 7(?: 00| 1[78]| 77 - )| + ) ) \d{4} @@ -7900,7 +7907,7 @@ 55\d{6}| 6(?: 0(?: - 2\d| + 2[0-35-9]| 3[3467]| 5[2457-9] )| @@ -7913,6 +7920,10 @@ 60201234 + + 78\d{6} + 78123456 + @@ -11033,10 +11044,14 @@ - + 077 $1-$2 + + 077 + $1-$2-$3 + 088 $1-$2-$3 @@ -11809,7 +11824,7 @@ [1-9]\d{8,9}| 0(?: - 7\d{5,6}| + 7\d{5,7}| 8\d{7} ) @@ -11821,12 +11836,12 @@ 0(?: 777(?: [01]\d{2}| - 5\d{3} + 5\d{3}| + 8\d{4} )| 882[1245]\d{4} ) - \d{7,9} 0777012 @@ -11899,12 +11914,12 @@ 0(?: 777(?: [01]\d{2}| - 5\d{3} + 5\d{3}| + 8\d{4} )| 882[1245]\d{4} ) - \d{7,10} 120123456 @@ -11941,22 +11956,23 @@ nationalPrefix="0" nationalPrefixFormattingRule="$NP$FG"> - - [2-6]| - 91 - + [24-6] $1 $2 - - [78]| - 90 - + 7 $1 $2 + + [89] + $1 $2 $3 + - \d{6,10} + + 20\d{4,7}| + [4-9]\d{5,9} + \d{4,10} @@ -11972,41 +11988,52 @@ 202012345 - + 7(?: 0[0-5]| [123]\d| 5[0-3]| - 7[0-5] + 7[0-5]| + 8[6-9] )\d{6} \d{9} 712123456 - - - 8(?: - 00| - 88 - )\d{6,7} - + + 800[245-8]\d{5,6} \d{9,10} - 800123456 + 800223456 - - 9(?: - 00| - 1 - )\d{6,7} - - \d{8,10} - 900123456 + + 9(?: + 00[2-578]| + 11\d + )\d{5} + + \d{9} + 900223456 + + + 1(?: + 0[089]| + 1(?: + [06]| + 99 + )| + 2[123]| + 3[013]| + 4[14]| + 501 + ) + + \d{3,4} + 116 + @@ -17750,24 +17777,50 @@ $1 $2 $3 $4 + + + + [124]| + 3[2-4]| + 5[24-689]| + 6[1-3578]| + 7[14-7]| + 8[1-7] + + $1 $2 + 39| 5[013]| - 6[069]| + 6[0469]| 7[0289]| 8[08] $1 $2 $3 + + + 64 + $1 $2 $3 + + + 64 + $1 $2 + - [1-9]\d{8} - \d{9} + + [1-58]\d{6,8}| + 9\d{8}| + [67]\d{5,8} + + \d{6,9} + (?: 1[2-8]| @@ -17776,8 +17829,12 @@ 4[1-468]| 5[24-689]| 6[1-3578]| - 7[14-7]| - 8[1-79]| + 7[14-6]| + 8[1-7] + )\d{5,7}| + 77\d{4,6}| + (?: + 89| 9[145] )\d{7} @@ -17792,22 +17849,31 @@ 88 )\d{7} + \d{9} 512345678 + + 642\d{3,6} + 642123456 + 800\d{6} + \d{9} 800123456 70\d{7} + \d{9} 701234567 801\d{6} + \d{9} 801234567 39\d{7} + \d{9} 391234567 @@ -19312,13 +19378,7 @@ 1312 - - 112| - 9(?: - 11| - 9[59] - ) - + 99[59] \d{3} 999 @@ -19914,7 +19974,7 @@ (?: - 7[1245]| + 7[1-5]| 8[1-9] )\d{5} @@ -20044,7 +20104,12 @@ \d{7}(?:\d{3})? - 72154[2-8]\d{4} + + 7215(?: + 4[2-8]| + 8[239] + )\d{4} + 7215425678 @@ -20054,7 +20119,7 @@ 7215(?: 1[02]| 2\d| - 5[0346]| + 5[03469]| 8[01678] )\d{4} @@ -20411,6 +20476,7 @@ + @@ -20437,10 +20503,15 @@ [2-9]\d{7,8}| - 1\d{9} + 1\d{3}(?:\d{6})? - \d{8,10} + \d{4}|\d{8,10} + + 1\d{3} + \d{4} + 1100 + (?: @@ -20477,6 +20548,13 @@ \d{9} 601234567 + + + 1\d{3} + \d{4} + 1100 + 1(?: @@ -20587,14 +20665,19 @@ - - [1-9]\d{3} + [2-5]\d{3} \d{4} - 3190 + + [2-4]\d{3} + + 3010 + + + 5\d{3} + 5190 + diff --git a/resources/PhoneNumberMetaDataForTesting.xml b/resources/PhoneNumberMetaDataForTesting.xml index 55bb209..56e207c 100644 --- a/resources/PhoneNumberMetaDataForTesting.xml +++ b/resources/PhoneNumberMetaDataForTesting.xml @@ -346,9 +346,9 @@ $1 $2 $3 $4 - 222|333 - (?:222|333)1 - (?:222|333)11 + 111|222|333 + (?:111|222|333)1 + (?:111|222|333)11 $1 $2 $3 @@ -364,11 +364,15 @@ - + [23] *$1 + + [23]\d{3} + \d{4} + -- 2.7.4