Browse Source

Fixing Issue 2. Patch submitted by tronikos.

pull/567/head
Shaopeng Jia 16 years ago
committed by Mihaela Rosca
parent
commit
ff875e6b79
5 changed files with 21 additions and 23 deletions
  1. +4
    -6
      java/resources/com/google/i18n/phonenumbers/src/PhoneNumberMetaData.xml
  2. +5
    -5
      java/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java
  3. +1
    -1
      java/src/com/google/i18n/phonenumbers/Phonemetadata.java
  4. +11
    -9
      java/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java
  5. +0
    -2
      java/test/com/google/i18n/phonenumbers/RegexCacheTest.java

+ 4
- 6
java/resources/com/google/i18n/phonenumbers/src/PhoneNumberMetaData.xml View File

@ -4759,12 +4759,10 @@
<!-- http://www.itu.int/oth/T020200009B/en --> <!-- http://www.itu.int/oth/T020200009B/en -->
<territory id="NE" countryCode="227" internationalPrefix="00"> <territory id="NE" countryCode="227" internationalPrefix="00">
<availableFormats> <availableFormats>
<numberFormat>
<numberFormat leadingDigits="[29]|09"
pattern="([029]\d)(\d{2})(\d{2})(\d{2})">$1 $2 $3 $4</numberFormat>
<numberFormat leadingDigits="08"
pattern="(08)(\d{3})(\d{3})">$1 $2 $3</numberFormat>
</numberFormat>
<numberFormat leadingDigits="[29]|09"
pattern="([029]\d)(\d{2})(\d{2})(\d{2})">$1 $2 $3 $4</numberFormat>
<numberFormat leadingDigits="08"
pattern="(08)(\d{3})(\d{3})">$1 $2 $3</numberFormat>
</availableFormats> </availableFormats>
<generalDesc> <generalDesc>
<nationalNumberPattern>[029]\d{7}</nationalNumberPattern> <nationalNumberPattern>[029]\d{7}</nationalNumberPattern>


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

@ -571,7 +571,7 @@ public class PhoneNumberUtil {
// they won't have an area code, which means clients don't need to worry about appending the // they won't have an area code, which means clients don't need to worry about appending the
// leading zero to the geographical area code they derive from the length we return here. // leading zero to the geographical area code they derive from the length we return here.
return numberGroups[2].length(); return numberGroups[2].length();
}
}
/** /**
* Normalizes a string of characters representing a phone number by replacing all characters found * Normalizes a string of characters representing a phone number by replacing all characters found
@ -808,7 +808,7 @@ public Set<String> getSupportedCountries() {
} else if (countryCode == getCountryCodeForRegion(countryCallingFrom)) { } else if (countryCode == getCountryCodeForRegion(countryCallingFrom)) {
// For countries that share a country calling code, the country code need not be dialled. This // For countries that share a country calling code, the country code need not be dialled. This
// also applies when dialling within a country, so this if clause covers both these cases. // also applies when dialling within a country, so this if clause covers both these cases.
// Technically this is the case for dialling from la RŽunion to other overseas departments of
// Technically this is the case for dialling from la Reunion to other overseas departments of
// France (French Guiana, Martinique, Guadeloupe), but not vice versa - so we don't cover this // France (French Guiana, Martinique, Guadeloupe), but not vice versa - so we don't cover this
// edge case for now and for those cases return the version including country code. // edge case for now and for those cases return the version including country code.
// Details here: http://www.petitfute.com/voyage/225-info-pratiques-reunion // Details here: http://www.petitfute.com/voyage/225-info-pratiques-reunion
@ -866,11 +866,11 @@ public Set<String> getSupportedCountries() {
return format(number, PhoneNumberFormat.INTERNATIONAL).substring(1); return format(number, PhoneNumberFormat.INTERNATIONAL).substring(1);
case FROM_DEFAULT_COUNTRY: case FROM_DEFAULT_COUNTRY:
default: default:
return format(number, PhoneNumberFormat.NATIONAL);
return format(number, PhoneNumberFormat.NATIONAL);
} }
} }
/** /**
* Gets the national significant number of the a phone number. Note a national significant number * Gets the national significant number of the a phone number. Note a national significant number
* doesn't contain a national prefix or any formatting. * doesn't contain a national prefix or any formatting.
@ -918,7 +918,7 @@ public Set<String> getSupportedCountries() {
String regionCode, String regionCode,
PhoneNumberFormat numberFormat) { PhoneNumberFormat numberFormat) {
return formatNationalNumber(number, regionCode, numberFormat, null); return formatNationalNumber(number, regionCode, numberFormat, null);
}
}
// Note in some countries, the national number can be written in two completely different ways // Note in some countries, the national number can be written in two completely different ways
// depending on whether it forms part of the NATIONAL format or INTERNATIONAL format. The // depending on whether it forms part of the NATIONAL format or INTERNATIONAL format. The


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

@ -481,7 +481,7 @@ public final class Phonemetadata {
hasLeadingDigits = true; hasLeadingDigits = true;
leadingDigits_ = value; leadingDigits_ = value;
return this; return this;
}
}
public void writeExternal(ObjectOutput objectOutput) throws IOException { public void writeExternal(ObjectOutput objectOutput) throws IOException {
objectOutput.writeBoolean(hasGeneralDesc); objectOutput.writeBoolean(hasGeneralDesc);


+ 11
- 9
java/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java View File

@ -59,14 +59,16 @@ public class PhoneNumberUtilTest extends TestCase {
super.tearDown(); super.tearDown();
} }
private boolean assertEquals(PhoneNumber number1, PhoneNumber number2) {
private void assertEquals(PhoneNumber number1, PhoneNumber number2) {
boolean equal = false;
if (number1 == null && number2 == null) { if (number1 == null && number2 == null) {
return true;
equal = true;
} else if (number1 != null && number2 != null) {
equal = number1.exactlySameAs(number2);
} }
if (number1 == null || number2 == null) {
return false;
if (!equal) {
fail("The phone numbers do not match");
} }
return number1.exactlySameAs(number2);
} }
public void testGetInstanceLoadUSMetadata() throws IOException { public void testGetInstanceLoadUSMetadata() throws IOException {
@ -496,7 +498,7 @@ public class PhoneNumberUtilTest extends TestCase {
assertEquals("424 123 1234", phoneUtil.format(usNumber, assertEquals("424 123 1234", phoneUtil.format(usNumber,
PhoneNumberUtil.PhoneNumberFormat.NATIONAL)); PhoneNumberUtil.PhoneNumberFormat.NATIONAL));
assertEquals("424 123 1234", phoneUtil.formatNationalNumberWithCarrierCode(usNumber, "15")); assertEquals("424 123 1234", phoneUtil.formatNationalNumberWithCarrierCode(usNumber, "15"));
}
}
public void testFormatByPattern() { public void testFormatByPattern() {
PhoneNumber usNumber = new PhoneNumber(); PhoneNumber usNumber = new PhoneNumber();
@ -783,7 +785,7 @@ public class PhoneNumberUtilTest extends TestCase {
// This number is no longer valid. // This number is no longer valid.
assertFalse(phoneUtil.isValidNumber(bsNumber)); assertFalse(phoneUtil.isValidNumber(bsNumber));
// La Mayotte and RŽunion use 'leadingDigits' to differentiate them.
// La Mayotte and Reunion use 'leadingDigits' to differentiate them.
PhoneNumber reNumber = new PhoneNumber(); PhoneNumber reNumber = new PhoneNumber();
reNumber.setCountryCode(262).setNationalNumber(262123456L); reNumber.setCountryCode(262).setNationalNumber(262123456L);
assertTrue(phoneUtil.isValidNumber(reNumber)); assertTrue(phoneUtil.isValidNumber(reNumber));
@ -793,7 +795,7 @@ public class PhoneNumberUtilTest extends TestCase {
reNumber.setNationalNumber(269601234L); reNumber.setNationalNumber(269601234L);
assertTrue(phoneUtil.isValidNumberForRegion(reNumber, "YT")); assertTrue(phoneUtil.isValidNumberForRegion(reNumber, "YT"));
assertFalse(phoneUtil.isValidNumberForRegion(reNumber, "RE")); assertFalse(phoneUtil.isValidNumberForRegion(reNumber, "RE"));
// This number is no longer valid for La RŽunion.
// This number is no longer valid for La Reunion.
reNumber.setNationalNumber(269123456L); reNumber.setNationalNumber(269123456L);
assertFalse(phoneUtil.isValidNumberForRegion(reNumber, "YT")); assertFalse(phoneUtil.isValidNumberForRegion(reNumber, "YT"));
assertFalse(phoneUtil.isValidNumberForRegion(reNumber, "RE")); assertFalse(phoneUtil.isValidNumberForRegion(reNumber, "RE"));
@ -1475,7 +1477,7 @@ public class PhoneNumberUtilTest extends TestCase {
// Null is also allowed for the region code in these cases. // Null is also allowed for the region code in these cases.
assertEquals(nzNumber, phoneUtil.parseAndKeepRawInput("+64 3 331 6005", null)); assertEquals(nzNumber, phoneUtil.parseAndKeepRawInput("+64 3 331 6005", null));
} }
public void testParseExtensions() throws Exception { public void testParseExtensions() throws Exception {
PhoneNumber nzNumber = new PhoneNumber(); PhoneNumber nzNumber = new PhoneNumber();
nzNumber.setCountryCode(64).setNationalNumber(33316005L).setExtension("3456"); nzNumber.setCountryCode(64).setNationalNumber(33316005L).setExtension("3456");


+ 0
- 2
java/test/com/google/i18n/phonenumbers/RegexCacheTest.java View File

@ -18,8 +18,6 @@ package com.google.i18n.phonenumbers;
import junit.framework.TestCase; import junit.framework.TestCase;
import java.util.regex.Pattern;
/** /**
* Unittests for LRU Cache for compiled regular expressions used by the libphonenumbers libary. * Unittests for LRU Cache for compiled regular expressions used by the libphonenumbers libary.
* *


Loading…
Cancel
Save