// This case has a trailing RTL char.
assertEquals("650) 253-0000", PhoneNumberUtil.extractPossibleNumber("(650) 253-0000\u200F"));
}
public void testMaybeStripNationalPrefix() {
PhoneMetadata metadata = new PhoneMetadata();
metadata.setNationalPrefixForParsing("34");
metadata.setGeneralDesc(new PhoneNumberDesc().setNationalNumberPattern("\\d{4,8}"));
StringBuilder numberToStrip = new StringBuilder("34356778");
String strippedNumber = "356778";
assertTrue(phoneUtil.maybeStripNationalPrefixAndCarrierCode(numberToStrip, metadata, null));
assertEquals("Should have had national prefix stripped.",
strippedNumber, numberToStrip.toString());
// Retry stripping - now the number should not start with the national prefix, so no more
// stripping should occur.
assertFalse(phoneUtil.maybeStripNationalPrefixAndCarrierCode(numberToStrip, metadata, null));
assertEquals("Should have had no change - no national prefix present.",
strippedNumber, numberToStrip.toString());
// Some countries have no national prefix. Repeat test with none specified.
metadata.setNationalPrefixForParsing("");
assertFalse(phoneUtil.maybeStripNationalPrefixAndCarrierCode(numberToStrip, metadata, null));
assertEquals("Should not strip anything with empty national prefix.",
strippedNumber, numberToStrip.toString());
// If the resultant number doesn't match the national rule, it shouldn't be stripped.
metadata.setNationalPrefixForParsing("3");
numberToStrip = new StringBuilder("3123");
strippedNumber = "3123";
assertFalse(phoneUtil.maybeStripNationalPrefixAndCarrierCode(numberToStrip, metadata, null));
assertEquals("Should have had no change - after stripping, it wouldn't have matched " +
"the national rule.",
strippedNumber, numberToStrip.toString());
// Test extracting carrier selection code.
metadata.setNationalPrefixForParsing("0(81)?");
numberToStrip = new StringBuilder("08122123456");
strippedNumber = "22123456";
StringBuilder carrierCode = new StringBuilder();
assertTrue(phoneUtil.maybeStripNationalPrefixAndCarrierCode(
numberToStrip, metadata, carrierCode));
assertEquals("81", carrierCode.toString());
assertEquals("Should have had national prefix and carrier code stripped.",
strippedNumber, numberToStrip.toString());
// If there was a transform rule, check it was applied.
metadata.setNationalPrefixTransformRule("5$15");
// Note that a capturing group is present here.
metadata.setNationalPrefixForParsing("0(\\d{2})");
numberToStrip = new StringBuilder("031123");
String transformedNumber = "5315123";
assertTrue(phoneUtil.maybeStripNationalPrefixAndCarrierCode(numberToStrip, metadata, null));
assertEquals("Should transform the 031 to a 5315.",
transformedNumber, numberToStrip.toString());