phonelib 0.5.6 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/data/extended_data.dat +0 -0
  3. data/data/libphonenumber/FALSEHOODS.md +221 -0
  4. data/data/libphonenumber/FAQ.md +8 -0
  5. data/data/libphonenumber/README.md +4 -4
  6. data/data/libphonenumber/cpp/CMakeLists.txt +2 -1
  7. data/data/libphonenumber/cpp/README +62 -2
  8. data/data/libphonenumber/cpp/src/phonenumbers/lite_metadata.cc +9480 -9440
  9. data/data/libphonenumber/cpp/src/phonenumbers/metadata.cc +10349 -10308
  10. data/data/libphonenumber/cpp/src/phonenumbers/phonenumbermatcher.cc +1 -1
  11. data/data/libphonenumber/cpp/src/phonenumbers/phonenumberutil.cc +108 -5
  12. data/data/libphonenumber/cpp/src/phonenumbers/phonenumberutil.h +37 -4
  13. data/data/libphonenumber/cpp/src/phonenumbers/short_metadata.cc +544 -514
  14. data/data/libphonenumber/cpp/test/phonenumbers/phonenumbermatcher_test.cc +9 -1
  15. data/data/libphonenumber/cpp/test/phonenumbers/phonenumberutil_test.cc +61 -1
  16. data/data/libphonenumber/debian/control +1 -1
  17. data/data/libphonenumber/java/carrier/pom.xml +4 -4
  18. data/data/libphonenumber/java/carrier/src/com/google/i18n/phonenumbers/carrier/data/225_en +0 -0
  19. data/data/libphonenumber/java/carrier/src/com/google/i18n/phonenumbers/carrier/data/229_en +0 -0
  20. data/data/libphonenumber/java/carrier/src/com/google/i18n/phonenumbers/carrier/data/252_en +0 -0
  21. data/data/libphonenumber/java/carrier/src/com/google/i18n/phonenumbers/carrier/data/254_en +0 -0
  22. data/data/libphonenumber/java/carrier/src/com/google/i18n/phonenumbers/carrier/data/84_en +0 -0
  23. data/data/libphonenumber/java/carrier/src/com/google/i18n/phonenumbers/carrier/data/853_en +0 -0
  24. data/data/libphonenumber/java/carrier/src/com/google/i18n/phonenumbers/carrier/data/86_en +0 -0
  25. data/data/libphonenumber/java/carrier/src/com/google/i18n/phonenumbers/carrier/data/968_en +0 -0
  26. data/data/libphonenumber/java/demo/pom.xml +5 -5
  27. data/data/libphonenumber/java/geocoder/pom.xml +4 -4
  28. data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/251_en +0 -0
  29. data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/254_en +0 -0
  30. data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/84_en +0 -0
  31. data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/86_en +0 -0
  32. data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/86_zh +0 -0
  33. data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/timezones/data/map_data +0 -0
  34. data/data/libphonenumber/java/internal/prefixmapper/pom.xml +3 -3
  35. data/data/libphonenumber/java/libphonenumber/pom.xml +2 -2
  36. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java +120 -12
  37. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BJ +0 -0
  38. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BZ +0 -0
  39. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CI +0 -0
  40. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CL +0 -0
  41. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CN +0 -0
  42. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_ET +0 -0
  43. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_FO +0 -0
  44. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GQ +0 -0
  45. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_IN +0 -0
  46. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_KE +0 -0
  47. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_KW +0 -0
  48. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_ML +0 -0
  49. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MO +0 -0
  50. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_NO +0 -0
  51. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_OM +0 -0
  52. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SE +0 -0
  53. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SO +0 -0
  54. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_TK +0 -0
  55. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_VN +0 -0
  56. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/ShortNumberMetadataProto_FO +0 -0
  57. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/ShortNumberMetadataProto_FR +0 -0
  58. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/ShortNumberMetadataProto_KE +0 -0
  59. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/SingleFilePhoneNumberMetadataProto +0 -0
  60. data/data/libphonenumber/java/libphonenumber/test/com/google/i18n/phonenumbers/ExampleNumbersTest.java +22 -4
  61. data/data/libphonenumber/java/libphonenumber/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java +22 -1
  62. data/data/libphonenumber/java/pending_code_changes.txt +1 -0
  63. data/data/libphonenumber/java/pom.xml +1 -1
  64. data/data/libphonenumber/java/release_notes.txt +33 -1
  65. data/data/libphonenumber/javascript/README.md +2 -2
  66. data/data/libphonenumber/javascript/i18n/phonenumbers/demo-compiled.js +157 -155
  67. data/data/libphonenumber/javascript/i18n/phonenumbers/metadata.js +49 -41
  68. data/data/libphonenumber/javascript/i18n/phonenumbers/metadatalite.js +49 -41
  69. data/data/libphonenumber/javascript/i18n/phonenumbers/phonenumberutil.js +39 -10
  70. data/data/libphonenumber/javascript/i18n/phonenumbers/phonenumberutil_test.js +8 -0
  71. data/data/libphonenumber/resources/PhoneNumberMetadata.xml +176 -125
  72. data/data/libphonenumber/resources/ShortNumberMetadata.xml +158 -24
  73. data/data/libphonenumber/resources/carrier/en/225.txt +1 -0
  74. data/data/libphonenumber/resources/carrier/en/229.txt +3 -0
  75. data/data/libphonenumber/resources/carrier/en/252.txt +1 -0
  76. data/data/libphonenumber/resources/carrier/en/254.txt +24 -8
  77. data/data/libphonenumber/resources/carrier/en/84.txt +3 -0
  78. data/data/libphonenumber/resources/carrier/en/853.txt +10 -0
  79. data/data/libphonenumber/resources/carrier/en/86.txt +9 -0
  80. data/data/libphonenumber/resources/carrier/en/968.txt +11 -1
  81. data/data/libphonenumber/resources/geocoding/en/251.txt +1 -0
  82. data/data/libphonenumber/resources/geocoding/en/254.txt +5 -5
  83. data/data/libphonenumber/resources/geocoding/en/84.txt +9 -1
  84. data/data/libphonenumber/resources/geocoding/en/86.txt +18 -14
  85. data/data/libphonenumber/resources/geocoding/zh/86.txt +17 -15
  86. data/data/libphonenumber/resources/phonenumber.proto +7 -6
  87. data/data/libphonenumber/resources/timezones/map_data.txt +63 -19
  88. data/data/phone_data.dat +0 -0
  89. data/lib/phonelib/phone_analyzer.rb +11 -7
  90. data/lib/phonelib/phone_analyzer_helper.rb +4 -3
  91. data/lib/phonelib/version.rb +1 -1
  92. metadata +4 -2
@@ -864,11 +864,15 @@ static const NumberTest kStrictGroupingCases[] = {
864
864
  // Should be found by strict grouping but not exact grouping, as the last two
865
865
  // groups are formatted together as a block.
866
866
  NumberTest("0800-2491234", RegionCode::DE()),
867
+ // If the user is using alternate formats, test that numbers formatted in
868
+ // that way are found.
869
+ #ifdef I18N_PHONENUMBERS_USE_ALTERNATE_FORMATS
867
870
  // Doesn't match any formatting in the test file, but almost matches an
868
871
  // alternate format (the last two groups have been squashed together here).
869
872
  NumberTest("0900-1 123123", RegionCode::DE()),
870
873
  NumberTest("(0)900-1 123123", RegionCode::DE()),
871
874
  NumberTest("0 900-1 123123", RegionCode::DE()),
875
+ #endif // I18N_PHONENUMBERS_USE_ALTERNATE_FORMATS
872
876
  // NDC also found as part of the country calling code; this shouldn't ruin the
873
877
  // grouping expectations.
874
878
  NumberTest("+33 3 34 2312", RegionCode::FR()),
@@ -903,13 +907,17 @@ static const NumberTest kExactGroupingCases[] = {
903
907
  NumberTest("0494949 ext. 49", RegionCode::DE()),
904
908
  NumberTest("01 (33) 3461 2234", RegionCode::MX()), // Optional NP present
905
909
  NumberTest("(33) 3461 2234", RegionCode::MX()), // Optional NP omitted
906
- // Breakdown assistance number with normal formatting.
910
+ // If the user is using alternate formats, test that numbers formatted in
911
+ // that way are found.
912
+ #ifdef I18N_PHONENUMBERS_USE_ALTERNATE_FORMATS
913
+ // Breakdown assistance number using alternate formatting pattern.
907
914
  NumberTest("1800-10-10 22", RegionCode::AU()),
908
915
  // Doesn't match any formatting in the test file, but matches an alternate
909
916
  // format exactly.
910
917
  NumberTest("0900-1 123 123", RegionCode::DE()),
911
918
  NumberTest("(0)900-1 123 123", RegionCode::DE()),
912
919
  NumberTest("0 900-1 123 123", RegionCode::DE()),
920
+ #endif // I18N_PHONENUMBERS_USE_ALTERNATE_FORMATS
913
921
  NumberTest("+33 3 34 23 12", RegionCode::FR()),
914
922
  };
915
923
 
@@ -372,6 +372,25 @@ TEST_F(PhoneNumberUtilTest, GetExampleNumber) {
372
372
  EXPECT_FALSE(phone_util_.GetExampleNumber(RegionCode::UN001(), &test_number));
373
373
  }
374
374
 
375
+ TEST_F(PhoneNumberUtilTest, GetInvalidExampleNumber) {
376
+ // RegionCode 001 is reserved for supporting non-geographical country calling
377
+ // codes. We don't support getting an invalid example number for it with
378
+ // GetInvalidExampleNumber.
379
+ PhoneNumber test_number;
380
+ EXPECT_FALSE(phone_util_.GetInvalidExampleNumber(RegionCode::UN001(),
381
+ &test_number));
382
+ EXPECT_EQ(PhoneNumber::default_instance(), test_number);
383
+ EXPECT_FALSE(phone_util_.GetInvalidExampleNumber(RegionCode::CS(),
384
+ &test_number));
385
+ EXPECT_EQ(PhoneNumber::default_instance(), test_number);
386
+
387
+ EXPECT_TRUE(phone_util_.GetInvalidExampleNumber(RegionCode::US(),
388
+ &test_number));
389
+ // At least the country calling code should be set correctly.
390
+ EXPECT_EQ(1, test_number.country_code());
391
+ EXPECT_NE(0, test_number.national_number());
392
+ }
393
+
375
394
  TEST_F(PhoneNumberUtilTest, GetExampleNumberForNonGeoEntity) {
376
395
  PhoneNumber toll_free_number;
377
396
  toll_free_number.set_country_code(800);
@@ -390,6 +409,30 @@ TEST_F(PhoneNumberUtilTest, GetExampleNumberForNonGeoEntity) {
390
409
  EXPECT_EQ(universal_premium_rate, test_number);
391
410
  }
392
411
 
412
+ TEST_F(PhoneNumberUtilTest, GetExampleNumberWithoutRegion) {
413
+ // In our test metadata we don't cover all types: in our real metadata, we do.
414
+ PhoneNumber test_number;
415
+ bool success = phone_util_.GetExampleNumberForType(
416
+ PhoneNumberUtil::FIXED_LINE,
417
+ &test_number);
418
+ // We test that the call to get an example number succeeded, and that the
419
+ // number passed in was modified.
420
+ EXPECT_TRUE(success);
421
+ EXPECT_NE(PhoneNumber::default_instance(), test_number);
422
+ test_number.Clear();
423
+
424
+ success = phone_util_.GetExampleNumberForType(PhoneNumberUtil::MOBILE,
425
+ &test_number);
426
+ EXPECT_TRUE(success);
427
+ EXPECT_NE(PhoneNumber::default_instance(), test_number);
428
+ test_number.Clear();
429
+
430
+ success = phone_util_.GetExampleNumberForType(PhoneNumberUtil::PREMIUM_RATE,
431
+ &test_number);
432
+ EXPECT_TRUE(success);
433
+ EXPECT_NE(PhoneNumber::default_instance(), test_number);
434
+ }
435
+
393
436
  TEST_F(PhoneNumberUtilTest, FormatUSNumber) {
394
437
  PhoneNumber test_number;
395
438
  string formatted_number;
@@ -1852,6 +1895,22 @@ TEST_F(PhoneNumberUtilTest, IsNumberGeographical) {
1852
1895
  number.set_country_code(800);
1853
1896
  number.set_national_number(12345678ULL);
1854
1897
  EXPECT_FALSE(IsNumberGeographical(number)); // Internation toll free number.
1898
+
1899
+ // We test that mobile phone numbers in relevant regions are indeed considered
1900
+ // geographical.
1901
+
1902
+ number.set_country_code(54);
1903
+ number.set_national_number(91187654321ULL);
1904
+ EXPECT_TRUE(IsNumberGeographical(number)); // Argentina, mobile phone number.
1905
+
1906
+ number.set_country_code(52);
1907
+ number.set_national_number(12345678900ULL);
1908
+ EXPECT_TRUE(IsNumberGeographical(number)); // Mexico, mobile phone number.
1909
+
1910
+ number.set_country_code(52);
1911
+ number.set_national_number(15512345678ULL);
1912
+ EXPECT_TRUE(IsNumberGeographical(number)); // Mexico, another mobile phone
1913
+ // number.
1855
1914
  }
1856
1915
 
1857
1916
  TEST_F(PhoneNumberUtilTest, IsLeadingZeroPossible) {
@@ -2363,7 +2422,7 @@ TEST_F(PhoneNumberUtilTest, ConvertAlphaCharactersInNumber) {
2363
2422
 
2364
2423
  // Try with some non-ASCII characters.
2365
2424
  input.assign("1\xE3\x80\x80\xEF\xBC\x88" "800) ABC-DEF"
2366
- /* "1 (800) ABCD-DEF" */);
2425
+ /* "1 (800) ABC-DEF" */);
2367
2426
  static const string kExpectedFullwidthOutput =
2368
2427
  "1\xE3\x80\x80\xEF\xBC\x88" "800) 222-333" /* "1 (800) 222-333" */;
2369
2428
  phone_util_.ConvertAlphaCharactersInNumber(&input);
@@ -3184,6 +3243,7 @@ TEST_F(PhoneNumberUtilTest, ParseWithInternationalPrefixes) {
3184
3243
  phone_util_.Parse("\xEF\xBC\x8B" "1 (650) 333-6000",
3185
3244
  /* "+1 (650) 333-6000" */
3186
3245
  RegionCode::SG(), &test_number));
3246
+ EXPECT_EQ(us_number, test_number);
3187
3247
  // Using a soft hyphen U+00AD.
3188
3248
  EXPECT_EQ(PhoneNumberUtil::NO_PARSING_ERROR,
3189
3249
  phone_util_.Parse("1 (650) 333" "\xC2\xAD" "-6000",
@@ -3,7 +3,7 @@ Priority: optional
3
3
  Maintainer: Debian Java Maintainers <pkg-java-maintainers@lists.alioth.debian.org>
4
4
  Uploaders: Daniel Pocock <daniel@pocock.pro>, Fredrik Roubert <roubert@google.com>
5
5
  Build-Depends: cdbs,
6
- cmake (>= 3.1),
6
+ cmake (>= 2.8),
7
7
  debhelper (>= 9),
8
8
  default-jdk | java-sdk,
9
9
  libboost-dev (>= 1.40),
@@ -3,14 +3,14 @@
3
3
  <modelVersion>4.0.0</modelVersion>
4
4
  <groupId>com.googlecode.libphonenumber</groupId>
5
5
  <artifactId>carrier</artifactId>
6
- <version>1.27-SNAPSHOT</version>
6
+ <version>1.30-SNAPSHOT</version>
7
7
  <packaging>jar</packaging>
8
8
  <url>https://github.com/googlei18n/libphonenumber/</url>
9
9
 
10
10
  <parent>
11
11
  <groupId>com.googlecode.libphonenumber</groupId>
12
12
  <artifactId>libphonenumber-parent</artifactId>
13
- <version>7.2.7-SNAPSHOT</version>
13
+ <version>7.3.1-SNAPSHOT</version>
14
14
  </parent>
15
15
 
16
16
  <build>
@@ -34,12 +34,12 @@
34
34
  <dependency>
35
35
  <groupId>com.googlecode.libphonenumber</groupId>
36
36
  <artifactId>libphonenumber</artifactId>
37
- <version>7.2.7-SNAPSHOT</version>
37
+ <version>7.3.1-SNAPSHOT</version>
38
38
  </dependency>
39
39
  <dependency>
40
40
  <groupId>com.googlecode.libphonenumber</groupId>
41
41
  <artifactId>prefixmapper</artifactId>
42
- <version>2.37-SNAPSHOT</version>
42
+ <version>2.40-SNAPSHOT</version>
43
43
  </dependency>
44
44
  </dependencies>
45
45
 
@@ -4,11 +4,11 @@
4
4
  <parent>
5
5
  <artifactId>libphonenumber-parent</artifactId>
6
6
  <groupId>com.googlecode.libphonenumber</groupId>
7
- <version>7.2.7-SNAPSHOT</version>
7
+ <version>7.3.1-SNAPSHOT</version>
8
8
  </parent>
9
9
  <groupId>com.googlecode.libphonenumber</groupId>
10
10
  <artifactId>demo</artifactId>
11
- <version>7.2.7-SNAPSHOT</version>
11
+ <version>7.3.1-SNAPSHOT</version>
12
12
 
13
13
  <properties>
14
14
  <gae.version>1.9.32</gae.version>
@@ -48,17 +48,17 @@
48
48
  <dependency>
49
49
  <groupId>com.googlecode.libphonenumber</groupId>
50
50
  <artifactId>libphonenumber</artifactId>
51
- <version>7.2.7-SNAPSHOT</version>
51
+ <version>7.3.1-SNAPSHOT</version>
52
52
  </dependency>
53
53
  <dependency>
54
54
  <groupId>com.googlecode.libphonenumber</groupId>
55
55
  <artifactId>geocoder</artifactId>
56
- <version>2.37-SNAPSHOT</version>
56
+ <version>2.40-SNAPSHOT</version>
57
57
  </dependency>
58
58
  <dependency>
59
59
  <groupId>com.googlecode.libphonenumber</groupId>
60
60
  <artifactId>carrier</artifactId>
61
- <version>1.27-SNAPSHOT</version>
61
+ <version>1.30-SNAPSHOT</version>
62
62
  </dependency>
63
63
  </dependencies>
64
64
 
@@ -3,14 +3,14 @@
3
3
  <modelVersion>4.0.0</modelVersion>
4
4
  <groupId>com.googlecode.libphonenumber</groupId>
5
5
  <artifactId>geocoder</artifactId>
6
- <version>2.37-SNAPSHOT</version>
6
+ <version>2.40-SNAPSHOT</version>
7
7
  <packaging>jar</packaging>
8
8
  <url>https://github.com/googlei18n/libphonenumber/</url>
9
9
 
10
10
  <parent>
11
11
  <groupId>com.googlecode.libphonenumber</groupId>
12
12
  <artifactId>libphonenumber-parent</artifactId>
13
- <version>7.2.7-SNAPSHOT</version>
13
+ <version>7.3.1-SNAPSHOT</version>
14
14
  </parent>
15
15
 
16
16
  <build>
@@ -42,12 +42,12 @@
42
42
  <dependency>
43
43
  <groupId>com.googlecode.libphonenumber</groupId>
44
44
  <artifactId>libphonenumber</artifactId>
45
- <version>7.2.7-SNAPSHOT</version>
45
+ <version>7.3.1-SNAPSHOT</version>
46
46
  </dependency>
47
47
  <dependency>
48
48
  <groupId>com.googlecode.libphonenumber</groupId>
49
49
  <artifactId>prefixmapper</artifactId>
50
- <version>2.37-SNAPSHOT</version>
50
+ <version>2.40-SNAPSHOT</version>
51
51
  </dependency>
52
52
  </dependencies>
53
53
 
@@ -3,14 +3,14 @@
3
3
  <modelVersion>4.0.0</modelVersion>
4
4
  <groupId>com.googlecode.libphonenumber</groupId>
5
5
  <artifactId>prefixmapper</artifactId>
6
- <version>2.37-SNAPSHOT</version>
6
+ <version>2.40-SNAPSHOT</version>
7
7
  <packaging>jar</packaging>
8
8
  <url>https://github.com/googlei18n/libphonenumber/</url>
9
9
 
10
10
  <parent>
11
11
  <groupId>com.googlecode.libphonenumber</groupId>
12
12
  <artifactId>libphonenumber-parent</artifactId>
13
- <version>7.2.7-SNAPSHOT</version>
13
+ <version>7.3.1-SNAPSHOT</version>
14
14
  <relativePath>../../pom.xml</relativePath>
15
15
  </parent>
16
16
 
@@ -29,7 +29,7 @@
29
29
  <dependency>
30
30
  <groupId>com.googlecode.libphonenumber</groupId>
31
31
  <artifactId>libphonenumber</artifactId>
32
- <version>7.2.7-SNAPSHOT</version>
32
+ <version>7.3.1-SNAPSHOT</version>
33
33
  </dependency>
34
34
  </dependencies>
35
35
 
@@ -3,14 +3,14 @@
3
3
  <modelVersion>4.0.0</modelVersion>
4
4
  <groupId>com.googlecode.libphonenumber</groupId>
5
5
  <artifactId>libphonenumber</artifactId>
6
- <version>7.2.7-SNAPSHOT</version>
6
+ <version>7.3.1-SNAPSHOT</version>
7
7
  <packaging>jar</packaging>
8
8
  <url>https://github.com/googlei18n/libphonenumber/</url>
9
9
 
10
10
  <parent>
11
11
  <groupId>com.googlecode.libphonenumber</groupId>
12
12
  <artifactId>libphonenumber-parent</artifactId>
13
- <version>7.2.7-SNAPSHOT</version>
13
+ <version>7.3.1-SNAPSHOT</version>
14
14
  </parent>
15
15
 
16
16
  <build>
@@ -88,6 +88,11 @@ public class PhoneNumberUtil {
88
88
  // be the length of the area code plus the length of the mobile token.
89
89
  private static final Map<Integer, String> MOBILE_TOKEN_MAPPINGS;
90
90
 
91
+ // Set of country calling codes that have geographically assigned mobile numbers. This may not be
92
+ // complete; we add calling codes case by case, as we find geographical mobile numbers or hear
93
+ // from user reports.
94
+ private static final Set<Integer> GEO_MOBILE_COUNTRIES;
95
+
91
96
  // The PLUS_SIGN signifies the international prefix.
92
97
  static final char PLUS_SIGN = '+';
93
98
 
@@ -119,6 +124,12 @@ public class PhoneNumberUtil {
119
124
  mobileTokenMap.put(54, "9");
120
125
  MOBILE_TOKEN_MAPPINGS = Collections.unmodifiableMap(mobileTokenMap);
121
126
 
127
+ HashSet<Integer> geoMobileCountries = new HashSet<Integer>();
128
+ geoMobileCountries.add(52); // Mexico
129
+ geoMobileCountries.add(54); // Argentina
130
+ geoMobileCountries.add(55); // Brazil
131
+ GEO_MOBILE_COUNTRIES = Collections.unmodifiableSet(geoMobileCountries);
132
+
122
133
  // Simple ASCII digits map used to populate ALPHA_PHONE_MAPPINGS and
123
134
  // ALL_PLUS_NUMBER_GROUPING_SYMBOLS.
124
135
  HashMap<Character, Character> asciiDigitMappings = new HashMap<Character, Character>();
@@ -1014,10 +1025,11 @@ public class PhoneNumberUtil {
1014
1025
  */
1015
1026
  boolean isNumberGeographical(PhoneNumber phoneNumber) {
1016
1027
  PhoneNumberType numberType = getNumberType(phoneNumber);
1017
- // TODO: Include mobile phone numbers from countries like Indonesia, which has some
1018
- // mobile numbers that are geographical.
1019
- return numberType == PhoneNumberType.FIXED_LINE ||
1020
- numberType == PhoneNumberType.FIXED_LINE_OR_MOBILE;
1028
+
1029
+ return numberType == PhoneNumberType.FIXED_LINE
1030
+ || numberType == PhoneNumberType.FIXED_LINE_OR_MOBILE
1031
+ || (GEO_MOBILE_COUNTRIES.contains(phoneNumber.getCountryCode())
1032
+ && numberType == PhoneNumberType.MOBILE);
1021
1033
  }
1022
1034
 
1023
1035
  /**
@@ -1818,6 +1830,62 @@ public class PhoneNumberUtil {
1818
1830
  return getExampleNumberForType(regionCode, PhoneNumberType.FIXED_LINE);
1819
1831
  }
1820
1832
 
1833
+ /**
1834
+ * Gets an invalid number for the specified region. This is useful for unit-testing purposes,
1835
+ * where you want to test what will happen with an invalid number. Note that the number that is
1836
+ * returned will always be able to be parsed and will have the correct country code. It may also
1837
+ * be a valid *short* number/code for this region. Validity checking such numbers is handled with
1838
+ * {@link com.google.i18n.phonenumbers.ShortNumberInfo}.
1839
+ *
1840
+ * @param regionCode the region for which an example number is needed
1841
+ * @return an invalid number for the specified region. Returns null when an unsupported region or
1842
+ * the region 001 (Earth) is passed in.
1843
+ */
1844
+ public PhoneNumber getInvalidExampleNumber(String regionCode) {
1845
+ if (!isValidRegionCode(regionCode)) {
1846
+ logger.log(Level.WARNING, "Invalid or unknown region code provided: " + regionCode);
1847
+ return null;
1848
+ }
1849
+ // We start off with a valid fixed-line number since every country supports this. Alternatively
1850
+ // we could start with a different number type, since fixed-line numbers typically have a wide
1851
+ // breadth of valid number lengths and we may have to make it very short before we get an
1852
+ // invalid number.
1853
+ PhoneNumberDesc desc = getNumberDescByType(getMetadataForRegion(regionCode),
1854
+ PhoneNumberType.FIXED_LINE);
1855
+ if (desc.exampleNumber.equals("")) {
1856
+ // This shouldn't happen; we have a test for this.
1857
+ return null;
1858
+ }
1859
+ String exampleNumber = desc.exampleNumber;
1860
+ // Try and make the number invalid. We do this by changing the length. We try reducing the
1861
+ // length of the number, since currently no region has a number that is the same length as
1862
+ // MIN_LENGTH_FOR_NSN. This is probably quicker than making the number longer, which is another
1863
+ // alternative. We could also use the possible number pattern to extract the possible lengths of
1864
+ // the number to make this faster, but this method is only for unit-testing so simplicity is
1865
+ // preferred to performance. We don't want to return a number that can't be parsed, so we check
1866
+ // the number is long enough. We try all possible lengths because phone number plans often have
1867
+ // overlapping prefixes so the number 123456 might be valid as a fixed-line number, and 12345 as
1868
+ // a mobile number. It would be faster to loop in a different order, but we prefer numbers that
1869
+ // look closer to real numbers (and it gives us a variety of different lengths for the resulting
1870
+ // phone numbers - otherwise they would all be MIN_LENGTH_FOR_NSN digits long.)
1871
+ for (int phoneNumberLength = exampleNumber.length() - 1;
1872
+ phoneNumberLength >= MIN_LENGTH_FOR_NSN;
1873
+ phoneNumberLength--) {
1874
+ String numberToTry = exampleNumber.substring(0, phoneNumberLength);
1875
+ try {
1876
+ PhoneNumber possiblyValidNumber = parse(numberToTry, regionCode);
1877
+ if (!isValidNumber(possiblyValidNumber)) {
1878
+ return possiblyValidNumber;
1879
+ }
1880
+ } catch (NumberParseException e) {
1881
+ // Shouldn't happen: we have already checked the length, we know example numbers have
1882
+ // only valid digits, and we know the region code is fine.
1883
+ }
1884
+ }
1885
+ // We have a test to check that this doesn't happen for any of our supported regions.
1886
+ return null;
1887
+ }
1888
+
1821
1889
  /**
1822
1890
  * Gets a valid number for the specified region and number type.
1823
1891
  *
@@ -1845,6 +1913,37 @@ public class PhoneNumberUtil {
1845
1913
  return null;
1846
1914
  }
1847
1915
 
1916
+ /**
1917
+ * Gets a valid number for the specified number type (it may belong to any country).
1918
+ *
1919
+ * @param type the type of number that is needed
1920
+ * @return a valid number for the specified type. Returns null when the metadata
1921
+ * does not contain such information. This should only happen when no numbers of this type are
1922
+ * allocated anywhere in the world anymore.
1923
+ */
1924
+ public PhoneNumber getExampleNumberForType(PhoneNumberType type) {
1925
+ for (String regionCode : getSupportedRegions()) {
1926
+ PhoneNumber exampleNumber = getExampleNumberForType(regionCode, type);
1927
+ if (exampleNumber != null) {
1928
+ return exampleNumber;
1929
+ }
1930
+ }
1931
+ // If there wasn't an example number for a region, try the non-geographical entities.
1932
+ for (int countryCallingCode : getSupportedGlobalNetworkCallingCodes()) {
1933
+ PhoneNumberDesc desc = getNumberDescByType(
1934
+ getMetadataForNonGeographicalRegion(countryCallingCode), type);
1935
+ try {
1936
+ if (!desc.exampleNumber.equals("")) {
1937
+ return parse("+" + countryCallingCode + desc.exampleNumber, UNKNOWN_REGION);
1938
+ }
1939
+ } catch (NumberParseException e) {
1940
+ logger.log(Level.SEVERE, e.toString());
1941
+ }
1942
+ }
1943
+ // There are no example numbers of this type for any country in the library.
1944
+ return null;
1945
+ }
1946
+
1848
1947
  /**
1849
1948
  * Gets a valid number for the specified country calling code for a non-geographical entity.
1850
1949
  *
@@ -1859,7 +1958,7 @@ public class PhoneNumberUtil {
1859
1958
  PhoneNumberDesc desc = metadata.generalDesc;
1860
1959
  try {
1861
1960
  if (!desc.exampleNumber.equals("")) {
1862
- return parse("+" + countryCallingCode + desc.exampleNumber, "ZZ");
1961
+ return parse("+" + countryCallingCode + desc.exampleNumber, UNKNOWN_REGION);
1863
1962
  }
1864
1963
  } catch (NumberParseException e) {
1865
1964
  logger.log(Level.SEVERE, e.toString());
@@ -2670,10 +2769,18 @@ public class PhoneNumberUtil {
2670
2769
  }
2671
2770
 
2672
2771
  /**
2673
- * Parses a string and returns it in proto buffer format. This method will throw a
2674
- * {@link com.google.i18n.phonenumbers.NumberParseException} if the number is not considered to be
2675
- * a possible number. Note that validation of whether the number is actually a valid number for a
2676
- * particular region is not performed. This can be done separately with {@link #isValidNumber}.
2772
+ * Parses a string and returns it as a phone number in proto buffer format. The method is quite
2773
+ * lenient and looks for a number in the input text (raw input) and does not check whether the
2774
+ * string is definitely only a phone number. To do this, it ignores punctuation and white-space,
2775
+ * as well as any text before the number (e.g. a leading “Tel: ”) and trims the non-number bits.
2776
+ * It will accept a number in any format (E164, national, international etc), assuming it can be
2777
+ * interpreted with the defaultRegion supplied. It also attempts to convert any alpha characters
2778
+ * into digits if it thinks this is a vanity number of the type "1800 MICROSOFT".
2779
+ *
2780
+ * <p> This method will throw a {@link com.google.i18n.phonenumbers.NumberParseException} if the
2781
+ * number is not considered to be a possible number. Note that validation of whether the number
2782
+ * is actually a valid number for a particular region is not performed. This can be done
2783
+ * separately with {@link #isValidNumber}.
2677
2784
  *
2678
2785
  * @param numberToParse number that we are attempting to parse. This can contain formatting
2679
2786
  * such as +, ( and -, as well as a phone number extension. It can also
@@ -2685,9 +2792,10 @@ public class PhoneNumberUtil {
2685
2792
  * start with a '+' followed by the country calling code, then
2686
2793
  * "ZZ" or null can be supplied.
2687
2794
  * @return a phone number proto buffer filled with the parsed number
2688
- * @throws NumberParseException if the string is not considered to be a viable phone number or if
2689
- * no default region was supplied and the number is not in
2690
- * international format (does not start with +)
2795
+ * @throws NumberParseException if the string is not considered to be a viable phone number (e.g.
2796
+ * too few or too many digits) or if no default region was supplied
2797
+ * and the number is not in international format (does not start
2798
+ * with +)
2691
2799
  */
2692
2800
  public PhoneNumber parse(String numberToParse, String defaultRegion)
2693
2801
  throws NumberParseException {