Browse Source

Updating JS project to Java version to r60. Patch submitted by tronikos.

pull/567/head
Lara Scheidegger 15 years ago
committed by Mihaela Rosca
parent
commit
8651ec907b
9 changed files with 970 additions and 348 deletions
  1. +6
    -3
      java/resources/com/google/i18n/phonenumbers/BuildMetadataJsonFromXml.java
  2. +1
    -1
      javascript/README
  3. +4
    -1
      javascript/i18n/phonenumbers/asyoutypeformatter.js
  4. +415
    -166
      javascript/i18n/phonenumbers/metadata.js
  5. +22
    -5
      javascript/i18n/phonenumbers/metadatafortesting.js
  6. +412
    -163
      javascript/i18n/phonenumbers/metadatalite.js
  7. +59
    -0
      javascript/i18n/phonenumbers/phonemetadata.pb.js
  8. +27
    -9
      javascript/i18n/phonenumbers/phonenumberutil.js
  9. +24
    -0
      javascript/i18n/phonenumbers/phonenumberutil_test.js

+ 6
- 3
java/resources/com/google/i18n/phonenumbers/BuildMetadataJsonFromXml.java View File

@ -296,7 +296,6 @@ public class BuildMetadataJsonFromXml {
} else {
jsArrayBuilder.append(null);
}
// required string id = 9;
jsArrayBuilder.append(metadata.getId());
// required int32 country_code = 10;
@ -364,8 +363,12 @@ public class BuildMetadataJsonFromXml {
} else {
jsArrayBuilder.append(null);
}
// missing 21
jsArrayBuilder.append(null);
// required PhoneNumberDesc pager = 21;
if (metadata.hasPager()) {
toJsArray(metadata.getPager(), jsArrayBuilder);
} else {
jsArrayBuilder.append(null);
}
// optional bool main_country_for_code = 22 [default=false];
if (metadata.getMainCountryForCode()) {
jsArrayBuilder.append(1);


+ 1
- 1
javascript/README View File

@ -25,7 +25,7 @@ pages with your web browser:
How to update:
==============
The JavaScript library is ported from the Java implementation (revision 53).
The JavaScript library is ported from the Java implementation (revision 60).
When the Java project gets updated follow these steps to update the JavaScript
project:


+ 4
- 1
javascript/i18n/phonenumbers/asyoutypeformatter.js View File

@ -538,7 +538,10 @@ i18n.phonenumbers.AsYouTypeFormatter.prototype.getRememberedPosition =
this.accruedInputWithoutFormatting_.toString();
/** @type {string} */
var currentOutput = this.currentOutput_.toString();
while (accruedInputIndex < this.positionToRemember_) {
/** @type {number} */
var currentOutputLength = currentOutput.length;
while (accruedInputIndex < this.positionToRemember_ &&
currentOutputIndex < currentOutputLength) {
if (accruedInputWithoutFormatting.charAt(accruedInputIndex) ==
currentOutput.charAt(currentOutputIndex)) {
accruedInputIndex++;


+ 415
- 166
javascript/i18n/phonenumbers/metadata.js
File diff suppressed because it is too large
View File


+ 22
- 5
javascript/i18n/phonenumbers/metadatafortesting.js View File

@ -61,7 +61,8 @@ i18n.phonenumbers.metadata.countryToMetadata = {
,[,,"NA","NA"]
,[,,"NA","NA"]
,[,,"NA","NA"]
,"AD",376,"00",,,,,,,1]
,"AD",376,"00",,,,,,,1,,,[,,"NA","NA"]
]
,"AO":[,[,,"[29]\\d{8}","\\d{9}"]
,[,,"2\\d(?:[26-9]\\d|\\d[26-9])\\d{5}","\\d{9}",,,"222123456"]
,[,,"9[1-3]\\d{7}","\\d{9}",,,"923123456"]
@ -72,6 +73,7 @@ i18n.phonenumbers.metadata.countryToMetadata = {
,[,,"NA","NA"]
,"AO",244,"00","0~0",,,"0~0",,,,[[,"(\\d{3})(\\d{3})(\\d{3})","$1 $2 $3",,"",""]
]
,,[,,"NA","NA"]
]
,"AR":[,[,,"[1-3689]\\d{9,10}","\\d{6,11}"]
,[,,"[1-3]\\d{9}","\\d{6,10}"]
@ -103,6 +105,7 @@ i18n.phonenumbers.metadata.countryToMetadata = {
,[,"(\\d{3})(\\d{3})(\\d{4})","$1-$2-$3",["[68]"]
,,""]
]
,[,,"NA","NA"]
]
,"AU":[,[,,"[1-578]\\d{4,14}","\\d{5,15}"]
,[,,"[2378]\\d{8}","\\d{9}"]
@ -117,6 +120,7 @@ i18n.phonenumbers.metadata.countryToMetadata = {
,[,"(\\d{1})(\\d{4})(\\d{4})","$1 $2 $3",["[2-478]"]
,"0$1",""]
]
,,[,,"NA","NA"]
]
,"BS":[,[,,"(242|8(00|66|77|88)|900)\\d{7}","\\d{7,10}"]
,[,,"242(?:3(?:02|[236][1-9]|4[0-24-9]|5[0-68]|7[3-57]|9[2-5])|4(?:2[237]|51|64|77)|502|636|702)\\d{4}","\\d{7,10}"]
@ -126,7 +130,8 @@ i18n.phonenumbers.metadata.countryToMetadata = {
,[,,"NA","NA"]
,[,,"NA","NA"]
,[,,"NA","NA"]
,"BS",1,"011","1",,,"1"]
,"BS",1,"011","1",,,"1",,,,,,[,,"NA","NA"]
]
,"DE":[,[,,"\\d{4,14}","\\d{2,14}"]
,[,,"(?:[24-6]\\d{2}|3[03-9]\\d|[789](?:[1-9]\\d|0[2-9]))\\d{3,8}","\\d{2,14}",,,"30123456"]
,[,,"1(5\\d{9}|7\\d{8}|6[02]\\d{8}|63\\d{7})","\\d{10,11}"]
@ -146,6 +151,7 @@ i18n.phonenumbers.metadata.countryToMetadata = {
,[,"(\\d{3})(\\d{3,4})(\\d{4})","$1 $2 $3",["900"]
,"0$1",""]
]
,,[,,"NA","NA"]
]
,"GB":[,[,,"\\d{10}","\\d{6,10}"]
,[,,"[1-6]\\d{9}","\\d{6,10}"]
@ -164,6 +170,7 @@ i18n.phonenumbers.metadata.countryToMetadata = {
,[,"(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["8[47]"]
,"(0$1)",""]
]
,,[,,"NA","NA"]
]
,"IT":[,[,,"[0389]\\d{5,10}","\\d{6,11}"]
,[,,"0\\d{9,10}","\\d{10,11}"]
@ -182,6 +189,7 @@ i18n.phonenumbers.metadata.countryToMetadata = {
,[,"(\\d{3})(\\d{3,6})","$1 $2",["8"]
,"",""]
]
,,[,,"NA","NA"]
]
,"JP":[,[]
,[]
@ -200,6 +208,7 @@ i18n.phonenumbers.metadata.countryToMetadata = {
,[,"(\\d{3})(\\d{2})(\\d{4})","$1 $2 $3",["[23]"]
,"0$1",""]
]
,,[,,"NA","NA"]
]
,"KR":[,[,,"[1-79]\\d{3,9}|8\\d{8}","\\d{4,10}"]
,[,,"(?:2|[34][1-3]|5[1-5]|6[1-4])(?:1\\d{2,3}|[2-9]\\d{6,7})","\\d{4,10}",,,"22123456"]
@ -234,6 +243,7 @@ i18n.phonenumbers.metadata.countryToMetadata = {
,[,"(\\d{2})(\\d{4})","$1-$2",["[3-9][1-9]1","[3-9][1-9]1[36]","[3-9][1-9]1(?:3[035-9]|6[03-578])"]
,"0$1",""]
]
,,[,,"NA","NA"]
]
,"MX":[,[,,"[1-9]\\d{9,10}","\\d{7,11}"]
,[,,"[2-9]\\d{9}","\\d{7,10}"]
@ -265,6 +275,7 @@ i18n.phonenumbers.metadata.countryToMetadata = {
,[,"(1)(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3 $4",["1(?:[124579]|3[0-24-9]|5[0-46-9]|8[02-9])"]
,,""]
]
,[,,"NA","NA"]
]
,"NZ":[,[,,"[2-9]\\d{7,9}","\\d{7,10}"]
,[,,"24099\\d{3}|(?:3[2-79]|[479][2-689]|6[235-9])\\d{6}","\\d{7,8}"]
@ -281,6 +292,7 @@ i18n.phonenumbers.metadata.countryToMetadata = {
,[,"(\\d{3})(\\d{3})(\\d{3,4})","$1 $2 $3",["[89]"]
,"0$1",""]
]
,,[,,"NA","NA"]
]
,"PL":[,[,,"[1-9]\\d{8}","\\d{9}"]
,[,,"[1-9]\\d{8}","\\d{9}"]
@ -292,6 +304,7 @@ i18n.phonenumbers.metadata.countryToMetadata = {
,[,,"NA","NA"]
,"PL",48,"0~0","0",,,"0",,,,[[,"(\\d{2})(\\d{3})(\\d{2})(\\d{2})","$1 $2 $3 $4",,"0$1",""]
]
,,[,,"NA","NA"]
]
,"RE":[,[,,"[268]\\d{8}","\\d{9}"]
,[,,"262\\d{6}","\\d{9}",,,"262161234"]
@ -303,7 +316,8 @@ i18n.phonenumbers.metadata.countryToMetadata = {
,[,,"NA","NA"]
,"RE",262,"00","0",,,"0",,,,[[,"([268]\\d{2})(\\d{2})(\\d{2})(\\d{2})","$1 $2 $3 $4",,"0$1",""]
]
,,,,"262|6(?:9[23]|47)|8"]
,,[,,"NA","NA"]
,,"262|6(?:9[23]|47)|8"]
,"SG":[,[,,"[13689]\\d{7,10}","\\d{8,11}"]
,[,,"[36]\\d{7}","\\d{8}"]
,[,,"[89]\\d{7}","\\d{8}"]
@ -319,6 +333,7 @@ i18n.phonenumbers.metadata.countryToMetadata = {
,[,"(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",["800"]
,"",""]
]
,,[,,"NA","NA"]
]
,"US":[,[,,"[13-9]\\d{9}|2[0-35-9]\\d{8}","\\d{7,10}",,,"1234567890"]
,[,,"[13-9]\\d{9}|2[0-35-9]\\d{8}","\\d{7,10}",,,"1234567890"]
@ -333,7 +348,8 @@ i18n.phonenumbers.metadata.countryToMetadata = {
]
,[[,"(\\d{3})(\\d{3})(\\d{4})","$1 $2 $3",,,""]
]
,,1]
,[,,"NA","NA"]
,1]
,"YT":[,[,,"[268]\\d{8}","\\d{9}"]
,[,,"2696[0-4]\\d{4}","\\d{9}",,,"269601234"]
,[,,"639\\d{6}","\\d{9}",,,"639123456"]
@ -342,5 +358,6 @@ i18n.phonenumbers.metadata.countryToMetadata = {
,[,,"NA","NA"]
,[,,"NA","NA"]
,[,,"NA","NA"]
,"YT",262,"00","0",,,"0",,,,,,,,"269|639"]
,"YT",262,"00","0",,,"0",,,,,,[,,"NA","NA"]
,,"269|639"]
};

+ 412
- 163
javascript/i18n/phonenumbers/metadatalite.js
File diff suppressed because it is too large
View File


+ 59
- 0
javascript/i18n/phonenumbers/phonemetadata.pb.js View File

@ -922,6 +922,59 @@ i18n.phonenumbers.PhoneMetadata.prototype.clearVoip = function() {
};
/**
* Gets the value of the pager field.
* @return {?i18n.phonenumbers.PhoneNumberDesc} The value.
*/
i18n.phonenumbers.PhoneMetadata.prototype.getPager = function() {
return /** @type {?i18n.phonenumbers.PhoneNumberDesc} */ (this.get$Value(21));
};
/**
* Gets the value of the pager field or the default value if not set.
* @return {i18n.phonenumbers.PhoneNumberDesc} The value.
*/
i18n.phonenumbers.PhoneMetadata.prototype.getPagerOrDefault = function() {
return /** @type {i18n.phonenumbers.PhoneNumberDesc} */ (this.get$ValueOrDefault(21));
};
/**
* Sets the value of the pager field.
* @param {i18n.phonenumbers.PhoneNumberDesc} value The value.
*/
i18n.phonenumbers.PhoneMetadata.prototype.setPager = function(value) {
this.set$Value(21, /** @type {Object} */ (value));
};
/**
* Returns whether the pager field has a value.
* @return {boolean} true if the field has a value.
*/
i18n.phonenumbers.PhoneMetadata.prototype.hasPager = function() {
return this.has$Value(21);
};
/**
* Gets the number of values in the pager field.
* @return {number}
*/
i18n.phonenumbers.PhoneMetadata.prototype.pagerCount = function() {
return this.count$Values(21);
};
/**
* Clears the values in the pager field.
*/
i18n.phonenumbers.PhoneMetadata.prototype.clearPager = function() {
this.clear$Field(21);
};
/**
* Gets the value of the id field.
* @return {?string} The value.
@ -1880,6 +1933,12 @@ goog.proto2.Message.set$Metadata(i18n.phonenumbers.PhoneMetadata, {
fieldType: goog.proto2.Message.FieldType.MESSAGE,
type: i18n.phonenumbers.NumberFormat
},
'21' : {
name: 'pager',
required: true,
fieldType: goog.proto2.Message.FieldType.MESSAGE,
type: i18n.phonenumbers.PhoneNumberDesc
},
'22' : {
name: 'main_country_for_code',
fieldType: goog.proto2.Message.FieldType.BOOL,


+ 27
- 9
javascript/i18n/phonenumbers/phonenumberutil.js View File

@ -322,6 +322,14 @@ i18n.phonenumbers.PhoneNumberUtil.VALID_ALPHA_ = 'A-Za-z';
*/
i18n.phonenumbers.PhoneNumberUtil.PLUS_CHARS_ = '+\uFF0B';
/**
* @const
* @type {RegExp}
* @private
*/
i18n.phonenumbers.PhoneNumberUtil.PLUS_CHARS_PATTERN_ =
new RegExp('^[' + i18n.phonenumbers.PhoneNumberUtil.PLUS_CHARS_ + ']+');
/**
* @const
* @type {RegExp}
@ -392,15 +400,16 @@ i18n.phonenumbers.PhoneNumberUtil.VALID_ALPHA_PHONE_PATTERN_ =
* alpha characters and digits in the phone number. Does not include extension
* data. The symbol 'x' is allowed here as valid punctuation since it is often
* used as a placeholder for carrier codes, for example in Brazilian phone
* numbers. Corresponds to the following:
* plus_sign?([punctuation]*[digits]){3,}([punctuation]|[digits]|[alpha])*
* numbers. We also allow multiple '+' characters at the start.
* Corresponds to the following:
* plus_sign*([punctuation]*[digits]){3,}([punctuation]|[digits]|[alpha])*
*
* @const
* @type {string}
* @private
*/
i18n.phonenumbers.PhoneNumberUtil.VALID_PHONE_NUMBER_ =
'[' + i18n.phonenumbers.PhoneNumberUtil.PLUS_CHARS_ + ']?(?:[' +
'[' + i18n.phonenumbers.PhoneNumberUtil.PLUS_CHARS_ + ']*(?:[' +
i18n.phonenumbers.PhoneNumberUtil.VALID_PUNCTUATION_ + ']*[' +
i18n.phonenumbers.PhoneNumberUtil.VALID_DIGITS_ + ']){3,}[' +
i18n.phonenumbers.PhoneNumberUtil.VALID_ALPHA_ +
@ -537,9 +546,10 @@ i18n.phonenumbers.PhoneNumberType = {
// to either a MOBILE or FIXED_LINE number. Some more information can be found
// here: http://en.wikipedia.org/wiki/Personal_Numbers
PERSONAL_NUMBER: 7,
PAGER: 8,
// A phone number is of type UNKNOWN when it does not fit any of the known
// patterns for a specific country.
UNKNOWN: 8
UNKNOWN: 9
};
/**
@ -1435,6 +1445,8 @@ i18n.phonenumbers.PhoneNumberUtil.prototype.getNumberDescByType_ =
return metadata.getVoip();
case i18n.phonenumbers.PhoneNumberType.PERSONAL_NUMBER:
return metadata.getPersonalNumber();
case i18n.phonenumbers.PhoneNumberType.PAGER:
return metadata.getPager();
default:
return metadata.getGeneralDesc();
}
@ -1494,6 +1506,10 @@ i18n.phonenumbers.PhoneNumberUtil.prototype.getNumberTypeHelper_ =
metadata.getPersonalNumber())) {
return i18n.phonenumbers.PhoneNumberType.PERSONAL_NUMBER;
}
if (this.isNumberMatchingDesc_(nationalNumber,
metadata.getPager())) {
return i18n.phonenumbers.PhoneNumberType.PAGER;
}
/** @type {boolean} */
var isFixedLine = this.isNumberMatchingDesc_(nationalNumber, metadata
@ -2182,12 +2198,14 @@ i18n.phonenumbers.PhoneNumberUtil.prototype.
if (numberStr.length == 0) {
return i18n.phonenumbers.PhoneNumber.CountryCodeSource.FROM_DEFAULT_COUNTRY;
}
if (numberStr.charAt(0) == i18n.phonenumbers.PhoneNumberUtil.PLUS_SIGN) {
// Check to see if the number begins with one or more plus signs.
if (i18n.phonenumbers.PhoneNumberUtil.PLUS_CHARS_PATTERN_.test(numberStr)) {
numberStr = numberStr.replace(
i18n.phonenumbers.PhoneNumberUtil.PLUS_CHARS_PATTERN_, '');
// Can now normalize the rest of the number since we've consumed the "+"
// sign at the start.
number.clear();
number.append(
i18n.phonenumbers.PhoneNumberUtil.normalize(numberStr.substring(1)));
number.append(i18n.phonenumbers.PhoneNumberUtil.normalize(numberStr));
return i18n.phonenumbers.PhoneNumber.CountryCodeSource
.FROM_NUMBER_WITH_PLUS_SIGN;
}
@ -2324,7 +2342,7 @@ i18n.phonenumbers.PhoneNumberUtil.prototype.maybeStripExtension =
i18n.phonenumbers.PhoneNumberUtil.prototype.parse = function(numberToParse,
defaultCountry) {
if (!this.isValidRegionCode_(defaultCountry)) {
if (numberToParse.charAt(0) !=
if (numberToParse.length > 0 && numberToParse.charAt(0) !=
i18n.phonenumbers.PhoneNumberUtil.PLUS_SIGN) {
throw i18n.phonenumbers.Error.INVALID_COUNTRY_CODE;
}
@ -2355,7 +2373,7 @@ i18n.phonenumbers.PhoneNumberUtil.prototype.parseAndKeepRawInput =
function(numberToParse, defaultCountry) {
if (!this.isValidRegionCode_(defaultCountry)) {
if (numberToParse.charAt(0) !=
if (numberToParse.length > 0 && numberToParse.charAt(0) !=
i18n.phonenumbers.PhoneNumberUtil.PLUS_SIGN) {
throw i18n.phonenumbers.Error.INVALID_COUNTRY_CODE;
}


+ 24
- 0
javascript/i18n/phonenumbers/phonenumberutil_test.js View File

@ -1565,6 +1565,18 @@ function testParseWithInternationalPrefixes() {
// Calling the US number from Poland
assertTrue(usNumber.exactlySameAs(
phoneUtil.parse('0~01-650-333-6000', 'PL')));
// Using '++' at the start.
assertTrue(usNumber.exactlySameAs(
phoneUtil.parse('++1 (650) 333-6000', 'PL')));
// Using a full-width plus sign.
assertTrue(usNumber.exactlySameAs(
phoneUtil.parse('\uFF0B1 (650) 333-6000', 'SG')));
// The whole number, including punctuation, is here represented in full-width
// form.
assertTrue(usNumber.exactlySameAs(
phoneUtil.parse('\uFF0B\uFF11\u3000\uFF08\uFF16\uFF15\uFF10\uFF09' +
'\u3000\uFF13\uFF13\uFF13\uFF0D\uFF16\uFF10\uFF10\uFF10',
'SG')));
}
function testParseWithLeadingZero() {
@ -1799,6 +1811,18 @@ function testFailedParseOnInvalidNumbers() {
i18n.phonenumbers.Error.TOO_SHORT_AFTER_IDD,
e);
}
try {
/** @type {string} */
var emptyNumber = '';
// Invalid region.
phoneUtil.parse(emptyNumber, 'ZZ');
fail('Empty string - should fail.');
} catch (e) {
// Expected this exception.
assertEquals('Wrong error type stored in exception.',
i18n.phonenumbers.Error.NOT_A_NUMBER,
e);
}
}
function testParseNumbersWithPlusWithNoRegion() {


Loading…
Cancel
Save