Commits

Anonymous committed c6a9d52

Reorganize project structure to make it easy to build.

  • Participants
  • Parent commits b852d2e
  • Branches default

Comments (0)

Files changed (14)

File java/build.xml

     <mkdir dir="${classes.dir}"/>
     <javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath"/>
     <javac srcdir="${test.dir}" destdir="${classes.dir}" classpathref="classpath"/>
+    <javac srcdir="${resources.dir}" destdir="${classes.dir}" classpathref="classpath"/>
   </target>
 
   <target name="jar" depends="compile">
         <include name="**/*.class"/>
         <exclude name="**/*Test*"/>
       </fileset>
-      <fileset dir="${resources.dir}">
+      <fileset dir="${src.dir}">
         <include name="**/PhoneNumberMetadataProto"/>
       </fileset>
     </jar>
         <include name="**/*.class"/>
         <exclude name="**/*Test*"/>
       </fileset>
-      <fileset dir="${resources.dir}">
+      <fileset dir="${src.dir}">
         <include name="**/PhoneNumberMetadataProto"/>
+      </fileset>
+      <fileset dir="${test.dir}">
         <include name="**/PhoneNumberMetadataProtoForTesting"/>
       </fileset>
     </jar>

File java/resources/com/google/i18n/phonenumbers/BuildMetadataProtoFromXml.java

+/*
+ * Copyright (C) 2009 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.i18n.phonenumbers;
+
+import com.google.i18n.phonenumbers.Phonemetadata.NumberFormat;
+import com.google.i18n.phonenumbers.Phonemetadata.PhoneMetadata;
+import com.google.i18n.phonenumbers.Phonemetadata.PhoneMetadataCollection;
+import com.google.i18n.phonenumbers.Phonemetadata.PhoneNumberDesc;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.regex.Pattern;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+/**
+ * Tool to convert phone number metadata from the XML format to protocol buffer format. It is
+ * wrapped in the genrule of the BUILD file and run as a preprocessing step when building the
+ * phone number library. Example command line invocation:
+ *
+ * ./BuildMetadataProtoFromXml PhoneNumberMetadata.xml PhoneNumberMetadataProto true
+ *
+ * When liteBuild flag is set to true, the outputFile generated omits certain metadata which is not
+ * needed for clients using liteBuild. At this moment, example numbers information is omitted.
+ *
+ * @author Shaopeng Jia
+ */
+public class BuildMetadataProtoFromXml {
+  private BuildMetadataProtoFromXml() {
+  }
+  private static final Logger LOGGER = Logger.getLogger(BuildMetadataProtoFromXml.class.getName());
+  private static Boolean liteBuild;
+
+  public static void main(String[] args) {
+    String inputFile = args[0];
+    String outputFile = args[1];
+    liteBuild = args.length > 2 && Boolean.getBoolean(args[2]);
+    File xmlFile = new File(inputFile);
+    try {
+      FileOutputStream output = new FileOutputStream(outputFile);
+      DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
+      DocumentBuilder builder = builderFactory.newDocumentBuilder();
+      Document document = builder.parse(xmlFile);
+      document.getDocumentElement().normalize();
+      Element rootElement = document.getDocumentElement();
+      NodeList territory = rootElement.getElementsByTagName("territory");
+      PhoneMetadataCollection metadataCollection = new PhoneMetadataCollection();
+      int numOfTerritories = territory.getLength();
+      for (int i = 0; i < numOfTerritories; i++) {
+        Element territoryElement = (Element) territory.item(i);
+        String regionCode = territoryElement.getAttribute("id");
+        PhoneMetadata metadata = loadCountryMetadata(regionCode, territoryElement);
+        metadataCollection.addMetadata(metadata);
+      }
+      ObjectOutputStream out = new ObjectOutputStream(output);
+      out.writeObject(metadataCollection);
+      out.close();
+    } catch (IOException e) {
+      LOGGER.log(Level.SEVERE, e.toString());
+    } catch (SAXException e) {
+      LOGGER.log(Level.SEVERE, e.toString());
+    } catch (ParserConfigurationException e) {
+      LOGGER.log(Level.SEVERE, e.toString());
+    }
+  }
+
+  private static String validateRE(String regex) {
+    Pattern regexPattern = Pattern.compile(regex);
+    // return regex itself if it is of correct regex syntax
+    return regex;
+  }
+
+  private static PhoneMetadata loadCountryMetadata(String regionCode, Element element) {
+    PhoneMetadata metadata = new PhoneMetadata();
+    metadata.setId(regionCode);
+    metadata.setCountryCode(Integer.parseInt(element.getAttribute("countryCode")));
+    metadata.setInternationalPrefix(validateRE(element.getAttribute("internationalPrefix")));
+    if (element.hasAttribute("preferredInternationalPrefix")) {
+      String preferredInternationalPrefix = element.getAttribute("preferredInternationalPrefix");
+      metadata.setPreferredInternationalPrefix(preferredInternationalPrefix);
+    }
+    String nationalPrefix = "";
+    String nationalPrefixFormattingRule = "";
+    if (element.hasAttribute("nationalPrefix")) {
+      nationalPrefix = element.getAttribute("nationalPrefix");
+      metadata.setNationalPrefix(nationalPrefix);
+       nationalPrefixFormattingRule =
+          validateRE(getNationalPrefixFormattingRuleFromElement(element, nationalPrefix));
+
+      if (element.hasAttribute("nationalPrefixForParsing")) {
+        metadata.setNationalPrefixForParsing(
+            validateRE(element.getAttribute("nationalPrefixForParsing")));
+        if (element.hasAttribute("nationalPrefixTransformRule")) {
+          metadata.setNationalPrefixTransformRule(
+              element.getAttribute("nationalPrefixTransformRule"));
+        }
+      } else {
+        metadata.setNationalPrefixForParsing(nationalPrefix);
+      }
+    }
+    if (element.hasAttribute("preferredExtnPrefix")) {
+      metadata.setPreferredExtnPrefix(element.getAttribute("preferredExtnPrefix"));
+    }
+
+    // Extract availableFormats
+    NodeList numberFormatElements = element.getElementsByTagName("numberFormat");
+    int numOfFormatElements = numberFormatElements.getLength();
+    if (numOfFormatElements > 0) {
+      for (int i = 0; i < numOfFormatElements; i++) {
+        Element numberFormatElement = (Element) numberFormatElements.item(i);
+        NumberFormat format = new NumberFormat();
+        if (numberFormatElement.hasAttribute("nationalPrefixFormattingRule")) {
+          format.setNationalPrefixFormattingRule(validateRE(
+              getNationalPrefixFormattingRuleFromElement(numberFormatElement, nationalPrefix)));
+        } else {
+          format.setNationalPrefixFormattingRule(nationalPrefixFormattingRule);
+        }
+        if (numberFormatElement.hasAttribute("leadingDigits")) {
+          format.setLeadingDigits(validateRE(numberFormatElement.getAttribute("leadingDigits")));
+        }
+        format.setPattern(validateRE(numberFormatElement.getAttribute("pattern")));
+        format.setFormat(validateRE(numberFormatElement.getFirstChild().getNodeValue()));
+        metadata.addNumberFormat(format);
+      }
+    }
+
+    NodeList intlNumberFormatElements = element.getElementsByTagName("intlNumberFormat");
+    int numOfIntlFormatElements = intlNumberFormatElements.getLength();
+    if (numOfIntlFormatElements > 0) {
+      for (int i = 0; i < numOfIntlFormatElements; i++) {
+        Element numberFormatElement = (Element) intlNumberFormatElements.item(i);
+        NumberFormat format = new NumberFormat();
+        if (numberFormatElement.hasAttribute("leadingDigits")) {
+          format.setLeadingDigits(validateRE(numberFormatElement.getAttribute("leadingDigits")));
+        }
+        format.setPattern(validateRE(numberFormatElement.getAttribute("pattern")));
+        format.setFormat(validateRE(numberFormatElement.getFirstChild().getNodeValue()));
+        metadata.addIntlNumberFormat(format);
+      }
+    }
+
+    PhoneNumberDesc generalDesc =
+        processPhoneNumberDescElement(new PhoneNumberDesc(), element, "generalDesc");
+    metadata.setGeneralDesc(generalDesc);
+    metadata.setFixedLine(processPhoneNumberDescElement(generalDesc, element, "fixedLine"));
+    metadata.setMobile(processPhoneNumberDescElement(generalDesc, element, "mobile"));
+    metadata.setTollFree(processPhoneNumberDescElement(generalDesc, element, "tollFree"));
+    metadata.setPremiumRate(processPhoneNumberDescElement(generalDesc, element, "premiumRate"));
+    metadata.setSharedCost(processPhoneNumberDescElement(generalDesc, element, "sharedCost"));
+    metadata.setVoip(processPhoneNumberDescElement(generalDesc, element, "voip"));
+    metadata.setPersonalNumber(processPhoneNumberDescElement(generalDesc, element,
+                                                             "personalNumber"));
+
+    if (metadata.getMobile().getNationalNumberPattern().equals(
+        metadata.getFixedLine().getNationalNumberPattern())) {
+      metadata.setSameMobileAndFixedLinePattern(true);
+    }
+    return metadata;
+  }
+
+  private static String getNationalPrefixFormattingRuleFromElement(Element element,
+                                                                   String nationalPrefix) {
+    String nationalPrefixFormattingRule = element.getAttribute("nationalPrefixFormattingRule");
+    // Replace $NP with national prefix and $FG with the first group ($1).
+    nationalPrefixFormattingRule =
+        nationalPrefixFormattingRule.replaceFirst("\\$NP", nationalPrefix)
+            .replaceFirst("\\$FG", "\\$1");
+    return nationalPrefixFormattingRule;
+  }
+
+  /**
+   * Processes a phone number description element from the XML file and returns it as a
+   * PhoneNumberDesc. If the description element is a fixed line or mobile number, the general
+   * description will be used to fill in the whole element if necessary, or any components that are
+   * missing. For all other types, the general description will only be used to fill in missing
+   * components if the type has a partial definition. For example, if no "tollFree" element exists,
+   * we assume there are no toll free numbers for that locale, and return a phone number description
+   * with "NA" for both the national and possible number patterns.
+   *
+   * @param generalDesc  a generic phone number description that will be used to fill in missing
+   *                     parts of the description
+   * @param countryElement  the XML element representing all the country information
+   * @param numberType  the name of the number type, corresponding to the appropriate tag in the XML
+   *                    file with information about that type
+   * @return  complete description of that phone number type
+   */
+  private static PhoneNumberDesc processPhoneNumberDescElement(PhoneNumberDesc generalDesc,
+                                                               Element countryElement,
+                                                               String numberType) {
+    NodeList phoneNumberDescList = countryElement.getElementsByTagName(numberType);
+    PhoneNumberDesc numberDesc = new PhoneNumberDesc();
+    if (phoneNumberDescList.getLength() == 0 &&
+        (!numberType.equals("fixedLine") && !numberType.equals("mobile") &&
+         !numberType.equals("generalDesc"))) {
+      numberDesc.setNationalNumberPattern("NA");
+      numberDesc.setPossibleNumberPattern("NA");
+      return numberDesc;
+    }
+    numberDesc.mergeFrom(generalDesc);
+    if (phoneNumberDescList.getLength() > 0) {
+      Element element = (Element) phoneNumberDescList.item(0);
+      NodeList possiblePattern = element.getElementsByTagName("possibleNumberPattern");
+      if (possiblePattern.getLength() > 0) {
+        numberDesc.setPossibleNumberPattern(
+            validateRE(possiblePattern.item(0).getFirstChild().getNodeValue()));
+      }
+
+      NodeList validPattern = element.getElementsByTagName("nationalNumberPattern");
+      if (validPattern.getLength() > 0) {
+        numberDesc.setNationalNumberPattern(
+            validateRE(validPattern.item(0).getFirstChild().getNodeValue()));
+      }
+
+      if (!liteBuild) {
+        NodeList exampleNumber = element.getElementsByTagName("exampleNumber");
+        if (exampleNumber.getLength() > 0) {
+          numberDesc.setExampleNumber(exampleNumber.item(0).getFirstChild().getNodeValue());
+        }
+      }
+    }
+    return numberDesc;
+  }
+}

File java/resources/com/google/i18n/phonenumbers/phonemetadata.proto

+/*
+ * Copyright (C) 2009 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Definition of protocol buffer for holding metadata for international
+// telephone numbers.
+// @author Shaopeng Jia
+
+syntax = "proto2";
+
+option java_package = "com.google.i18n.phonenumbers";
+option optimize_for = LITE_RUNTIME;
+package i18n.phonenumbers;
+
+message NumberFormat {
+  // pattern is a regex that is used to match the national (significant)
+  // number. For example, the pattern "(20)(\d{4})(\d{4})" will match number
+  // "2070313000", which is the national (significant) number for Google London.
+  // Note the presence of the parentheses, which are capturing groups what
+  // specifies the grouping of numbers.
+  required string pattern = 1;
+
+  // format specifies how the national (significant) number matched by
+  // pattern should be formatted.
+  // Using the same example as above, format could contain "$1 $2 $3",
+  // meaning that the number should be formatted as "20 7031 3000".
+  // Each $x are replaced by the numbers captured by group x in the
+  // regex specified by pattern.
+  required string format = 2;
+
+  // leadingDigits is a regex that is used to match up to the first four digits
+  // of the national (significant) number. When the match is successful, the
+  // accompanying pattern and format should be used to format this number. For
+  // example, if leading_digits="[1-3]|44", then all the national numbers
+  // starting with 1, 2, 3 or 44 should be formatted using the accompanying
+  // pattern and format.
+  optional string leading_digits = 3;
+
+  // This field specifies how the national prefix ($NP) together with the first
+  // group ($FG) in the national significant number should be formatted in
+  // the NATIONAL format when a national prefix exists for a certain country.
+  // For example, when this field contains "($NP$FG)", a number from Beijing,
+  // China (whose $NP = 0), which would by default be formatted without
+  // national prefix as 10 1234 5678 in NATIONAL format, will instead be
+  // formatted as (010) 1234 5678; to format it as (0)10 1234 5678, the field
+  // would contain "($NP)$FG". Note $FG should always be present in this field,
+  // but $NP can be omitted. For example, having "$FG" could indicate the
+  // number should be formatted in NATIONAL format without the national prefix.
+  // This is commonly used to override the rule from generalDesc.
+  //
+  // When this field is missing, a number will be formatted without national
+  // prefix in NATIONAL format. This field does not affect how a number
+  // is formatted in other formats, such as INTERNATIONAL.
+  optional string national_prefix_formatting_rule = 4;
+}
+
+message PhoneNumberDesc {
+  // The national_number_pattern is the pattern that a valid national
+  // significant number would match. This specifies information such as its
+  // total length and leading digits.
+  optional string national_number_pattern = 2;
+
+  // The possible_number_pattern represents what a potentially valid phone
+  // number for this region may be written as. This is a superset of the
+  // national_number_pattern above and includes numbers that have the area code
+  // omitted. Typically the only restrictions here are in the number of digits.
+  // This could be used to highlight tokens in a text that may be a phone
+  // number, or to quickly prune numbers that could not possibly be a phone
+  // number for this locale.
+  optional string possible_number_pattern = 3;
+
+  // An example national significant number for the specific type. It should
+  // not contain any formatting information.
+  optional string example_number = 6;
+}
+
+message PhoneMetadata {
+  // The general_desc contains information which is a superset of descriptions
+  // for all types of phone numbers. If any element is missing in the
+  // description of a specific type in the XML file, the element will inherit
+  // from its counterpart in the general_desc. Every locale is assumed to have
+  // fixed line and mobile numbers - if these types are missing in the XML
+  // file, they will inherit all fields from the general_desc. For all other
+  // types, if the whole type is missing in the xml file, it will be given a
+  // national_number_pattern of "NA" and a possible_number_pattern of "NA".
+  required PhoneNumberDesc general_desc = 1;
+  required PhoneNumberDesc fixed_line = 2;
+  required PhoneNumberDesc mobile = 3;
+  required PhoneNumberDesc toll_free = 4;
+  required PhoneNumberDesc premium_rate = 5;
+  required PhoneNumberDesc shared_cost = 6;
+  required PhoneNumberDesc personal_number = 7;
+  required PhoneNumberDesc voip = 8;
+
+  // The ISO 3166-1 alpha-2 representation of a country/region
+  required string id = 9;
+
+  // The country calling code that one would dial from overseas when trying to
+  // dial a phone number in this country. For example, this would be "64" for
+  // New Zealand.
+  required int32 country_code = 10;
+
+  // The international_prefix of country A is the number that needs to be
+  // dialled from country A to another country (country B). This is followed
+  // by the country code for country B. Note that some countries may have more
+  // than one international prefix, and for those cases, a regular expression
+  // matching the international prefixes will be stored in this field.
+  required string international_prefix = 11;
+
+  // If more than one international prefix is present, a preferred prefix can
+  // be specified here for out-of-country formatting purposes. If this field is
+  // not present, and multiple international prefixes are present, then "+"
+  // will be used instead.
+  optional string preferred_international_prefix = 17;
+
+  // The national prefix of country A is the number that needs to be dialled
+  // before the national significant number when dialling internally. This
+  // would not be dialled when dialling internationally. For example, in New
+  // Zealand, the number that would be locally dialled as 09 345 3456 would be
+  // dialled from overseas as +64 9 345 3456. In this case, 0 is the national
+  // prefix.
+  optional string national_prefix = 12;
+
+  // The preferred prefix when specifying an extension in this country. This is
+  // used for formatting only, and if this is not specified, a suitable default
+  // should be used instead. For example, if you wanted extensions to be
+  // formatted in the following way:
+  // 1 (365) 345 445 ext. 2345
+  // " ext. "  should be the preferred extension prefix.
+  optional string preferred_extn_prefix = 13;
+
+  // This field is used for cases where the national prefix of a country
+  // contains a carrier selection code, and is written in the form of a
+  // regular expression. For example, to dial the number 2222-2222 in
+  // Fortaleza, Brazil (area code 85) using the long distance carrier Oi
+  // (selection code 31), one would dial 0 31 85 2222 2222. Assuming the
+  // only other possible carrier selection code is 32, the field will
+  // contain "03[12]".
+  //
+  // When it is missing from the XML file, this field inherits the value of
+  // national_prefix, if that is present.
+  optional string national_prefix_for_parsing = 15;
+
+  // This field is only populated and used under very rare situations.
+  // For example, mobile numbers in Argentina are written in two completely
+  // different ways when dialed in-country and out-of-country
+  // (e.g. 0343 15 555 1212 is exactly the same number as +54 9 343 555 1212).
+  // This field is used together with national_prefix_for_parsing to transform
+  // the number into a particular representation for storing in the phonenumber
+  // proto buffer in those rare cases.
+  optional string national_prefix_transform_rule = 16;
+
+  // Specifies whether the mobile and fixed-line patterns are the same or not.
+  // This is used to speed up determining phone number type in countries where
+  // these two types of phone numbers can never be distinguished.
+  optional bool same_mobile_and_fixed_line_pattern = 18 [default=false];
+
+  // Note that the number format here is used for formatting only, not parsing.
+  // Hence all the varied ways a user *may* write a number need not be recorded
+  // - just the ideal way we would like to format it for them. When this element
+  // is absent, the national significant number will be formatted as a whole
+  // without any formatting applied.
+  //
+  // When formatting, the library goes through the list of formats from the
+  // beginning and the first successful match is used to do the formatting.
+  // A match is successful if the phone number being formatted starts with
+  // digits matching the leadingDigits and the number itself matches the
+  // corresponding pattern. However, AsYouTypeFormatter goes through the whole
+  // list and selects formats whose leadingDigits match what has been typed
+  // so far. Therefore, having more specific leadingDigits improves the
+  // performance of AsYouTypeFormatter in terms of speed.
+  repeated NumberFormat number_format = 19;
+
+  // This field is populated only when the national significant number is
+  // formatted differently when it forms part of the INTERNATIONAL format
+  // and NATIONAL format. A case in point is mobile numbers in Argentina:
+  // The number, which would be written in INTERNATIONAL format as
+  // +54 9 343 555 1212, will be written as 0343 15 555 1212 for NATIONAL
+  // format. In this case, the prefix 9 is inserted when dialling from
+  // overseas, but otherwise the prefix 0 and the carrier selection code
+  // 15 (inserted after the area code of 343) is used.
+  repeated NumberFormat intl_number_format = 20;
+
+  // Deprecated.
+  optional string national_prefix_formatting_rule = 21;
+}
+
+message PhoneMetadataCollection {
+  repeated PhoneMetadata metadata = 1;
+}

File java/resources/com/google/i18n/phonenumbers/proto/phonenumber.proto

+/*
+ * Copyright (C) 2009 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Definition of protocol buffer for representing international telephone numbers.
+// @author Shaopeng Jia
+
+syntax = "proto2";
+
+option java_package = "com.google.i18n.phonenumbers";
+option optimize_for = LITE_RUNTIME;
+package i18n.phonenumbers;
+
+message PhoneNumber {
+  required int32 country_code = 1;
+
+// National (significant) Number is defined in International Telecommunication Union Recommendation
+// E.164. It is a language/country-neutral representation of a phone number at a country level. For
+// countries which have the concept of Area Code, the National (significant) Number contains the
+// area code. It contains a maximum number of digits which equal to 15 - n, where n is the number of
+// digits of the country code. Take note that National (significant) Number does not contain
+// National(trunk) prefix. Obviously, as a uint64, it will never contain any formatting (hypens,
+// spaces, parentheses), nor any alphanumeric spellings.
+  required uint64 national_number = 2;
+
+// Extension is not standardized in ITU recommendations, except for being defined as a series of
+// numbers with a maximum length of 40 digits. It is defined as a string here to accommodate for the
+// possible use of a leading zero in the extension (organizations have complete freedom to do so,
+// as there is no standard defined). However, only ASCII digits should be stored here.
+  optional string extension = 3;
+
+// The leading zero in the national (significant) number of an Italian phone number has a special
+// meaning. Unlike the rest of the world, it indicates the number is a fixed-line number. There have
+// been plans to migrate fixed-line numbers to start with the digit two since December 2000, but it
+// has not happened yet. See http://en.wikipedia.org/wiki/%2B39 for more details.
+//
+// This field can be safely ignored (no need to set it) if you are not dealing with Italian
+// phone numbers. For an Italian phone number, if its national (significant) number starts
+// with the digit zero, set this flag to true.
+  optional bool italian_leading_zero = 4;
+
+// This field is used to store the raw input string containing phone numbers before it was
+// canonicalized by the library. For example, it could be used to store alphanumerical numbers
+// such as "1-800-GOOG-411".
+  optional string raw_input = 5;
+
+// The source from which the country_code is derived. This is not set in the general parsing method,
+// but in the method that parses and keeps raw_input. New fields could be added upon request.
+  enum CountryCodeSource {
+    // The country_code is derived based on a phone number with a leading "+", e.g. the French
+    // number "+33 (0)1 42 68 53 00".
+    FROM_NUMBER_WITH_PLUS_SIGN = 1;
+
+    // The country_code is derived based on a phone number with a leading IDD, e.g. the French
+    // number "011 33 (0)1 42 68 53 00", as it is dialled from US.
+    FROM_NUMBER_WITH_IDD = 5;
+
+    // The country_code is derived based on a phone number without a leading "+", e.g. the French
+    // number "33 (0)1 42 68 53 00" when defaultCountry is supplied as France.
+    FROM_NUMBER_WITHOUT_PLUS_SIGN = 10;
+
+    // The country_code is derived NOT based on the phone number itself, but from the defaultCountry
+    // parameter provided in the parsing function by the clients. This happens mostly for numbers
+    // written in the national format (without country code). For example, this would be set when
+    // parsing the French number "(0)1 42 68 53 00", when defaultCountry is supplied as France.
+    FROM_DEFAULT_COUNTRY = 20;
+  }
+
+// The source from which the country_code is derived.
+  optional CountryCodeSource country_code_source = 6;
+}
+
+// Examples
+//
+// Google MTV, +1 650-253-0000, (650) 253-0000
+// country_code: 1
+// national_number: 6502530000
+//
+// Google Paris, +33 (0)1 42 68 53 00, 01 42 68 53 00
+// country_code: 33
+// national_number: 142685300
+//
+// Google Beijing, +86-10-62503000, (010) 62503000
+// country_code: 86
+// national_number: 1062503000
+//
+// Google Italy, +39 02-36618 300, 02-36618 300
+// country_code: 39
+// national_number: 236618300
+// italian_leading_zero: true

File java/resources/com/google/i18n/phonenumbers/src/generated_files/PhoneNumberMetadataProto

Binary file removed.

File java/resources/com/google/i18n/phonenumbers/test/generated_files/PhoneNumberMetadataProtoForTesting

Binary file removed.

File java/src/com/google/i18n/phonenumbers/BuildMetadataProtoFromXml.java

-/*
- * Copyright (C) 2009 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.i18n.phonenumbers;
-
-import com.google.i18n.phonenumbers.Phonemetadata.NumberFormat;
-import com.google.i18n.phonenumbers.Phonemetadata.PhoneMetadata;
-import com.google.i18n.phonenumbers.Phonemetadata.PhoneMetadataCollection;
-import com.google.i18n.phonenumbers.Phonemetadata.PhoneNumberDesc;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
-import org.xml.sax.SAXException;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.ObjectOutputStream;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import java.util.regex.Pattern;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
-/**
- * Tool to convert phone number metadata from the XML format to protocol buffer format. It is
- * wrapped in the genrule of the BUILD file and run as a preprocessing step when building the
- * phone number library. Example command line invocation:
- *
- * ./BuildMetadataProtoFromXml PhoneNumberMetadata.xml PhoneNumberMetadataProto true
- *
- * When liteBuild flag is set to true, the outputFile generated omits certain metadata which is not
- * needed for clients using liteBuild. At this moment, example numbers information is omitted.
- *
- * @author Shaopeng Jia
- */
-public class BuildMetadataProtoFromXml {
-  private BuildMetadataProtoFromXml() {
-  }
-  private static final Logger LOGGER = Logger.getLogger(BuildMetadataProtoFromXml.class.getName());
-  private static Boolean liteBuild;
-
-  public static void main(String[] args) {
-    String inputFile = args[0];
-    String outputFile = args[1];
-    liteBuild = args.length > 2 && Boolean.getBoolean(args[2]);
-    File xmlFile = new File(inputFile);
-    try {
-      FileOutputStream output = new FileOutputStream(outputFile);
-      DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
-      DocumentBuilder builder = builderFactory.newDocumentBuilder();
-      Document document = builder.parse(xmlFile);
-      document.getDocumentElement().normalize();
-      Element rootElement = document.getDocumentElement();
-      NodeList territory = rootElement.getElementsByTagName("territory");
-      PhoneMetadataCollection metadataCollection = new PhoneMetadataCollection();
-      int numOfTerritories = territory.getLength();
-      for (int i = 0; i < numOfTerritories; i++) {
-        Element territoryElement = (Element) territory.item(i);
-        String regionCode = territoryElement.getAttribute("id");
-        PhoneMetadata metadata = loadCountryMetadata(regionCode, territoryElement);
-        metadataCollection.addMetadata(metadata);
-      }
-      ObjectOutputStream out = new ObjectOutputStream(output);
-      out.writeObject(metadataCollection);
-      out.close();
-    } catch (IOException e) {
-      LOGGER.log(Level.SEVERE, e.toString());
-    } catch (SAXException e) {
-      LOGGER.log(Level.SEVERE, e.toString());
-    } catch (ParserConfigurationException e) {
-      LOGGER.log(Level.SEVERE, e.toString());
-    }
-  }
-
-  private static String validateRE(String regex) {
-    Pattern regexPattern = Pattern.compile(regex);
-    // return regex itself if it is of correct regex syntax
-    return regex;
-  }
-
-  private static PhoneMetadata loadCountryMetadata(String regionCode, Element element) {
-    PhoneMetadata metadata = new PhoneMetadata();
-    metadata.setId(regionCode);
-    metadata.setCountryCode(Integer.parseInt(element.getAttribute("countryCode")));
-    metadata.setInternationalPrefix(validateRE(element.getAttribute("internationalPrefix")));
-    if (element.hasAttribute("preferredInternationalPrefix")) {
-      String preferredInternationalPrefix = element.getAttribute("preferredInternationalPrefix");
-      metadata.setPreferredInternationalPrefix(preferredInternationalPrefix);
-    }
-    String nationalPrefix = "";
-    String nationalPrefixFormattingRule = "";
-    if (element.hasAttribute("nationalPrefix")) {
-      nationalPrefix = element.getAttribute("nationalPrefix");
-      metadata.setNationalPrefix(nationalPrefix);
-       nationalPrefixFormattingRule =
-          validateRE(getNationalPrefixFormattingRuleFromElement(element, nationalPrefix));
-
-      if (element.hasAttribute("nationalPrefixForParsing")) {
-        metadata.setNationalPrefixForParsing(
-            validateRE(element.getAttribute("nationalPrefixForParsing")));
-        if (element.hasAttribute("nationalPrefixTransformRule")) {
-          metadata.setNationalPrefixTransformRule(
-              element.getAttribute("nationalPrefixTransformRule"));
-        }
-      } else {
-        metadata.setNationalPrefixForParsing(nationalPrefix);
-      }
-    }
-    if (element.hasAttribute("preferredExtnPrefix")) {
-      metadata.setPreferredExtnPrefix(element.getAttribute("preferredExtnPrefix"));
-    }
-
-    // Extract availableFormats
-    NodeList numberFormatElements = element.getElementsByTagName("numberFormat");
-    int numOfFormatElements = numberFormatElements.getLength();
-    if (numOfFormatElements > 0) {
-      for (int i = 0; i < numOfFormatElements; i++) {
-        Element numberFormatElement = (Element) numberFormatElements.item(i);
-        NumberFormat format = new NumberFormat();
-        if (numberFormatElement.hasAttribute("nationalPrefixFormattingRule")) {
-          format.setNationalPrefixFormattingRule(validateRE(
-              getNationalPrefixFormattingRuleFromElement(numberFormatElement, nationalPrefix)));
-        } else {
-          format.setNationalPrefixFormattingRule(nationalPrefixFormattingRule);
-        }
-        if (numberFormatElement.hasAttribute("leadingDigits")) {
-          format.setLeadingDigits(validateRE(numberFormatElement.getAttribute("leadingDigits")));
-        }
-        format.setPattern(validateRE(numberFormatElement.getAttribute("pattern")));
-        format.setFormat(validateRE(numberFormatElement.getFirstChild().getNodeValue()));
-        metadata.addNumberFormat(format);
-      }
-    }
-
-    NodeList intlNumberFormatElements = element.getElementsByTagName("intlNumberFormat");
-    int numOfIntlFormatElements = intlNumberFormatElements.getLength();
-    if (numOfIntlFormatElements > 0) {
-      for (int i = 0; i < numOfIntlFormatElements; i++) {
-        Element numberFormatElement = (Element) intlNumberFormatElements.item(i);
-        NumberFormat format = new NumberFormat();
-        if (numberFormatElement.hasAttribute("leadingDigits")) {
-          format.setLeadingDigits(validateRE(numberFormatElement.getAttribute("leadingDigits")));
-        }
-        format.setPattern(validateRE(numberFormatElement.getAttribute("pattern")));
-        format.setFormat(validateRE(numberFormatElement.getFirstChild().getNodeValue()));
-        metadata.addIntlNumberFormat(format);
-      }
-    }
-
-    PhoneNumberDesc generalDesc =
-        processPhoneNumberDescElement(new PhoneNumberDesc(), element, "generalDesc");
-    metadata.setGeneralDesc(generalDesc);
-    metadata.setFixedLine(processPhoneNumberDescElement(generalDesc, element, "fixedLine"));
-    metadata.setMobile(processPhoneNumberDescElement(generalDesc, element, "mobile"));
-    metadata.setTollFree(processPhoneNumberDescElement(generalDesc, element, "tollFree"));
-    metadata.setPremiumRate(processPhoneNumberDescElement(generalDesc, element, "premiumRate"));
-    metadata.setSharedCost(processPhoneNumberDescElement(generalDesc, element, "sharedCost"));
-    metadata.setVoip(processPhoneNumberDescElement(generalDesc, element, "voip"));
-    metadata.setPersonalNumber(processPhoneNumberDescElement(generalDesc, element,
-                                                             "personalNumber"));
-
-    if (metadata.getMobile().getNationalNumberPattern().equals(
-        metadata.getFixedLine().getNationalNumberPattern())) {
-      metadata.setSameMobileAndFixedLinePattern(true);
-    }
-    return metadata;
-  }
-
-  private static String getNationalPrefixFormattingRuleFromElement(Element element,
-                                                                   String nationalPrefix) {
-    String nationalPrefixFormattingRule = element.getAttribute("nationalPrefixFormattingRule");
-    // Replace $NP with national prefix and $FG with the first group ($1).
-    nationalPrefixFormattingRule =
-        nationalPrefixFormattingRule.replaceFirst("\\$NP", nationalPrefix)
-            .replaceFirst("\\$FG", "\\$1");
-    return nationalPrefixFormattingRule;
-  }
-
-  /**
-   * Processes a phone number description element from the XML file and returns it as a
-   * PhoneNumberDesc. If the description element is a fixed line or mobile number, the general
-   * description will be used to fill in the whole element if necessary, or any components that are
-   * missing. For all other types, the general description will only be used to fill in missing
-   * components if the type has a partial definition. For example, if no "tollFree" element exists,
-   * we assume there are no toll free numbers for that locale, and return a phone number description
-   * with "NA" for both the national and possible number patterns.
-   *
-   * @param generalDesc  a generic phone number description that will be used to fill in missing
-   *                     parts of the description
-   * @param countryElement  the XML element representing all the country information
-   * @param numberType  the name of the number type, corresponding to the appropriate tag in the XML
-   *                    file with information about that type
-   * @return  complete description of that phone number type
-   */
-  private static PhoneNumberDesc processPhoneNumberDescElement(PhoneNumberDesc generalDesc,
-                                                               Element countryElement,
-                                                               String numberType) {
-    NodeList phoneNumberDescList = countryElement.getElementsByTagName(numberType);
-    PhoneNumberDesc numberDesc = new PhoneNumberDesc();
-    if (phoneNumberDescList.getLength() == 0 &&
-        (!numberType.equals("fixedLine") && !numberType.equals("mobile") &&
-         !numberType.equals("generalDesc"))) {
-      numberDesc.setNationalNumberPattern("NA");
-      numberDesc.setPossibleNumberPattern("NA");
-      return numberDesc;
-    }
-    numberDesc.mergeFrom(generalDesc);
-    if (phoneNumberDescList.getLength() > 0) {
-      Element element = (Element) phoneNumberDescList.item(0);
-      NodeList possiblePattern = element.getElementsByTagName("possibleNumberPattern");
-      if (possiblePattern.getLength() > 0) {
-        numberDesc.setPossibleNumberPattern(
-            validateRE(possiblePattern.item(0).getFirstChild().getNodeValue()));
-      }
-
-      NodeList validPattern = element.getElementsByTagName("nationalNumberPattern");
-      if (validPattern.getLength() > 0) {
-        numberDesc.setNationalNumberPattern(
-            validateRE(validPattern.item(0).getFirstChild().getNodeValue()));
-      }
-
-      if (!liteBuild) {
-        NodeList exampleNumber = element.getElementsByTagName("exampleNumber");
-        if (exampleNumber.getLength() > 0) {
-          numberDesc.setExampleNumber(exampleNumber.item(0).getFirstChild().getNodeValue());
-        }
-      }
-    }
-    return numberDesc;
-  }
-}

File java/src/com/google/i18n/phonenumbers/PhoneNumberMetadataProto

Binary file added.

File java/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java

   private static final int MIN_LENGTH_FOR_NSN = 3;
   private static final int MAX_LENGTH_FOR_NSN = 15;
   private static final String META_DATA_FILE =
-      "/com/google/i18n/phonenumbers/src/generated_files/PhoneNumberMetadataProto";
+      "/com/google/i18n/phonenumbers/PhoneNumberMetadataProto";
   private static final Logger LOGGER = Logger.getLogger(PhoneNumberUtil.class.getName());
 
   // A mapping from a country code to a region code which denotes the country/region

File java/src/com/google/i18n/phonenumbers/phonemetadata.proto

-/*
- * Copyright (C) 2009 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-// Definition of protocol buffer for holding metadata for international
-// telephone numbers.
-// @author Shaopeng Jia
-
-syntax = "proto2";
-
-option java_package = "com.google.i18n.phonenumbers";
-option optimize_for = LITE_RUNTIME;
-package i18n.phonenumbers;
-
-message NumberFormat {
-  // pattern is a regex that is used to match the national (significant)
-  // number. For example, the pattern "(20)(\d{4})(\d{4})" will match number
-  // "2070313000", which is the national (significant) number for Google London.
-  // Note the presence of the parentheses, which are capturing groups what
-  // specifies the grouping of numbers.
-  required string pattern = 1;
-
-  // format specifies how the national (significant) number matched by
-  // pattern should be formatted.
-  // Using the same example as above, format could contain "$1 $2 $3",
-  // meaning that the number should be formatted as "20 7031 3000".
-  // Each $x are replaced by the numbers captured by group x in the
-  // regex specified by pattern.
-  required string format = 2;
-
-  // leadingDigits is a regex that is used to match up to the first four digits
-  // of the national (significant) number. When the match is successful, the
-  // accompanying pattern and format should be used to format this number. For
-  // example, if leading_digits="[1-3]|44", then all the national numbers
-  // starting with 1, 2, 3 or 44 should be formatted using the accompanying
-  // pattern and format.
-  optional string leading_digits = 3;
-
-  // This field specifies how the national prefix ($NP) together with the first
-  // group ($FG) in the national significant number should be formatted in
-  // the NATIONAL format when a national prefix exists for a certain country.
-  // For example, when this field contains "($NP$FG)", a number from Beijing,
-  // China (whose $NP = 0), which would by default be formatted without
-  // national prefix as 10 1234 5678 in NATIONAL format, will instead be
-  // formatted as (010) 1234 5678; to format it as (0)10 1234 5678, the field
-  // would contain "($NP)$FG". Note $FG should always be present in this field,
-  // but $NP can be omitted. For example, having "$FG" could indicate the
-  // number should be formatted in NATIONAL format without the national prefix.
-  // This is commonly used to override the rule from generalDesc.
-  //
-  // When this field is missing, a number will be formatted without national
-  // prefix in NATIONAL format. This field does not affect how a number
-  // is formatted in other formats, such as INTERNATIONAL.
-  optional string national_prefix_formatting_rule = 4;
-}
-
-message PhoneNumberDesc {
-  // The national_number_pattern is the pattern that a valid national
-  // significant number would match. This specifies information such as its
-  // total length and leading digits.
-  optional string national_number_pattern = 2;
-
-  // The possible_number_pattern represents what a potentially valid phone
-  // number for this region may be written as. This is a superset of the
-  // national_number_pattern above and includes numbers that have the area code
-  // omitted. Typically the only restrictions here are in the number of digits.
-  // This could be used to highlight tokens in a text that may be a phone
-  // number, or to quickly prune numbers that could not possibly be a phone
-  // number for this locale.
-  optional string possible_number_pattern = 3;
-
-  // An example national significant number for the specific type. It should
-  // not contain any formatting information.
-  optional string example_number = 6;
-}
-
-message PhoneMetadata {
-  // The general_desc contains information which is a superset of descriptions
-  // for all types of phone numbers. If any element is missing in the
-  // description of a specific type in the XML file, the element will inherit
-  // from its counterpart in the general_desc. Every locale is assumed to have
-  // fixed line and mobile numbers - if these types are missing in the XML
-  // file, they will inherit all fields from the general_desc. For all other
-  // types, if the whole type is missing in the xml file, it will be given a
-  // national_number_pattern of "NA" and a possible_number_pattern of "NA".
-  required PhoneNumberDesc general_desc = 1;
-  required PhoneNumberDesc fixed_line = 2;
-  required PhoneNumberDesc mobile = 3;
-  required PhoneNumberDesc toll_free = 4;
-  required PhoneNumberDesc premium_rate = 5;
-  required PhoneNumberDesc shared_cost = 6;
-  required PhoneNumberDesc personal_number = 7;
-  required PhoneNumberDesc voip = 8;
-
-  // The ISO 3166-1 alpha-2 representation of a country/region
-  required string id = 9;
-
-  // The country calling code that one would dial from overseas when trying to
-  // dial a phone number in this country. For example, this would be "64" for
-  // New Zealand.
-  required int32 country_code = 10;
-
-  // The international_prefix of country A is the number that needs to be
-  // dialled from country A to another country (country B). This is followed
-  // by the country code for country B. Note that some countries may have more
-  // than one international prefix, and for those cases, a regular expression
-  // matching the international prefixes will be stored in this field.
-  required string international_prefix = 11;
-
-  // If more than one international prefix is present, a preferred prefix can
-  // be specified here for out-of-country formatting purposes. If this field is
-  // not present, and multiple international prefixes are present, then "+"
-  // will be used instead.
-  optional string preferred_international_prefix = 17;
-
-  // The national prefix of country A is the number that needs to be dialled
-  // before the national significant number when dialling internally. This
-  // would not be dialled when dialling internationally. For example, in New
-  // Zealand, the number that would be locally dialled as 09 345 3456 would be
-  // dialled from overseas as +64 9 345 3456. In this case, 0 is the national
-  // prefix.
-  optional string national_prefix = 12;
-
-  // The preferred prefix when specifying an extension in this country. This is
-  // used for formatting only, and if this is not specified, a suitable default
-  // should be used instead. For example, if you wanted extensions to be
-  // formatted in the following way:
-  // 1 (365) 345 445 ext. 2345
-  // " ext. "  should be the preferred extension prefix.
-  optional string preferred_extn_prefix = 13;
-
-  // This field is used for cases where the national prefix of a country
-  // contains a carrier selection code, and is written in the form of a
-  // regular expression. For example, to dial the number 2222-2222 in
-  // Fortaleza, Brazil (area code 85) using the long distance carrier Oi
-  // (selection code 31), one would dial 0 31 85 2222 2222. Assuming the
-  // only other possible carrier selection code is 32, the field will
-  // contain "03[12]".
-  //
-  // When it is missing from the XML file, this field inherits the value of
-  // national_prefix, if that is present.
-  optional string national_prefix_for_parsing = 15;
-
-  // This field is only populated and used under very rare situations.
-  // For example, mobile numbers in Argentina are written in two completely
-  // different ways when dialed in-country and out-of-country
-  // (e.g. 0343 15 555 1212 is exactly the same number as +54 9 343 555 1212).
-  // This field is used together with national_prefix_for_parsing to transform
-  // the number into a particular representation for storing in the phonenumber
-  // proto buffer in those rare cases.
-  optional string national_prefix_transform_rule = 16;
-
-  // Specifies whether the mobile and fixed-line patterns are the same or not.
-  // This is used to speed up determining phone number type in countries where
-  // these two types of phone numbers can never be distinguished.
-  optional bool same_mobile_and_fixed_line_pattern = 18 [default=false];
-
-  // Note that the number format here is used for formatting only, not parsing.
-  // Hence all the varied ways a user *may* write a number need not be recorded
-  // - just the ideal way we would like to format it for them. When this element
-  // is absent, the national significant number will be formatted as a whole
-  // without any formatting applied.
-  //
-  // When formatting, the library goes through the list of formats from the
-  // beginning and the first successful match is used to do the formatting.
-  // A match is successful if the phone number being formatted starts with
-  // digits matching the leadingDigits and the number itself matches the
-  // corresponding pattern. However, AsYouTypeFormatter goes through the whole
-  // list and selects formats whose leadingDigits match what has been typed
-  // so far. Therefore, having more specific leadingDigits improves the
-  // performance of AsYouTypeFormatter in terms of speed.
-  repeated NumberFormat number_format = 19;
-
-  // This field is populated only when the national significant number is
-  // formatted differently when it forms part of the INTERNATIONAL format
-  // and NATIONAL format. A case in point is mobile numbers in Argentina:
-  // The number, which would be written in INTERNATIONAL format as
-  // +54 9 343 555 1212, will be written as 0343 15 555 1212 for NATIONAL
-  // format. In this case, the prefix 9 is inserted when dialling from
-  // overseas, but otherwise the prefix 0 and the carrier selection code
-  // 15 (inserted after the area code of 343) is used.
-  repeated NumberFormat intl_number_format = 20;
-
-  // Deprecated.
-  optional string national_prefix_formatting_rule = 21;
-}
-
-message PhoneMetadataCollection {
-  repeated PhoneMetadata metadata = 1;
-}

File java/src/com/google/i18n/phonenumbers/phonenumber.proto

-/*
- * Copyright (C) 2009 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-// Definition of protocol buffer for representing international telephone numbers.
-// @author Shaopeng Jia
-
-syntax = "proto2";
-
-option java_package = "com.google.i18n.phonenumbers";
-option optimize_for = LITE_RUNTIME;
-package i18n.phonenumbers;
-
-message PhoneNumber {
-  required int32 country_code = 1;
-
-// National (significant) Number is defined in International Telecommunication Union Recommendation
-// E.164. It is a language/country-neutral representation of a phone number at a country level. For
-// countries which have the concept of Area Code, the National (significant) Number contains the
-// area code. It contains a maximum number of digits which equal to 15 - n, where n is the number of
-// digits of the country code. Take note that National (significant) Number does not contain
-// National(trunk) prefix. Obviously, as a uint64, it will never contain any formatting (hypens,
-// spaces, parentheses), nor any alphanumeric spellings.
-  required uint64 national_number = 2;
-
-// Extension is not standardized in ITU recommendations, except for being defined as a series of
-// numbers with a maximum length of 40 digits. It is defined as a string here to accommodate for the
-// possible use of a leading zero in the extension (organizations have complete freedom to do so,
-// as there is no standard defined). However, only ASCII digits should be stored here.
-  optional string extension = 3;
-
-// The leading zero in the national (significant) number of an Italian phone number has a special
-// meaning. Unlike the rest of the world, it indicates the number is a fixed-line number. There have
-// been plans to migrate fixed-line numbers to start with the digit two since December 2000, but it
-// has not happened yet. See http://en.wikipedia.org/wiki/%2B39 for more details.
-//
-// This field can be safely ignored (no need to set it) if you are not dealing with Italian
-// phone numbers. For an Italian phone number, if its national (significant) number starts
-// with the digit zero, set this flag to true.
-  optional bool italian_leading_zero = 4;
-
-// This field is used to store the raw input string containing phone numbers before it was
-// canonicalized by the library. For example, it could be used to store alphanumerical numbers
-// such as "1-800-GOOG-411".
-  optional string raw_input = 5;
-
-// The source from which the country_code is derived. This is not set in the general parsing method,
-// but in the method that parses and keeps raw_input. New fields could be added upon request.
-  enum CountryCodeSource {
-    // The country_code is derived based on a phone number with a leading "+", e.g. the French
-    // number "+33 (0)1 42 68 53 00".
-    FROM_NUMBER_WITH_PLUS_SIGN = 1;
-
-    // The country_code is derived based on a phone number with a leading IDD, e.g. the French
-    // number "011 33 (0)1 42 68 53 00", as it is dialled from US.
-    FROM_NUMBER_WITH_IDD = 5;
-
-    // The country_code is derived based on a phone number without a leading "+", e.g. the French
-    // number "33 (0)1 42 68 53 00" when defaultCountry is supplied as France.
-    FROM_NUMBER_WITHOUT_PLUS_SIGN = 10;
-
-    // The country_code is derived NOT based on the phone number itself, but from the defaultCountry
-    // parameter provided in the parsing function by the clients. This happens mostly for numbers
-    // written in the national format (without country code). For example, this would be set when
-    // parsing the French number "(0)1 42 68 53 00", when defaultCountry is supplied as France.
-    FROM_DEFAULT_COUNTRY = 20;
-  }
-
-// The source from which the country_code is derived.
-  optional CountryCodeSource country_code_source = 6;
-}
-
-// Examples
-//
-// Google MTV, +1 650-253-0000, (650) 253-0000
-// country_code: 1
-// national_number: 6502530000
-//
-// Google Paris, +33 (0)1 42 68 53 00, 01 42 68 53 00
-// country_code: 33
-// national_number: 142685300
-//
-// Google Beijing, +86-10-62503000, (010) 62503000
-// country_code: 86
-// national_number: 1062503000
-//
-// Google Italy, +39 02-36618 300, 02-36618 300
-// country_code: 39
-// national_number: 236618300
-// italian_leading_zero: true

File java/test/com/google/i18n/phonenumbers/AsYouTypeFormatterTest.java

 public class AsYouTypeFormatterTest extends TestCase {
   private PhoneNumberUtil phoneUtil;
   private static final String TEST_META_DATA_FILE =
-      "/com/google/i18n/phonenumbers/test/generated_files/PhoneNumberMetadataProtoForTesting";
+      "/com/google/i18n/phonenumbers/PhoneNumberMetadataProtoForTesting";
 
   public AsYouTypeFormatterTest() {
     PhoneNumberUtil.resetInstance();

File java/test/com/google/i18n/phonenumbers/PhoneNumberMetadataProtoForTesting

Binary file added.

File java/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java

 public class PhoneNumberUtilTest extends TestCase {
   private PhoneNumberUtil phoneUtil;
   private static final String TEST_META_DATA_FILE =
-      "/com/google/i18n/phonenumbers/test/generated_files/PhoneNumberMetadataProtoForTesting";
+      "/com/google/i18n/phonenumbers/PhoneNumberMetadataProtoForTesting";
 
   public PhoneNumberUtilTest() {
     PhoneNumberUtil.resetInstance();