private static final char SEPARATOR_BEFORE_NATIONAL_NUMBER = ' ';
private static final PhoneMetadata EMPTY_METADATA =
new PhoneMetadata().setInternationalPrefix("NA");
- private PhoneMetadata defaultMetaData;
- private PhoneMetadata currentMetaData;
+ private PhoneMetadata defaultMetadata;
+ private PhoneMetadata currentMetadata;
// A pattern that is used to match character classes in regular expressions. An example of a
// character class is [1-4].
*/
AsYouTypeFormatter(String regionCode) {
defaultCountry = regionCode;
- currentMetaData = getMetadataForRegion(defaultCountry);
- defaultMetaData = currentMetaData;
+ currentMetadata = getMetadataForRegion(defaultCountry);
+ defaultMetadata = currentMetadata;
}
// The metadata needed by this class is the same for all regions sharing the same country calling
private void getAvailableFormats(String leadingThreeDigits) {
List<NumberFormat> formatList =
- (isCompleteNumber && currentMetaData.intlNumberFormatSize() > 0)
- ? currentMetaData.intlNumberFormats()
- : currentMetaData.numberFormats();
- boolean nationalPrefixIsUsedByCountry = currentMetaData.hasNationalPrefix();
+ (isCompleteNumber && currentMetadata.intlNumberFormatSize() > 0)
+ ? currentMetadata.intlNumberFormats()
+ : currentMetadata.numberFormats();
+ boolean nationalPrefixIsUsedByCountry = currentMetadata.hasNationalPrefix();
for (NumberFormat format : formatList) {
if (!nationalPrefixIsUsedByCountry || isCompleteNumber ||
format.isNationalPrefixOptionalWhenFormatting() ||
isExpectingCountryCallingCode = false;
possibleFormats.clear();
shouldAddSpaceAfterNationalPrefix = false;
- if (!currentMetaData.equals(defaultMetaData)) {
- currentMetaData = getMetadataForRegion(defaultCountry);
+ if (!currentMetadata.equals(defaultMetadata)) {
+ currentMetadata = getMetadataForRegion(defaultCountry);
}
}
// that national significant numbers in NANPA always start with [2-9] after the national prefix.
// Numbers beginning with 1[01] can only be short/emergency numbers, which don't need the
// national prefix.
- return (currentMetaData.getCountryCode() == 1) && (nationalNumber.charAt(0) == '1') &&
+ return (currentMetadata.getCountryCode() == 1) && (nationalNumber.charAt(0) == '1') &&
(nationalNumber.charAt(1) != '0') && (nationalNumber.charAt(1) != '1');
}
startOfNationalNumber = 1;
prefixBeforeNationalNumber.append('1').append(SEPARATOR_BEFORE_NATIONAL_NUMBER);
isCompleteNumber = true;
- } else if (currentMetaData.hasNationalPrefixForParsing()) {
+ } else if (currentMetadata.hasNationalPrefixForParsing()) {
Pattern nationalPrefixForParsing =
- regexCache.getPatternForRegex(currentMetaData.getNationalPrefixForParsing());
+ regexCache.getPatternForRegex(currentMetadata.getNationalPrefixForParsing());
Matcher m = nationalPrefixForParsing.matcher(nationalNumber);
if (m.lookingAt()) {
// When the national prefix is detected, we use international formatting rules instead of
private boolean attemptToExtractIdd() {
Pattern internationalPrefix =
regexCache.getPatternForRegex("\\" + PhoneNumberUtil.PLUS_SIGN + "|" +
- currentMetaData.getInternationalPrefix());
+ currentMetadata.getInternationalPrefix());
Matcher iddMatcher = internationalPrefix.matcher(accruedInputWithoutFormatting);
if (iddMatcher.lookingAt()) {
isCompleteNumber = true;
nationalNumber.append(numberWithoutCountryCallingCode);
String newRegionCode = phoneUtil.getRegionCodeForCountryCode(countryCode);
if (PhoneNumberUtil.REGION_CODE_FOR_NON_GEO_ENTITY.equals(newRegionCode)) {
- currentMetaData = phoneUtil.getMetadataForNonGeographicalRegion(countryCode);
+ currentMetadata = phoneUtil.getMetadataForNonGeographicalRegion(countryCode);
} else if (!newRegionCode.equals(defaultCountry)) {
- currentMetaData = getMetadataForRegion(newRegionCode);
+ currentMetadata = getMetadataForRegion(newRegionCode);
}
String countryCodeString = Integer.toString(countryCode);
prefixBeforeNationalNumber.append(countryCodeString).append(SEPARATOR_BEFORE_NATIONAL_NUMBER);
* @private
*/
this.defaultCountry_ = regionCode;
- this.currentMetaData_ = this.getMetadataForRegion_(this.defaultCountry_);
+ this.currentMetadata_ = this.getMetadataForRegion_(this.defaultCountry_);
/**
* @type {i18n.phonenumbers.PhoneMetadata}
* @private
*/
- this.defaultMetaData_ = this.currentMetaData_;
+ this.defaultMetadata_ = this.currentMetadata_;
};
/** @type {Array.<i18n.phonenumbers.NumberFormat>} */
var formatList =
(this.isCompleteNumber_ &&
- this.currentMetaData_.intlNumberFormatCount() > 0) ?
- this.currentMetaData_.intlNumberFormatArray() :
- this.currentMetaData_.numberFormatArray();
+ this.currentMetadata_.intlNumberFormatCount() > 0) ?
+ this.currentMetadata_.intlNumberFormatArray() :
+ this.currentMetadata_.numberFormatArray();
/** @type {number} */
var formatListLength = formatList.length;
for (var i = 0; i < formatListLength; ++i) {
var format = formatList[i];
/** @type {boolean} */
var nationalPrefixIsUsedByCountry =
- this.currentMetaData_.hasNationalPrefix();
+ this.currentMetadata_.hasNationalPrefix();
if (!nationalPrefixIsUsedByCountry || this.isCompleteNumber_ ||
format.getNationalPrefixOptionalWhenFormatting() ||
this.phoneUtil_.formattingRuleHasFirstGroupOnly(
this.isExpectingCountryCallingCode_ = false;
this.possibleFormats_ = [];
this.shouldAddSpaceAfterNationalPrefix_ = false;
- if (this.currentMetaData_ != this.defaultMetaData_) {
- this.currentMetaData_ = this.getMetadataForRegion_(this.defaultCountry_);
+ if (this.currentMetadata_ != this.defaultMetadata_) {
+ this.currentMetadata_ = this.getMetadataForRegion_(this.defaultCountry_);
}
};
// prefix. The reason is that national significant numbers in NANPA always
// start with [2-9] after the national prefix. Numbers beginning with 1[01]
// can only be short/emergency numbers, which don't need the national prefix.
- if (this.currentMetaData_.getCountryCode() != 1) {
+ if (this.currentMetadata_.getCountryCode() != 1) {
return false;
}
/** @type {string} */
this.prefixBeforeNationalNumber_.append('1').append(
i18n.phonenumbers.AsYouTypeFormatter.SEPARATOR_BEFORE_NATIONAL_NUMBER_);
this.isCompleteNumber_ = true;
- } else if (this.currentMetaData_.hasNationalPrefixForParsing()) {
+ } else if (this.currentMetadata_.hasNationalPrefixForParsing()) {
/** @type {RegExp} */
var nationalPrefixForParsing = new RegExp(
- '^(?:' + this.currentMetaData_.getNationalPrefixForParsing() + ')');
+ '^(?:' + this.currentMetadata_.getNationalPrefixForParsing() + ')');
/** @type {Array.<string>} */
var m = nationalNumber.match(nationalPrefixForParsing);
if (m != null && m[0] != null && m[0].length > 0) {
/** @type {RegExp} */
var internationalPrefix = new RegExp(
'^(?:' + '\\' + i18n.phonenumbers.PhoneNumberUtil.PLUS_SIGN + '|' +
- this.currentMetaData_.getInternationalPrefix() + ')');
+ this.currentMetadata_.getInternationalPrefix() + ')');
/** @type {Array.<string>} */
var m = accruedInputWithoutFormatting.match(internationalPrefix);
if (m != null && m[0] != null && m[0].length > 0) {
var newRegionCode = this.phoneUtil_.getRegionCodeForCountryCode(countryCode);
if (i18n.phonenumbers.PhoneNumberUtil.REGION_CODE_FOR_NON_GEO_ENTITY ==
newRegionCode) {
- this.currentMetaData_ =
+ this.currentMetadata_ =
this.phoneUtil_.getMetadataForNonGeographicalRegion(countryCode);
} else if (newRegionCode != this.defaultCountry_) {
- this.currentMetaData_ = this.getMetadataForRegion_(newRegionCode);
+ this.currentMetadata_ = this.getMetadataForRegion_(newRegionCode);
}
/** @type {string} */
var countryCodeString = '' + countryCode;