Update external/libphonenumber to v5.0
Change-Id: I6a4af4e7ac1986ba0034573795d733735f7f5ba4
diff --git a/README.android b/README.android
index 797c640..c0cd643 100644
--- a/README.android
+++ b/README.android
@@ -1,5 +1,5 @@
URL: http://code.google.com/p/libphonenumber/
-Version: 4.9 (r473)
+Version: 5.0 (r500)
License: Apache 2
Description: Google Phone Number Library.
Local Modification:
diff --git a/java/release_notes.txt b/java/release_notes.txt
index f7aae05..43a4497 100644
--- a/java/release_notes.txt
+++ b/java/release_notes.txt
@@ -1,17 +1,30 @@
+July 12th, 2012: libphonenumber-5.0
+* Code changes:
+ - Support for alternate formats when finding phone numbers.
+ - Allowing two-digit numbers to be parsed if they are entered in national-format with no
+ punctuation
+* Metadata changes
+ - IL, GA
+* Other
+ - Reflowed this file to 100 char width to make it unambiguous as to what the standard should be.
+
+July 6th, 2012: libphonenumber-4.9.1
+* Metadata changes
+ - AR, BA, BF, CR, DE, EC, ES, KZ, MK, NC, NG, PF, SB, UZ, non-geo entity 882
+ - Geocoding data updates for country calling codes 54 (AR) and 81 (JP), new data for 234 (NG)
+
June 21st, 2012: libphonenumber-4.9
* Bug fix
- - formatInOriginalFormat fixed not to add a star sign if it was not present
- originally.
+ - formatInOriginalFormat fixed not to add a star sign if it was not present originally.
* Metadata changes
- BF, CZ, ES, KW
- - Non-geographical entities with calling code 882 (BebbiCell, Maritime
- Communications, Oration Technologies, Telespazio and Thuraya)
+ - Non-geographical entities with calling code 882 (BebbiCell, Maritime Communications, Oration
+ Technologies, Telespazio and Thuraya)
- Geocoding data updates for country calling codes 221, 224, 226, 242, 244, 245
* Functionality changes:
- - Minimum allowed length for a national significant number (NSN) when parsing
- changed from 3 to 2.
- - Support parsing of RFC3966-formatted strings with an isdn-subaddress or extra
- parameters specified.
+ - Minimum allowed length for a national significant number (NSN) when parsing changed from 3 to 2.
+ - Support parsing of RFC3966-formatted strings with an isdn-subaddress or extra parameters
+ specified.
- Allow soft hyphen to appear in phone numbers (\u00AD)
* Testing changes:
- Add extra unit tests for non-geographical phone number entities
@@ -117,33 +130,31 @@
November 10th, 2011: libphonenumber-4.2
* Code changes
- Providing an "exact match" isEmergencyNumber method
- - Improvement to PhoneNumberMatcher: requires national prefix to be present
- when matching national-format numbers, unless matching for a region where it
- is explicitly marked in the metadata that they may be omitted. Applies to
- leniency level VALID and higher.
+ - Improvement to PhoneNumberMatcher: requires national prefix to be present when matching
+ national-format numbers, unless matching for a region where it is explicitly marked in the
+ metadata that they may be omitted. Applies to leniency level VALID and higher.
- Change formatNumberForMobileDialing not to modify the phoneNumber passed in.
* Metadata changes
- Emergency numbers added for all remaining countries
- - Collected data on which numbers we format with a national prefix are
- commonly written without one and added this
+ - Collected data on which numbers we format with a national prefix are commonly written without one
+ and added this
- Updates for AR, AT, BH, CZ, GR, IR, KM, LT, MX, PT, SE, SO, UG
- Addition of SX (Sint Maarten)
October 19th, 2011: libphonenumber-4.1
* Code changes
- - Update code and metadata for countries with IDD "8~10" to accept phone
- numbers where the "~" is omitted.
- - Modify formatInOriginalFormat to use raw_input (when present) when the number
- is considered as invalid by the library.
- - Add ShortNumberUtil to deal with international short phone numbers, such as
- short codes and emergency numbers.
+ - Update code and metadata for countries with IDD "8~10" to accept phone numbers where the "~" is
+ omitted.
+ - Modify formatInOriginalFormat to use raw_input (when present) when the number is considered as
+ invalid by the library.
+ - Add ShortNumberUtil to deal with international short phone numbers, such as short codes and
+ emergency numbers.
- Increase the maximum phone-number length accepted when parsing (now set to
16).
* Metadata changes
- - Updates: BF, BN, CN, DE, DK, DO, FR, IN, KI, KW, MC, MD, ML, PA, QA, SB, UK,
- WS
+ - Updates: BF, BN, CN, DE, DK, DO, FR, IN, KI, KW, MC, MD, ML, PA, QA, SB, UK, WS
- Emergency number information also added to: AE, AF, AL, AM, AR, AT, AU, BA,
BB, BD, BE, BG, BH, BO, BR, BY, CA, CH, CL, CN, CO, CR, CY, CZ, DE, DJ, DK,
DO, DZ, EC, EE, EG, ES, FI, FJ, FO, FR, GB, GE, GF, GH, GI, GL, GR, GT, GY,
@@ -155,10 +166,9 @@
October 6th, 2011: libphonenumber-4.0
* Code changes
- - New function formatNumberForMobileDialing, which attempts to format a number in
- such a way that the call can be connected from a mobile phone. If this is
- impossible, for example for numbers that cannot be internationally dialled,
- then an empty string is returned.
+ - New function formatNumberForMobileDialing, which attempts to format a number in such a way that
+ the call can be connected from a mobile phone. If this is impossible, for example for numbers
+ that cannot be internationally dialled, then an empty string is returned.
- Fallback functionality to English for non-CJK languages for geocoding
* Metadata changes
@@ -172,8 +182,7 @@
- Enable AsYouTypeFormatter to handle long IDD and NDD.
- Allow the presence of an IDD following a +.
- Fix formatting of phone numbers which contain only 0s in the national number.
- - Refactored some code in geocoding including AreaCodeMap and the storage
- strategies.
+ - Refactored some code in geocoding including AreaCodeMap and the storage strategies.
* Metadata changes
- Updates: AM, BE, BH, BJ, BR, BT, BZ, CI, CL, CN, DE, DK, DM, DZ, EC, EG, FJ,
@@ -188,16 +197,14 @@
* Code changes
- Fix to demo to not throw null-ptr exceptions for invalid NANPA numbers
- Fixed AYTF to not accept plus signs in the middle of input
- - PhoneNumberMatcher improvements - added STRICT_GROUPING and EXACT_GROUPING
- levels, numbers followed/preceded by a currency symbol will not match,
- multiple numbers separated by phone-number punctuation will now match. ", "
- is no longer accepted as an extension symbol when matching, only when
- parsing. "x" is only accepted as a carrier code or extension marker, not
- otherwise.
- - Changes to handling of leading zeroes - these will not be silently ignored
- anymore, but will be stored as part of the number.
- - PhoneNumberOfflineGeocoder - new method to get the description of a number that assumes
- the validity of the number has already been checked and will not re-verify it.
+ - PhoneNumberMatcher improvements - added STRICT_GROUPING and EXACT_GROUPING levels, numbers
+ followed/preceded by a currency symbol will not match, multiple numbers separated by phone-number
+ punctuation will now match. ", " is no longer accepted as an extension symbol when matching, only
+ when parsing. "x" is only accepted as a carrier code or extension marker, not otherwise.
+ - Changes to handling of leading zeroes - these will not be silently ignored anymore, but will be
+ stored as part of the number.
+ - PhoneNumberOfflineGeocoder - new method to get the description of a number that assumes the
+ validity of the number has already been checked and will not re-verify it.
- Split geocoding US binary data into multiple files.
* Metadata changes
@@ -455,16 +462,16 @@
August 4th, 2010
* Further improve startup performance
- Preload no country specific metadata at startup.
- - Stop creating the file containing mapping from country calling code to region code
- and loading it at startup; instead, do the initialization in PhoneNumberUtil.
+ - Stop creating the file containing mapping from country calling code to region code and loading
+ it at startup; instead, do the initialization in PhoneNumberUtil.
July 31th, 2010
* Improve startup performance
- Separate generated metadata binary file to one file per region
- Preload US at start up, and load other region at the time when needed
- - Create a file containing mapping from country calling code to region code,
- and load it at startup
+ - Create a file containing mapping from country calling code to region code, and load it at
+ startup
- Same change also applied to unittests
July 30th, 2010
diff --git a/java/src/com/android/i18n/phonenumbers/AlternateFormatsCountryCodeSet.java b/java/src/com/android/i18n/phonenumbers/AlternateFormatsCountryCodeSet.java
new file mode 100644
index 0000000..0b1de98
--- /dev/null
+++ b/java/src/com/android/i18n/phonenumbers/AlternateFormatsCountryCodeSet.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2012 The Libphonenumber Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* This file is automatically generated by {@link BuildMetadataProtoFromXml}.
+ * Please don't modify it directly.
+ */
+
+package com.android.i18n.phonenumbers;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class AlternateFormatsCountryCodeSet {
+ // A set of all country codes for which data is available.
+ static Set<Integer> getCountryCodeSet() {
+ // The capacity is set to 6 as there are 5 different country codes,
+ // and this offers a load factor of roughly 0.75.
+ Set<Integer> countryCodeSet = new HashSet<Integer>(6);
+
+ countryCodeSet.add(44);
+ countryCodeSet.add(49);
+ countryCodeSet.add(55);
+ countryCodeSet.add(61);
+ countryCodeSet.add(81);
+
+ return countryCodeSet;
+ }
+}
diff --git a/java/src/com/android/i18n/phonenumbers/MetadataManager.java b/java/src/com/android/i18n/phonenumbers/MetadataManager.java
new file mode 100644
index 0000000..76a36e6
--- /dev/null
+++ b/java/src/com/android/i18n/phonenumbers/MetadataManager.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2012 The Libphonenumber Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.i18n.phonenumbers;
+
+import com.android.i18n.phonenumbers.Phonemetadata.PhoneMetadata;
+import com.android.i18n.phonenumbers.Phonemetadata.PhoneMetadataCollection;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Class encapsulating loading of PhoneNumber Metadata information. Currently this is used only for
+ * additional data files such as PhoneNumberAlternateFormats, but in the future it is envisaged it
+ * would handle the main metadata file (PhoneNumberMetaData.xml) as well.
+ *
+ * @author Lara Rennie
+ */
+class MetadataManager {
+ private static final String ALTERNATE_FORMATS_FILE_PREFIX =
+ "/com/android/i18n/phonenumbers/data/PhoneNumberAlternateFormatsProto";
+
+ private static final Logger LOGGER = Logger.getLogger(MetadataManager.class.getName());
+
+ private static final Map<Integer, PhoneMetadata> callingCodeToAlternateFormatsMap =
+ Collections.synchronizedMap(new HashMap<Integer, PhoneMetadata>());
+
+ // A set of which country calling codes there are alternate format data for. If the set has an
+ // entry for a code, then there should be data for that code linked into the resources.
+ private static final Set<Integer> countryCodeSet =
+ AlternateFormatsCountryCodeSet.getCountryCodeSet();
+
+ private MetadataManager() {
+ }
+
+ private static void close(InputStream in) {
+ if (in != null) {
+ try {
+ in.close();
+ } catch (IOException e) {
+ LOGGER.log(Level.WARNING, e.toString());
+ }
+ }
+ }
+
+ private static void loadMetadataFromFile(int countryCallingCode) {
+ InputStream source = PhoneNumberMatcher.class.getResourceAsStream(
+ ALTERNATE_FORMATS_FILE_PREFIX + "_" + countryCallingCode);
+ ObjectInputStream in = null;
+ try {
+ in = new ObjectInputStream(source);
+ PhoneMetadataCollection alternateFormats = new PhoneMetadataCollection();
+ alternateFormats.readExternal(in);
+ for (PhoneMetadata metadata : alternateFormats.getMetadataList()) {
+ callingCodeToAlternateFormatsMap.put(metadata.getCountryCode(), metadata);
+ }
+ } catch (IOException e) {
+ LOGGER.log(Level.WARNING, e.toString());
+ } finally {
+ close(in);
+ }
+ }
+
+ static PhoneMetadata getAlternateFormatsForCountry(int countryCallingCode) {
+ if (!countryCodeSet.contains(countryCallingCode)) {
+ return null;
+ }
+ synchronized (callingCodeToAlternateFormatsMap) {
+ if (!callingCodeToAlternateFormatsMap.containsKey(countryCallingCode)) {
+ loadMetadataFromFile(countryCallingCode);
+ }
+ }
+ return callingCodeToAlternateFormatsMap.get(countryCallingCode);
+ }
+}
diff --git a/java/src/com/android/i18n/phonenumbers/PhoneNumberMatcher.java b/java/src/com/android/i18n/phonenumbers/PhoneNumberMatcher.java
index 911433e..21fea51 100644
--- a/java/src/com/android/i18n/phonenumbers/PhoneNumberMatcher.java
+++ b/java/src/com/android/i18n/phonenumbers/PhoneNumberMatcher.java
@@ -433,7 +433,8 @@
/**
* Small helper interface such that the number groups can be checked according to different
- * criteria.
+ * criteria, both for our default way of performing formatting and for any alternate formats we
+ * may want to check.
*/
interface NumberGroupingChecker {
/**
@@ -553,6 +554,17 @@
if (checker.checkGroups(util, number, normalizedCandidate, formattedNumberGroups)) {
return true;
}
+ // If this didn't pass, see if there are any alternate formats, and try them instead.
+ PhoneMetadata alternateFormats =
+ MetadataManager.getAlternateFormatsForCountry(number.getCountryCode());
+ if (alternateFormats != null) {
+ for (NumberFormat alternateFormat : alternateFormats.numberFormats()) {
+ formattedNumberGroups = getNationalNumberGroups(util, number, alternateFormat);
+ if (checker.checkGroups(util, number, normalizedCandidate, formattedNumberGroups)) {
+ return true;
+ }
+ }
+ }
return false;
}
diff --git a/java/src/com/android/i18n/phonenumbers/PhoneNumberUtil.java b/java/src/com/android/i18n/phonenumbers/PhoneNumberUtil.java
index 581dee3..cea9860 100644
--- a/java/src/com/android/i18n/phonenumbers/PhoneNumberUtil.java
+++ b/java/src/com/android/i18n/phonenumbers/PhoneNumberUtil.java
@@ -265,9 +265,17 @@
// carrier codes, for example in Brazilian phone numbers. We also allow multiple "+" characters at
// the start.
// Corresponds to the following:
+ // [digits]{minLengthNsn}|
// plus_sign*(([punctuation]|[star])*[digits]){3,}([punctuation]|[star]|[digits]|[alpha])*
+ //
+ // The first reg-ex is to allow short numbers (two digits long) to be parsed if they are entered
+ // as "15" etc, but only if there is no punctuation in them. The second expression restricts the
+ // number of digits to three or more, but then allows them to be in international form, and to
+ // have alpha-characters and punctuation.
+ //
// Note VALID_PUNCTUATION starts with a -, so must be the first in the range.
private static final String VALID_PHONE_NUMBER =
+ DIGITS + "{" + MIN_LENGTH_FOR_NSN + "}" + "|" +
"[" + PLUS_CHARS + "]*+(?:[" + VALID_PUNCTUATION + STAR_SIGN + "]*" + DIGITS + "){3,}[" +
VALID_PUNCTUATION + STAR_SIGN + VALID_ALPHA + DIGITS + "]*";
diff --git a/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_882 b/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_882
index 9befe41..a161efd 100644
--- a/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_882
+++ b/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_882
Binary files differ
diff --git a/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_AR b/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_AR
index 1613720..e6e7fbb 100644
--- a/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_AR
+++ b/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_AR
Binary files differ
diff --git a/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_BA b/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_BA
index f7274f0..1a405ec 100644
--- a/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_BA
+++ b/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_BA
Binary files differ
diff --git a/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_BF b/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_BF
index 479d8fc..c3880ea 100644
--- a/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_BF
+++ b/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_BF
Binary files differ
diff --git a/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_CR b/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_CR
index 3803a1a..7f6746e 100644
--- a/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_CR
+++ b/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_CR
Binary files differ
diff --git a/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_DE b/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_DE
index b35d44f..872ea55 100644
--- a/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_DE
+++ b/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_DE
Binary files differ
diff --git a/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_EC b/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_EC
index 67fef12..409cea8 100644
--- a/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_EC
+++ b/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_EC
Binary files differ
diff --git a/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_ES b/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_ES
index d4bc38d..c309a66 100644
--- a/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_ES
+++ b/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_ES
Binary files differ
diff --git a/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_GA b/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_GA
index fb204d0..1b49771 100644
--- a/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_GA
+++ b/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_GA
Binary files differ
diff --git a/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_GB b/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_GB
index 5be977b..e6d3b8f 100644
--- a/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_GB
+++ b/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_GB
Binary files differ
diff --git a/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_IL b/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_IL
index 9419291..b01451a 100644
--- a/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_IL
+++ b/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_IL
Binary files differ
diff --git a/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_MK b/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_MK
index c84ddd7..310f43b 100644
--- a/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_MK
+++ b/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_MK
Binary files differ
diff --git a/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_NC b/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_NC
index 7b237ff..8404529 100644
--- a/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_NC
+++ b/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_NC
Binary files differ
diff --git a/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_NG b/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_NG
index ea25d06..d3a53ac 100644
--- a/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_NG
+++ b/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_NG
Binary files differ
diff --git a/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_PF b/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_PF
index 825dca4..6990570 100644
--- a/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_PF
+++ b/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_PF
Binary files differ
diff --git a/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_SB b/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_SB
index 605df51..579e741 100644
--- a/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_SB
+++ b/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_SB
Binary files differ
diff --git a/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_UZ b/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_UZ
index 020ad53..a1816d9 100644
--- a/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_UZ
+++ b/java/src/com/android/i18n/phonenumbers/data/PhoneNumberMetadataProto_UZ
Binary files differ
diff --git a/java/src/com/android/i18n/phonenumbers/geocoding/data/234_en b/java/src/com/android/i18n/phonenumbers/geocoding/data/234_en
new file mode 100644
index 0000000..da1af17
--- /dev/null
+++ b/java/src/com/android/i18n/phonenumbers/geocoding/data/234_en
Binary files differ
diff --git a/java/src/com/android/i18n/phonenumbers/geocoding/data/54_en b/java/src/com/android/i18n/phonenumbers/geocoding/data/54_en
index 354bd2e..be1c258 100644
--- a/java/src/com/android/i18n/phonenumbers/geocoding/data/54_en
+++ b/java/src/com/android/i18n/phonenumbers/geocoding/data/54_en
Binary files differ
diff --git a/java/src/com/android/i18n/phonenumbers/geocoding/data/54_es b/java/src/com/android/i18n/phonenumbers/geocoding/data/54_es
index 7523b6c..afd958b 100644
--- a/java/src/com/android/i18n/phonenumbers/geocoding/data/54_es
+++ b/java/src/com/android/i18n/phonenumbers/geocoding/data/54_es
Binary files differ
diff --git a/java/src/com/android/i18n/phonenumbers/geocoding/data/81_en b/java/src/com/android/i18n/phonenumbers/geocoding/data/81_en
index f9d096f..bb2776f 100644
--- a/java/src/com/android/i18n/phonenumbers/geocoding/data/81_en
+++ b/java/src/com/android/i18n/phonenumbers/geocoding/data/81_en
Binary files differ
diff --git a/java/src/com/android/i18n/phonenumbers/geocoding/data/config b/java/src/com/android/i18n/phonenumbers/geocoding/data/config
index 181a1e2..9c46be3 100644
--- a/java/src/com/android/i18n/phonenumbers/geocoding/data/config
+++ b/java/src/com/android/i18n/phonenumbers/geocoding/data/config
Binary files differ
diff --git a/java/test/com/android/i18n/phonenumbers/MetadataManagerTest.java b/java/test/com/android/i18n/phonenumbers/MetadataManagerTest.java
new file mode 100644
index 0000000..8017879
--- /dev/null
+++ b/java/test/com/android/i18n/phonenumbers/MetadataManagerTest.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2012 The Libphonenumber Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.i18n.phonenumbers;
+
+import com.android.i18n.phonenumbers.Phonemetadata.PhoneMetadata;
+
+import junit.framework.TestCase;
+
+/**
+ * Some basic tests to check that the phone number metadata can be correctly loaded.
+ *
+ * @author Lara Rennie
+ */
+public class MetadataManagerTest extends TestCase {
+
+ public void testAlternateFormatsContainsData() throws Exception {
+ // We should have some data for Germany.
+ PhoneMetadata germanyAlternateFormats = MetadataManager.getAlternateFormatsForCountry(49);
+ assertNotNull(germanyAlternateFormats);
+ assertTrue(germanyAlternateFormats.numberFormats().size() > 0);
+ }
+
+ public void testAlternateFormatsFailsGracefully() throws Exception {
+ PhoneMetadata noAlternateFormats = MetadataManager.getAlternateFormatsForCountry(999);
+ assertNull(noAlternateFormats);
+ }
+}
diff --git a/java/test/com/android/i18n/phonenumbers/PhoneNumberMatcherTest.java b/java/test/com/android/i18n/phonenumbers/PhoneNumberMatcherTest.java
index 22afc71..e7f1a06 100644
--- a/java/test/com/android/i18n/phonenumbers/PhoneNumberMatcherTest.java
+++ b/java/test/com/android/i18n/phonenumbers/PhoneNumberMatcherTest.java
@@ -400,7 +400,12 @@
new NumberTest("\uFF14\uFF11\uFF15\uFF16\uFF16\uFF16\uFF16-\uFF17\uFF17\uFF17", RegionCode.US),
new NumberTest("2012-0102 08", RegionCode.US), // Very strange formatting.
new NumberTest("2012-01-02 08", RegionCode.US),
- new NumberTest("1800-10-10 22", RegionCode.AU), // Breakdown assistance number.
+ // Breakdown assistance number with unexpected formatting.
+ new NumberTest("1800-1-0-10 22", RegionCode.AU),
+ new NumberTest("030-3-2 23 12 34", RegionCode.DE),
+ new NumberTest("03 0 -3 2 23 12 34", RegionCode.DE),
+ new NumberTest("(0)3 0 -3 2 23 12 34", RegionCode.DE),
+ new NumberTest("0 3 0 -3 2 23 12 34", RegionCode.DE),
};
/**
@@ -413,6 +418,11 @@
// Should be found by strict grouping but not exact grouping, as the last two groups are
// formatted together as a block.
new NumberTest("0800-2491234", RegionCode.DE),
+ // Doesn't match any formatting in the test file, but almost matches an alternate format (the
+ // last two groups have been squashed together here).
+ new NumberTest("0900-1 123123", RegionCode.DE),
+ new NumberTest("(0)900-1 123123", RegionCode.DE),
+ new NumberTest("0 900-1 123123", RegionCode.DE),
};
/**
@@ -439,6 +449,11 @@
new NumberTest("0494949 ext. 49", RegionCode.DE),
new NumberTest("01 (33) 3461 2234", RegionCode.MX), // Optional NP present
new NumberTest("(33) 3461 2234", RegionCode.MX), // Optional NP omitted
+ new NumberTest("1800-10-10 22", RegionCode.AU), // Breakdown assistance number.
+ // Doesn't match any formatting in the test file, but matches an alternate format exactly.
+ new NumberTest("0900-1 123 123", RegionCode.DE),
+ new NumberTest("(0)900-1 123 123", RegionCode.DE),
+ new NumberTest("0 900-1 123 123", RegionCode.DE),
};
public void testMatchesWithPossibleLeniency() throws Exception {
@@ -863,7 +878,7 @@
contextPairs.add(new NumberContext("It's cheap! Call ", " before 6:30"));
// With a second number later.
contextPairs.add(new NumberContext("Call ", " or +1800-123-4567!"));
- contextPairs.add(new NumberContext("Call me on June 21 at", "")); // with a Month-Day date
+ contextPairs.add(new NumberContext("Call me on June 2 at", "")); // with a Month-Day date
// With publication pages.
contextPairs.add(new NumberContext(
"As quoted by Alfonso 12-15 (2009), you may call me at ", ""));
diff --git a/java/test/com/android/i18n/phonenumbers/PhoneNumberUtilTest.java b/java/test/com/android/i18n/phonenumbers/PhoneNumberUtilTest.java
index 6f39d82..8c3e57f 100644
--- a/java/test/com/android/i18n/phonenumbers/PhoneNumberUtilTest.java
+++ b/java/test/com/android/i18n/phonenumbers/PhoneNumberUtilTest.java
@@ -1256,16 +1256,20 @@
}
public void testIsViablePhoneNumber() {
+ assertFalse(PhoneNumberUtil.isViablePhoneNumber("1"));
// Only one or two digits before strange non-possible punctuation.
- assertFalse(PhoneNumberUtil.isViablePhoneNumber("12. March"));
assertFalse(PhoneNumberUtil.isViablePhoneNumber("1+1+1"));
assertFalse(PhoneNumberUtil.isViablePhoneNumber("80+0"));
- assertFalse(PhoneNumberUtil.isViablePhoneNumber("00"));
- // Three digits is viable.
+ // Two digits is viable.
+ assertTrue(PhoneNumberUtil.isViablePhoneNumber("00"));
assertTrue(PhoneNumberUtil.isViablePhoneNumber("111"));
// Alpha numbers.
assertTrue(PhoneNumberUtil.isViablePhoneNumber("0800-4-pizza"));
assertTrue(PhoneNumberUtil.isViablePhoneNumber("0800-4-PIZZA"));
+ // We need at least three digits before any alpha characters.
+ assertFalse(PhoneNumberUtil.isViablePhoneNumber("08-PIZZA"));
+ assertFalse(PhoneNumberUtil.isViablePhoneNumber("8-PIZZA"));
+ assertFalse(PhoneNumberUtil.isViablePhoneNumber("12. March"));
}
public void testIsViablePhoneNumberNonAscii() {
@@ -1600,6 +1604,10 @@
// Test star numbers. Although this is not strictly valid, we would like to make sure we can
// parse the output we produce when formatting the number.
assertEquals(JP_STAR_NUMBER, phoneUtil.parse("+81 *2345", RegionCode.JP));
+
+ PhoneNumber shortNumber = new PhoneNumber();
+ shortNumber.setCountryCode(64).setNationalNumber(12L);
+ assertEquals(shortNumber, phoneUtil.parse("12", RegionCode.NZ));
}
public void testParseNumberWithAlphaCharacters() throws Exception {
@@ -1766,6 +1774,36 @@
e.getErrorType());
}
try {
+ String sentencePhoneNumber = "1 Still not a number";
+ phoneUtil.parse(sentencePhoneNumber, RegionCode.NZ);
+ fail("This should not parse without throwing an exception " + sentencePhoneNumber);
+ } catch (NumberParseException e) {
+ // Expected this exception.
+ assertEquals("Wrong error type stored in exception.",
+ NumberParseException.ErrorType.NOT_A_NUMBER,
+ e.getErrorType());
+ }
+ try {
+ String sentencePhoneNumber = "1 MICROSOFT";
+ phoneUtil.parse(sentencePhoneNumber, RegionCode.NZ);
+ fail("This should not parse without throwing an exception " + sentencePhoneNumber);
+ } catch (NumberParseException e) {
+ // Expected this exception.
+ assertEquals("Wrong error type stored in exception.",
+ NumberParseException.ErrorType.NOT_A_NUMBER,
+ e.getErrorType());
+ }
+ try {
+ String sentencePhoneNumber = "12 MICROSOFT";
+ phoneUtil.parse(sentencePhoneNumber, RegionCode.NZ);
+ fail("This should not parse without throwing an exception " + sentencePhoneNumber);
+ } catch (NumberParseException e) {
+ // Expected this exception.
+ assertEquals("Wrong error type stored in exception.",
+ NumberParseException.ErrorType.NOT_A_NUMBER,
+ e.getErrorType());
+ }
+ try {
String tooLongPhoneNumber = "01495 72553301873 810104";
phoneUtil.parse(tooLongPhoneNumber, RegionCode.GB);
fail("This should not parse without throwing an exception " + tooLongPhoneNumber);
@@ -2209,7 +2247,7 @@
// Invalid numbers that can't be parsed.
assertEquals(PhoneNumberUtil.MatchType.NOT_A_NUMBER,
- phoneUtil.isNumberMatch("43", "3 331 6043"));
+ phoneUtil.isNumberMatch("4", "3 331 6043"));
assertEquals(PhoneNumberUtil.MatchType.NOT_A_NUMBER,
phoneUtil.isNumberMatch("+43", "+64 3 331 6005"));
assertEquals(PhoneNumberUtil.MatchType.NOT_A_NUMBER,
@@ -2321,7 +2359,10 @@
assertTrue(phoneUtil.isAlphaNumber("1800 six-flags"));
assertTrue(phoneUtil.isAlphaNumber("1800 six-flags ext. 1234"));
assertTrue(phoneUtil.isAlphaNumber("+800 six-flags"));
+ assertTrue(phoneUtil.isAlphaNumber("180 six-flags"));
assertFalse(phoneUtil.isAlphaNumber("1800 123-1234"));
+ assertFalse(phoneUtil.isAlphaNumber("1 six-flags"));
+ assertFalse(phoneUtil.isAlphaNumber("18 six-flags"));
assertFalse(phoneUtil.isAlphaNumber("1800 123-1234 extension: 1234"));
assertFalse(phoneUtil.isAlphaNumber("+800 1234-1234"));
}