Browse Source

Metadata update, UAN code support and isNumberMatch changes.

pull/567/head
Lara Scheidegger 15 years ago
committed by Mihaela Rosca
parent
commit
b48ba18623
261 changed files with 1776 additions and 405 deletions
  1. +15
    -0
      java/release_notes.txt
  2. +7
    -4
      java/resources/com/google/i18n/phonenumbers/BuildMetadataFromXml.java
  3. +4
    -0
      java/resources/com/google/i18n/phonenumbers/proto/phonemetadata.proto
  4. +1476
    -359
      java/resources/com/google/i18n/phonenumbers/src/PhoneNumberMetaData.xml
  5. +10
    -2
      java/resources/com/google/i18n/phonenumbers/test/PhoneNumberMetaDataForTesting.xml
  6. +124
    -36
      java/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java
  7. +48
    -0
      java/src/com/google/i18n/phonenumbers/Phonemetadata.java
  8. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AD
  9. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AE
  10. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AF
  11. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AG
  12. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AI
  13. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AL
  14. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AM
  15. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AN
  16. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AO
  17. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AR
  18. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AS
  19. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AT
  20. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AU
  21. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AW
  22. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AZ
  23. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BA
  24. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BB
  25. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BD
  26. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BE
  27. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BF
  28. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BG
  29. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BH
  30. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BI
  31. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BJ
  32. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BL
  33. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BM
  34. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BN
  35. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BO
  36. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BR
  37. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BS
  38. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BT
  39. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BW
  40. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BY
  41. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BZ
  42. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CA
  43. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CD
  44. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CF
  45. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CG
  46. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CH
  47. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CI
  48. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CK
  49. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CL
  50. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CM
  51. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CN
  52. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CO
  53. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CR
  54. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CU
  55. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CV
  56. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CY
  57. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CZ
  58. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_DE
  59. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_DJ
  60. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_DK
  61. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_DM
  62. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_DO
  63. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_DZ
  64. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_EC
  65. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_EE
  66. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_EG
  67. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_ER
  68. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_ES
  69. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_ET
  70. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_FI
  71. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_FJ
  72. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_FK
  73. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_FM
  74. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_FO
  75. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_FR
  76. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GA
  77. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GB
  78. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GD
  79. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GE
  80. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GF
  81. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GG
  82. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GH
  83. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GI
  84. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GL
  85. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GM
  86. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GN
  87. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GP
  88. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GQ
  89. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GR
  90. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GT
  91. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GU
  92. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GW
  93. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GY
  94. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_HK
  95. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_HN
  96. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_HR
  97. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_HT
  98. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_HU
  99. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_ID
  100. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_IE

+ 15
- 0
java/release_notes.txt View File

@ -1,3 +1,18 @@
Feb 9th, 2011
* Code changes:
- Better isNumberMatch method. This will now recognise numbers starting with a national prefix as
an NSN_MATCH, instead of SHORT_NSN_MATCH.
== Note Non-backwards-compatible API change here! ==
This will no longer throw a NumberParseException - instead we will return NOT_A_NUMBER if one
or other of the numbers provided do not match.
- New number-type UAN now supported in the code. This represents Company Numbers or Universally
Accessible Numbers.
* Metadata changes:
- Bug-fixes and updates for the following countries: AG, AZ, BA, BE, CA, CU, ES, FI, GB, GD, GG,
IE, IL, IM, IN, IR, IT, JE, JP, KR, KW, NG, NZ, PK, PS, PT, RU, SE, SG, SY, US
- New countries: CO, LU, LY, MC, SM
- Addition of "Personal Number" ranges to all NANPA countries
Jan 31st, 2011
* Code changes:
- Introducing equals() and hashCode() methods for the Phonenumber.PhoneNumber class


+ 7
- 4
java/resources/com/google/i18n/phonenumbers/BuildMetadataFromXml.java View File

@ -138,7 +138,7 @@ public class BuildMetadataFromXml {
nationalPrefix = element.getAttribute("nationalPrefix");
metadata.setNationalPrefix(nationalPrefix);
nationalPrefixFormattingRule =
validateRE(getNationalPrefixFormattingRuleFromElement(element, nationalPrefix));
getNationalPrefixFormattingRuleFromElement(element, nationalPrefix);
if (!metadata.hasNationalPrefixForParsing()) {
metadata.setNationalPrefixForParsing(nationalPrefix);
@ -159,8 +159,8 @@ public class BuildMetadataFromXml {
Element numberFormatElement = (Element) numberFormatElements.item(i);
NumberFormat format = new NumberFormat();
if (numberFormatElement.hasAttribute("nationalPrefixFormattingRule")) {
format.setNationalPrefixFormattingRule(validateRE(
getNationalPrefixFormattingRuleFromElement(numberFormatElement, nationalPrefix)));
format.setNationalPrefixFormattingRule(
getNationalPrefixFormattingRuleFromElement(numberFormatElement, nationalPrefix));
} else {
format.setNationalPrefixFormattingRule(nationalPrefixFormattingRule);
}
@ -180,7 +180,7 @@ public class BuildMetadataFromXml {
throw new RuntimeException("Invalid number of format patterns for country: " +
regionCode);
}
format.setFormat(validateRE(formatPattern.item(0).getFirstChild().getNodeValue()));
format.setFormat(formatPattern.item(0).getFirstChild().getNodeValue());
metadata.addNumberFormat(format);
}
}
@ -224,6 +224,9 @@ public class BuildMetadataFromXml {
metadata.setPersonalNumber(processPhoneNumberDescElement(generalDesc, element,
"personalNumber"));
metadata.setPager(processPhoneNumberDescElement(generalDesc, element, "pager"));
metadata.setUan(processPhoneNumberDescElement(generalDesc, element, "uan"));
metadata.setNoInternationalDialling(processPhoneNumberDescElement(generalDesc, element,
"noInternationalDialling"));
if (metadata.getMobile().getNationalNumberPattern().equals(
metadata.getFixedLine().getNationalNumberPattern())) {


+ 4
- 0
java/resources/com/google/i18n/phonenumbers/proto/phonemetadata.proto View File

@ -118,6 +118,10 @@ message PhoneMetadata {
required PhoneNumberDesc personal_number = 7;
required PhoneNumberDesc voip = 8;
required PhoneNumberDesc pager = 21;
required PhoneNumberDesc uan = 25;
// The rules here distinguish the numbers that are only able to be dialled
// nationally.
required PhoneNumberDesc no_international_dialling = 24;
// The ISO 3166-1 alpha-2 representation of a country/region
required string id = 9;


+ 1476
- 359
java/resources/com/google/i18n/phonenumbers/src/PhoneNumberMetaData.xml
File diff suppressed because it is too large
View File


+ 10
- 2
java/resources/com/google/i18n/phonenumbers/test/PhoneNumberMetaDataForTesting.xml View File

@ -558,7 +558,10 @@
</numberFormat>
</availableFormats>
<generalDesc>
<nationalNumberPattern>[2-9]\d{7,9}</nationalNumberPattern>
<nationalNumberPattern>
[289]\d{7,9}|
[3-7]\d{7}
</nationalNumberPattern>
<possibleNumberPattern>\d{7,10}</possibleNumberPattern>
</generalDesc>
<fixedLine>
@ -702,8 +705,13 @@
<possibleNumberPattern>\d{7,10}</possibleNumberPattern>
<exampleNumber>1234567890</exampleNumber>
</generalDesc>
<noInternationalDialling>
<!-- This range is added for testing purposes only. -->
<nationalNumberPattern>800\d{7}</nationalNumberPattern>
<possibleNumberPattern>\d{10}</possibleNumberPattern>
</noInternationalDialling>
<tollFree>
<nationalNumberPattern>8(00|66|77|88)\d{7}</nationalNumberPattern>
<nationalNumberPattern>8(?:00|66|77|88)\d{7}</nationalNumberPattern>
<possibleNumberPattern>\d{10}</possibleNumberPattern>
</tollFree>
<premiumRate>


+ 124
- 36
java/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java View File

@ -47,9 +47,13 @@ import java.util.regex.Pattern;
* @author Lara Rennie
*/
public class PhoneNumberUtil {
/** Flags to use when compiling regular expressions for phone numbers. */
static final int REGEX_FLAGS = Pattern.UNICODE_CASE | Pattern.CASE_INSENSITIVE;
// The minimum and maximum length of the national significant number.
private static final int MIN_LENGTH_FOR_NSN = 3;
private static final int MAX_LENGTH_FOR_NSN = 15;
static final int MAX_LENGTH_FOR_NSN = 15;
// The maximum length of the country code.
static final int MAX_LENGTH_COUNTRY_CODE = 3;
static final String META_DATA_FILE_PREFIX =
"/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto";
static final String COUNTRY_CODE_TO_REGION_CODE_MAP_CLASS_NAME =
@ -68,6 +72,8 @@ public class PhoneNumberUtil {
// load factor of roughly 0.75.
private final Set<String> supportedCountries = new HashSet<String>(300);
// Region-code for the unknown region.
private static final String UNKNOWN_REGION = "ZZ";
// The set of countries that share country code 1.
// There are roughly 26 countries of them and we set the initial capacity of the HashSet to 35
@ -94,33 +100,43 @@ public class PhoneNumberUtil {
digitMap.put('0', '0');
digitMap.put('\uFF10', '0'); // Fullwidth digit 0
digitMap.put('\u0660', '0'); // Arabic-indic digit 0
digitMap.put('\u06F0', '0'); // Eastern-Arabic digit 0
digitMap.put('1', '1');
digitMap.put('\uFF11', '1'); // Fullwidth digit 1
digitMap.put('\u0661', '1'); // Arabic-indic digit 1
digitMap.put('\u06F1', '1'); // Eastern-Arabic digit 1
digitMap.put('2', '2');
digitMap.put('\uFF12', '2'); // Fullwidth digit 2
digitMap.put('\u0662', '2'); // Arabic-indic digit 2
digitMap.put('\u06F2', '2'); // Eastern-Arabic digit 2
digitMap.put('3', '3');
digitMap.put('\uFF13', '3'); // Fullwidth digit 3
digitMap.put('\u0663', '3'); // Arabic-indic digit 3
digitMap.put('\u06F3', '3'); // Eastern-Arabic digit 3
digitMap.put('4', '4');
digitMap.put('\uFF14', '4'); // Fullwidth digit 4
digitMap.put('\u0664', '4'); // Arabic-indic digit 4
digitMap.put('\u06F4', '4'); // Eastern-Arabic digit 4
digitMap.put('5', '5');
digitMap.put('\uFF15', '5'); // Fullwidth digit 5
digitMap.put('\u0665', '5'); // Arabic-indic digit 5
digitMap.put('\u06F5', '5'); // Eastern-Arabic digit 5
digitMap.put('6', '6');
digitMap.put('\uFF16', '6'); // Fullwidth digit 6
digitMap.put('\u0666', '6'); // Arabic-indic digit 6
digitMap.put('\u06F6', '6'); // Eastern-Arabic digit 6
digitMap.put('7', '7');
digitMap.put('\uFF17', '7'); // Fullwidth digit 7
digitMap.put('\u0667', '7'); // Arabic-indic digit 7
digitMap.put('\u06F7', '7'); // Eastern-Arabic digit 7
digitMap.put('8', '8');
digitMap.put('\uFF18', '8'); // Fullwidth digit 8
digitMap.put('\u0668', '8'); // Arabic-indic digit 8
digitMap.put('\u06F8', '8'); // Eastern-Arabic digit 8
digitMap.put('9', '9');
digitMap.put('\uFF19', '9'); // Fullwidth digit 9
digitMap.put('\u0669', '9'); // Arabic-indic digit 9
digitMap.put('\u06F9', '9'); // Eastern-Arabic digit 9
DIGIT_MAPPINGS = Collections.unmodifiableMap(digitMap);
HashMap<Character, Character> alphaMap = new HashMap<Character, Character>(40);
@ -171,6 +187,7 @@ public class PhoneNumberUtil {
aSet.add(241); // Gabon
aSet.add(242); // Congo (Rep. of the)
aSet.add(268); // Swaziland
aSet.add(378); // San Marino
aSet.add(379); // Vatican City
aSet.add(501); // Belize
LEADING_ZERO_COUNTRIES = Collections.unmodifiableSet(aSet);
@ -190,17 +207,17 @@ 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\u30FC\uFF0D-\uFF0F " +
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
// Digits accepted in phone numbers that we understand.
private static final String VALID_DIGITS =
Arrays.toString(DIGIT_MAPPINGS.keySet().toArray()).replaceAll(", ", "");
Arrays.toString(DIGIT_MAPPINGS.keySet().toArray()).replaceAll("[, \\[\\]]", "");
// We accept alpha characters in phone numbers, ASCII only, upper and lower case.
private static final String VALID_ALPHA =
Arrays.toString(ALPHA_MAPPINGS.keySet().toArray()).replaceAll(", ", "") +
Arrays.toString(ALPHA_MAPPINGS.keySet().toArray()).toLowerCase().replaceAll(", ", "");
private static final String PLUS_CHARS = "+\uFF0B";
Arrays.toString(ALPHA_MAPPINGS.keySet().toArray()).replaceAll("[, \\[\\]]", "") +
Arrays.toString(ALPHA_MAPPINGS.keySet().toArray()).toLowerCase().replaceAll("[, \\[\\]]", "");
static final String PLUS_CHARS = "+\uFF0B";
private static final Pattern PLUS_CHARS_PATTERN = Pattern.compile("[" + PLUS_CHARS + "]+");
private static final Pattern CAPTURING_DIGIT_PATTERN =
Pattern.compile("([" + VALID_DIGITS + "])");
@ -220,7 +237,7 @@ public class PhoneNumberUtil {
// actually two phone numbers, (530) 583-6985 x302 and (530) 583-6985 x2303. We remove the second
// extension so that the first number is parsed correctly.
private static final String SECOND_NUMBER_START = "[\\\\/] *x";
private static final Pattern SECOND_NUMBER_START_PATTERN = Pattern.compile(SECOND_NUMBER_START);
static final Pattern SECOND_NUMBER_START_PATTERN = Pattern.compile(SECOND_NUMBER_START);
// Regular expression of trailing characters that we want to remove. We remove all characters that
// are not alpha or numerical characters. The hash character is retained here, as it may signify
@ -240,9 +257,10 @@ public class PhoneNumberUtil {
// the start.
// Corresponds to the following:
// plus_sign*([punctuation]*[digits]){3,}([punctuation]|[digits]|[alpha])*
// Note VALID_PUNCTUATION starts with a -, so must be the first in the range.
private static final String VALID_PHONE_NUMBER =
"[" + PLUS_CHARS + "]*(?:[" + VALID_PUNCTUATION + "]*[" + VALID_DIGITS + "]){3,}[" +
VALID_ALPHA + VALID_PUNCTUATION + VALID_DIGITS + "]*";
VALID_PUNCTUATION + VALID_ALPHA + VALID_DIGITS + "]*";
// Default extension prefix to use when formatting. This will be put in front of any extension
// component of the number, after the main national number is formatted. For example, if you wish
@ -261,7 +279,7 @@ public class PhoneNumberUtil {
// Canonical-equivalence doesn't seem to be an option with Android java, so we allow two options
// for representing the accented o - the character itself, and one in the unicode decomposed form
// with the combining acute accent.
private static final String KNOWN_EXTN_PATTERNS = "[ \u00A0\\t,]*" +
static final String KNOWN_EXTN_PATTERNS = "[ \u00A0\\t,]*" +
"(?:ext(?:ensi(?:o\u0301?|\u00F3))?n?|" +
"\uFF45\uFF58\uFF54\uFF4E?|[,x\uFF58#\uFF03~\uFF5E]|int|anexo|\uFF49\uFF4E\uFF54)" +
"[:\\.\uFF0E]?[ \u00A0\\t,-]*([" + VALID_DIGITS + "]{1,7})#?|[- ]+([" + VALID_DIGITS +
@ -270,14 +288,12 @@ public class PhoneNumberUtil {
// Regexp of all known extension prefixes used by different countries followed by 1 or more valid
// digits, for use when parsing.
private static final Pattern EXTN_PATTERN =
Pattern.compile("(?:" + KNOWN_EXTN_PATTERNS + ")$",
Pattern.UNICODE_CASE | Pattern.CASE_INSENSITIVE);
Pattern.compile("(?:" + KNOWN_EXTN_PATTERNS + ")$", REGEX_FLAGS);
// 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.compile(VALID_PHONE_NUMBER + "(?:" + KNOWN_EXTN_PATTERNS + ")?", REGEX_FLAGS);
private static final Pattern NON_DIGITS_PATTERN = Pattern.compile("(\\D+)");
private static final Pattern FIRST_GROUP_PATTERN = Pattern.compile("(\\$1)");
@ -334,6 +350,9 @@ public class PhoneNumberUtil {
// http://en.wikipedia.org/wiki/Personal_Numbers
PERSONAL_NUMBER,
PAGER,
// Used for "Universal Access Numbers" or "Company Numbers". They may be further routed to
// specific offices, but allow one number to be used for a company.
UAN,
// A phone number is of type UNKNOWN when it does not fit any of the known patterns for a
// specific country.
UNKNOWN
@ -343,6 +362,7 @@ public class PhoneNumberUtil {
* Types of phone number matches. See detailed description beside the isNumberMatch() method.
*/
public enum MatchType {
NOT_A_NUMBER,
NO_MATCH,
SHORT_NSN_MATCH,
NSN_MATCH,
@ -1120,6 +1140,8 @@ public class PhoneNumberUtil {
return metadata.getPersonalNumber();
case PAGER:
return metadata.getPager();
case UAN:
return metadata.getUan();
default:
return metadata.getGeneralDesc();
}
@ -1165,6 +1187,9 @@ public class PhoneNumberUtil {
if (isNumberMatchingDesc(nationalNumber, metadata.getPager())) {
return PhoneNumberType.PAGER;
}
if (isNumberMatchingDesc(nationalNumber, metadata.getUan())) {
return PhoneNumberType.UAN;
}
boolean isFixedLine = isNumberMatchingDesc(nationalNumber, metadata.getFixedLine());
if (isFixedLine) {
@ -1294,7 +1319,7 @@ public class PhoneNumberUtil {
*/
public String getRegionCodeForCountryCode(int countryCode) {
List<String> regionCodes = countryCodeToRegionCodeMap.get(countryCode);
return regionCodes == null ? "ZZ" : regionCodes.get(0);
return regionCodes == null ? UNKNOWN_REGION : regionCodes.get(0);
}
/**
@ -1509,7 +1534,7 @@ public class PhoneNumberUtil {
int extractCountryCode(StringBuffer fullNumber, StringBuffer nationalNumber) {
int potentialCountryCode;
int numberLength = fullNumber.length();
for (int i = 1; i <= 3 && i <= numberLength; i++) {
for (int i = 1; i <= MAX_LENGTH_COUNTRY_CODE && i <= numberLength; i++) {
potentialCountryCode = Integer.parseInt(fullNumber.substring(0, i));
if (countryCodeToRegionCodeMap.containsKey(potentialCountryCode)) {
nationalNumber.append(fullNumber.substring(i));
@ -2025,18 +2050,35 @@ public class PhoneNumberUtil {
* specified with + at the start.
* @param secondNumber second number to compare. Can contain formatting, and can have country
* code specified with + at the start.
* @return NO_MATCH, SHORT_NSN_MATCH, NSN_MATCH, EXACT_MATCH. See isNumberMatch(PhoneNumber
* firstNumber, PhoneNumber secondNumber) for more details.
* @throws NumberParseException if either number is not considered to be a viable phone
* number
* @return NOT_A_NUMBER, NO_MATCH, SHORT_NSN_MATCH, NSN_MATCH, EXACT_MATCH. See
* isNumberMatch(PhoneNumber firstNumber, PhoneNumber secondNumber) for more details.
*/
public MatchType isNumberMatch(String firstNumber, String secondNumber)
throws NumberParseException {
PhoneNumber number1 = new PhoneNumber();
parseHelper(firstNumber, null, false, false, number1);
PhoneNumber number2 = new PhoneNumber();
parseHelper(secondNumber, null, false, false, number2);
return isNumberMatch(number1, number2);
public MatchType isNumberMatch(String firstNumber, String secondNumber) {
try {
PhoneNumber firstNumberAsProto = parse(firstNumber, UNKNOWN_REGION);
return isNumberMatch(firstNumberAsProto, secondNumber);
} catch (NumberParseException e) {
if (e.getErrorType() == NumberParseException.ErrorType.INVALID_COUNTRY_CODE) {
try {
PhoneNumber secondNumberAsProto = parse(secondNumber, UNKNOWN_REGION);
return isNumberMatch(secondNumberAsProto, firstNumber);
} catch (NumberParseException e2) {
if (e2.getErrorType() == NumberParseException.ErrorType.INVALID_COUNTRY_CODE) {
try {
PhoneNumber firstNumberProto = new PhoneNumber();
PhoneNumber secondNumberProto = new PhoneNumber();
parseHelper(firstNumber, null, false, false, firstNumberProto);
parseHelper(secondNumber, null, false, false, secondNumberProto);
return isNumberMatch(firstNumberProto, secondNumberProto);
} catch (NumberParseException e3) {
// Fall through and return MatchType.NOT_A_NUMBER.
}
}
}
}
}
// One or more of the phone numbers we are trying to match is not a viable phone number.
return MatchType.NOT_A_NUMBER;
}
/**
@ -2046,15 +2088,61 @@ public class PhoneNumberUtil {
* @param firstNumber first number to compare in proto buffer format.
* @param secondNumber second number to compare. Can contain formatting, and can have country
* code specified with + at the start.
* @return NO_MATCH, SHORT_NSN_MATCH, NSN_MATCH, EXACT_MATCH. See isNumberMatch(PhoneNumber
* firstNumber, PhoneNumber secondNumber) for more details.
* @throws NumberParseException if the second number is not considered to be a viable phone
* number
* @return NOT_A_NUMBER, NO_MATCH, SHORT_NSN_MATCH, NSN_MATCH, EXACT_MATCH. See
* isNumberMatch(PhoneNumber firstNumber, PhoneNumber secondNumber) for more details.
*/
public MatchType isNumberMatch(PhoneNumber firstNumber, String secondNumber)
throws NumberParseException {
PhoneNumber number2 = new PhoneNumber();
parseHelper(secondNumber, null, false, false, number2);
return isNumberMatch(firstNumber, number2);
public MatchType isNumberMatch(PhoneNumber firstNumber, String secondNumber) {
// First see if the second number has an implicit country code, by attempting to parse it.
try {
PhoneNumber secondNumberAsProto = parse(secondNumber, UNKNOWN_REGION);
return isNumberMatch(firstNumber, secondNumberAsProto);
} catch (NumberParseException e) {
if (e.getErrorType() == NumberParseException.ErrorType.INVALID_COUNTRY_CODE) {
// The second number has no country code. EXACT_MATCH is no longer possible.
// We parse it as if the region was the same as that for the first number, and if
// EXACT_MATCH is returned, we replace this with NSN_MATCH.
String firstNumberRegion = getRegionCodeForCountryCode(firstNumber.getCountryCode());
try {
if (!firstNumberRegion.equals(UNKNOWN_REGION)) {
PhoneNumber secondNumberWithFirstNumberRegion = parse(secondNumber, firstNumberRegion);
MatchType match = isNumberMatch(firstNumber, secondNumberWithFirstNumberRegion);
if (match == MatchType.EXACT_MATCH) {
return MatchType.NSN_MATCH;
}
return match;
} else {
// If the first number didn't have a valid country code, then we parse the second number
// without one as well.
PhoneNumber secondNumberProto = new PhoneNumber();
parseHelper(secondNumber, null, false, false, secondNumberProto);
return isNumberMatch(firstNumber, secondNumberProto);
}
} catch (NumberParseException e2) {
// Fall-through to return NOT_A_NUMBER.
}
}
}
// One or more of the phone numbers we are trying to match is not a viable phone number.
return MatchType.NOT_A_NUMBER;
}
/**
* Returns true if the number can only be dialled from within the country. If unknown, or the
* number can be dialled from outside the country as well, returns false. Does not check the
* number is a valid number.
* TODO: Make this method public when we have enough metadata to make it worthwhile. Currently
* visible for testing purposes only.
*
* @param number the phone-number for which we want to know whether it is only diallable from
* within the country
*/
boolean canBeInternationallyDialled(PhoneNumber number) {
String regionCode = getRegionCodeForNumber(number);
String nationalSignificantNumber = getNationalSignificantNumber(number);
if (!isValidRegionCode(regionCode)) {
return true;
}
PhoneMetadata metadata = getMetadataForRegion(regionCode);
return !isNumberMatchingDesc(nationalSignificantNumber, metadata.getNoInternationalDialling());
}
}

+ 48
- 0
java/src/com/google/i18n/phonenumbers/Phonemetadata.java View File

@ -374,6 +374,34 @@ public final class Phonemetadata {
return this;
}
// required PhoneNumberDesc uan = 25;
private boolean hasUan;
private PhoneNumberDesc uan_ = null;
public boolean hasUan() { return hasUan; }
public PhoneNumberDesc getUan() { return uan_; }
public PhoneMetadata setUan(PhoneNumberDesc value) {
if (value == null) {
throw new NullPointerException();
}
hasUan = true;
uan_ = value;
return this;
}
// required PhoneNumberDesc noInternationalDialling = 24;
private boolean hasNoInternationalDialling;
private PhoneNumberDesc noInternationalDialling_ = null;
public boolean hasNoInternationalDialling() { return hasNoInternationalDialling; }
public PhoneNumberDesc getNoInternationalDialling() { return noInternationalDialling_; }
public PhoneMetadata setNoInternationalDialling(PhoneNumberDesc value) {
if (value == null) {
throw new NullPointerException();
}
hasNoInternationalDialling = true;
noInternationalDialling_ = value;
return this;
}
// required string id = 9;
private boolean hasId;
private String id_ = "";
@ -568,6 +596,14 @@ public final class Phonemetadata {
if (hasPager) {
pager_.writeExternal(objectOutput);
}
objectOutput.writeBoolean(hasUan);
if (hasUan) {
uan_.writeExternal(objectOutput);
}
objectOutput.writeBoolean(hasNoInternationalDialling);
if (hasNoInternationalDialling) {
noInternationalDialling_.writeExternal(objectOutput);
}
objectOutput.writeUTF(id_);
objectOutput.writeInt(countryCode_);
@ -675,6 +711,18 @@ public final class Phonemetadata {
desc.readExternal(objectInput);
setPager(desc);
}
hasDesc = objectInput.readBoolean();
if (hasDesc) {
PhoneNumberDesc desc = new PhoneNumberDesc();
desc.readExternal(objectInput);
setUan(desc);
}
hasDesc = objectInput.readBoolean();
if (hasDesc) {
PhoneNumberDesc desc = new PhoneNumberDesc();
desc.readExternal(objectInput);
setNoInternationalDialling(desc);
}
setId(objectInput.readUTF());
setCountryCode(objectInput.readInt());


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AD View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AE View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AF View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AG View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AI View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AL View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AM View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AN View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AO View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AR View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AS View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AT View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AU View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AW View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AZ View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BA View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BB View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BD View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BE View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BF View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BG View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BH View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BI View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BJ View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BL View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BM View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BN View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BO View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BR View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BS View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BT View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BW View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BY View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BZ View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CA View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CD View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CF View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CG View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CH View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CI View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CK View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CL View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CM View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CN View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CO View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CR View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CU View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CV View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CY View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CZ View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_DE View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_DJ View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_DK View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_DM View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_DO View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_DZ View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_EC View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_EE View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_EG View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_ER View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_ES View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_ET View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_FI View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_FJ View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_FK View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_FM View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_FO View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_FR View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GA View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GB View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GD View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GE View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GF View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GG View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GH View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GI View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GL View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GM View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GN View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GP View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GQ View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GR View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GT View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GU View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GW View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GY View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_HK View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_HN View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_HR View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_HT View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_HU View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_ID View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_IE View File


Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save