Browse Source

DATA: Minor fix to change MetaData to Metadata for consistency

pull/567/head
David Yonge-Mallo 13 years ago
committed by Mihaela Rosca
parent
commit
344d8034c7
3 changed files with 31 additions and 31 deletions
  1. +16
    -16
      java/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java
  2. +14
    -14
      javascript/i18n/phonenumbers/asyoutypeformatter.js
  3. +1
    -1
      resources/PhoneNumberMetadataForTesting.xml

+ 16
- 16
java/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java View File

@ -63,8 +63,8 @@ public class AsYouTypeFormatter {
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].
@ -126,8 +126,8 @@ public class AsYouTypeFormatter {
*/
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
@ -174,10 +174,10 @@ public class AsYouTypeFormatter {
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() ||
@ -277,8 +277,8 @@ public class AsYouTypeFormatter {
isExpectingCountryCallingCode = false;
possibleFormats.clear();
shouldAddSpaceAfterNationalPrefix = false;
if (!currentMetaData.equals(defaultMetaData)) {
currentMetaData = getMetadataForRegion(defaultCountry);
if (!currentMetadata.equals(defaultMetadata)) {
currentMetadata = getMetadataForRegion(defaultCountry);
}
}
@ -509,7 +509,7 @@ public class AsYouTypeFormatter {
// 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');
}
@ -520,9 +520,9 @@ public class AsYouTypeFormatter {
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
@ -548,7 +548,7 @@ public class AsYouTypeFormatter {
private boolean attemptToExtractIdd() {
Pattern internationalPrefix =
regexCache.getPatternForRegex("\\" + PhoneNumberUtil.PLUS_SIGN + "|" +
currentMetaData.getInternationalPrefix());
currentMetadata.getInternationalPrefix());
Matcher iddMatcher = internationalPrefix.matcher(accruedInputWithoutFormatting);
if (iddMatcher.lookingAt()) {
isCompleteNumber = true;
@ -586,9 +586,9 @@ public class AsYouTypeFormatter {
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);


+ 14
- 14
javascript/i18n/phonenumbers/asyoutypeformatter.js View File

@ -181,12 +181,12 @@ i18n.phonenumbers.AsYouTypeFormatter = function(regionCode) {
* @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_;
};
@ -351,9 +351,9 @@ i18n.phonenumbers.AsYouTypeFormatter.prototype.getAvailableFormats_ =
/** @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) {
@ -361,7 +361,7 @@ i18n.phonenumbers.AsYouTypeFormatter.prototype.getAvailableFormats_ =
var format = formatList[i];
/** @type {boolean} */
var nationalPrefixIsUsedByCountry =
this.currentMetaData_.hasNationalPrefix();
this.currentMetadata_.hasNationalPrefix();
if (!nationalPrefixIsUsedByCountry || this.isCompleteNumber_ ||
format.getNationalPrefixOptionalWhenFormatting() ||
this.phoneUtil_.formattingRuleHasFirstGroupOnly(
@ -515,8 +515,8 @@ i18n.phonenumbers.AsYouTypeFormatter.prototype.clear = function() {
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_);
}
};
@ -887,7 +887,7 @@ i18n.phonenumbers.AsYouTypeFormatter.prototype.
// 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} */
@ -916,10 +916,10 @@ i18n.phonenumbers.AsYouTypeFormatter.prototype.
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) {
@ -955,7 +955,7 @@ i18n.phonenumbers.AsYouTypeFormatter.prototype.attemptToExtractIdd_ =
/** @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) {
@ -1008,10 +1008,10 @@ i18n.phonenumbers.AsYouTypeFormatter.prototype.
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;


+ 1
- 1
resources/PhoneNumberMetadataForTesting.xml View File

@ -14,7 +14,7 @@
@author: Shaopeng Jia
MetaData on Phone Number Plan and formatting rules. This file is used
Metadata on Phone Number Plan and formatting rules. This file is used
solely for the purpose of unittesting, so data in this file is not
necessarily consistent with that of PhoneNumberMetadata.xml.
-->


Loading…
Cancel
Save