Browse Source

JAVA/JS/CPP: libphonenumber v6.1

pull/567/head
Lara Scheidegger 12 years ago
committed by Mihaela Rosca
parent
commit
a201099230
123 changed files with 61485 additions and 50854 deletions
  1. +1
    -1
      cpp/CMakeLists.txt
  2. +22
    -21
      cpp/src/phonenumbers/asyoutypeformatter.cc
  3. +1
    -1
      cpp/src/phonenumbers/asyoutypeformatter.h
  4. +9598
    -9931
      cpp/src/phonenumbers/lite_metadata.cc
  5. +9844
    -10172
      cpp/src/phonenumbers/metadata.cc
  6. +2304
    -2291
      cpp/src/phonenumbers/short_metadata.cc
  7. +618
    -603
      cpp/src/phonenumbers/test_metadata.cc
  8. +22
    -0
      cpp/test/phonenumbers/asyoutypeformatter_test.cc
  9. +2
    -0
      cpp/test/phonenumbers/regexp_cache_test.cc
  10. +23
    -0
      debian/changelog
  11. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/1473_en
  12. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/1758_en
  13. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/1767_en
  14. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/1784_en
  15. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/1869_en
  16. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/227_en
  17. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/231_en
  18. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/233_en
  19. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/258_en
  20. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/66_en
  21. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/86_en
  22. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/config
  23. BIN
      java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/1242_en
  24. BIN
      java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/32_de
  25. BIN
      java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/32_en
  26. BIN
      java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/32_nl
  27. BIN
      java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/55_en
  28. BIN
      java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/56_en
  29. BIN
      java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/56_es
  30. BIN
      java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/86_en
  31. BIN
      java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/86_zh
  32. BIN
      java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/config
  33. +17
    -14
      java/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java
  34. +34
    -0
      java/libphonenumber/src/com/google/i18n/phonenumbers/MetadataLoader.java
  35. +47
    -27
      java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java
  36. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AR
  37. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BF
  38. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BR
  39. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BS
  40. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CL
  41. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CN
  42. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CO
  43. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CR
  44. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_DE
  45. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_DM
  46. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_EC
  47. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_EG
  48. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_FR
  49. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GA
  50. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GD
  51. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GH
  52. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_HU
  53. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_ID
  54. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_IL
  55. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_IN
  56. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_JP
  57. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_KH
  58. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_KI
  59. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_KN
  60. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_LA
  61. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_LC
  62. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_LR
  63. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_ML
  64. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MU
  65. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MX
  66. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MZ
  67. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_NA
  68. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_NE
  69. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_PF
  70. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_PL
  71. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_RU
  72. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SM
  73. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_TH
  74. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_TW
  75. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_UZ
  76. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_VA
  77. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_VC
  78. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/ShortNumberMetadataProto_BI
  79. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/ShortNumberMetadataProto_CR
  80. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/ShortNumberMetadataProto_PL
  81. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/ShortNumberMetadataProto_TH
  82. +22
    -1
      java/libphonenumber/test/com/google/i18n/phonenumbers/AsYouTypeFormatterTest.java
  83. +6
    -2
      java/libphonenumber/test/com/google/i18n/phonenumbers/CountryCodeToRegionCodeMapForTesting.java
  84. +3
    -20
      java/libphonenumber/test/com/google/i18n/phonenumbers/ExampleNumbersTest.java
  85. +4
    -3
      java/libphonenumber/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java
  86. +3
    -3
      java/libphonenumber/test/com/google/i18n/phonenumbers/TestMetadataTestCase.java
  87. BIN
      java/libphonenumber/test/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProtoForTesting_AR
  88. BIN
      java/libphonenumber/test/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProtoForTesting_CN
  89. BIN
      java/libphonenumber/test/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProtoForTesting_MX
  90. +22
    -0
      java/release_notes.txt
  91. +18
    -18
      javascript/i18n/phonenumbers/asyoutypeformatter.js
  92. +22
    -0
      javascript/i18n/phonenumbers/asyoutypeformatter_test.js
  93. +188
    -187
      javascript/i18n/phonenumbers/demo-compiled.js
  94. +125
    -112
      javascript/i18n/phonenumbers/metadata.js
  95. +23
    -6
      javascript/i18n/phonenumbers/metadatafortesting.js
  96. +124
    -111
      javascript/i18n/phonenumbers/metadatalite.js
  97. +8
    -6
      javascript/i18n/phonenumbers/phonenumberutil.js
  98. +246
    -135
      resources/PhoneNumberMetadata.xml
  99. +19
    -0
      resources/PhoneNumberMetadataForTesting.xml
  100. +110
    -11
      resources/ShortNumberMetadata.xml

+ 1
- 1
cpp/CMakeLists.txt View File

@ -18,7 +18,7 @@ cmake_minimum_required (VERSION 2.8)
project (libphonenumber)
set (libphonenumber_VERSION_MAJOR 6)
set (libphonenumber_VERSION_MINOR 0)
set (libphonenumber_VERSION_MINOR 1)
# Helper functions dealing with finding libraries and programs this library
# depends on.


+ 22
- 21
cpp/src/phonenumbers/asyoutypeformatter.cc View File

@ -14,6 +14,7 @@
#include "phonenumbers/asyoutypeformatter.h"
#include <math.h>
#include <cctype>
#include <list>
#include <string>
@ -193,8 +194,7 @@ bool AsYouTypeFormatter::MaybeCreateNewTemplate() {
return false;
}
void AsYouTypeFormatter::GetAvailableFormats(
const string& leading_three_digits) {
void AsYouTypeFormatter::GetAvailableFormats(const string& leading_digits) {
const RepeatedPtrField<NumberFormat>& format_list =
(is_complete_number_ &&
current_metadata_->intl_number_format().size() > 0)
@ -213,7 +213,7 @@ void AsYouTypeFormatter::GetAvailableFormats(
}
}
}
NarrowDownPossibleFormats(leading_three_digits);
NarrowDownPossibleFormats(leading_digits);
}
void AsYouTypeFormatter::NarrowDownPossibleFormats(
@ -225,18 +225,21 @@ void AsYouTypeFormatter::NarrowDownPossibleFormats(
it != possible_formats_.end(); ) {
DCHECK(*it);
const NumberFormat& format = **it;
if (format.leading_digits_pattern_size() >
index_of_leading_digits_pattern) {
const scoped_ptr<RegExpInput> input(
regexp_factory_->CreateInput(leading_digits));
if (!regexp_cache_.GetRegExp(format.leading_digits_pattern().Get(
index_of_leading_digits_pattern)).Consume(input.get())) {
it = possible_formats_.erase(it);
continue;
}
} // else the particular format has no more specific leadingDigitsPattern,
// and it should be retained.
if (format.leading_digits_pattern_size() == 0) {
// Keep everything that isn't restricted by leading digits.
++it;
continue;
}
int last_leading_digits_pattern =
std::min(index_of_leading_digits_pattern,
format.leading_digits_pattern_size() - 1);
const scoped_ptr<RegExpInput> input(
regexp_factory_->CreateInput(leading_digits));
if (!regexp_cache_.GetRegExp(format.leading_digits_pattern().Get(
last_leading_digits_pattern)).Consume(input.get())) {
it = possible_formats_.erase(it);
continue;
}
++it;
}
}
@ -427,7 +430,7 @@ void AsYouTypeFormatter::InputDigitWithOptionToRememberPosition(
return;
}
if (possible_formats_.size() > 0) {
// The formatting pattern is already chosen.
// The formatting patterns are already chosen.
string temp_national_number;
InputDigitHelper(normalized_next_char, &temp_national_number);
// See if accrued digits can be formatted properly already. If not, use
@ -550,12 +553,10 @@ void AsYouTypeFormatter::AppendNationalNumber(const string& national_number,
void AsYouTypeFormatter::AttemptToChooseFormattingPattern(
string* formatted_number) {
DCHECK(formatted_number);
// We start to attempt to format only when at least MIN_LEADING_DIGITS_LENGTH
// digits of national number (excluding national prefix) have been entered.
if (national_number_.length() >= kMinLeadingDigitsLength) {
const string leading_digits =
national_number_.substr(0, kMinLeadingDigitsLength);
GetAvailableFormats(leading_digits);
GetAvailableFormats(national_number_);
formatted_number->clear();
AttemptToFormatAccruedDigits(formatted_number);
// See if the accrued digits can be formatted properly already.


+ 1
- 1
cpp/src/phonenumbers/asyoutypeformatter.h View File

@ -93,7 +93,7 @@ class AsYouTypeFormatter {
// existing template.
bool MaybeCreateNewTemplate();
void GetAvailableFormats(const string& leading_three_digits);
void GetAvailableFormats(const string& leading_digits);
void NarrowDownPossibleFormats(const string& leading_digits);


+ 9598
- 9931
cpp/src/phonenumbers/lite_metadata.cc
File diff suppressed because it is too large
View File


+ 9844
- 10172
cpp/src/phonenumbers/metadata.cc
File diff suppressed because it is too large
View File


+ 2304
- 2291
cpp/src/phonenumbers/short_metadata.cc
File diff suppressed because it is too large
View File


+ 618
- 603
cpp/src/phonenumbers/test_metadata.cc
File diff suppressed because it is too large
View File


+ 22
- 0
cpp/test/phonenumbers/asyoutypeformatter_test.cc View File

@ -1172,5 +1172,27 @@ TEST_F(AsYouTypeFormatterTest, AYTF_ShortNumberFormattingFix_US) {
EXPECT_EQ("1 22", formatter_->InputDigit('2', &result_));
}
TEST_F(AsYouTypeFormatterTest,
NumberPatternsBecomingInvalidShouldNotResultInDigitLoss) {
formatter_.reset(phone_util_.GetAsYouTypeFormatter(RegionCode::CN()));
EXPECT_EQ("+", formatter_->InputDigit('+', &result_));
EXPECT_EQ("+8", formatter_->InputDigit('8', &result_));
EXPECT_EQ("+86 ", formatter_->InputDigit('6', &result_));
EXPECT_EQ("+86 9", formatter_->InputDigit('9', &result_));
EXPECT_EQ("+86 98", formatter_->InputDigit('8', &result_));
EXPECT_EQ("+86 988", formatter_->InputDigit('8', &result_));
EXPECT_EQ("+86 988 1", formatter_->InputDigit('1', &result_));
// Now the number pattern is no longer valid because there are multiple
// leading digit patterns; when we try again to extract a country code we
// should ensure we use the last leading digit pattern, rather than the first
// one such that it *thinks* it's found a valid formatting rule again.
// https://code.google.com/p/libphonenumber/issues/detail?id=437
EXPECT_EQ("+8698812", formatter_->InputDigit('2', &result_));
EXPECT_EQ("+86988123", formatter_->InputDigit('3', &result_));
EXPECT_EQ("+869881234", formatter_->InputDigit('4', &result_));
EXPECT_EQ("+8698812345", formatter_->InputDigit('5', &result_));
}
} // namespace phonenumbers
} // namespace i18n

+ 2
- 0
cpp/test/phonenumbers/regexp_cache_test.cc View File

@ -19,6 +19,7 @@
#include <gtest/gtest.h>
#include "phonenumbers/base/synchronization/lock.h"
#include "phonenumbers/regexp_cache.h"
#include "phonenumbers/regexp_factory.h"
@ -39,6 +40,7 @@ class RegExpCacheTest : public testing::Test {
};
TEST_F(RegExpCacheTest, CacheConstructor) {
AutoLock l(cache_.lock_);
ASSERT_TRUE(cache_.cache_impl_ != NULL);
EXPECT_TRUE(cache_.cache_impl_->empty());
}


+ 23
- 0
debian/changelog View File

@ -1,3 +1,26 @@
libphonenumber (6.1) precise; urgency=low
* Code changes:
- Adding MetadataLoader support to allow custom metadata loading from
alternative sources (should have no visible impact to users).
- Fixing bug where digits could be lost in as-you-type formatting and
formatting patterns incorrectly applied.
* Metadata changes:
- Updated phone metadata for region code(s):
AR, BF, BR, BS, CL, CN, CO, CR, DE, DM, EC, EG, FR, GA, GD, GH, HU,
ID, IL, IN, JP, KH, KI, KN, LA, LC, LR, ML, MU, MX, MZ, NA, NE, PF, PL,
RU, SM, TH, TW, UZ, VA, VC
- Updated short number metadata for region code(s): BI, CR, PL, TH
- New geocoding data for country calling code(s): 32 (de), 1242 (en)
- Updated geocoding data for country calling code(s):
32 (en, nl), 55 (en), 56 (en, es), 86 (en, zh)
- New carrier data for country calling code(s):
1758 (en), 1784 (en), 1869 (en)
- Updated carrier data for country calling code(s):
66 (en), 86 (en), 227 (en), 231 (en), 233 (en), 258 (en), 1473 (en),
1767 (en)
-- Lara Scheidegger <lararennie@google.com> Thu, 08 May 2014 14:08:34 +0200
libphonenumber (6.0) precise; urgency=low
* Code changes:


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/1473_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/1758_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/1767_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/1784_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/1869_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/227_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/231_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/233_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/258_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/66_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/86_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/config View File


BIN
java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/1242_en View File


BIN
java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/32_de View File


BIN
java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/32_en View File


BIN
java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/32_nl View File


BIN
java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/55_en View File


BIN
java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/56_en View File


BIN
java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/56_es View File


BIN
java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/86_en View File


BIN
java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/86_zh View File


BIN
java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/config View File


+ 17
- 14
java/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java View File

@ -172,7 +172,7 @@ public class AsYouTypeFormatter {
return false;
}
private void getAvailableFormats(String leadingThreeDigits) {
private void getAvailableFormats(String leadingDigits) {
List<NumberFormat> formatList =
(isCompleteNumber && currentMetadata.intlNumberFormatSize() > 0)
? currentMetadata.intlNumberFormats()
@ -187,7 +187,7 @@ public class AsYouTypeFormatter {
}
}
}
narrowDownPossibleFormats(leadingThreeDigits);
narrowDownPossibleFormats(leadingDigits);
}
private boolean isFormatEligible(String format) {
@ -199,16 +199,18 @@ public class AsYouTypeFormatter {
Iterator<NumberFormat> it = possibleFormats.iterator();
while (it.hasNext()) {
NumberFormat format = it.next();
if (format.leadingDigitsPatternSize() > indexOfLeadingDigitsPattern) {
Pattern leadingDigitsPattern =
regexCache.getPatternForRegex(
format.getLeadingDigitsPattern(indexOfLeadingDigitsPattern));
Matcher m = leadingDigitsPattern.matcher(leadingDigits);
if (!m.lookingAt()) {
it.remove();
}
} // else the particular format has no more specific leadingDigitsPattern, and it should be
// retained.
if (format.leadingDigitsPatternSize() == 0) {
// Keep everything that isn't restricted by leading digits.
continue;
}
int lastLeadingDigitsPattern =
Math.min(indexOfLeadingDigitsPattern, format.leadingDigitsPatternSize() - 1);
Pattern leadingDigitsPattern = regexCache.getPatternForRegex(
format.getLeadingDigitsPattern(lastLeadingDigitsPattern));
Matcher m = leadingDigitsPattern.matcher(leadingDigits);
if (!m.lookingAt()) {
it.remove();
}
}
}
@ -362,7 +364,7 @@ public class AsYouTypeFormatter {
}
return prefixBeforeNationalNumber + nationalNumber.toString();
}
if (possibleFormats.size() > 0) { // The formatting pattern is already chosen.
if (possibleFormats.size() > 0) { // The formatting patterns are already chosen.
String tempNationalNumber = inputDigitHelper(nextChar);
// See if the accrued digits can be formatted properly already. If not, use the results
// from inputDigitHelper, which does formatting based on the formatting pattern chosen.
@ -481,7 +483,8 @@ public class AsYouTypeFormatter {
// We start to attempt to format only when at least MIN_LEADING_DIGITS_LENGTH digits of national
// number (excluding national prefix) have been entered.
if (nationalNumber.length() >= MIN_LEADING_DIGITS_LENGTH) {
getAvailableFormats(nationalNumber.substring(0, MIN_LEADING_DIGITS_LENGTH));
getAvailableFormats(nationalNumber.toString());
// See if the accrued digits can be formatted properly already.
String formattedNumber = attemptToFormatAccruedDigits();
if (formattedNumber.length() > 0) {


+ 34
- 0
java/libphonenumber/src/com/google/i18n/phonenumbers/MetadataLoader.java View File

@ -0,0 +1,34 @@
/*
* Copyright (C) 2014 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.google.i18n.phonenumbers;
import java.io.InputStream;
/**
* Interface for caller to specify a customized phone metadata loader.
*/
public interface MetadataLoader {
/**
* Returns an input stream corresponding to the metadata to load.
*
* @param metadataFileName File name (including path) of metadata to load. File path is an
* absolute class path like /com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto.
* @return The input stream for the metadata file. The library will close this stream
* after it is done. Return null in case the metadata file could not be found.
*/
public InputStream loadMetadata(String metadataFileName);
}

+ 47
- 27
java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java View File

@ -56,6 +56,13 @@ import java.util.regex.Pattern;
* @author Shaopeng Jia
*/
public class PhoneNumberUtil {
// @VisibleForTesting
static final MetadataLoader DEFAULT_METADATA_LOADER = new MetadataLoader() {
public InputStream loadMetadata(String metadataFileName) {
return PhoneNumberUtil.class.getResourceAsStream(metadataFileName);
}
};
private static final Logger logger = Logger.getLogger(PhoneNumberUtil.class.getName());
/** Flags to use when compiling regular expressions for phone numbers. */
@ -69,7 +76,8 @@ public class PhoneNumberUtil {
// We don't allow input strings for parsing to be longer than 250 chars. This prevents malicious
// input from overflowing the regular-expression engine.
private static final int MAX_INPUT_STRING_LENGTH = 250;
static final String META_DATA_FILE_PREFIX =
private static final String META_DATA_FILE_PREFIX =
"/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto";
// Region-code for the unknown region.
@ -565,13 +573,17 @@ public class PhoneNumberUtil {
// The prefix of the metadata files from which region data is loaded.
private final String currentFilePrefix;
// The metadata loader used to inject alternative metadata sources.
private final MetadataLoader metadataLoader;
/**
* This class implements a singleton, so the only constructor is private.
*/
private PhoneNumberUtil(String filePrefix,
// @VisibleForTesting
PhoneNumberUtil(String filePrefix, MetadataLoader metadataLoader,
Map<Integer, List<String>> countryCallingCodeToRegionCodeMap) {
this.currentFilePrefix = filePrefix;
this.metadataLoader = metadataLoader;
this.countryCallingCodeToRegionCodeMap = countryCallingCodeToRegionCodeMap;
for (Map.Entry<Integer, List<String>> entry : countryCallingCodeToRegionCodeMap.entrySet()) {
List<String> regionCodes = entry.getValue();
@ -596,11 +608,12 @@ public class PhoneNumberUtil {
}
// @VisibleForTesting
void loadMetadataFromFile(String filePrefix, String regionCode, int countryCallingCode) {
void loadMetadataFromFile(String filePrefix, String regionCode, int countryCallingCode,
MetadataLoader metadataLoader) {
boolean isNonGeoRegion = REGION_CODE_FOR_NON_GEO_ENTITY.equals(regionCode);
String fileName = filePrefix + "_" +
(isNonGeoRegion ? String.valueOf(countryCallingCode) : regionCode);
InputStream source = PhoneNumberUtil.class.getResourceAsStream(fileName);
InputStream source = metadataLoader.loadMetadata(fileName);
if (source == null) {
logger.log(Level.SEVERE, "missing metadata: " + fileName);
throw new IllegalStateException("missing metadata: " + fileName);
@ -637,7 +650,7 @@ public class PhoneNumberUtil {
* @param source the non-null stream from which metadata is to be read.
* @return the loaded metadata protocol buffer.
*/
private static PhoneMetadataCollection loadMetadataAndCloseInput(ObjectInput source) {
private static PhoneMetadataCollection loadMetadataAndCloseInput(ObjectInputStream source) {
PhoneMetadataCollection metadataCollection = new PhoneMetadataCollection();
try {
metadataCollection.readExternal(source);
@ -960,26 +973,12 @@ public class PhoneNumberUtil {
}
/**
* An unsafe version of getInstance() which must only be used for testing purposes.
* Sets or resets the PhoneNumberUtil singleton instance. If set to null, the next call to
* {@code getInstance()} will load (and return) the default instance.
*/
// @VisibleForTesting
static synchronized PhoneNumberUtil getInstance(
String baseFileLocation,
Map<Integer, List<String>> countryCallingCodeToRegionCodeMap) {
if (instance != null) {
throw new IllegalStateException(
"PhoneNumberUtil instance is already set (you should call resetInstance() first)");
}
instance = new PhoneNumberUtil(baseFileLocation, countryCallingCodeToRegionCodeMap);
return instance;
}
/**
* Used for testing purposes only to reset the PhoneNumberUtil singleton to null.
*/
// @VisibleForTesting
static synchronized void resetInstance() {
instance = null;
static synchronized void setInstance(PhoneNumberUtil util) {
instance = util;
}
/**
@ -1009,12 +1008,32 @@ public class PhoneNumberUtil {
*/
public static synchronized PhoneNumberUtil getInstance() {
if (instance == null) {
return getInstance(META_DATA_FILE_PREFIX,
CountryCodeToRegionCodeMap.getCountryCodeToRegionCodeMap());
setInstance(createInstance(DEFAULT_METADATA_LOADER));
}
return instance;
}
/**
* Create a new {@link PhoneNumberUtil} instance to carry out international phone number
* formatting, parsing, or validation. The instance is loaded with all metadata by
* using the metadataLoader specified.
*
* This method should only be used in the rare case in which you want to manage your own
* metadata loading. Calling this method multiple times is very expensive, as each time
* a new instance is created from scratch. When in doubt, use {@link #getInstance}.
*
* @param metadataLoader Customized metadata loader. If null, default metadata loader will
* be used. This should not be null.
* @return a PhoneNumberUtil instance
*/
public static PhoneNumberUtil createInstance(MetadataLoader metadataLoader) {
if (metadataLoader == null) {
throw new IllegalArgumentException("metadataLoader could not be null.");
}
return new PhoneNumberUtil(META_DATA_FILE_PREFIX, metadataLoader,
CountryCodeToRegionCodeMap.getCountryCodeToRegionCodeMap());
}
/**
* Helper function to check if the national prefix formatting rule has the first group only, i.e.,
* does not start with the national prefix.
@ -2011,7 +2030,7 @@ public class PhoneNumberUtil {
if (!regionToMetadataMap.containsKey(regionCode)) {
// The regionCode here will be valid and won't be '001', so we don't need to worry about
// what to pass in for the country calling code.
loadMetadataFromFile(currentFilePrefix, regionCode, 0);
loadMetadataFromFile(currentFilePrefix, regionCode, 0, metadataLoader);
}
}
return regionToMetadataMap.get(regionCode);
@ -2023,7 +2042,8 @@ public class PhoneNumberUtil {
return null;
}
if (!countryCodeToNonGeographicalMetadataMap.containsKey(countryCallingCode)) {
loadMetadataFromFile(currentFilePrefix, REGION_CODE_FOR_NON_GEO_ENTITY, countryCallingCode);
loadMetadataFromFile(
currentFilePrefix, REGION_CODE_FOR_NON_GEO_ENTITY, countryCallingCode, metadataLoader);
}
}
return countryCodeToNonGeographicalMetadataMap.get(countryCallingCode);


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


BIN
java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_IL View File


BIN
java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_IN View File


BIN
java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_JP View File


BIN
java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_KH View File


BIN
java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_KI View File


BIN
java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_KN View File


BIN
java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_LA View File


BIN
java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_LC View File


BIN
java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_LR View File


BIN
java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_ML View File


BIN
java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MU View File


BIN
java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MX View File


BIN
java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MZ View File


BIN
java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_NA View File


BIN
java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_NE View File


BIN
java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_PF View File


BIN
java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_PL View File


BIN
java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_RU View File


BIN
java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SM View File


BIN
java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_TH View File


BIN
java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_TW View File


BIN
java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_UZ View File


BIN
java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_VA View File


BIN
java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_VC View File


BIN
java/libphonenumber/src/com/google/i18n/phonenumbers/data/ShortNumberMetadataProto_BI View File


BIN
java/libphonenumber/src/com/google/i18n/phonenumbers/data/ShortNumberMetadataProto_CR View File


BIN
java/libphonenumber/src/com/google/i18n/phonenumbers/data/ShortNumberMetadataProto_PL View File


BIN
java/libphonenumber/src/com/google/i18n/phonenumbers/data/ShortNumberMetadataProto_TH View File


+ 22
- 1
java/libphonenumber/test/com/google/i18n/phonenumbers/AsYouTypeFormatterTest.java View File

@ -1128,7 +1128,7 @@ public class AsYouTypeFormatterTest extends TestMetadataTestCase {
assertEquals("0", formatter.getExtractedNationalPrefix());
// Once the IDD "00700" has been extracted, it no longer makes sense for the initial "0" to be
// treated as an NDD.
// treated as an NDD.
assertEquals("00700 1 ", formatter.inputDigit('1'));
assertEquals("", formatter.getExtractedNationalPrefix());
@ -1149,4 +1149,25 @@ public class AsYouTypeFormatterTest extends TestMetadataTestCase {
assertEquals("007001234567890123456", formatter.inputDigit('6'));
assertEquals("0070012345678901234567", formatter.inputDigit('7'));
}
public void testAYTFNumberPatternsBecomingInvalidShouldNotResultInDigitLoss() {
AsYouTypeFormatter formatter = phoneUtil.getAsYouTypeFormatter(RegionCode.CN);
assertEquals("+", formatter.inputDigit('+'));
assertEquals("+8", formatter.inputDigit('8'));
assertEquals("+86 ", formatter.inputDigit('6'));
assertEquals("+86 9", formatter.inputDigit('9'));
assertEquals("+86 98", formatter.inputDigit('8'));
assertEquals("+86 988", formatter.inputDigit('8'));
assertEquals("+86 988 1", formatter.inputDigit('1'));
// Now the number pattern is no longer valid because there are multiple leading digit patterns;
// when we try again to extract a country code we should ensure we use the last leading digit
// pattern, rather than the first one such that it *thinks* it's found a valid formatting rule
// again.
// https://code.google.com/p/libphonenumber/issues/detail?id=437
assertEquals("+8698812", formatter.inputDigit('2'));
assertEquals("+86988123", formatter.inputDigit('3'));
assertEquals("+869881234", formatter.inputDigit('4'));
assertEquals("+8698812345", formatter.inputDigit('5'));
}
}

+ 6
- 2
java/libphonenumber/test/com/google/i18n/phonenumbers/CountryCodeToRegionCodeMapForTesting.java View File

@ -31,10 +31,10 @@ public class CountryCodeToRegionCodeMapForTesting {
// countries sharing a calling code, such as the NANPA countries, the one
// indicated with "isMainCountryForCode" in the metadata should be first.
static Map<Integer, List<String>> getCountryCodeToRegionCodeMap() {
// The capacity is set to 29 as there are 22 different entries,
// The capacity is set to 30 as there are 23 different entries,
// and this offers a load factor of roughly 0.75.
Map<Integer, List<String>> countryCodeToRegionCodeMap =
new HashMap<Integer, List<String>>(29);
new HashMap<Integer, List<String>>(30);
ArrayList<String> listWithRegionCode;
@ -102,6 +102,10 @@ public class CountryCodeToRegionCodeMapForTesting {
listWithRegionCode.add("KR");
countryCodeToRegionCodeMap.put(82, listWithRegionCode);
listWithRegionCode = new ArrayList<String>(1);
listWithRegionCode.add("CN");
countryCodeToRegionCodeMap.put(86, listWithRegionCode);
listWithRegionCode = new ArrayList<String>(1);
listWithRegionCode.add("AO");
countryCodeToRegionCodeMap.put(244, listWithRegionCode);


+ 3
- 20
java/libphonenumber/test/com/google/i18n/phonenumbers/ExampleNumbersTest.java View File

@ -35,29 +35,12 @@ import java.util.logging.Logger;
*/
public class ExampleNumbersTest extends TestCase {
private static final Logger LOGGER = Logger.getLogger(ExampleNumbersTest.class.getName());
private PhoneNumberUtil phoneNumberUtil;
private ShortNumberInfo shortNumberInfo;
private PhoneNumberUtil phoneNumberUtil =
PhoneNumberUtil.createInstance(PhoneNumberUtil.DEFAULT_METADATA_LOADER);
private ShortNumberInfo shortNumberInfo = new ShortNumberInfo(phoneNumberUtil);
private List<PhoneNumber> invalidCases = new ArrayList<PhoneNumber>();
private List<PhoneNumber> wrongTypeCases = new ArrayList<PhoneNumber>();
public ExampleNumbersTest() {
PhoneNumberUtil.resetInstance();
phoneNumberUtil = PhoneNumberUtil.getInstance();
shortNumberInfo = new ShortNumberInfo(phoneNumberUtil);
}
@Override
protected void setUp() throws Exception {
super.setUp();
invalidCases.clear();
wrongTypeCases.clear();
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
}
/**
* @param exampleNumberRequestedType type we are requesting an example number for
* @param possibleExpectedTypes acceptable types that this number should match, such as


+ 4
- 3
java/libphonenumber/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java View File

@ -126,14 +126,15 @@ public class PhoneNumberUtilTest extends TestMetadataTestCase {
// exist. However if the library is packaged incorrectly in the jar, this could happen and the
// best we can do is make sure the exception has the file name in it.
try {
phoneUtil.loadMetadataFromFile("no/such/file", "XX", -1);
phoneUtil.loadMetadataFromFile(
"no/such/file", "XX", -1, PhoneNumberUtil.DEFAULT_METADATA_LOADER);
fail("expected exception");
} catch (RuntimeException e) {
assertTrue("Unexpected error: " + e, e.toString().contains("no/such/file_XX"));
}
try {
phoneUtil.loadMetadataFromFile(
"no/such/file", PhoneNumberUtil.REGION_CODE_FOR_NON_GEO_ENTITY, 123);
phoneUtil.loadMetadataFromFile("no/such/file", PhoneNumberUtil.REGION_CODE_FOR_NON_GEO_ENTITY,
123, PhoneNumberUtil.DEFAULT_METADATA_LOADER);
fail("expected exception");
} catch (RuntimeException e) {
assertTrue("Unexpected error: " + e, e.getMessage().contains("no/such/file_123"));


+ 3
- 3
java/libphonenumber/test/com/google/i18n/phonenumbers/TestMetadataTestCase.java View File

@ -37,10 +37,10 @@ public class TestMetadataTestCase extends TestCase {
}
static PhoneNumberUtil initializePhoneUtilForTesting() {
PhoneNumberUtil.resetInstance();
PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance(
TEST_META_DATA_FILE_PREFIX,
PhoneNumberUtil phoneUtil = new PhoneNumberUtil(
TEST_META_DATA_FILE_PREFIX, PhoneNumberUtil.DEFAULT_METADATA_LOADER,
CountryCodeToRegionCodeMapForTesting.getCountryCodeToRegionCodeMap());
PhoneNumberUtil.setInstance(phoneUtil);
return phoneUtil;
}
}

BIN
java/libphonenumber/test/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProtoForTesting_AR View File


BIN
java/libphonenumber/test/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProtoForTesting_CN View File


BIN
java/libphonenumber/test/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProtoForTesting_MX View File


+ 22
- 0
java/release_notes.txt View File

@ -1,3 +1,25 @@
May 08, 2014: libphonenumber-6.1
* Code changes:
- Adding MetadataLoader support to allow custom metadata loading from
alternative sources (should have no visible impact to users).
- Fixing bug where digits could be lost in as-you-type formatting and
formatting patterns incorrectly applied.
* Metadata changes:
- Updated phone metadata for region code(s):
AR, BF, BR, BS, CL, CN, CO, CR, DE, DM, EC, EG, FR, GA, GD, GH, HU, ID, IL,
IN, JP, KH, KI, KN, LA, LC, LR, ML, MU, MX, MZ, NA, NE, PF, PL, RU, SM, TH,
TW, UZ, VA, VC
- Updated short number metadata for region code(s): BI, CR, PL, TH
- New geocoding data for country calling code(s): 32 (de), 1242 (en)
- Updated geocoding data for country calling code(s):
32 (en, nl), 55 (en), 56 (en, es), 86 (en, zh)
- New carrier data for country calling code(s):
1758 (en), 1784 (en), 1869 (en)
- Updated carrier data for country calling code(s):
66 (en), 86 (en), 227 (en), 231 (en), 233 (en), 258 (en), 1473 (en),
1767 (en)
Feb 25, 2014: libphonenumber-6.0
* Code changes:
- Better support for detecting phone numbers in text that are beside each other


+ 18
- 18
javascript/i18n/phonenumbers/asyoutypeformatter.js View File

@ -342,11 +342,11 @@ i18n.phonenumbers.AsYouTypeFormatter.prototype.maybeCreateNewTemplate_ =
/**
* @param {string} leadingThreeDigits first three digits of entered number.
* @param {string} leadingDigits leading digits of entered number.
* @private
*/
i18n.phonenumbers.AsYouTypeFormatter.prototype.getAvailableFormats_ =
function(leadingThreeDigits) {
function(leadingDigits) {
/** @type {Array.<i18n.phonenumbers.NumberFormat>} */
var formatList =
@ -371,7 +371,7 @@ i18n.phonenumbers.AsYouTypeFormatter.prototype.getAvailableFormats_ =
}
}
}
this.narrowDownPossibleFormats_(leadingThreeDigits);
this.narrowDownPossibleFormats_(leadingDigits);
};
@ -405,16 +405,18 @@ i18n.phonenumbers.AsYouTypeFormatter.prototype.narrowDownPossibleFormats_ =
for (var i = 0; i < possibleFormatsLength; ++i) {
/** @type {i18n.phonenumbers.NumberFormat} */
var format = this.possibleFormats_[i];
if (format.leadingDigitsPatternCount() > indexOfLeadingDigitsPattern) {
/** @type {string} */
var leadingDigitsPattern =
format.getLeadingDigitsPatternOrDefault(indexOfLeadingDigitsPattern);
if (leadingDigits.search(leadingDigitsPattern) == 0) {
possibleFormats.push(this.possibleFormats_[i]);
}
} else {
// else the particular format has no more specific leadingDigitsPattern,
// and it should be retained.
if (format.leadingDigitsPatternCount() == 0) {
// Keep everything that isn't restricted by leading digits.
possibleFormats.push(this.possibleFormats_[i]);
continue;
}
/** @type {number} */
var lastLeadingDigitsPattern = Math.min(
indexOfLeadingDigitsPattern, format.leadingDigitsPatternCount() - 1);
/** @type {string} */
var leadingDigitsPattern = /** @type {string} */
(format.getLeadingDigitsPattern(lastLeadingDigitsPattern));
if (leadingDigits.search(leadingDigitsPattern) == 0) {
possibleFormats.push(this.possibleFormats_[i]);
}
}
@ -630,7 +632,7 @@ i18n.phonenumbers.AsYouTypeFormatter.prototype.
this.nationalNumber_.toString();
}
if (this.possibleFormats_.length > 0) {
// The formatting pattern is already chosen.
// The formatting patterns are already chosen.
/** @type {string} */
var tempNationalNumber = this.inputDigitHelper_(nextChar);
// See if the accrued digits can be formatted properly already. If not,
@ -845,9 +847,7 @@ i18n.phonenumbers.AsYouTypeFormatter.prototype.
// digits of national number (excluding national prefix) have been entered.
if (nationalNumber.length >=
i18n.phonenumbers.AsYouTypeFormatter.MIN_LEADING_DIGITS_LENGTH_) {
this.getAvailableFormats_(
nationalNumber.substring(0,
i18n.phonenumbers.AsYouTypeFormatter.MIN_LEADING_DIGITS_LENGTH_));
this.getAvailableFormats_(nationalNumber);
// See if the accrued digits can be formatted properly already.
var formattedNumber = this.attemptToFormatAccruedDigits_();
if (formattedNumber.length > 0) {
@ -1036,7 +1036,7 @@ i18n.phonenumbers.AsYouTypeFormatter.prototype.
i18n.phonenumbers.AsYouTypeFormatter.SEPARATOR_BEFORE_NATIONAL_NUMBER_);
// When we have successfully extracted the IDD, the previously extracted NDD
// should be cleared because it is no longer valid.
this.extractedNationalPrefix_ = "";
this.extractedNationalPrefix_ = '';
return true;
};


+ 22
- 0
javascript/i18n/phonenumbers/asyoutypeformatter_test.js View File

@ -1181,3 +1181,25 @@ function testAYTFClearNDDAfterIddExtraction() {
assertEquals('007001234567890123456', f.inputDigit('6'));
assertEquals('0070012345678901234567', f.inputDigit('7'));
}
function testAYTFNumberPatternsBecomingInvalidShouldNotResultInDigitLoss() {
/** @type {i18n.phonenumbers.AsYouTypeFormatter} */
var f = new i18n.phonenumbers.AsYouTypeFormatter(RegionCode.CN);
assertEquals('+', f.inputDigit('+'));
assertEquals('+8', f.inputDigit('8'));
assertEquals('+86 ', f.inputDigit('6'));
assertEquals('+86 9', f.inputDigit('9'));
assertEquals('+86 98', f.inputDigit('8'));
assertEquals('+86 988', f.inputDigit('8'));
assertEquals('+86 988 1', f.inputDigit('1'));
// Now the number pattern is no longer valid because there are multiple leading digit patterns;
// when we try again to extract a country code we should ensure we use the last leading digit
// pattern, rather than the first one such that it *thinks* it's found a valid formatting rule
// again.
// https://code.google.com/p/libphonenumber/issues/detail?id=437
assertEquals('+8698812', f.inputDigit('2'));
assertEquals('+86988123', f.inputDigit('3'));
assertEquals('+869881234', f.inputDigit('4'));
assertEquals('+8698812345', f.inputDigit('5'));
}

+ 188
- 187
javascript/i18n/phonenumbers/demo-compiled.js
File diff suppressed because it is too large
View File


+ 125
- 112
javascript/i18n/phonenumbers/metadata.js
File diff suppressed because it is too large
View File


+ 23
- 6
javascript/i18n/phonenumbers/metadatafortesting.js View File

@ -46,6 +46,7 @@ i18n.phonenumbers.metadata.countryCodeToRegionCodeMap = {
,65:["SG"]
,81:["JP"]
,82:["KR"]
,86:["CN"]
,244:["AO"]
,262:["RE","YT"]
,375:["BY"]
@ -120,15 +121,15 @@ i18n.phonenumbers.metadata.countryToMetadata = {
,[,"(\\d{3})(\\d{3})(\\d{4})","$1-$2-$3",["[68]"]
,"0$1","",0]
]
,[[,"(\\d{2})(\\d{4})(\\d{4})","$1 $2-$3",["11","11"]
,[[,"(\\d{2})(\\d{4})(\\d{4})","$1 $2-$3",["11"]
,"0$1","",0]
,[,"(\\d{4})(\\d{2})(\\d{4})","$1 $2-$3",["1[02-9]|[23]","1[02-9]|[23]"]
,[,"(\\d{4})(\\d{2})(\\d{4})","$1 $2-$3",["1[02-9]|[23]"]
,"0$1","",0]
,[,"(9)(11)(\\d{4})(\\d{4})","$1 $2 $3 $4",["911"]
]
,[,"(9)(\\d{4})(\\d{2})(\\d{4})","$1 $2 $3 $4",["9(?:1[02-9]|[23])"]
]
,[,"(\\d{3})(\\d{3})(\\d{4})","$1-$2-$3",["[68]","[68]"]
,[,"(\\d{3})(\\d{3})(\\d{4})","$1-$2-$3",["[68]"]
,"0$1","",0]
]
,[,,"NA","NA"]
@ -213,6 +214,22 @@ i18n.phonenumbers.metadata.countryToMetadata = {
,[,,"NA","NA"]
,,,[,,"NA","NA"]
]
,"CN":[,[]
,[]
,[]
,[,,"NA","NA"]
,[,,"NA","NA"]
,[,,"NA","NA"]
,[,,"NA","NA"]
,[,,"NA","NA"]
,"CN",86,"",,,,,,,1,[[,"(\\d{3})(\\d{5,6})","$1 $2",["[3-9]","[3-9]\\d{2}[19]","[3-9]\\d{2}(?:10|95)"]
,"$1","$CC $1",0]
]
,,[,,"NA","NA"]
,,,[,,"NA","NA"]
,[,,"NA","NA"]
,,,[,,"NA","NA"]
]
,"CX":[,[]
,[]
,[]
@ -423,11 +440,11 @@ i18n.phonenumbers.metadata.countryToMetadata = {
,[,"(1)(\\d{3})(\\d{3})(\\d{4})","045 $2 $3 $4",["1(?:[124579]|3[0-24-9]|5[0-46-9]|8[02-9])"]
,"$1","",1]
]
,[[,"(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["[89]00","[89]00"]
,[[,"(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["[89]00"]
,"01 $1","",1]
,[,"(\\d{2})(\\d{4})(\\d{4})","$1 $2 $3",["33|55|81","33|55|81"]
,[,"(\\d{2})(\\d{4})(\\d{4})","$1 $2 $3",["33|55|81"]
,"01 $1","",1]
,[,"(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["[2467]|3[0-24-9]|5[0-46-9]|8[2-9]|9[1-9]","[2467]|3[0-24-9]|5[0-46-9]|8[2-9]|9[1-9]"]
,[,"(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["[2467]|3[0-24-9]|5[0-46-9]|8[2-9]|9[1-9]"]
,"01 $1","",1]
,[,"(1)(\\d{2})(\\d{4})(\\d{4})","$1 $2 $3 $4",["1(?:33|55|81)"]
]


+ 124
- 111
javascript/i18n/phonenumbers/metadatalite.js
File diff suppressed because it is too large
View File


+ 8
- 6
javascript/i18n/phonenumbers/phonenumberutil.js View File

@ -2238,8 +2238,8 @@ i18n.phonenumbers.PhoneNumberUtil.prototype.getNationalSignificantNumber =
/** @type {string} */
var nationalNumber = '' + number.getNationalNumber();
if (number.hasItalianLeadingZero() && number.getItalianLeadingZero()) {
return Array(number.getNumberOfLeadingZerosOrDefault() + 1).join('0')
+ nationalNumber;
return Array(number.getNumberOfLeadingZerosOrDefault() + 1).join('0') +
nationalNumber;
}
return nationalNumber;
};
@ -3546,8 +3546,8 @@ i18n.phonenumbers.PhoneNumberUtil.prototype.
// Check if the original number is viable.
/** @type {boolean} */
var isViableOriginalNumber =
i18n.phonenumbers.PhoneNumberUtil.matchesEntirely_(
nationalNumberRule, numberStr);
i18n.phonenumbers.PhoneNumberUtil.matchesEntirely_(
nationalNumberRule, numberStr);
// prefixMatcher[numOfGroups] == null implies nothing was captured by the
// capturing groups in possibleNationalPrefix; therefore, no transformation
// is necessary, and we just remove the national prefix.
@ -3564,10 +3564,12 @@ i18n.phonenumbers.PhoneNumberUtil.prototype.
// we return.
if (isViableOriginalNumber &&
!i18n.phonenumbers.PhoneNumberUtil.matchesEntirely_(
nationalNumberRule, numberStr.substring(prefixMatcher[0].length))) {
nationalNumberRule,
numberStr.substring(prefixMatcher[0].length))) {
return false;
}
if (carrierCode != null && numOfGroups > 0 && prefixMatcher[numOfGroups] != null) {
if (carrierCode != null &&
numOfGroups > 0 && prefixMatcher[numOfGroups] != null) {
carrierCode.append(prefixMatcher[1]);
}
number.set(numberStr.substring(prefixMatcher[0].length));


+ 246
- 135
resources/PhoneNumberMetadata.xml View File

@ -781,8 +781,8 @@
)
)
</leadingDigits>
<!-- We exclude here several 294X four-digit area codes: 2940, 2942, 2945, 2946 and 2948 -
and several 38[3578]X four-digit area codes. -->
<!-- We exclude here several 294X four-digit area codes: 2940, 2942, 2945, 2946 and 2948,
2983, and several 38[3578]X four-digit area codes. -->
<leadingDigits>
9(?:
2(?:
@ -792,8 +792,9 @@
6[01346]|
80|
9(?:
[17-9]|
4[13479]
[179]|
4[13479]|
8[0-24-9]
)
)|
3(?:
@ -2419,8 +2420,7 @@
<mobile>
<nationalNumberPattern>
6(?:
[0-24-689]\d|
3[0-7]|
[0-689]\d|
7[0-2]
)\d{5}|
7\d{7}
@ -2966,9 +2966,9 @@
<!-- http://en.wikipedia.org/wiki/%2B55 -->
<!-- http://www.itu.int/oth/T020200001D/en -->
<territory id="BR" countryCode="55"
internationalPrefix="00(?:1[45]|2[135]|[34]1|43)"
internationalPrefix="00(?:1[45]|2[135]|31|4[13])"
nationalPrefix="0"
nationalPrefixForParsing="0(?:(1[245]|2[135]|[34]1)(\d{10,11}))?"
nationalPrefixForParsing="0(?:(1[245]|2[135]|31|4[13])(\d{10,11}))?"
nationalPrefixTransformRule="$2" mobileNumberPortableRegion="true">
<!-- The national prefix for parsing here also contains a capturing group for the main number,
since the carrier codes here may also be area codes, so we want to check the length of
@ -3123,6 +3123,7 @@
461|
502|
6(?:
0[12]|
12|
7[67]|
8[78]|
@ -4102,7 +4103,7 @@
<numberFormat pattern="(\d)(\d{4})(\d{4})"
nationalPrefixFormattingRule="($FG)"
carrierCodeFormattingRule="$CC ($FG)">
<leadingDigits>2</leadingDigits>
<leadingDigits>22</leadingDigits>
<format>$1 $2 $3</format>
</numberFormat>
<numberFormat pattern="(\d{2})(\d{3})(\d{4})"
@ -4148,6 +4149,12 @@
<leadingDigits>1</leadingDigits>
<format>$1 $2 $3</format>
</numberFormat>
<numberFormat pattern="(\d{5})(\d{4})"
nationalPrefixFormattingRule="($FG)"
carrierCodeFormattingRule="$CC ($FG)">
<leadingDigits>219</leadingDigits>
<format>$1 $2</format>
</numberFormat>
<!-- Format some short numbers as a block. -->
<numberFormat nationalPrefixFormattingRule="$FG"
pattern="(\d{4,5})">
@ -4184,8 +4191,11 @@
http://www.subtel.cl/index.php?option=com_content&view=article&id=3081:&catid=3:noticias
-->
<nationalNumberPattern>
2(?:
2\d{7}|
1962\d{4}
)|
(?:
22|
3[2-5]|
[47][1-35]|
5[1-3578]|
@ -4491,8 +4501,8 @@
</leadingDigits>
<format>$1 $2 $3</format>
</numberFormat>
<numberFormat pattern="(1[3-58]\d)(\d{4})(\d{4})" carrierCodeFormattingRule="$CC $FG">
<leadingDigits>1[3-58]</leadingDigits>
<numberFormat pattern="(\d{3})(\d{4})(\d{4})" carrierCodeFormattingRule="$CC $FG">
<leadingDigits>1[3-578]</leadingDigits>
<format>$1 $2 $3</format>
</numberFormat>
<numberFormat pattern="(10800)(\d{3})(\d{4})">
@ -4644,11 +4654,13 @@
<exampleNumber>1012345678</exampleNumber>
</fixedLine>
<mobile>
<!-- 170, 176, 177 and 178 prefixes are introduced in early 2014 for 4G networks. -->
<nationalNumberPattern>
1(?:
[38]\d|
4[57]|
5[0-35-9]
5[0-35-9]|
7[06-8]
)\d{8}
</nationalNumberPattern>
<possibleNumberPattern>\d{11}</possibleNumberPattern>
@ -4806,10 +4818,7 @@
</fixedLine>
<mobile>
<nationalNumberPattern>
5(?:
0[0-4]|
7[0-3]
)\d{5}|
57[0-3]\d{5}|
6(?:
[0-2]\d|
30
@ -5386,10 +5395,14 @@
(?:
18|
90
)0
)0|
137
</leadingDigits>
<leadingDigits>
180|
1(?:
37|
80
)|
900[1359]
</leadingDigits>
<format>$1 $2 $3</format>
@ -5420,6 +5433,10 @@
<leadingDigits>700</leadingDigits>
<format>$1 $2 $3</format>
</numberFormat>
<numberFormat pattern="(138)(\d{4})">
<leadingDigits>138</leadingDigits>
<format>$1 $2</format>
</numberFormat>
</availableFormats>
<generalDesc>
<!-- When deciding whether to assume a leading 49 is a country code or not, the number is
@ -5513,7 +5530,10 @@
<exampleNumber>8001234567890</exampleNumber>
</tollFree>
<premiumRate>
<!-- Includes the more expensive of the "televoting" line numbers. See the shared cost
section for more information. -->
<nationalNumberPattern>
137[7-9]\d{6}|
900(?:
[135]\d{6}|
9\d{7}
@ -5523,8 +5543,23 @@
<exampleNumber>9001234567</exampleNumber>
</premiumRate>
<sharedCost>
<nationalNumberPattern>180\d{5,11}</nationalNumberPattern>
<possibleNumberPattern>\d{8,14}</possibleNumberPattern>
<!-- Includes some mass-traffic numbers, used for e.g. phone voting, raffles, since their
costs when dialling from a fixed-line phone is similar.
Prices:
http://www.billiger-telefonieren.de/0180-0137-0900-sonderrufnummern/
Documentation:
http://www.bundesnetzagentur.de/SharedDocs/Downloads/DE/Sachgebiete/Telekommunikation/Unternehmen_Institutionen/Nummerierung/Rufnummern/0137/0137_Nummernplan.pdf?__blob=publicationFile&v=2
-->
<nationalNumberPattern>
1(?:
3(?:
7[1-6]\d{6}|
8\d{4}
)|
80\d{5,11}
)
</nationalNumberPattern>
<possibleNumberPattern>\d{7,14}</possibleNumberPattern>
<exampleNumber>18012345</exampleNumber>
</sharedCost>
<personalNumber>
@ -5644,7 +5679,8 @@
2[01]|
4[0-25-9]
)|
50[0-4]
50[0-4]|
70[1-3]
)\d{4}
</nationalNumberPattern>
<exampleNumber>7674201234</exampleNumber>
@ -6156,7 +6192,7 @@
092 and with 5 and 6 for 96. -->
<nationalNumberPattern>
(?:
1(
1(?:
3[23]\d|
5(?:
[23]|
@ -6905,26 +6941,38 @@
<!-- Gabon -->
<!-- http://www.itu.int/oth/T020200004E/en -->
<!-- www.arcep.ga -->
<territory id="GA" countryCode="241" internationalPrefix="00" leadingZeroPossible="true">
<!-- Note: We cannot set nationalPrefix="0" while fixed line numbers can start with a zero
as this breaks parsing (it treats all leading zeros as national prefixes. -->
<territory id="GA" countryCode="241" internationalPrefix="00" leadingZeroPossible="true" >
<availableFormats>
<numberFormat pattern="(0\d)(\d{2})(\d{2})(\d{2})">
<!-- If no leading zero was supplied, format with the national prefix. -->
<numberFormat pattern="(\d)(\d{2})(\d{2})(\d{2})" nationalPrefixFormattingRule="0$FG">
<leadingDigits>[2-7]</leadingDigits>
<format>$1 $2 $3 $4</format>
</numberFormat>
<!-- This already has a leading zero so we format is "as is". -->
<numberFormat pattern="(\d{2})(\d{2})(\d{2})(\d{2})">
<leadingDigits>0</leadingDigits>
<format>$1 $2 $3 $4</format>
</numberFormat>
</availableFormats>
<generalDesc>
<nationalNumberPattern>0\d{7}</nationalNumberPattern>
<possibleNumberPattern>\d{8}</possibleNumberPattern>
<nationalNumberPattern>0?\d{7}</nationalNumberPattern>
<possibleNumberPattern>\d{7,8}</possibleNumberPattern>
</generalDesc>
<!-- A 7-digit fixed-line plan was scheduled to be implemented on June 17, 2012 to unify fixed
line and mobile numbering. However, it seems that this has not happened; their own
website now lists numbers as "+241 01 44 68 11" and upon ringing numbers they will not
connect without the 0 from outside the country. This was last tested June 2013. -->
line and mobile numbering. However, this has only partially happened; mobile numbers can
now be dialed without a leading zero, but fixed line numbers still require it. Their own
website still lists fixed line numbers as "+241 01 44 68 11" and upon ringing they will
not connect from outside the country without the 0. This was last tested March 2014. -->
<fixedLine>
<nationalNumberPattern>01\d{6}</nationalNumberPattern>
<possibleNumberPattern>\d{8}</possibleNumberPattern>
<exampleNumber>01441234</exampleNumber>
</fixedLine>
<mobile>
<nationalNumberPattern>0[2-7]\d{6}</nationalNumberPattern>
<!-- Mobile numbers can be 7 or 8 digits (with or without a leading zero). -->
<nationalNumberPattern>0?[2-7]\d{6}</nationalNumberPattern>
<exampleNumber>06031234</exampleNumber>
</mobile>
</territory>
@ -7552,6 +7600,7 @@
58|
84
)|
800|
938
)\d{4}
</nationalNumberPattern>
@ -7561,7 +7610,7 @@
<nationalNumberPattern>
473(?:
4(?:
0[3-79]|
0[2-79]|
1[04-9]|
20|
58
@ -7569,7 +7618,8 @@
5(?:
2[01]|
3[3-8]
)
)|
901
)\d{4}
</nationalNumberPattern>
<possibleNumberPattern>\d{10}</possibleNumberPattern>
@ -7917,9 +7967,12 @@
<mobile>
<nationalNumberPattern>
(?:
2[034678]|
5[047]
)\d{7}
2[034678]\d|
5(?:
[047]\d|
54
)
)\d{6}
</nationalNumberPattern>
<possibleNumberPattern>\d{9}</possibleNumberPattern>
<exampleNumber>231234567</exampleNumber>
@ -8977,6 +9030,11 @@
<nationalNumberPattern>[1-9]\d{7,8}</nationalNumberPattern>
<possibleNumberPattern>\d{6,9}</possibleNumberPattern>
</generalDesc>
<noInternationalDialling>
<nationalNumberPattern>[48]0\d{6}</nationalNumberPattern>
<possibleNumberPattern>\d{8}</possibleNumberPattern>
<exampleNumber>80123456</exampleNumber>
</noInternationalDialling>
<fixedLine>
<!-- Includes numbers for corporate networks. -->
<nationalNumberPattern>
@ -9034,7 +9092,7 @@
nationalPrefix="0" nationalPrefixFormattingRule="$NP$FG">
<availableFormats>
<numberFormat nationalPrefixFormattingRule="($NP$FG)"
pattern="(\d{2})(\d{7,8})">
pattern="(\d{2})(\d{5,8})">
<leadingDigits>
2[124]|
[36]1
@ -9064,8 +9122,8 @@
<leadingDigits>800</leadingDigits>
<format>$1 $2</format>
</numberFormat>
<numberFormat pattern="(809)(\d)(\d{3})(\d{3})">
<leadingDigits>809</leadingDigits>
<numberFormat pattern="(80\d)(\d)(\d{3})(\d{3})">
<leadingDigits>80[79]</leadingDigits>
<format>$1 $2 $3 $4</format>
</numberFormat>
</availableFormats>
@ -9078,10 +9136,15 @@
http://www.telkom.co.id/customer-services/area-and-country-code/?type=area.
We also added 0770 after user feedback because it seems to be used on Bintan island.
Where known, fixed mobile prefixes have been represented as Mobile. -->
<!-- Very short (5/6 digit) local numbers in Jakarta seem to be special cases for various
well known companies (Mc Donalds, KFC etc...). Some of these are listed in:
http://cms.binus.edu/datapage/file/io/Spring2014SE/International_Student_Handbook_BINUS.pdf -->
<nationalNumberPattern>
2(?:
1(?:
14\d{3}|
[0-8]\d{6,7}|
500\d{3}|
9\d{6}
)|
[24]\d{7,8}
@ -9243,6 +9306,16 @@
<possibleNumberPattern>\d{8,11}</possibleNumberPattern>
<exampleNumber>8001234567</exampleNumber>
</tollFree>
<uan>
<nationalNumberPattern>8071\d{6}</nationalNumberPattern>
<possibleNumberPattern>\d{10}</possibleNumberPattern>
<exampleNumber>8071123456</exampleNumber>
</uan>
<noInternationalDialling>
<nationalNumberPattern>8071\d{6}</nationalNumberPattern>
<possibleNumberPattern>\d{10}</possibleNumberPattern>
<exampleNumber>8071123456</exampleNumber>
</noInternationalDialling>
<!-- The information below is provided by an Indonesian -->
<premiumRate>
<nationalNumberPattern>809\d{7}</nationalNumberPattern>
@ -9564,7 +9637,7 @@
47\d|
6(?:
5\d|
8[08]
8[068]
)|
7\d{2}|
8(?:
@ -9697,6 +9770,7 @@
<numberFormat pattern="(\d{2})(\d{2})(\d{6})">
<leadingDigits>
7(?:
0[2-4]|
2[0579]|
3[057-9]|
4[0-389]|
@ -9719,6 +9793,11 @@
</leadingDigits>
<leadingDigits>
7(?:
0(?:
2[2-9]|
3|
4[0-7]
)|
2(?:
0[04-9]|
5[09]|
@ -10183,6 +10262,11 @@
<nationalNumberPattern>
(?:
7(?:
0(?:
2[2-9]|
3\d|
4[0-7]
)|
2(?:
0[04-9]|
5[09]|
@ -12567,7 +12651,8 @@
started issuing fixed-line numbers like this. Apparently, mobile-company-issued
fixed-line numbers are one digit longer than government-issued numbers. Moreover, the
range beginning with 6 seems to include some numbers that are one digit longer as well.
Allowing 238\d{6} based on information from Cambodia Yellow Pages. -->
Allowing 238\d{6} and 234[234]\d{4} based on information from Cambodia Yellow Pages.
Note that numbers beginning with 234 are split across two patterns. -->
<nationalNumberPattern>
(?:
2[3-6]|
@ -12580,7 +12665,10 @@
5\d|
6\d?
)\d{5}|
238\d{6}
23(?:
4[234]|
8\d{2}
)\d{4}
</nationalNumberPattern>
<possibleNumberPattern>\d{6,9}</possibleNumberPattern>
<exampleNumber>23756789</exampleNumber>
@ -12652,7 +12740,8 @@
<!-- Numbers should be formatted as a block." -->
<generalDesc>
<nationalNumberPattern>
[2-58]\d{4}|
[2458]\d{4}|
3\d{4,7}|
7\d{7}
</nationalNumberPattern>
<possibleNumberPattern>\d{5,8}</possibleNumberPattern>
@ -12682,6 +12771,11 @@
<possibleNumberPattern>\d{8}</possibleNumberPattern>
<exampleNumber>72012345</exampleNumber>
</mobile>
<premiumRate>
<!-- ITU refers to these as "Telemedia and audiotext". -->
<nationalNumberPattern>3001\d{4}</nationalNumberPattern>
<exampleNumber>30010000</exampleNumber>
</premiumRate>
</territory>
<!-- Comoros -->
@ -12744,7 +12838,7 @@
)|
302|
4(?:
6[5-9]|
6[015-9]|
70
)
)\d{4}
@ -12764,7 +12858,8 @@
)\d{4}
</nationalNumberPattern>
<possibleNumberPattern>\d{10}</possibleNumberPattern>
<exampleNumber>8695561234</exampleNumber>
<!-- Example number from the ITU document. -->
<exampleNumber>8697652917</exampleNumber>
</mobile>
<tollFree>
<nationalNumberPattern>
@ -13421,25 +13516,36 @@
<numberFormat pattern="([2-8]\d)(\d{3})(\d{3})">
<leadingDigits>
2[13]|
[3-8]
3[14]|
[4-8]
</leadingDigits>
<format>$1 $2 $3</format>
</numberFormat>
<numberFormat pattern="(30)(\d{2})(\d{2})(\d{3})">
<leadingDigits>30</leadingDigits>
<format>$1 $2 $3 $4</format>
</numberFormat>
</availableFormats>
<generalDesc>
<nationalNumberPattern>[2-8]\d{7,9}</nationalNumberPattern>
<possibleNumberPattern>\d{6,10}</possibleNumberPattern>
</generalDesc>
<fixedLine>
<!-- The Lonely Planet says that newer WIN phones (fixed phones without a physical landline)
start with 030 (and are longer). There are plenty of examples online. -->
<nationalNumberPattern>
(?:
2[13]|
[35-7][14]|
3(?:
0\d|
[14]
)|
[5-7][14]|
41|
8[1468]
)\d{6}
</nationalNumberPattern>
<possibleNumberPattern>\d{6,8}</possibleNumberPattern>
<possibleNumberPattern>\d{6,9}</possibleNumberPattern>
<exampleNumber>21212862</exampleNumber>
</fixedLine>
<mobile>
@ -13545,26 +13651,22 @@
<possibleNumberPattern>\d{7}(?:\d{3})?</possibleNumberPattern>
</generalDesc>
<fixedLine>
<!-- Adding 430 and 572 since numbers have been found with these prefixes online. -->
<!-- Adding 430 since numbers have been found with these prefixes online. -->
<nationalNumberPattern>
758(?:
234|
4(?:
30|
5[0-9]|
6[2-9]|
8[0-2]
)|
572|
638|
758
57[0-2]|
638
)\d{4}
</nationalNumberPattern>
<exampleNumber>7582345678</exampleNumber>
<exampleNumber>7584305678</exampleNumber>
</fixedLine>
<mobile>
<!-- Adding 72[1256] as these prefixes are found widely on the internet and SMS messages
have been successfully delivered to these numbers. -->
<nationalNumberPattern>
758(?:
28[4-7]|
@ -13580,7 +13682,7 @@
)|
7(?:
1[2-9]|
2[0-6]
2[0-8]
)
)\d{4}
</nationalNumberPattern>
@ -13815,12 +13917,12 @@
<availableFormats>
<!-- Formatting from Ministry of Agriculture,
http://www.moa.gov.lr/content.php?sub=Email&?related=Contacts -->
<numberFormat pattern="([279]\d)(\d{3})(\d{3})">
<leadingDigits>[279]</leadingDigits>
<numberFormat pattern="(2\d)(\d{3})(\d{3})">
<leadingDigits>2</leadingDigits>
<format>$1 $2 $3</format>
</numberFormat>
<numberFormat pattern="(7\d{2})(\d{3})(\d{3})">
<leadingDigits>7</leadingDigits>
<numberFormat pattern="([79]\d{2})(\d{3})(\d{3})">
<leadingDigits>[79]</leadingDigits>
<format>$1 $2 $3</format>
</numberFormat>
<numberFormat pattern="([4-6])(\d{3})(\d{3})">
@ -13834,12 +13936,9 @@
</availableFormats>
<generalDesc>
<nationalNumberPattern>
(?:
[29]\d|
[4-6]|
7\d{1,2}|
[38]\d{2}
)\d{6}
2\d{7}|
[37-9]\d{8}|
[45]\d{6}
</nationalNumberPattern>
<possibleNumberPattern>\d{7,9}</possibleNumberPattern>
</generalDesc>
@ -13849,34 +13948,38 @@
<exampleNumber>21234567</exampleNumber>
</fixedLine>
<mobile>
<!-- According to information from Lonestar Communications Corporation, the prefix 6 is
being removed, but as of June 2012 is in parallel running with their new prefix 88.
According to Cellcom Liberia, they have issued 9 digit numbers starting with 77. -->
<!-- West Africa Telecom seems to be a mobile company from their website. Adding Atlantic
Wireless from the document, even though from online news reports it is not clear they
are still operating. -->
<nationalNumberPattern>
(?:
330\d|
4[67]|
5\d|
6[4-8]|
77?\d{2}|
88\d{2}
77\d{2}|
88\d{2}|
994\d
)\d{5}
</nationalNumberPattern>
<exampleNumber>4612345</exampleNumber>
<exampleNumber>770123456</exampleNumber>
</mobile>
<premiumRate>
<!-- Telemedia service is listed under premium rate. -->
<!-- Note that as of March 2013, the ITU document talks about the withdrawal of the range
(90) 0 XXX XXX. This is a 9 digit range and one we have never supported, but this could
be a mistake in the ITU document and refer to (90) 0XX XXX. However as this is unclear
at the moment, we decided to leave the (90) range unchanged for now. -->
<nationalNumberPattern>90\d{6}</nationalNumberPattern>
<possibleNumberPattern>\d{8}</possibleNumberPattern>
<exampleNumber>90123456</exampleNumber>
<!-- Telelinks and Interactive media service are listed under premium rate. -->
<nationalNumberPattern>90[03]\d{6}</nationalNumberPattern>
<possibleNumberPattern>\d{9}</possibleNumberPattern>
<exampleNumber>900123456</exampleNumber>
</premiumRate>
<voip>
<!-- The plan lists the following range as being assigned to TEMAS. On their homepage they
say they are involved in the VoIP sector. -->
<nationalNumberPattern>33200\d{4}</nationalNumberPattern>
say they are involved in the VoIP sector. Adding WASSCOM and Atlantic Realty &
Investment Corporation here as well; no numbers can be found online, nor company
information. -->
<nationalNumberPattern>
332(?:
0[02]|
5\d
)\d{4}
</nationalNumberPattern>
<possibleNumberPattern>\d{9}</possibleNumberPattern>
<exampleNumber>332001234</exampleNumber>
</voip>
@ -15623,7 +15726,7 @@
[013568]\d|
2[4-7]
)|
5(
5(?:
44\d|
471
)|
@ -16129,7 +16232,7 @@
<numberFormat pattern="([28]\d)(\d{3})(\d{3,4})">
<leadingDigits>
2|
8[246]
8[2-7]
</leadingDigits>
<format>$1 $2 $3</format>
</numberFormat>
@ -16155,7 +16258,7 @@
<exampleNumber>21123456</exampleNumber>
</fixedLine>
<mobile>
<nationalNumberPattern>8[246]\d{7}</nationalNumberPattern>
<nationalNumberPattern>8[23467]\d{7}</nationalNumberPattern>
<possibleNumberPattern>\d{9}</possibleNumberPattern>
<exampleNumber>821234567</exampleNumber>
</mobile>
@ -16309,7 +16412,7 @@
<voip>
<!-- Including virtual telephone and VOIP services. -->
<nationalNumberPattern>
8(
8(?:
3\d{2}|
86
)\d{5}
@ -16412,12 +16515,12 @@
<exampleNumber>20201234</exampleNumber>
</fixedLine>
<mobile>
<!-- Added 90, 91, 92, 97, 98 & 99 from online data. Airtel have confirmed that they use the
89 and 97 prefixes, and Orange use 92. -->
<!-- Added 90, 91, 92, 95, 97, 98 & 99 from online data. Airtel have confirmed that they use the
89 and 97 prefixes, and Orange use 92. MOOV started using 95 in Jan 2014. -->
<nationalNumberPattern>
(?:
89|
9[0-46-9]
9\d
)\d{6}
</nationalNumberPattern>
<exampleNumber>93123456</exampleNumber>
@ -17499,8 +17602,7 @@
<mobile>
<nationalNumberPattern>
(?:
[27]\d{2}|
3[0-79]\d|
[237]\d{2}|
411|
89\d{3}
)\d{3}
@ -18071,17 +18173,9 @@
</leadingDigits>
<format>$1 $2 $3 $4</format>
</numberFormat>
<numberFormat pattern="(\d{2})(\d{4,6})">
<!-- Pattern for shorter fixed-line numbers. -->
<leadingDigits>
[124]|
3[2-4]|
5[24-689]|
6[1-3578]|
7[14-7]|
8[1-7]
</leadingDigits>
<format>$1 $2</format>
<numberFormat pattern="(\d{2})(\d{1})(\d{4})">
<leadingDigits>[12]2</leadingDigits>
<format>$1 $2 $3</format>
</numberFormat>
<!-- We are formatting 70 numbers as per mobile numbers, based on information from some
Poles that this is more usual. -->
@ -18107,14 +18201,16 @@
</availableFormats>
<generalDesc>
<nationalNumberPattern>
[1-58]\d{6,8}|
9\d{8}|
[67]\d{5,8}
[12]\d{6,8}|
[3-57-9]\d{8}|
6\d{5,8}
</nationalNumberPattern>
<possibleNumberPattern>\d{6,9}</possibleNumberPattern>
</generalDesc>
<fixedLine>
<!-- Grouped by prefix-length. -->
<!-- The plan says all geographical numbers are 9 digits; but in at least Warsaw (22) and
Krakow (12) we have found internationally diallable numbers that are 7 digits instead,
so we support those too. -->
<nationalNumberPattern>
(?:
1[2-8]|
@ -18123,14 +18219,11 @@
4[1-468]|
5[24-689]|
6[1-3578]|
7[14-6]|
8[1-7]
)\d{5,7}|
77\d{4,7}|
(?:
89|
7[14-7]|
8[1-79]|
9[145]
)\d{7}
)\d{7}|
[12]2\d{5}
</nationalNumberPattern>
<exampleNumber>123456789</exampleNumber>
</fixedLine>
@ -18147,8 +18240,8 @@
<exampleNumber>512345678</exampleNumber>
</mobile>
<pager>
<nationalNumberPattern>642\d{3,6}</nationalNumberPattern>
<exampleNumber>642123456</exampleNumber>
<nationalNumberPattern>64\d{4,7}</nationalNumberPattern>
<exampleNumber>641234567</exampleNumber>
</pager>
<tollFree>
<nationalNumberPattern>800\d{6}</nationalNumberPattern>
@ -20778,9 +20871,11 @@
<exampleNumber>1100</exampleNumber>
</noInternationalDialling>
<fixedLine>
<!-- Numbers online have been found that start with 20, despite the ITU doc not covering
these. -->
<nationalNumberPattern>
(?:
2[1-9]|
2\d|
3[2-9]|
4[2-5]|
5[2-6]|
@ -20808,8 +20903,8 @@
</premiumRate>
<voip>
<!-- The ITU document says that the 89 prefix is also VOIP but there are lots of numbers
online to suggest they are actually used as mobile numbers -->
<nationalNumberPattern>60\d{7}</nationalNumberPattern>
online to suggest they are actually used as mobile numbers. -->
<nationalNumberPattern>6[08]\d{7}</nationalNumberPattern>
<possibleNumberPattern>\d{9}</possibleNumberPattern>
<exampleNumber>601234567</exampleNumber>
</voip>
@ -21407,8 +21502,8 @@
<availableFormats>
<numberFormat pattern="([2-8])(\d{3,4})(\d{4})">
<leadingDigits>
[2-7]|
8[1-9]
[2-6]|
[78][1-9]
</leadingDigits>
<format>$1 $2 $3</format>
</numberFormat>
@ -21419,10 +21514,17 @@
</leadingDigits>
<format>$1 $2 $3</format>
</numberFormat>
<numberFormat pattern="(70)(\d{4})(\d{4})">
<leadingDigits>70</leadingDigits>
<format>$1 $2 $3</format>
</numberFormat>
</availableFormats>
<generalDesc>
<nationalNumberPattern>[2-9]\d{7,8}</nationalNumberPattern>
<possibleNumberPattern>\d{8,9}</possibleNumberPattern>
<nationalNumberPattern>
[2-689]\d{7,8}|
7\d{7,9}
</nationalNumberPattern>
<possibleNumberPattern>\d{8,10}</possibleNumberPattern>
</generalDesc>
<fixedLine>
<nationalNumberPattern>[2-8]\d{7,8}</nationalNumberPattern>
@ -21444,6 +21546,12 @@
<possibleNumberPattern>\d{9}</possibleNumberPattern>
<exampleNumber>900123456</exampleNumber>
</premiumRate>
<!-- http://www.chief.com.tw/telecom_eng/front/bin/ptlist.phtml?Category=107 -->
<voip>
<nationalNumberPattern>70\d{8}</nationalNumberPattern>
<possibleNumberPattern>\d{10}</possibleNumberPattern>
<exampleNumber>7012345678</exampleNumber>
</voip>
</territory>
<!-- Tanzania -->
@ -22266,7 +22374,7 @@
7[079]
)
)|
9(
9(?:
2(?:
1[1267]|
5\d|
@ -22448,8 +22556,8 @@
<mobile>
<!-- We have no information on mobile numbers from the Vatican. It is probable that they use
Italian mobile contracts. -->
<nationalNumberPattern>N/A</nationalNumberPattern>
<possibleNumberPattern>N/A</possibleNumberPattern>
<nationalNumberPattern>NA</nationalNumberPattern>
<possibleNumberPattern>NA</possibleNumberPattern>
</mobile>
<!-- No information exists about other types of numbers. -->
</territory>
@ -22463,6 +22571,8 @@
<nationalNumberPattern>[5789]\d{9}</nationalNumberPattern>
<possibleNumberPattern>\d{7}(?:\d{3})?</possibleNumberPattern>
</generalDesc>
<!-- For 570, 571 and 572 prefixes, we believe the ITU doc incorrectly listed them to be under
area code 758, which should be 784. -->
<fixedLine>
<nationalNumberPattern>
784(?:
@ -22475,10 +22585,13 @@
4(?:
38|
5[0-36-8]|
8\d|
9[01]
8[0-8]
)|
5(?:
55|
7[0-2]|
93
)|
555|
638|
784
)\d{4}
@ -22486,19 +22599,17 @@
<exampleNumber>7842661234</exampleNumber>
</fixedLine>
<mobile>
<!-- Adding 784 433 and 784 534 since online numbers can be found with these prefixes, and
the latter seems, according to some online sources, to be assigned to Digicell. -->
<nationalNumberPattern>
784(?:
4(?:
3[0-4]|
5[45]|
9[2-5]
89|
9[0-5]
)|
5(?:
2[6-9]|
3[0-4]|
93
3[0-4]
)
)\d{4}
</nationalNumberPattern>


+ 19
- 0
resources/PhoneNumberMetadataForTesting.xml View File

@ -227,6 +227,25 @@
<territory id="CC" countryCode="61">
</territory>
<!-- China -->
<!-- Used to test as-you-type-formatter with complicated number format patterns. -->
<territory id="CN" countryCode="86">
<availableFormats>
<numberFormat nationalPrefixFormattingRule="$NP$FG" pattern="(\d{3})(\d{5,6})"
carrierCodeFormattingRule="$CC $FG">
<leadingDigits>[3-9]</leadingDigits>
<leadingDigits>[3-9]\d{2}[19]</leadingDigits>
<leadingDigits>
[3-9]\d{2}(?:
10|
95
)
</leadingDigits>
<format>$1 $2</format>
</numberFormat>
</availableFormats>
</territory>
<!-- Christmas Islands -->
<!-- Country calling code shared with Australia. -->
<!-- This country is used to test ShortNumberInfo, so at least the country calling code must be


+ 110
- 11
resources/ShortNumberMetadata.xml View File

@ -1016,7 +1016,7 @@
1(?:
1\d|
5[3-6]|
6[01]
60
)|
611|
7(?:
@ -2211,7 +2211,7 @@
<!-- http://www.itu.int/oth/T0202000030/en -->
<territory id="CR">
<generalDesc>
<nationalNumberPattern>[19]\d{2,3}</nationalNumberPattern>
<nationalNumberPattern>[1359]\d{2,3}</nationalNumberPattern>
<possibleNumberPattern>\d{3,4}</possibleNumberPattern>
</generalDesc>
<shortCode>
@ -2243,10 +2243,7 @@
00|
1[56]
)|
5(?:
15|
5[15]
)|
515|
693|
7(?:
00|
@ -2256,6 +2253,14 @@
)|
975
)|
3855|
5(?:
0(?:
30|
49
)|
510
)|
911
</nationalNumberPattern>
<exampleNumber>1022</exampleNumber>
@ -6068,6 +6073,11 @@
</nationalNumberPattern>
<exampleNumber>1011</exampleNumber>
</shortCode>
<carrierServices>
<nationalNumberPattern>1[0235]\d{2}</nationalNumberPattern>
<possibleNumberPattern>\d{4}</possibleNumberPattern>
<exampleNumber>1011</exampleNumber>
</carrierServices>
<emergency>
<!-- 11X is national, 19X is for Maputo. -->
<!-- http://www.lonelyplanet.com/shop_pickandmix/previews/mozambique-maputo-preview.pdf -->
@ -6632,13 +6642,28 @@
<!-- http://www.itu.int/oth/T02020000A8/en -->
<territory id="PL">
<generalDesc>
<nationalNumberPattern>[19]\d{2}</nationalNumberPattern>
<possibleNumberPattern>\d{3}</possibleNumberPattern>
<nationalNumberPattern>
1\d{2}(?:\d{3})?|
9\d{2}
</nationalNumberPattern>
<possibleNumberPattern>\d{3,6}</possibleNumberPattern>
</generalDesc>
<shortCode>
<nationalNumberPattern>
112|
99[789]
11(?:
2|
6(?:
000|
1(?:
11|
23
)
)
)|
9(?:
8[4-7]|
9[1-9]
)
</nationalNumberPattern>
<exampleNumber>112</exampleNumber>
</shortCode>
@ -6647,8 +6672,19 @@
112|
99[789]
</nationalNumberPattern>
<possibleNumberPattern>\d{3}</possibleNumberPattern>
<exampleNumber>112</exampleNumber>
</emergency>
<expandedEmergency>
<nationalNumberPattern>
9(?:
8[4-6]|
9[56]
)
</nationalNumberPattern>
<possibleNumberPattern>\d{3}</possibleNumberPattern>
<exampleNumber>984</exampleNumber>
</expandedEmergency>
</territory>
<!-- Saint Pierre and Miquelon (Collectivité territoriale de la République française) -->
@ -7602,6 +7638,8 @@
<!-- Thailand -->
<!-- http://www.itu.int/oth/T02020000CD/en -->
<!-- http://www.barascientific.com/bscnews/variety/emergency/Tel-4Digi.pdf -->
<!-- http://en.wikipedia.org/wiki/+66 -->
<!-- Other numbers found in online searches. -->
<territory id="TH">
<generalDesc>
<nationalNumberPattern>1\d{2,3}</nationalNumberPattern>
@ -7610,12 +7648,60 @@
<shortCode>
<nationalNumberPattern>
1(?:
669|
0[0-2]|
1(?:
00|
12|
25|
33|
5[05]|
7[58]|
9[37]
)|
3(?:
18|
31|
56|
73
)|
5(?:
5[45]|
66|
72|
8[01]|
9[59]
)|
6(?:
00|
69|
7[28]|
9[01]
)|
790|
9[19]
)
</nationalNumberPattern>
<exampleNumber>191</exampleNumber>
</shortCode>
<carrierServices>
<nationalNumberPattern>
1(?:
1(?:
00|
75
)|
331|
678
)
</nationalNumberPattern>
<possibleNumberPattern>\d{4}</possibleNumberPattern>
<exampleNumber>1175</exampleNumber>
</carrierServices>
<directoryServices>
<nationalNumberPattern>1133</nationalNumberPattern>
<possibleNumberPattern>\d{4}</possibleNumberPattern>
<exampleNumber>1133</exampleNumber>
</directoryServices>
<emergency>
<nationalNumberPattern>
1(?:
@ -7625,6 +7711,19 @@
</nationalNumberPattern>
<exampleNumber>191</exampleNumber>
</emergency>
<expandedEmergency>
<nationalNumberPattern>
1(?:
1(?:
50|
93
)|
691
)
</nationalNumberPattern>
<possibleNumberPattern>\d{4}</possibleNumberPattern>
<exampleNumber>1193</exampleNumber>
</expandedEmergency>
</territory>
<!-- Tajikistan -->


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

Loading…
Cancel
Save