From d507625e1c003eace1fd7221e389f0441dbf7817 Mon Sep 17 00:00:00 2001 From: lararennie Date: Tue, 23 Oct 2018 09:10:16 +0200 Subject: [PATCH] Updating AsYouTypeFormatter for better format selection (#2272) Updating AsYouTypeFormatter for better format selection for numbers dialled domestically --- cpp/src/phonenumbers/asyoutypeformatter.cc | 36 +++- cpp/src/phonenumbers/test_metadata.cc | 196 +++++++++--------- .../i18n/phonenumbers/AsYouTypeFormatter.java | 45 ++-- .../PhoneNumberMetadataProtoForTesting_US | Bin 539 -> 540 bytes .../i18n/phonenumbers/asyoutypeformatter.js | 51 +++-- javascript/i18n/phonenumbers/demo-compiled.js | 117 ++++++----- .../i18n/phonenumbers/metadatafortesting.js | 2 +- pending_code_changes.txt | 7 +- resources/PhoneNumberMetadataForTesting.xml | 5 +- 9 files changed, 249 insertions(+), 210 deletions(-) diff --git a/cpp/src/phonenumbers/asyoutypeformatter.cc b/cpp/src/phonenumbers/asyoutypeformatter.cc index 6590296a7..95ba28ac2 100644 --- a/cpp/src/phonenumbers/asyoutypeformatter.cc +++ b/cpp/src/phonenumbers/asyoutypeformatter.cc @@ -195,22 +195,40 @@ bool AsYouTypeFormatter::MaybeCreateNewTemplate() { } void AsYouTypeFormatter::GetAvailableFormats(const string& leading_digits) { + // First decide whether we should use international or national number rules. + bool is_international_number = + is_complete_number_ && extracted_national_prefix_.empty(); const RepeatedPtrField& format_list = - (is_complete_number_ && + (is_international_number && current_metadata_->intl_number_format().size() > 0) ? current_metadata_->intl_number_format() : current_metadata_->number_format(); - bool national_prefix_used_by_country = - current_metadata_->has_national_prefix(); for (RepeatedPtrField::const_iterator it = format_list.begin(); it != format_list.end(); ++it) { - if (!national_prefix_used_by_country || is_complete_number_ || - it->national_prefix_optional_when_formatting() || + // Discard a few formats that we know are not relevant based on the presence + // of the national prefix. + if (!extracted_national_prefix_.empty() && phone_util_.FormattingRuleHasFirstGroupOnly( - it->national_prefix_formatting_rule())) { - if (phone_util_.IsFormatEligibleForAsYouTypeFormatter(it->format())) { - possible_formats_.push_back(&*it); - } + it->national_prefix_formatting_rule()) && + !it->national_prefix_optional_when_formatting() && + !it->has_domestic_carrier_code_formatting_rule()) { + // If it is a national number that had a national prefix, any rules that + // aren't valid with a national prefix should be excluded. A rule that has + // a carrier-code formatting rule is kept since the national prefix might + // actually be an extracted carrier code - we don't distinguish between + // these when extracting it in the AYTF. + continue; + } else if (extracted_national_prefix_.empty() && + !is_complete_number_ && + !phone_util_.FormattingRuleHasFirstGroupOnly( + it->national_prefix_formatting_rule()) && + !it->national_prefix_optional_when_formatting()) { + // This number was entered without a national prefix, and this formatting + // rule requires one, so we discard it. + continue; + } + if (phone_util_.IsFormatEligibleForAsYouTypeFormatter(it->format())) { + possible_formats_.push_back(&*it); } } NarrowDownPossibleFormats(leading_digits); diff --git a/cpp/src/phonenumbers/test_metadata.cc b/cpp/src/phonenumbers/test_metadata.cc index 8b3c8a963..78d1e3e38 100644 --- a/cpp/src/phonenumbers/test_metadata.cc +++ b/cpp/src/phonenumbers/test_metadata.cc @@ -902,7 +902,7 @@ static const unsigned char data[] = { 0xFF, 0xFF, 0x01, 0xC2, 0x01, 0x0B, 0x48, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0xCA, 0x01, 0x0B, 0x48, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0xE2, 0x01, 0x0B, 0x48, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x0A, 0xB2, 0x03, 0x0A, 0x22, 0x12, 0x1C, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x0A, 0xB0, 0x03, 0x0A, 0x22, 0x12, 0x1C, 0x5B, 0x31, 0x33, 0x2D, 0x36, 0x38, 0x39, 0x5D, 0x5C, 0x64, 0x7B, 0x39, 0x7D, 0x7C, 0x32, 0x5B, 0x30, 0x2D, 0x33, 0x35, 0x2D, 0x39, 0x5D, 0x5C, 0x64, 0x7B, 0x38, 0x7D, 0x48, 0x0A, 0x50, 0x07, 0x12, 0x2C, 0x12, 0x1C, 0x5B, 0x31, 0x33, @@ -922,108 +922,108 @@ static const unsigned char data[] = { 0xFF, 0xFF, 0x01, 0x42, 0x0B, 0x48, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x4A, 0x02, 0x55, 0x53, 0x50, 0x01, 0x5A, 0x03, 0x30, 0x31, 0x31, 0x62, 0x01, 0x31, 0x6A, 0x07, 0x20, 0x65, 0x78, 0x74, 0x6E, 0x2E, 0x20, - 0x7A, 0x01, 0x31, 0x90, 0x01, 0x01, 0x9A, 0x01, 0x19, 0x0A, 0x0E, 0x28, 0x5C, + 0x7A, 0x01, 0x31, 0x90, 0x01, 0x01, 0x9A, 0x01, 0x17, 0x0A, 0x0E, 0x28, 0x5C, 0x64, 0x7B, 0x33, 0x7D, 0x29, 0x28, 0x5C, 0x64, 0x7B, 0x34, 0x7D, 0x29, 0x12, - 0x05, 0x24, 0x31, 0x20, 0x24, 0x32, 0x30, 0x01, 0x9A, 0x01, 0x23, 0x0A, 0x15, - 0x28, 0x5C, 0x64, 0x7B, 0x33, 0x7D, 0x29, 0x28, 0x5C, 0x64, 0x7B, 0x33, 0x7D, - 0x29, 0x28, 0x5C, 0x64, 0x7B, 0x34, 0x7D, 0x29, 0x12, 0x08, 0x24, 0x31, 0x20, - 0x24, 0x32, 0x20, 0x24, 0x33, 0x30, 0x01, 0xA2, 0x01, 0x23, 0x0A, 0x15, 0x28, - 0x5C, 0x64, 0x7B, 0x33, 0x7D, 0x29, 0x28, 0x5C, 0x64, 0x7B, 0x33, 0x7D, 0x29, - 0x28, 0x5C, 0x64, 0x7B, 0x34, 0x7D, 0x29, 0x12, 0x08, 0x24, 0x31, 0x20, 0x24, - 0x32, 0x20, 0x24, 0x33, 0x30, 0x01, 0xAA, 0x01, 0x0B, 0x48, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0xB0, 0x01, 0x01, 0xC2, 0x01, 0x16, - 0x12, 0x08, 0x38, 0x30, 0x30, 0x5C, 0x64, 0x7B, 0x37, 0x7D, 0x32, 0x0A, 0x38, - 0x30, 0x30, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0xCA, 0x01, 0x0B, 0x48, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0xE2, 0x01, 0x0B, - 0x48, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0x02, - 0x01, 0x0A, 0x97, 0x02, 0x0A, 0x0F, 0x12, 0x09, 0x5B, 0x36, 0x39, 0x5D, 0x5C, - 0x64, 0x7B, 0x38, 0x7D, 0x48, 0x09, 0x50, 0x07, 0x12, 0x18, 0x12, 0x09, 0x36, - 0x31, 0x32, 0x32, 0x5C, 0x64, 0x7B, 0x35, 0x7D, 0x32, 0x09, 0x36, 0x36, 0x32, - 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x50, 0x07, 0x1A, 0x1B, 0x12, 0x0E, 0x39, - 0x5B, 0x30, 0x2D, 0x35, 0x37, 0x2D, 0x39, 0x5D, 0x5C, 0x64, 0x7B, 0x37, 0x7D, - 0x32, 0x09, 0x39, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x22, 0x0B, - 0x48, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x2A, 0x0B, - 0x48, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x32, 0x0B, - 0x48, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF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, 0x5D, 0x5C, 0x64, 0x7B, 0x38, - 0x7D, 0x48, 0x09, 0x12, 0x1B, 0x12, 0x0E, 0x32, 0x36, 0x39, 0x36, 0x5B, 0x30, - 0x2D, 0x34, 0x5D, 0x5C, 0x64, 0x7B, 0x34, 0x7D, 0x32, 0x09, 0x32, 0x36, 0x39, - 0x36, 0x30, 0x31, 0x32, 0x33, 0x34, 0x1A, 0x15, 0x12, 0x08, 0x36, 0x33, 0x39, - 0x5C, 0x64, 0x7B, 0x36, 0x7D, 0x32, 0x09, 0x36, 0x33, 0x39, 0x31, 0x32, 0x33, - 0x34, 0x35, 0x36, 0x22, 0x14, 0x12, 0x07, 0x38, 0x30, 0x5C, 0x64, 0x7B, 0x37, - 0x7D, 0x32, 0x09, 0x38, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x2A, - 0x0B, 0x48, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x32, - 0x0B, 0x48, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x3A, - 0x0B, 0x48, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x42, - 0x0B, 0x48, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x4A, - 0x02, 0x59, 0x54, 0x50, 0x86, 0x02, 0x5A, 0x02, 0x30, 0x30, 0x62, 0x01, 0x30, - 0x7A, 0x01, 0x30, 0xAA, 0x01, 0x0B, 0x48, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0x01, 0xBA, 0x01, 0x07, 0x32, 0x36, 0x39, 0x7C, 0x36, 0x33, - 0x39, 0xC2, 0x01, 0x0B, 0x48, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF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x1E, 0x0A, 0x12, 0x28, 0x5C, 0x64, 0x29, 0x28, - 0x5C, 0x64, 0x7B, 0x34, 0x7D, 0x29, 0x28, 0x5C, 0x64, 0x7B, 0x34, 0x7D, 0x29, - 0x12, 0x08, 0x24, 0x31, 0x20, 0x24, 0x32, 0x20, 0x24, 0x33, 0xAA, 0x01, 0x0B, - 0x48, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0xC2, 0x01, - 0x0B, 0x48, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0xCA, + 0x05, 0x24, 0x31, 0x20, 0x24, 0x32, 0x9A, 0x01, 0x23, 0x0A, 0x15, 0x28, 0x5C, + 0x64, 0x7B, 0x33, 0x7D, 0x29, 0x28, 0x5C, 0x64, 0x7B, 0x33, 0x7D, 0x29, 0x28, + 0x5C, 0x64, 0x7B, 0x34, 0x7D, 0x29, 0x12, 0x08, 0x24, 0x31, 0x20, 0x24, 0x32, + 0x20, 0x24, 0x33, 0x30, 0x01, 0xA2, 0x01, 0x23, 0x0A, 0x15, 0x28, 0x5C, 0x64, + 0x7B, 0x33, 0x7D, 0x29, 0x28, 0x5C, 0x64, 0x7B, 0x33, 0x7D, 0x29, 0x28, 0x5C, + 0x64, 0x7B, 0x34, 0x7D, 0x29, 0x12, 0x08, 0x24, 0x31, 0x20, 0x24, 0x32, 0x20, + 0x24, 0x33, 0x30, 0x01, 0xAA, 0x01, 0x0B, 0x48, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0xB0, 0x01, 0x01, 0xC2, 0x01, 0x16, 0x12, 0x08, + 0x38, 0x30, 0x30, 0x5C, 0x64, 0x7B, 0x37, 0x7D, 0x32, 0x0A, 0x38, 0x30, 0x30, + 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0xCA, 0x01, 0x0B, 0x48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x7A, 0x01, + 0x38, 0x8A, 0x01, 0x04, 0x38, 0x7E, 0x31, 0x30, 0x9A, 0x01, 0x3A, 0x0A, 0x1E, + 0x28, 0x5B, 0x36, 0x37, 0x39, 0x5D, 0x5C, 0x64, 0x29, 0x28, 0x5C, 0x64, 0x7B, + 0x33, 0x7D, 0x29, 0x28, 0x5C, 0x64, 0x7B, 0x32, 0x7D, 0x29, 0x28, 0x5C, 0x64, + 0x7B, 0x32, 0x7D, 0x29, 0x12, 0x0B, 0x24, 0x31, 0x20, 0x24, 0x32, 0x20, 0x24, + 0x33, 0x20, 0x24, 0x34, 0x1A, 0x05, 0x5B, 0x36, 0x37, 0x39, 0x5D, 0x22, 0x04, + 0x38, 0x20, 0x24, 0x31, 0xAA, 0x01, 0x0B, 0x48, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0xC2, 0x01, 0x0B, 0x48, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0xCA, 0x01, 0x0B, 0x48, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0xE2, 0x01, 0x0B, 0x48, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x0A, 0xE1, 0x01, 0x0A, 0x0E, + 0x12, 0x0A, 0x5B, 0x32, 0x36, 0x38, 0x5D, 0x5C, 0x64, 0x7B, 0x38, 0x7D, 0x48, + 0x09, 0x12, 0x1B, 0x12, 0x0E, 0x32, 0x36, 0x39, 0x36, 0x5B, 0x30, 0x2D, 0x34, + 0x5D, 0x5C, 0x64, 0x7B, 0x34, 0x7D, 0x32, 0x09, 0x32, 0x36, 0x39, 0x36, 0x30, + 0x31, 0x32, 0x33, 0x34, 0x1A, 0x15, 0x12, 0x08, 0x36, 0x33, 0x39, 0x5C, 0x64, + 0x7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 0x5C, 0x64, 0x7B, 0x34, 0x7D, 0x29, 0x28, 0x5C, 0x64, 0x7B, 0x34, + 0x7D, 0x29, 0x12, 0x08, 0x24, 0x31, 0x20, 0x24, 0x32, 0x20, 0x24, 0x33, 0xAA, + 0x01, 0x0B, 0x48, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, + 0xC2, 0x01, 0x0B, 0x48, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x01, 0xCA, 0x01, 0x0B, 0x48, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0x01, 0xE2, 0x01, 0x0B, 0x48, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0x01 }; } // namespace diff --git a/java/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java b/java/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java index 641135932..0a0c84d12 100644 --- a/java/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java +++ b/java/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java @@ -19,7 +19,6 @@ package com.google.i18n.phonenumbers; import com.google.i18n.phonenumbers.Phonemetadata.NumberFormat; import com.google.i18n.phonenumbers.Phonemetadata.PhoneMetadata; import com.google.i18n.phonenumbers.internal.RegexCache; - import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -174,29 +173,41 @@ public class AsYouTypeFormatter { } private void getAvailableFormats(String leadingDigits) { + // First decide whether we should use international or national number rules. + boolean isInternationalNumber = isCompleteNumber && extractedNationalPrefix.length() == 0; List formatList = - (isCompleteNumber && currentMetadata.intlNumberFormatSize() > 0) - ? currentMetadata.intlNumberFormats() - : currentMetadata.numberFormats(); - boolean nationalPrefixIsUsedByCountry = currentMetadata.hasNationalPrefix(); + (isInternationalNumber && currentMetadata.intlNumberFormatSize() > 0) + ? currentMetadata.intlNumberFormats() + : currentMetadata.numberFormats(); for (NumberFormat format : formatList) { - if (!nationalPrefixIsUsedByCountry - || isCompleteNumber - || format.getNationalPrefixOptionalWhenFormatting() - || PhoneNumberUtil.formattingRuleHasFirstGroupOnly( - format.getNationalPrefixFormattingRule())) { - if (isFormatEligible(format.getFormat())) { - possibleFormats.add(format); - } + // Discard a few formats that we know are not relevant based on the presence of the national + // prefix. + if (extractedNationalPrefix.length() > 0 + && PhoneNumberUtil.formattingRuleHasFirstGroupOnly( + format.getNationalPrefixFormattingRule()) + && !format.getNationalPrefixOptionalWhenFormatting() + && !format.hasDomesticCarrierCodeFormattingRule()) { + // If it is a national number that had a national prefix, any rules that aren't valid with a + // national prefix should be excluded. A rule that has a carrier-code formatting rule is + // kept since the national prefix might actually be an extracted carrier code - we don't + // distinguish between these when extracting it in the AYTF. + continue; + } else if (extractedNationalPrefix.length() == 0 + && !isCompleteNumber + && !PhoneNumberUtil.formattingRuleHasFirstGroupOnly( + format.getNationalPrefixFormattingRule()) + && !format.getNationalPrefixOptionalWhenFormatting()) { + // This number was entered without a national prefix, and this formatting rule requires one, + // so we discard it. + continue; + } + if (ELIGIBLE_FORMAT_PATTERN.matcher(format.getFormat()).matches()) { + possibleFormats.add(format); } } narrowDownPossibleFormats(leadingDigits); } - private boolean isFormatEligible(String format) { - return ELIGIBLE_FORMAT_PATTERN.matcher(format).matches(); - } - private void narrowDownPossibleFormats(String leadingDigits) { int indexOfLeadingDigitsPattern = leadingDigits.length() - MIN_LEADING_DIGITS_LENGTH; Iterator it = possibleFormats.iterator(); diff --git a/java/libphonenumber/test/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProtoForTesting_US b/java/libphonenumber/test/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProtoForTesting_US index 7679d507cf3a6a08767c601869358e39c6112a0b..cd9cd06b6c824dd36c12794fb44b3c6ae6fa8988 100644 GIT binary patch delta 19 bcmbQuGKXcuAx1`q$?q98CckDhVB`V-Lu&>Z delta 15 XcmbQkGMi} */ var formatList = - (this.isCompleteNumber_ && + (isInternationalNumber && this.currentMetadata_.intlNumberFormatCount() > 0) ? this.currentMetadata_.intlNumberFormatArray() : this.currentMetadata_.numberFormatArray(); @@ -354,34 +358,37 @@ i18n.phonenumbers.AsYouTypeFormatter.prototype.getAvailableFormats_ = for (var i = 0; i < formatListLength; ++i) { /** @type {i18n.phonenumbers.NumberFormat} */ var format = formatList[i]; - /** @type {boolean} */ - var nationalPrefixIsUsedByCountry = - this.currentMetadata_.hasNationalPrefix(); - if (!nationalPrefixIsUsedByCountry || this.isCompleteNumber_ || - format.getNationalPrefixOptionalWhenFormatting() || + // Discard a few formats that we know are not relevant based on the + // presence of the national prefix. + if (this.extractedNationalPrefix_.length > 0 && this.phoneUtil_.formattingRuleHasFirstGroupOnly( - format.getNationalPrefixFormattingRuleOrDefault())) { - if (this.isFormatEligible_(format.getFormatOrDefault())) { - this.possibleFormats_.push(format); - } + format.getNationalPrefixFormattingRuleOrDefault()) && + !format.getNationalPrefixOptionalWhenFormatting() && + !format.hasDomesticCarrierCodeFormattingRule()) { + // If it is a national number that had a national prefix, any rules that + // aren't valid with a national prefix should be excluded. A rule that + // has a carrier-code formatting rule is kept since the national prefix + // might actually be an extracted carrier code - we don't distinguish + // between these when extracting it in the AYTF. + continue; + } else if (this.extractedNationalPrefix_.length == 0 && + !this.isCompleteNumber_ && + !this.phoneUtil_.formattingRuleHasFirstGroupOnly( + format.getNationalPrefixFormattingRuleOrDefault()) && + !format.getNationalPrefixOptionalWhenFormatting()) { + // This number was entered without a national prefix, and this formatting + // rule requires one, so we discard it. + continue; + } + if (i18n.phonenumbers.AsYouTypeFormatter.ELIGIBLE_FORMAT_PATTERN_.test( + format.getFormatOrDefault())) { + this.possibleFormats_.push(format); } } this.narrowDownPossibleFormats_(leadingDigits); }; -/** - * @param {string} format - * @return {boolean} - * @private - */ -i18n.phonenumbers.AsYouTypeFormatter.prototype.isFormatEligible_ = - function(format) { - return i18n.phonenumbers.AsYouTypeFormatter.ELIGIBLE_FORMAT_PATTERN_ - .test(format); -}; - - /** * @param {string} leadingDigits * @private diff --git a/javascript/i18n/phonenumbers/demo-compiled.js b/javascript/i18n/phonenumbers/demo-compiled.js index cdff5d74b..f68860c81 100644 --- a/javascript/i18n/phonenumbers/demo-compiled.js +++ b/javascript/i18n/phonenumbers/demo-compiled.js @@ -1,14 +1,14 @@ -(function(){function h(a){return"string"==typeof a}function aa(a){a.da=void 0;a.ca=function(){return a.da?a.da:a.da=new a}} +(function(){function aa(a){a.da=void 0;a.ca=function(){return a.da?a.da:a.da=new a}} function ba(a){var b=typeof a;if("object"==b)if(a){if(a instanceof Array)return"array";if(a instanceof Object)return b;var c=Object.prototype.toString.call(a);if("[object Window]"==c)return"object";if("[object Array]"==c||"number"==typeof a.length&&"undefined"!=typeof a.splice&&"undefined"!=typeof a.propertyIsEnumerable&&!a.propertyIsEnumerable("splice"))return"array";if("[object Function]"==c||"undefined"!=typeof a.call&&"undefined"!=typeof a.propertyIsEnumerable&&!a.propertyIsEnumerable("call"))return"function"}else return"null"; -else if("function"==b&&"undefined"==typeof a.call)return"object";return b}function l(a,b){function c(){}c.prototype=b.prototype;a.ea=b.prototype;a.prototype=new c;a.prototype.constructor=a;a.pa=function(a,c,f){for(var d=Array(arguments.length-2),e=2;ec?Math.max(0,a.length+c):c;if(h(a))return h(b)&&1==b.length?a.indexOf(b,c):-1;for(;cb?1:ac?Math.max(0,a.length+c):c;if(k(a))return k(b)&&1==b.length?a.indexOf(b,c):-1;for(;cb?1:aa.length?!1:N(ab,a)}function ib(a){return N(Za,a)?O(a,Sa):O(a,L)}function jb(a){var b=ib(a.toString());D(a);a.a(b)}function kb(a){return null!=a&&(1!=z(a,9)||-1!=x(a,9)[0])} -function O(a,b){for(var c=new C,d,e=a.length,f=0;fa.length?!1:N($a,a)}function hb(a){return N(Ya,a)?O(a,Ra):O(a,L)}function ib(a){var b=hb(a.toString());D(a);a.a(b)}function jb(a){return!!a&&(1!=z(a,9)||-1!=x(a,9)[0])} +function O(a,b){for(var c=new C,d,e=a.length,f=0;f=e?a=c:(d=d.substring(0,e),d=O(d,L),0==d.length?a=c:(g=g.clone(),Ga(g,4),d=[g],g=y(b,1),c=Q(b),g in K?(a=T(a,g,U(g)),e=ub(d,c),null!=e&&(d=e.clone(),e=y(e,4),0b?2:f[f.length-1]=e&&e<=d;++e)if(c=parseInt(a.substring(0,e),10),c in K)return b.a(a.substring(e)),c;return 0} -function Fb(a,b,c,d,e,f){if(0==b.length)return 0;b=new C(b);var g;null!=c&&(g=v(c,11));null==g&&(g="NonMatch");var k=b.toString();if(0==k.length)g=20;else if(M.test(k))k=k.replace(M,""),D(b),b.a(ib(k)),g=1;else{k=new RegExp(g);jb(b);g=b.toString();if(0==g.search(k)){k=g.match(k)[0].length;var m=g.substring(k).match(Va);m&&null!=m[1]&&0=b.b.length)throw Error("Phone number too short after IDD"); -a=Eb(b,d);if(0!=a)return w(f,1,a),a;throw Error("Invalid country calling code");}if(null!=c&&(g=y(c,10),k=""+g,m=b.toString(),0==m.lastIndexOf(k,0)&&(k=new C(m.substring(k.length)),m=v(c,1),m=new RegExp(y(m,2)),Gb(k,c,null),k=k.toString(),!N(m,b.toString())&&N(m,k)||3==Cb(a,b.toString(),c,-1))))return d.a(k),e&&w(f,6,10),w(f,1,g),g;w(f,1,0);return 0} -function Gb(a,b,c){var d=a.toString(),e=d.length,f=v(b,15);if(0!=e&&null!=f&&0!=f.length){var g=new RegExp("^(?:"+f+")");if(e=g.exec(d)){f=new RegExp(y(v(b,1),2));var k=N(f,d),m=e.length-1;b=v(b,16);if(null==b||0==b.length||null==e[m]||0==e[m].length){if(!k||N(f,d.substring(e[0].length)))null!=c&&0b.b.length)throw Error("The string supplied is too short to be a phone number");null!=g&&(c=new C,e=new C(b.toString()),Gb(e,g,c),a=Cb(a,e.toString(),g,-1),2!=a&&4!=a&&5!=a&&(b=e,d&&0a)throw Error("The string supplied is too short to be a phone number");if(17=e)a=c;else if(d=d.substring(0,e),d=O(d,L),d.length)if(g=g.clone(),Fa(g,4),d=[g],g=y(b,1),c=Q(b),g in K){a=T(a,g,U(g));if(e=ub(d,c))d=e.clone(),e=y(e,4),0b?2:f[f.length-1]=f&&f<=e;++f)if(d=parseInt(c.substring(0,f),10),d in K)return b.a(c.substring(f)),d;return 0} +function Fb(a,b,c,d,e,f){if(!b.length)return 0;b=new C(b);var g;c&&(g=v(c,11));null==g&&(g="NonMatch");var h=b.toString();if(h.length)if(M.test(h))h=h.replace(M,""),D(b),b.a(hb(h)),g=1;else{h=new RegExp(g);ib(b);g=b.toString();if(g.search(h))g=!1;else{var h=g.match(h)[0].length,m=g.substring(h).match(Ua);m&&null!=m[1]&&0=b.b.length)throw Error("Phone number too short after IDD");if(a=Eb(b, +d))return w(f,1,a),a;throw Error("Invalid country calling code");}if(c&&(g=y(c,10),h=""+g,m=b.toString(),!m.lastIndexOf(h,0)&&(h=new C(m.substring(h.length)),m=v(c,1),m=new RegExp(y(m,2)),Gb(h,c,null),h=h.toString(),!N(m,b.toString())&&N(m,h)||3==Cb(a,b.toString(),c,-1))))return d.a(h),e&&w(f,6,10),w(f,1,g),g;w(f,1,0);return 0} +function Gb(a,b,c){var d=a.toString(),e=d.length,f=v(b,15);if(e&&null!=f&&f.length){var g=new RegExp("^(?:"+f+")");if(e=g.exec(d)){var f=new RegExp(y(v(b,1),2)),h=N(f,d),m=e.length-1;b=v(b,16);if(null!=b&&b.length&&null!=e[m]&&e[m].length){if(d=d.replace(g,b),!h||N(f,d))c&&0b.b.length)throw Error("The string supplied is too short to be a phone number");g&&(c=new C,e=new C(b.toString()),Gb(e,g,c),a=Cb(a,e.toString(),g,-1),2!=a&&4!=a&&5!=a&&(b=e,d&&0a)throw Error("The string supplied is too short to be a phone number");if(17 + mainCountryForCode="true" mobileNumberPortableRegion="true"> $1 $2 NA - + $1 $2 $3