Browse Source

Stop modifying metadata in formatInOriginalFormat().

Bug: http://code.google.com/p/libphonenumber/issues/detail?id=91
Review URL: http://codereview.appspot.com/5573043
pull/567/head
Shaopeng Jia 14 years ago
committed by Mihaela Rosca
parent
commit
d96d17db8d
2 changed files with 6 additions and 2 deletions
  1. +4
    -2
      java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java
  2. +2
    -0
      java/libphonenumber/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java

+ 4
- 2
java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java View File

@ -1449,9 +1449,11 @@ public class PhoneNumberUtil {
break;
}
// Otherwise, we need to remove the national prefix from our output.
formatRule.clearNationalPrefixFormattingRule();
NumberFormat numFormatCopy = new NumberFormat();
numFormatCopy.mergeFrom(formatRule);
numFormatCopy.clearNationalPrefixFormattingRule();
List<NumberFormat> numberFormats = new ArrayList<NumberFormat>(1);
numberFormats.add(formatRule);
numberFormats.add(numFormatCopy);
formattedNumber = formatByPattern(number, PhoneNumberFormat.NATIONAL, numberFormats);
break;
}


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

@ -823,6 +823,8 @@ public class PhoneNumberUtilTest extends TestCase {
phoneUtil.parseAndKeepRawInput("2087654321", RegionCode.GB);
assertEquals("20 8765 4321",
phoneUtil.formatInOriginalFormat(numberWithoutNationalPrefixGB, RegionCode.GB));
// Make sure no metadata is modified as a result of the previous function call.
assertEquals("(020) 8765 4321", phoneUtil.formatInOriginalFormat(number5, RegionCode.GB));
PhoneNumber numberWithNationalPrefixMX =
phoneUtil.parseAndKeepRawInput("013312345678", RegionCode.MX);


Loading…
Cancel
Save