diff --git a/cpp/test/phonenumbers/phonenumberutil_test.cc b/cpp/test/phonenumbers/phonenumberutil_test.cc index ce206cecc..a66442649 100644 --- a/cpp/test/phonenumbers/phonenumberutil_test.cc +++ b/cpp/test/phonenumbers/phonenumberutil_test.cc @@ -270,7 +270,7 @@ TEST_F(PhoneNumberUtilTest, GetInstanceLoadUSMetadata) { EXPECT_EQ("(\\d{3})(\\d{3})(\\d{4})", metadata->number_format(1).pattern()); EXPECT_EQ("$1 $2 $3", metadata->number_format(1).format()); - EXPECT_EQ("[13-9]\\d{9}|2[0-35-9]\\d{8}", + EXPECT_EQ("[13-689]\\d{9}|2[0-35-9]\\d{8}", metadata->general_desc().national_number_pattern()); EXPECT_EQ("\\d{7}(?:\\d{3})?", metadata->general_desc().possible_number_pattern()); @@ -294,7 +294,7 @@ TEST_F(PhoneNumberUtilTest, GetInstanceLoadDEMetadata) { EXPECT_EQ("(\\d{3})(\\d{3,4})(\\d{4})", metadata->number_format(5).pattern()); EXPECT_EQ("$1 $2 $3", metadata->number_format(5).format()); - EXPECT_EQ("(?:[24-6]\\d{2}|3[03-9]\\d|[789](?:[1-9]\\d|0[2-9]))\\d{3,8}", + EXPECT_EQ("(?:[24-6]\\d{2}|3[03-9]\\d|[789](?:[1-9]\\d|0[2-9]))\\d{1,8}", metadata->fixed_line().national_number_pattern()); EXPECT_EQ("\\d{2,14}", metadata->fixed_line().possible_number_pattern()); EXPECT_EQ("30123456", metadata->fixed_line().example_number()); diff --git a/java/demo/src/com/google/phonenumbers/PhoneNumberParserServlet.java b/java/demo/src/com/google/phonenumbers/PhoneNumberParserServlet.java index 1e6d1203a..1b36c6b61 100644 --- a/java/demo/src/com/google/phonenumbers/PhoneNumberParserServlet.java +++ b/java/demo/src/com/google/phonenumbers/PhoneNumberParserServlet.java @@ -191,7 +191,8 @@ public class PhoneNumberParserServlet extends HttpServlet { "Result from isValidNumberForRegion()", Boolean.toString(phoneUtil.isValidNumberForRegion(number, defaultCountry)), output); - appendLine("Phone Number region", phoneUtil.getRegionCodeForNumber(number), output); + String region = phoneUtil.getRegionCodeForNumber(number); + appendLine("Phone Number region", region == null ? "" : region, output); appendLine("Result from isPossibleNumber()", Boolean.toString(phoneUtil.isPossibleNumber(number)), output); appendLine("Result from getNumberType()", phoneUtil.getNumberType(number).toString(), output); diff --git a/java/release_notes.txt b/java/release_notes.txt index cbcb8a589..e167e2c25 100644 --- a/java/release_notes.txt +++ b/java/release_notes.txt @@ -1,3 +1,26 @@ +August 10th, 2011: libphonenumber-3.8 +* Code changes + - Fix to demo to not throw null-ptr exceptions for invalid NANPA numbers + - Fixed AYTF to not accept plus signs in the middle of input + - PhoneNumberMatcher improvements - added STRICT_GROUPING and EXACT_GROUPING + levels, numbers followed/preceded by a currency symbol will not match, + multiple numbers separated by phone-number punctuation will now match. ", " + is no longer accepted as an extension symbol when matching, only when + parsing. "x" is only accepted as a carrier code or extension marker, not + otherwise. + - Changes to handling of leading zeroes - these will not be silently ignored + anymore, but will be stored as part of the number. + - PhoneNumberOfflineGeocoder - new method to get the description of a number that assumes + the validity of the number has already been checked and will not re-verify it. + +* Metadata changes + - Updates: AR, AT, AU, AZ, BE, BF, BH, CA, CN, CO, CR, HT, HU, IT, KG, KH, LB, + LI, ME, NC, RS, SE, TT, US, ZA + - New geocoding data for: AL, BF, BJ, BW, CI, CZ, DZ, EE, GH, GN, GR, HU, IS, + LK, LS, LT, LU, LV, MG, NA, PE, SK, SN, SZ, TN, VN, ZA + - Updated geocoding data for: GB, PT, US + - Revised sorting of geocoding data + July 5th, 2011 * Code changes - Refactored AreaCodeMap to minimize binary and memory footprint by using 2 different strategies. diff --git a/java/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java b/java/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java index 6e0668500..40aa2643c 100644 --- a/java/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java +++ b/java/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java @@ -279,9 +279,9 @@ public class AsYouTypeFormatter { if (rememberPosition) { originalPosition = accruedInput.length(); } - // We do formatting on-the-fly only when each character entered is either a plus sign or a - // digit. - if (!PhoneNumberUtil.VALID_START_CHAR_PATTERN.matcher(Character.toString(nextChar)).matches()) { + // We do formatting on-the-fly only when each character entered is either a digit, or a plus + // sign (accepted at the start of the number only). + if (!isDigitOrLeadingPlusSign(nextChar)) { ableToFormat = false; } if (!ableToFormat) { @@ -341,6 +341,12 @@ public class AsYouTypeFormatter { } } + private boolean isDigitOrLeadingPlusSign(char nextChar) { + return Character.isDigit(nextChar) || + (accruedInput.length() == 1 && + PhoneNumberUtil.PLUS_CHARS_PATTERN.matcher(Character.toString(nextChar)).matches()); + } + String attemptToFormatAccruedDigits() { for (NumberFormat numFormat : possibleFormats) { Matcher m = regexCache.getPatternForRegex(numFormat.getPattern()).matcher(nationalNumber); diff --git a/java/src/com/google/i18n/phonenumbers/PhoneNumberMatcher.java b/java/src/com/google/i18n/phonenumbers/PhoneNumberMatcher.java index c8a765130..76e98409b 100644 --- a/java/src/com/google/i18n/phonenumbers/PhoneNumberMatcher.java +++ b/java/src/com/google/i18n/phonenumbers/PhoneNumberMatcher.java @@ -79,9 +79,10 @@ final class PhoneNumberMatcher implements Iterator { /** * Matches white-space, which may indicate the end of a phone number and the start of something - * else (such as a neighbouring zip-code). + * else (such as a neighbouring zip-code). If white-space is found, continues to match all + * characters that are not typically used to start a phone number. */ - private static final Pattern GROUP_SEPARATOR = Pattern.compile("\\p{Z}+"); + private static final Pattern GROUP_SEPARATOR; /** * Punctuation that may be at the start of a phone number - brackets and plus signs. @@ -127,14 +128,16 @@ final class PhoneNumberMatcher implements Iterator { /* A digits block without punctuation. */ String digitSequence = "\\p{Nd}" + limit(1, digitBlockLimit); - String leadClass = "[" + openingParens + PhoneNumberUtil.PLUS_CHARS + "]"; + String leadClassChars = openingParens + PhoneNumberUtil.PLUS_CHARS; + String leadClass = "[" + leadClassChars + "]"; LEAD_CLASS = Pattern.compile(leadClass); + GROUP_SEPARATOR = Pattern.compile("\\p{Z}" + "[^" + leadClassChars + "\\p{Nd}]*"); /* Phone number pattern allowing optional punctuation. */ PATTERN = Pattern.compile( "(?:" + leadClass + punctuation + ")" + leadLimit + digitSequence + "(?:" + punctuation + digitSequence + ")" + blockLimit + - "(?:" + PhoneNumberUtil.KNOWN_EXTN_PATTERNS + ")?", + "(?:" + PhoneNumberUtil.EXTN_PATTERNS_FOR_MATCHING + ")?", PhoneNumberUtil.REGEX_FLAGS); } @@ -178,10 +181,10 @@ final class PhoneNumberMatcher implements Iterator { * * @param util the phone number util to use * @param text the character sequence that we will search, null for no text - * @param country the ISO 3166-1 two-letter country code indicating the country to assume for - * phone numbers not written in international format (with a leading plus, or - * with the international dialing prefix of the specified region). May be null or - * "ZZ" if only numbers with a leading plus should be considered. + * @param country the country to assume for phone numbers not written in international format + * (with a leading plus, or with the international dialing prefix of the + * specified region). May be null or "ZZ" if only numbers with a + * leading plus should be considered. * @param leniency the leniency to use when evaluating candidate phone numbers * @param maxTries the maximum number of invalid numbers to try before giving up on the text. * This is to cover degenerate cases where the text has a lot of false positives @@ -290,6 +293,10 @@ final class PhoneNumberMatcher implements Iterator { block.equals(UnicodeBlock.COMBINING_DIACRITICAL_MARKS); } + private static boolean isCurrencySymbol(char character) { + return Character.getType(character) == Character.CURRENCY_SYMBOL; + } + /** * Attempts to extract a match from a {@code candidate} character sequence. * @@ -303,21 +310,6 @@ final class PhoneNumberMatcher implements Iterator { return null; } - // If leniency is set to VALID only, we also want to skip numbers that are surrounded by Latin - // alphabetic characters, to skip cases like abc8005001234 or 8005001234def. - if (leniency == Leniency.VALID) { - // If the candidate is not at the start of the text, and does not start with punctuation and - // the previous character is not a Latin letter, return null. - if (offset > 0 && - (!LEAD_CLASS.matcher(candidate).lookingAt() && isLatinLetter(text.charAt(offset - 1)))) { - return null; - } - int lastCharIndex = offset + candidate.length(); - if (lastCharIndex < text.length() && isLatinLetter(text.charAt(lastCharIndex))) { - return null; - } - } - // Try to come up with a valid match given the entire candidate. String rawString = candidate.toString(); PhoneNumberMatch match = parseAndVerify(rawString, offset); @@ -344,20 +336,29 @@ final class PhoneNumberMatcher implements Iterator { Matcher groupMatcher = GROUP_SEPARATOR.matcher(candidate); if (groupMatcher.find()) { - int groupStartIndex = groupMatcher.end(); - // Remove the first group. - CharSequence withoutFirstGroup = candidate.substring(groupStartIndex); + // Try the first group by itself. + CharSequence firstGroupOnly = candidate.substring(0, groupMatcher.start()); + firstGroupOnly = trimAfterFirstMatch(PhoneNumberUtil.UNWANTED_END_CHAR_PATTERN, + firstGroupOnly); + PhoneNumberMatch match = parseAndVerify(firstGroupOnly.toString(), offset); + if (match != null) { + return match; + } + maxTries--; + + int withoutFirstGroupStart = groupMatcher.end(); + // Try the rest of the candidate without the first group. + CharSequence withoutFirstGroup = candidate.substring(withoutFirstGroupStart); withoutFirstGroup = trimAfterFirstMatch(PhoneNumberUtil.UNWANTED_END_CHAR_PATTERN, withoutFirstGroup); - PhoneNumberMatch match = parseAndVerify(withoutFirstGroup.toString(), - offset + groupStartIndex); + match = parseAndVerify(withoutFirstGroup.toString(), offset + withoutFirstGroupStart); if (match != null) { return match; } maxTries--; if (maxTries > 0) { - int lastGroupStart = groupStartIndex; + int lastGroupStart = withoutFirstGroupStart; while (groupMatcher.find()) { // Find the last group. lastGroupStart = groupMatcher.start(); @@ -365,6 +366,12 @@ final class PhoneNumberMatcher implements Iterator { CharSequence withoutLastGroup = candidate.substring(0, lastGroupStart); withoutLastGroup = trimAfterFirstMatch(PhoneNumberUtil.UNWANTED_END_CHAR_PATTERN, withoutLastGroup); + if (withoutLastGroup.equals(firstGroupOnly)) { + // If there are only two groups, then the group "without the last group" is the same as + // the first group. In these cases, we don't want to re-check the number group, so we exit + // already. + return null; + } match = parseAndVerify(withoutLastGroup.toString(), offset); if (match != null) { return match; @@ -391,8 +398,30 @@ final class PhoneNumberMatcher implements Iterator { if (!MATCHING_BRACKETS.matcher(candidate).matches()) { return null; } + + // If leniency is set to VALID or stricter, we also want to skip numbers that are surrounded + // by Latin alphabetic characters, to skip cases like abc8005001234 or 8005001234def. + if (leniency.compareTo(Leniency.VALID) >= 0) { + // If the candidate is not at the start of the text, and does not start with phone-number + // punctuation, check the previous character. + if (offset > 0 && !LEAD_CLASS.matcher(candidate).lookingAt()) { + char previousChar = text.charAt(offset - 1); + // We return null if it is a latin letter or a currency symbol. + if (isCurrencySymbol(previousChar) || isLatinLetter(previousChar)) { + return null; + } + } + int lastCharIndex = offset + candidate.length(); + if (lastCharIndex < text.length()) { + char nextChar = text.charAt(lastCharIndex); + if (isCurrencySymbol(nextChar) || isLatinLetter(nextChar)) { + return null; + } + } + } + PhoneNumber number = phoneUtil.parse(candidate, preferredRegion); - if (leniency.verify(number, phoneUtil)) { + if (leniency.verify(number, candidate, phoneUtil)) { return new PhoneNumberMatch(offset, candidate, number); } } catch (NumberParseException e) { diff --git a/java/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java b/java/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java index c312a3782..842e10c8d 100644 --- a/java/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java +++ b/java/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java @@ -202,7 +202,7 @@ public class PhoneNumberUtil { Arrays.toString(ALPHA_MAPPINGS.keySet().toArray()).replaceAll("[, \\[\\]]", "") + Arrays.toString(ALPHA_MAPPINGS.keySet().toArray()).toLowerCase().replaceAll("[, \\[\\]]", ""); static final String PLUS_CHARS = "+\uFF0B"; - private static final Pattern PLUS_CHARS_PATTERN = Pattern.compile("[" + PLUS_CHARS + "]+"); + static final Pattern PLUS_CHARS_PATTERN = Pattern.compile("[" + PLUS_CHARS + "]+"); private static final Pattern SEPARATOR_PATTERN = Pattern.compile("[" + VALID_PUNCTUATION + "]+"); private static final Pattern CAPTURING_DIGIT_PATTERN = Pattern.compile("(" + DIGITS + ")"); @@ -213,7 +213,7 @@ public class PhoneNumberUtil { // not include other punctuation, as this will be stripped later during parsing and is of no // information value when parsing a number. private static final String VALID_START_CHAR = "[" + PLUS_CHARS + DIGITS + "]"; - static final Pattern VALID_START_CHAR_PATTERN = Pattern.compile(VALID_START_CHAR); + private static final Pattern VALID_START_CHAR_PATTERN = Pattern.compile(VALID_START_CHAR); // Regular expression of characters typically used to start a second phone number for the purposes // of parsing. This allows us to strip off parts of the number that are actually the start of @@ -252,35 +252,57 @@ public class PhoneNumberUtil { // as the default extension prefix. This can be overridden by region-specific preferences. private static final String DEFAULT_EXTN_PREFIX = " ext. "; + // Pattern to capture digits used in an extension. Places a maximum length of "7" for an + // extension. + private static final String CAPTURING_EXTN_DIGITS = "(" + DIGITS + "{1,7})"; // Regexp of all possible ways to write extensions, for use when parsing. This will be run as a // case-insensitive regexp match. Wide character versions are also provided after each ASCII - // version. There are three regular expressions here. The first covers RFC 3966 format, where the - // extension is added using ";ext=". The second more generic one starts with optional white space - // and ends with an optional full stop (.), followed by zero or more spaces/tabs and then the - // numbers themselves. The other one covers the special case of American numbers where the - // extension is written with a hash at the end, such as "- 503#". - // Note that the only capturing groups should be around the digits that you want to capture as - // part of the extension, or else parsing will fail! - // Canonical-equivalence doesn't seem to be an option with Android java, so we allow two options - // for representing the accented o - the character itself, and one in the unicode decomposed form - // with the combining acute accent. - private static final String CAPTURING_EXTN_DIGITS = "(" + DIGITS + "{1,7})"; - static final String KNOWN_EXTN_PATTERNS = - RFC3966_EXTN_PREFIX + CAPTURING_EXTN_DIGITS + "|" + - "[ \u00A0\\t,]*(?:ext(?:ensi(?:o\u0301?|\u00F3))?n?|" + - "\uFF45\uFF58\uFF54\uFF4E?|[,x\uFF58#\uFF03~\uFF5E]|int|anexo|\uFF49\uFF4E\uFF54)" + - "[:\\.\uFF0E]?[ \u00A0\\t,-]*" + CAPTURING_EXTN_DIGITS + "#?|" + - "[- ]+(" + DIGITS + "{1,5})#"; + // version. + private static final String EXTN_PATTERNS_FOR_PARSING; + static final String EXTN_PATTERNS_FOR_MATCHING; + static { + // One-character symbols that can be used to indicate an extension. + String singleExtnSymbolsForMatching = "x\uFF58#\uFF03~\uFF5E"; + // For parsing, we are slightly more lenient in our interpretation than for matching. Here we + // allow a "comma" as a possible extension indicator. When matching, this is hardly ever used to + // indicate this. + String singleExtnSymbolsForParsing = "," + singleExtnSymbolsForMatching; + + EXTN_PATTERNS_FOR_PARSING = createExtnPattern(singleExtnSymbolsForParsing); + EXTN_PATTERNS_FOR_MATCHING = createExtnPattern(singleExtnSymbolsForMatching); + } + + /** + * Helper initialiser method to create the regular-expression pattern to match extensions, + * allowing the one-char extension symbols provided by {@code singleExtnSymbols}. + */ + private static String createExtnPattern(String singleExtnSymbols) { + // There are three regular expressions here. The first covers RFC 3966 format, where the + // extension is added using ";ext=". The second more generic one starts with optional white + // space and ends with an optional full stop (.), followed by zero or more spaces/tabs and then + // the numbers themselves. The other one covers the special case of American numbers where the + // extension is written with a hash at the end, such as "- 503#". + // Note that the only capturing groups should be around the digits that you want to capture as + // part of the extension, or else parsing will fail! + // Canonical-equivalence doesn't seem to be an option with Android java, so we allow two options + // for representing the accented o - the character itself, and one in the unicode decomposed + // form with the combining acute accent. + return (RFC3966_EXTN_PREFIX + CAPTURING_EXTN_DIGITS + "|" + "[ \u00A0\\t,]*" + + "(?:ext(?:ensi(?:o\u0301?|\u00F3))?n?|\uFF45\uFF58\uFF54\uFF4E?|" + + "[" + singleExtnSymbols + "]|int|anexo|\uFF49\uFF4E\uFF54)" + + "[:\\.\uFF0E]?[ \u00A0\\t,-]*" + CAPTURING_EXTN_DIGITS + "#?|" + + "[- ]+(" + DIGITS + "{1,5})#"); + } // Regexp of all known extension prefixes used by different regions followed by 1 or more valid // digits, for use when parsing. private static final Pattern EXTN_PATTERN = - Pattern.compile("(?:" + KNOWN_EXTN_PATTERNS + ")$", REGEX_FLAGS); + Pattern.compile("(?:" + EXTN_PATTERNS_FOR_PARSING + ")$", REGEX_FLAGS); // We append optionally the extension pattern to the end here, as a valid phone number may // have an extension prefix appended, followed by 1 or more digits. private static final Pattern VALID_PHONE_NUMBER_PATTERN = - Pattern.compile(VALID_PHONE_NUMBER + "(?:" + KNOWN_EXTN_PATTERNS + ")?", REGEX_FLAGS); + Pattern.compile(VALID_PHONE_NUMBER + "(?:" + EXTN_PATTERNS_FOR_PARSING + ")?", REGEX_FLAGS); private static final Pattern NON_DIGITS_PATTERN = Pattern.compile("(\\D+)"); @@ -375,7 +397,7 @@ public class PhoneNumberUtil { /** * Leniency when {@linkplain PhoneNumberUtil#findNumbers finding} potential phone numbers in text - * segments. + * segments. The levels here are ordered in increasing strictness. */ public enum Leniency { /** @@ -385,7 +407,7 @@ public class PhoneNumberUtil { */ POSSIBLE { @Override - boolean verify(PhoneNumber number, PhoneNumberUtil util) { + boolean verify(PhoneNumber number, String candidate, PhoneNumberUtil util) { return util.isPossibleNumber(number); } }, @@ -396,13 +418,175 @@ public class PhoneNumberUtil { */ VALID { @Override - boolean verify(PhoneNumber number, PhoneNumberUtil util) { - return util.isValidNumber(number); + boolean verify(PhoneNumber number, String candidate, PhoneNumberUtil util) { + if (!util.isValidNumber(number)) { + return false; + } + return containsOnlyValidXChars(number, candidate, util); + } + }, + /** + * Phone numbers accepted are {@linkplain PhoneNumberUtil#isValidNumber(PhoneNumber) valid} and + * are grouped in a possible way for this locale. For example, a US number written as + * "65 02 53 00 00" and "650253 0000" are not accepted at this leniency level, whereas + * "650 253 0000", "650 2530000" or "6502530000" are. + * Numbers with more than one '/' symbol are also dropped at this level. + *

+ * Warning: This level might result in lower coverage especially for regions outside of country + * code "+1". If you are not sure about which level to use, email the discussion group + * libphonenumber-discuss@googlegroups.com. + */ + STRICT_GROUPING { + @Override + boolean verify(PhoneNumber number, String candidate, PhoneNumberUtil util) { + if (!util.isValidNumber(number) || + !containsOnlyValidXChars(number, candidate, util) || + containsMoreThanOneSlash(candidate)) { + return false; + } + // TODO: Evaluate how this works for other locales (testing has been + // limited to NANPA regions) and optimise if necessary. + String[] formattedNumberGroups = getNationalNumberGroups(util, number); + StringBuilder normalizedCandidate = normalizeDigits(candidate, + true /* keep strip non-digits */); + int fromIndex = 0; + // Check each group of consecutive digits are not broken into separate groups in the + // {@code candidate} string. + for (int i = 0; i < formattedNumberGroups.length; i++) { + // Fails if the substring of {@code candidate} starting from {@code fromIndex} doesn't + // contain the consecutive digits in formattedNumberGroups[i]. + fromIndex = normalizedCandidate.indexOf(formattedNumberGroups[i], fromIndex); + if (fromIndex < 0) { + return false; + } + // Moves {@code fromIndex} forward. + fromIndex += formattedNumberGroups[i].length(); + if (i == 0 && fromIndex < normalizedCandidate.length()) { + // We are at the position right after the NDC. + if (Character.isDigit(normalizedCandidate.charAt(fromIndex))) { + // This means there is no formatting symbol after the NDC. In this case, we only + // accept the number if there is no formatting symbol at all in the number, except + // for extensions. + String nationalSignificantNumber = util.getNationalSignificantNumber(number); + return normalizedCandidate.substring(fromIndex - formattedNumberGroups[i].length()) + .startsWith(nationalSignificantNumber); + } + } + } + // The check here makes sure that we haven't mistakenly already used the extension to + // match the last group of the subscriber number. Note the extension cannot have + // formatting in-between digits. + return normalizedCandidate.substring(fromIndex).contains(number.getExtension()); + } + }, + /** + * Phone numbers accepted are {@linkplain PhoneNumberUtil#isValidNumber(PhoneNumber) valid} and + * are grouped in the same way that we would have formatted it, or as a single block. For + * example, a US number written as "650 2530000" is not accepted at this leniency level, whereas + * "650 253 0000" or "6502530000" are. + * Numbers with more than one '/' symbol are also dropped at this level. + *

+ * Warning: This level might result in lower coverage especially for regions outside of country + * code "+1". If you are not sure about which level to use, email the discussion group + * libphonenumber-discuss@googlegroups.com. + */ + EXACT_GROUPING { + @Override + boolean verify(PhoneNumber number, String candidate, PhoneNumberUtil util) { + if (!util.isValidNumber(number) || + !containsOnlyValidXChars(number, candidate, util) || + containsMoreThanOneSlash(candidate)) { + return false; + } + // TODO: Evaluate how this works for other locales (testing has been + // limited to NANPA regions) and optimise if necessary. + StringBuilder normalizedCandidate = normalizeDigits(candidate, + true /* keep strip non-digits */); + String[] candidateGroups = + NON_DIGITS_PATTERN.split(normalizedCandidate.toString()); + // Set this to the last group, skipping it if the number has an extension. + int candidateNumberGroupIndex = + number.hasExtension() ? candidateGroups.length - 2 : candidateGroups.length - 1; + // First we check if the national significant number is formatted as a block. + // We use contains and not equals, since the national significant number may be present with + // a prefix such as a national number prefix, or the country code itself. + if (candidateGroups.length == 1 || + candidateGroups[candidateNumberGroupIndex].contains( + util.getNationalSignificantNumber(number))) { + return true; + } + String[] formattedNumberGroups = getNationalNumberGroups(util, number); + // Starting from the end, go through in reverse, excluding the first group, and check the + // candidate and number groups are the same. + for (int formattedNumberGroupIndex = (formattedNumberGroups.length - 1); + formattedNumberGroupIndex > 0 && candidateNumberGroupIndex >= 0; + formattedNumberGroupIndex--, candidateNumberGroupIndex--) { + if (!candidateGroups[candidateNumberGroupIndex].equals( + formattedNumberGroups[formattedNumberGroupIndex])) { + return false; + } + } + // Now check the first group. There may be a national prefix at the start, so we only check + // that the candidate group ends with the formatted number group. + return (candidateNumberGroupIndex >= 0 && + candidateGroups[candidateNumberGroupIndex].endsWith(formattedNumberGroups[0])); } }; + /** + * Helper method to get the national-number part of a number, formatted without any national + * prefix, and return it as a set of digit blocks that would be formatted together. + */ + private static String[] getNationalNumberGroups(PhoneNumberUtil util, PhoneNumber number) { + // This will be in the format +CC-DG;ext=EXT where DG represents groups of digits. + String rfc3966Format = util.format(number, PhoneNumberFormat.RFC3966); + // We remove the extension part from the formatted string before splitting it into different + // groups. + int endIndex = rfc3966Format.indexOf(';'); + if (endIndex < 0) { + endIndex = rfc3966Format.length(); + } + // The country-code will have a '-' following it. + int startIndex = rfc3966Format.indexOf('-') + 1; + return rfc3966Format.substring(startIndex, endIndex).split("-"); + } + + private static boolean containsMoreThanOneSlash(String candidate) { + int firstSlashIndex = candidate.indexOf('/'); + return (firstSlashIndex > 0 && candidate.substring(firstSlashIndex + 1).contains("/")); + } + + private static boolean containsOnlyValidXChars( + PhoneNumber number, String candidate, PhoneNumberUtil util) { + // The characters 'x' and 'X' can be (1) a carrier code, in which case they always precede the + // national significant number or (2) an extension sign, in which case they always precede the + // extension number. We assume a carrier code is more than 1 digit, so the first case has to + // have more than 1 consecutive 'x' or 'X', whereas the second case can only have exactly 1 + // 'x' or 'X'. We ignore the character if it appears as the last character of the string. + for (int index = 0; index < candidate.length() - 1; index++) { + char charAtIndex = candidate.charAt(index); + if (charAtIndex == 'x' || charAtIndex == 'X') { + char charAtNextIndex = candidate.charAt(index + 1); + if (charAtNextIndex == 'x' || charAtNextIndex == 'X') { + // This is the carrier code case, in which the 'X's always precede the national + // significant number. + index++; + if (util.isNumberMatch(number, candidate.substring(index)) != MatchType.NSN_MATCH) { + return false; + } + // This is the extension sign case, in which the 'x' or 'X' should always precede the + // extension number. + } else if (!PhoneNumberUtil.normalizeDigitsOnly(candidate.substring(index)).equals( + number.getExtension())) { + return false; + } + } + } + return true; + } + /** Returns true if {@code number} is a verified number according to this leniency. */ - abstract boolean verify(PhoneNumber number, PhoneNumberUtil util); + abstract boolean verify(PhoneNumber number, String candidate, PhoneNumberUtil util); } /** @@ -534,15 +718,20 @@ public class PhoneNumberUtil { * @return the normalized string version of the phone number */ public static String normalizeDigitsOnly(String number) { - int numberLength = number.length(); - StringBuilder normalizedDigits = new StringBuilder(numberLength); - for (int i = 0; i < numberLength; i++) { - int d = Character.digit(number.charAt(i), 10); - if (d != -1) { - normalizedDigits.append(d); + return normalizeDigits(number, false /* strip non-digits */).toString(); + } + + private static StringBuilder normalizeDigits(String number, boolean keepNonDigits) { + StringBuilder normalizedDigits = new StringBuilder(number.length()); + for (char c : number.toCharArray()) { + int digit = Character.digit(c, 10); + if (digit != -1) { + normalizedDigits.append(digit); + } else if (keepNonDigits) { + normalizedDigits.append(c); } } - return normalizedDigits.toString(); + return normalizedDigits; } /** @@ -1603,7 +1792,7 @@ public class PhoneNumberUtil { * could contain a leading zero. An example of such a region is Italy. Returns false if no * metadata for the country is found. */ - public boolean isLeadingZeroPossible(int countryCallingCode) { + boolean isLeadingZeroPossible(int countryCallingCode) { PhoneMetadata mainMetadataForCallingCode = getMetadataForRegion( getRegionCodeForCountryCode(countryCallingCode)); if (mainMetadataForCallingCode == null) { @@ -1972,13 +2161,15 @@ public class PhoneNumberUtil { String possibleNationalPrefix = metadata.getNationalPrefixForParsing(); if (numberLength == 0 || possibleNationalPrefix.length() == 0) { // Early return for numbers of zero length. - return carrierCode; + return ""; } // Attempt to parse the first digits as a national prefix. Matcher prefixMatcher = regexCache.getPatternForRegex(possibleNationalPrefix).matcher(number); if (prefixMatcher.lookingAt()) { Pattern nationalNumberRule = regexCache.getPatternForRegex(metadata.getGeneralDesc().getNationalNumberPattern()); + // Check if the original number is viable. + boolean isViableOriginalNumber = nationalNumberRule.matcher(number).matches(); // prefixMatcher.group(numOfGroups) == null implies nothing was captured by the capturing // groups in possibleNationalPrefix; therefore, no transformation is necessary, and we just // remove the national prefix. @@ -1986,23 +2177,23 @@ public class PhoneNumberUtil { String transformRule = metadata.getNationalPrefixTransformRule(); if (transformRule == null || transformRule.length() == 0 || prefixMatcher.group(numOfGroups) == null) { - // Check that the resultant number is viable. If not, return. - Matcher nationalNumber = nationalNumberRule.matcher(number.substring(prefixMatcher.end())); - if (!nationalNumber.matches()) { - return carrierCode; + // If the original number was viable, and the resultant number is not, we return. + if (isViableOriginalNumber && + !nationalNumberRule.matcher(number.substring(prefixMatcher.end())).matches()) { + return ""; } if (numOfGroups > 0 && prefixMatcher.group(numOfGroups) != null) { carrierCode = prefixMatcher.group(1); } number.delete(0, prefixMatcher.end()); } else { - // Check that the resultant number is viable. If not, return. Check this by copying the - // string buffer and making the transformation on the copy first. + // Check that the resultant number is still viable. If not, return. Check this by copying + // the string buffer and making the transformation on the copy first. StringBuilder transformedNumber = new StringBuilder(number); transformedNumber.replace(0, numberLength, prefixMatcher.replaceFirst(transformRule)); - Matcher nationalNumber = nationalNumberRule.matcher(transformedNumber.toString()); - if (!nationalNumber.matches()) { - return carrierCode; + if (isViableOriginalNumber && + !nationalNumberRule.matcher(transformedNumber.toString()).matches()) { + return ""; } if (numOfGroups > 1) { carrierCode = prefixMatcher.group(1); @@ -2246,9 +2437,7 @@ public class PhoneNumberUtil { throw new NumberParseException(NumberParseException.ErrorType.TOO_LONG, "The string supplied is too long to be a phone number."); } - if (normalizedNationalNumber.charAt(0) == '0' && - regionMetadata != null && - regionMetadata.isLeadingZeroPossible()) { + if (normalizedNationalNumber.charAt(0) == '0') { phoneNumber.setItalianLeadingZero(true); } phoneNumber.setNationalNumber(Long.parseLong(normalizedNationalNumber.toString())); diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AR b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AR index 007ab2e93..a4f979385 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AR and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AR differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AT b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AT index 720010c9a..6cdcf99ac 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AT and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AT differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AU b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AU index b34fb0ad5..0b96301cd 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AU and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AU differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AZ b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AZ index 05813012e..8b6224b49 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AZ and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AZ differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BE b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BE index fa90f75c2..246366045 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BE and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BE differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BF b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BF index 63d7e642f..9cd27d8a0 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BF and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BF differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BH b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BH index 3589ec9fd..9e7b9c857 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BH and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BH differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CA b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CA index 5d9bfb2ad..396702d44 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CA and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CA differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CN b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CN index c80a25456..697b08c50 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CN and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CN differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CO b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CO index 49ff9016a..e87ef0110 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CO and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CO differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CR b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CR index f3496a8c5..509057586 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CR and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CR differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_HT b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_HT index 6d4d7b71f..6ee3bd1e4 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_HT and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_HT differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_HU b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_HU index 79efc3c79..98f85c9f0 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_HU and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_HU differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_IT b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_IT index b073a2fb7..da951bc4c 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_IT and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_IT differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_KG b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_KG index c4e37cffe..dc63e3111 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_KG and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_KG differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_KH b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_KH index 3b43e3946..f88db2f21 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_KH and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_KH differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_LB b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_LB index faf8a72f2..f1dfbca3b 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_LB and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_LB differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_LI b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_LI index e7921499b..e1d137c42 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_LI and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_LI differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_ME b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_ME index 352802e92..7cce9670a 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_ME and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_ME differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_NC b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_NC index cfa92c516..6e857221c 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_NC and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_NC differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_RS b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_RS index 6f97714be..d3691b529 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_RS and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_RS differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SE b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SE index 9d9490841..885134644 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SE and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SE differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_TT b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_TT index 233023376..a0239225d 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_TT and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_TT differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_US b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_US index b0b65970d..d6ac18f0d 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_US and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_US differ diff --git a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_ZA b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_ZA index 15930b356..b0369306b 100644 Binary files a/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_ZA and b/java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_ZA differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/AreaCodeMap.java b/java/src/com/google/i18n/phonenumbers/geocoding/AreaCodeMap.java index 9e1c85f29..f0ec2cca0 100644 --- a/java/src/com/google/i18n/phonenumbers/geocoding/AreaCodeMap.java +++ b/java/src/com/google/i18n/phonenumbers/geocoding/AreaCodeMap.java @@ -36,8 +36,6 @@ import java.util.logging.Logger; * @author Shaopeng Jia */ public class AreaCodeMap implements Externalizable { - private final int countryCallingCode; - private final boolean isLeadingZeroPossible; private final PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance(); private static final Logger LOGGER = Logger.getLogger(AreaCodeMap.class.getName()); @@ -50,16 +48,10 @@ public class AreaCodeMap implements Externalizable { /** * Creates an empty {@link AreaCodeMap}. The default constructor is necessary for implementing - * {@link Externalizable}. The empty map could later populated by + * {@link Externalizable}. The empty map could later be populated by * {@link #readAreaCodeMap(java.util.SortedMap)} or {@link #readExternal(java.io.ObjectInput)}. - * - * @param countryCallingCode the country calling code for the region that the area code map - * belongs to. */ - public AreaCodeMap(int countryCallingCode) { - this.countryCallingCode = countryCallingCode; - isLeadingZeroPossible = phoneUtil.isLeadingZeroPossible(countryCallingCode); - } + public AreaCodeMap() {} /** * Gets the size of the provided area code map storage. The map storage passed-in will be filled @@ -78,11 +70,11 @@ public class AreaCodeMap implements Externalizable { } private AreaCodeMapStorageStrategy createDefaultMapStorage() { - return new DefaultMapStorage(countryCallingCode, isLeadingZeroPossible); + return new DefaultMapStorage(); } private AreaCodeMapStorageStrategy createFlyweightMapStorage() { - return new FlyweightMapStorage(countryCallingCode, isLeadingZeroPossible); + return new FlyweightMapStorage(); } /** @@ -126,9 +118,9 @@ public class AreaCodeMap implements Externalizable { // Read the area code map storage strategy flag. boolean useFlyweightMapStorage = objectInput.readBoolean(); if (useFlyweightMapStorage) { - areaCodeMapStorage = new FlyweightMapStorage(countryCallingCode, isLeadingZeroPossible); + areaCodeMapStorage = new FlyweightMapStorage(); } else { - areaCodeMapStorage = new DefaultMapStorage(countryCallingCode, isLeadingZeroPossible); + areaCodeMapStorage = new DefaultMapStorage(); } areaCodeMapStorage.readExternal(objectInput); } @@ -152,9 +144,8 @@ public class AreaCodeMap implements Externalizable { if (numOfEntries == 0) { return ""; } - long phonePrefix = isLeadingZeroPossible - ? Long.parseLong(number.getCountryCode() + phoneUtil.getNationalSignificantNumber(number)) - : Long.parseLong(phoneUtil.getNationalSignificantNumber(number)); + long phonePrefix = + Long.parseLong(number.getCountryCode() + phoneUtil.getNationalSignificantNumber(number)); int currentIndex = numOfEntries - 1; SortedSet currentSetOfLengths = areaCodeMapStorage.getPossibleLengths(); while (currentSetOfLengths.size() > 0) { @@ -204,18 +195,6 @@ public class AreaCodeMap implements Externalizable { */ @Override public String toString() { - StringBuilder output = new StringBuilder(); - int numOfEntries = areaCodeMapStorage.getNumOfEntries(); - - for (int i = 0; i < numOfEntries; i++) { - if (!isLeadingZeroPossible) { - output.append(countryCallingCode); - } - output.append(areaCodeMapStorage.getPrefix(i)); - output.append("|"); - output.append(areaCodeMapStorage.getDescription(i)); - output.append("\n"); - } - return output.toString(); + return areaCodeMapStorage.toString(); } } diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/AreaCodeMapStorageStrategy.java b/java/src/com/google/i18n/phonenumbers/geocoding/AreaCodeMapStorageStrategy.java index 0b5f85fad..72b7eec37 100644 --- a/java/src/com/google/i18n/phonenumbers/geocoding/AreaCodeMapStorageStrategy.java +++ b/java/src/com/google/i18n/phonenumbers/geocoding/AreaCodeMapStorageStrategy.java @@ -23,29 +23,18 @@ import java.util.SortedMap; import java.util.TreeSet; /** - * Abstracts the way area code data is stored into memory and serialized to a stream. + * Abstracts the way area code data is stored into memory and serialized to a stream. It is used by + * {@link AreaCodeMap} to support the most space-efficient storage strategy according to the + * provided data. * * @author Philippe Liard */ // @VisibleForTesting abstract class AreaCodeMapStorageStrategy { - protected final int countryCallingCode; - protected final boolean isLeadingZeroPossible; protected int numOfEntries = 0; protected final TreeSet possibleLengths = new TreeSet(); - /** - * Constructs a new area code map storage strategy from the provided country calling code and - * boolean parameter. - * - * @param countryCallingCode the country calling code of the number prefixes contained in the map - * @param isLeadingZeroPossible whether the phone number prefixes belong to a region which - * {@link com.google.i18n.phonenumbers.PhoneNumberUtil#isLeadingZeroPossible} - */ - public AreaCodeMapStorageStrategy(int countryCallingCode, boolean isLeadingZeroPossible) { - this.countryCallingCode = countryCallingCode; - this.isLeadingZeroPossible = isLeadingZeroPossible; - } + public AreaCodeMapStorageStrategy() {} /** * Returns whether the underlying implementation of this abstract class is flyweight. @@ -113,52 +102,17 @@ abstract class AreaCodeMapStorageStrategy { */ public abstract void writeExternal(ObjectOutput objectOutput) throws IOException; - /** - * Utility class used to pass arguments by "reference". - */ - protected static class Reference { - private T data; - - T get () { - return data; - } - - void set (T data) { - this.data = data; - } - } + @Override + public String toString() { + StringBuilder output = new StringBuilder(); + int numOfEntries = getNumOfEntries(); - /** - * Removes the country calling code from the provided {@code prefix} if the country can't have any - * leading zero; otherwise it is left as it is. Sets the provided {@code lengthOfPrefixRef} - * parameter to the length of the resulting prefix. - * - * @param prefix a phone number prefix containing a leading country calling code - * @param lengthOfPrefixRef a "reference" to an integer set to the length of the resulting - * prefix. This parameter is ignored when set to null. - * @return the resulting prefix which may have been stripped - */ - protected int stripPrefix(int prefix, Reference lengthOfPrefixRef) { - int lengthOfCountryCode = (int) Math.log10(countryCallingCode) + 1; - int lengthOfPrefix = (int) Math.log10(prefix) + 1; - if (!isLeadingZeroPossible) { - lengthOfPrefix -= lengthOfCountryCode; - prefix -= countryCallingCode * (int) Math.pow(10, lengthOfPrefix); - } - if (lengthOfPrefixRef != null) { - lengthOfPrefixRef.set(lengthOfPrefix); + for (int i = 0; i < numOfEntries; i++) { + output.append(getPrefix(i)); + output.append("|"); + output.append(getDescription(i)); + output.append("\n"); } - return prefix; - } - - /** - * Removes the country calling code from the provided {@code prefix} if the country can't have any - * leading zero; otherwise it is left as it is. - * - * @param prefix a phone number prefix containing a leading country calling code - * @return the resulting prefix which may have been stripped - */ - protected int stripPrefix(int prefix) { - return stripPrefix(prefix, null); + return output.toString(); } } diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/DefaultMapStorage.java b/java/src/com/google/i18n/phonenumbers/geocoding/DefaultMapStorage.java index 03dfa1534..eacf1fd1b 100644 --- a/java/src/com/google/i18n/phonenumbers/geocoding/DefaultMapStorage.java +++ b/java/src/com/google/i18n/phonenumbers/geocoding/DefaultMapStorage.java @@ -30,9 +30,7 @@ import java.util.SortedMap; */ class DefaultMapStorage extends AreaCodeMapStorageStrategy { - public DefaultMapStorage(int countryCallingCode, boolean isLeadingZeroPossible) { - super(countryCallingCode, isLeadingZeroPossible); - } + public DefaultMapStorage() {} private int[] phoneNumberPrefixes; private String[] descriptions; @@ -59,10 +57,8 @@ class DefaultMapStorage extends AreaCodeMapStorageStrategy { descriptions = new String[numOfEntries]; int index = 0; for (int prefix : sortedAreaCodeMap.keySet()) { - Reference lengthOfPrefixRef = new Reference(); - int strippedPrefix = stripPrefix(prefix, lengthOfPrefixRef); - phoneNumberPrefixes[index++] = strippedPrefix; - possibleLengths.add(lengthOfPrefixRef.get()); + phoneNumberPrefixes[index++] = prefix; + possibleLengths.add((int) Math.log10(prefix) + 1); } sortedAreaCodeMap.values().toArray(descriptions); } diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/FlyweightMapStorage.java b/java/src/com/google/i18n/phonenumbers/geocoding/FlyweightMapStorage.java index abdf7c51a..c3fedebca 100644 --- a/java/src/com/google/i18n/phonenumbers/geocoding/FlyweightMapStorage.java +++ b/java/src/com/google/i18n/phonenumbers/geocoding/FlyweightMapStorage.java @@ -22,8 +22,6 @@ import java.io.ObjectOutput; import java.nio.ByteBuffer; import java.util.Arrays; import java.util.Comparator; -import java.util.HashMap; -import java.util.Map; import java.util.Map.Entry; import java.util.SortedMap; import java.util.SortedSet; @@ -32,7 +30,7 @@ import java.util.TreeSet; /** * Flyweight area code map storage strategy that uses a table to store unique strings and shorts to * store the prefix and description indexes when possible. It is particularly space-efficient when - * the provided area code map contains a lot of description duplicates. + * the provided area code map contains a lot of redundant descriptions. * * @author Philippe Liard */ @@ -47,17 +45,13 @@ class FlyweightMapStorage extends AreaCodeMapStorageStrategy { // description pool containing all the strings. private int descIndexSizeInBytes; - // Byte buffer of stripped phone number prefixes. A stripped phone number prefix is a phone number - // prefix omitting the country code. private ByteBuffer phoneNumberPrefixes; private ByteBuffer descriptionIndexes; // Sorted string array of unique description strings. private String[] descriptionPool; - public FlyweightMapStorage(int countryCallingCode, boolean isLeadingZeroPossible) { - super(countryCallingCode, isLeadingZeroPossible); - } + public FlyweightMapStorage() {} @Override public boolean isFlyweight() { @@ -78,7 +72,7 @@ class FlyweightMapStorage extends AreaCodeMapStorageStrategy { * * @param buffer the byte buffer to which the value is stored * @param wordSize the number of bytes used to store the provided value - * @param index the index in bytes to which the value is stored + * @param index the index to which the value is stored * @param value the value that is stored assuming it does not require more than the specified * number of bytes. */ @@ -98,7 +92,7 @@ class FlyweightMapStorage extends AreaCodeMapStorageStrategy { * * @param buffer the byte buffer from which the value is read * @param wordSize the number of bytes used to store the value - * @param index the index in bytes where the value is read from + * @param index the index where the value is read from * * @return the value read from the buffer */ @@ -121,20 +115,16 @@ class FlyweightMapStorage extends AreaCodeMapStorageStrategy { public void readFromSortedMap(SortedMap sortedAreaCodeMap) { SortedSet descriptionsSet = new TreeSet(); numOfEntries = sortedAreaCodeMap.size(); - prefixSizeInBytes = getOptimalNumberOfBytesForValue(stripPrefix(sortedAreaCodeMap.lastKey())); + prefixSizeInBytes = getOptimalNumberOfBytesForValue(sortedAreaCodeMap.lastKey()); phoneNumberPrefixes = ByteBuffer.allocate(numOfEntries * prefixSizeInBytes); - Map strippedToUnstrippedPrefixes = new HashMap(); // Fill the phone number prefixes byte buffer, the set of possible lengths of prefixes and the // description set. int index = 0; for (Entry entry : sortedAreaCodeMap.entrySet()) { int prefix = entry.getKey(); - Reference lengthOfPrefixRef = new Reference(); - int strippedPrefix = stripPrefix(prefix, lengthOfPrefixRef); - strippedToUnstrippedPrefixes.put(strippedPrefix, prefix); - storeWordInBuffer(phoneNumberPrefixes, prefixSizeInBytes, index++, strippedPrefix); - possibleLengths.add(lengthOfPrefixRef.get()); + storeWordInBuffer(phoneNumberPrefixes, prefixSizeInBytes, index++, prefix); + possibleLengths.add((int) Math.log10(prefix) + 1); descriptionsSet.add(entry.getValue()); } @@ -147,15 +137,14 @@ class FlyweightMapStorage extends AreaCodeMapStorageStrategy { // Map the phone number prefixes to the descriptions. index = 0; for (int i = 0; i < numOfEntries; i++) { - int strippedPrefix = readWordFromBuffer(phoneNumberPrefixes, prefixSizeInBytes, i); - int prefix = strippedToUnstrippedPrefixes.get(strippedPrefix); + int prefix = readWordFromBuffer(phoneNumberPrefixes, prefixSizeInBytes, i); String description = sortedAreaCodeMap.get(prefix); - int positionIndescriptionPool = + int positionInDescriptionPool = Arrays.binarySearch(descriptionPool, description, new Comparator() { public int compare(String o1, String o2) { return o1.compareTo(o2); } }); storeWordInBuffer(descriptionIndexes, descIndexSizeInBytes, index++, - positionIndescriptionPool); + positionInDescriptionPool); } } @@ -166,7 +155,7 @@ class FlyweightMapStorage extends AreaCodeMapStorageStrategy { * @param objectInput the object input stream from which the value is read * @param wordSize the number of bytes used to store the value read from the stream * @param outputBuffer the byte buffer to which the value is stored - * @param index the index in bytes where the value is stored in the buffer + * @param index the index where the value is stored in the buffer * @throws IOException if an error occurred reading from the object input stream */ private static void readExternalWord(ObjectInput objectInput, int wordSize, diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/PhoneNumberOfflineGeocoder.java b/java/src/com/google/i18n/phonenumbers/geocoding/PhoneNumberOfflineGeocoder.java index ce1ab47b1..7725fdb72 100644 --- a/java/src/com/google/i18n/phonenumbers/geocoding/PhoneNumberOfflineGeocoder.java +++ b/java/src/com/google/i18n/phonenumbers/geocoding/PhoneNumberOfflineGeocoder.java @@ -50,11 +50,7 @@ public class PhoneNumberOfflineGeocoder { // loaded. private Map availablePhonePrefixMaps = new HashMap(); - /** - * For testing purposes, we allow the phone number util variable to be injected. - * - * @VisibleForTesting - */ + // @VisibleForTesting PhoneNumberOfflineGeocoder(String phonePrefixDataDirectory) { this.phonePrefixDataDirectory = phonePrefixDataDirectory; loadMappingFileProvider(); @@ -79,18 +75,18 @@ public class PhoneNumberOfflineGeocoder { return null; } if (!availablePhonePrefixMaps.containsKey(fileName)) { - loadAreaCodeMapFromFile(fileName, countryCallingCode); + loadAreaCodeMapFromFile(fileName); } return availablePhonePrefixMaps.get(fileName); } - private void loadAreaCodeMapFromFile(String fileName, int countryCallingCode) { + private void loadAreaCodeMapFromFile(String fileName) { InputStream source = PhoneNumberOfflineGeocoder.class.getResourceAsStream(phonePrefixDataDirectory + fileName); ObjectInputStream in; try { in = new ObjectInputStream(source); - AreaCodeMap map = new AreaCodeMap(countryCallingCode); + AreaCodeMap map = new AreaCodeMap(); map.readExternal(in); availablePhonePrefixMaps.put(fileName, map); } catch (IOException e) { @@ -140,22 +136,40 @@ public class PhoneNumberOfflineGeocoder { /** * Returns a text description for the given language code for the given phone number. The * description might consist of the name of the country where the phone number is from and/or the - * name of the geographical area the phone number is from. + * name of the geographical area the phone number is from. This method assumes the validity of the + * number passed in has already been checked. * - * @param number the phone number for which we want to get a text description + * @param number a valid phone number for which we want to get a text description * @param languageCode the language code for which the description should be written * @return a text description for the given language code for the given phone number */ + public String getDescriptionForValidNumber(PhoneNumber number, Locale languageCode) { + String langStr = languageCode.getLanguage(); + String scriptStr = ""; // No script is specified + String regionStr = languageCode.getCountry(); + + String areaDescription = + getAreaDescriptionForNumber(number, langStr, scriptStr, regionStr); + return (areaDescription.length() > 0) + ? areaDescription : getCountryNameForNumber(number, languageCode); + } + + /** + * Returns a text description for the given language code for the given phone number. The + * description might consist of the name of the country where the phone number is from and/or the + * name of the geographical area the phone number is from. This method explictly checkes the + * validity of the number passed in. + * + * @param number the phone number for which we want to get a text description + * @param languageCode the language code for which the description should be written + * @return a text description for the given language code for the given phone number, or empty + * string if the number passed in is invalid + */ public String getDescriptionForNumber(PhoneNumber number, Locale languageCode) { if (!phoneUtil.isValidNumber(number)) { return ""; } - String areaDescription = - getAreaDescriptionForNumber( - number, languageCode.getLanguage(), "", // No script is specified. - languageCode.getCountry()); - return (areaDescription.length() > 0) - ? areaDescription : getCountryNameForNumber(number, languageCode); + return getDescriptionForValidNumber(number, languageCode); } /** diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/1_en b/java/src/com/google/i18n/phonenumbers/geocoding/data/1_en index b8661ef2f..109202ec3 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/1_en and b/java/src/com/google/i18n/phonenumbers/geocoding/data/1_en differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/213_en b/java/src/com/google/i18n/phonenumbers/geocoding/data/213_en index a99ce72d7..7a1379caf 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/213_en and b/java/src/com/google/i18n/phonenumbers/geocoding/data/213_en differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/216_en b/java/src/com/google/i18n/phonenumbers/geocoding/data/216_en index e17a7c05b..9af2d13ea 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/216_en and b/java/src/com/google/i18n/phonenumbers/geocoding/data/216_en differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/221_en b/java/src/com/google/i18n/phonenumbers/geocoding/data/221_en index 5b3945d42..b876d3015 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/221_en and b/java/src/com/google/i18n/phonenumbers/geocoding/data/221_en differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/224_en b/java/src/com/google/i18n/phonenumbers/geocoding/data/224_en index 7ec67609a..e63507da7 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/224_en and b/java/src/com/google/i18n/phonenumbers/geocoding/data/224_en differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/226_en b/java/src/com/google/i18n/phonenumbers/geocoding/data/226_en index 9bfc74026..ed31886e0 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/226_en and b/java/src/com/google/i18n/phonenumbers/geocoding/data/226_en differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/229_en b/java/src/com/google/i18n/phonenumbers/geocoding/data/229_en index 120288380..54a82e291 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/229_en and b/java/src/com/google/i18n/phonenumbers/geocoding/data/229_en differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/233_en b/java/src/com/google/i18n/phonenumbers/geocoding/data/233_en index 0e9be1602..aca192784 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/233_en and b/java/src/com/google/i18n/phonenumbers/geocoding/data/233_en differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/261_en b/java/src/com/google/i18n/phonenumbers/geocoding/data/261_en index 60a75b3bf..af8affbf6 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/261_en and b/java/src/com/google/i18n/phonenumbers/geocoding/data/261_en differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/264_en b/java/src/com/google/i18n/phonenumbers/geocoding/data/264_en index 623894a6b..ef92fe511 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/264_en and b/java/src/com/google/i18n/phonenumbers/geocoding/data/264_en differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/266_en b/java/src/com/google/i18n/phonenumbers/geocoding/data/266_en index 65c0370d6..3fc9c6f4f 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/266_en and b/java/src/com/google/i18n/phonenumbers/geocoding/data/266_en differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/267_en b/java/src/com/google/i18n/phonenumbers/geocoding/data/267_en index 1c885aa64..4c52bd278 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/267_en and b/java/src/com/google/i18n/phonenumbers/geocoding/data/267_en differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/27_en b/java/src/com/google/i18n/phonenumbers/geocoding/data/27_en new file mode 100644 index 000000000..c86a27c71 Binary files /dev/null and b/java/src/com/google/i18n/phonenumbers/geocoding/data/27_en differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/30_el b/java/src/com/google/i18n/phonenumbers/geocoding/data/30_el new file mode 100644 index 000000000..61c34dc2b Binary files /dev/null and b/java/src/com/google/i18n/phonenumbers/geocoding/data/30_el differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/31_nl b/java/src/com/google/i18n/phonenumbers/geocoding/data/31_nl index 4fa31ffcd..c1807c8a1 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/31_nl and b/java/src/com/google/i18n/phonenumbers/geocoding/data/31_nl differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/33_fr b/java/src/com/google/i18n/phonenumbers/geocoding/data/33_fr index 29011e96f..c18f305fd 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/33_fr and b/java/src/com/google/i18n/phonenumbers/geocoding/data/33_fr differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/34_es b/java/src/com/google/i18n/phonenumbers/geocoding/data/34_es index f9f7e4c33..e4719caa1 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/34_es and b/java/src/com/google/i18n/phonenumbers/geocoding/data/34_es differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/351_pt b/java/src/com/google/i18n/phonenumbers/geocoding/data/351_pt index ece5fea8d..04dc74ea6 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/351_pt and b/java/src/com/google/i18n/phonenumbers/geocoding/data/351_pt differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/352_de b/java/src/com/google/i18n/phonenumbers/geocoding/data/352_de new file mode 100644 index 000000000..f15168649 Binary files /dev/null and b/java/src/com/google/i18n/phonenumbers/geocoding/data/352_de differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/352_en b/java/src/com/google/i18n/phonenumbers/geocoding/data/352_en new file mode 100644 index 000000000..e510e7b7e Binary files /dev/null and b/java/src/com/google/i18n/phonenumbers/geocoding/data/352_en differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/354_en b/java/src/com/google/i18n/phonenumbers/geocoding/data/354_en index 17168235f..2e85aa2a2 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/354_en and b/java/src/com/google/i18n/phonenumbers/geocoding/data/354_en differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/355_en b/java/src/com/google/i18n/phonenumbers/geocoding/data/355_en index c6857ec41..b903bcdb0 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/355_en and b/java/src/com/google/i18n/phonenumbers/geocoding/data/355_en differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/36_hu b/java/src/com/google/i18n/phonenumbers/geocoding/data/36_hu new file mode 100644 index 000000000..d8b785ace Binary files /dev/null and b/java/src/com/google/i18n/phonenumbers/geocoding/data/36_hu differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/370_en b/java/src/com/google/i18n/phonenumbers/geocoding/data/370_en index 27b36d229..52b47bd3b 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/370_en and b/java/src/com/google/i18n/phonenumbers/geocoding/data/370_en differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/371_en b/java/src/com/google/i18n/phonenumbers/geocoding/data/371_en index 8fded678f..5273f0e75 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/371_en and b/java/src/com/google/i18n/phonenumbers/geocoding/data/371_en differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/372_en b/java/src/com/google/i18n/phonenumbers/geocoding/data/372_en index 385c195e1..aaaa3388c 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/372_en and b/java/src/com/google/i18n/phonenumbers/geocoding/data/372_en differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/39_it b/java/src/com/google/i18n/phonenumbers/geocoding/data/39_it index 3f5de0f1c..2bd7c5c7a 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/39_it and b/java/src/com/google/i18n/phonenumbers/geocoding/data/39_it differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/41_de b/java/src/com/google/i18n/phonenumbers/geocoding/data/41_de index e0021edb1..86723f305 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/41_de and b/java/src/com/google/i18n/phonenumbers/geocoding/data/41_de differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/41_en b/java/src/com/google/i18n/phonenumbers/geocoding/data/41_en index f5c26ccdd..79ab08683 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/41_en and b/java/src/com/google/i18n/phonenumbers/geocoding/data/41_en differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/41_fr b/java/src/com/google/i18n/phonenumbers/geocoding/data/41_fr index d417de27f..b62ae33ef 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/41_fr and b/java/src/com/google/i18n/phonenumbers/geocoding/data/41_fr differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/41_it b/java/src/com/google/i18n/phonenumbers/geocoding/data/41_it index 845a7f61f..847fc3f34 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/41_it and b/java/src/com/google/i18n/phonenumbers/geocoding/data/41_it differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/420_en b/java/src/com/google/i18n/phonenumbers/geocoding/data/420_en index 16956f9ad..6e39c4358 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/420_en and b/java/src/com/google/i18n/phonenumbers/geocoding/data/420_en differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/421_en b/java/src/com/google/i18n/phonenumbers/geocoding/data/421_en index ef3674dc5..5a5dc092f 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/421_en and b/java/src/com/google/i18n/phonenumbers/geocoding/data/421_en differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/43_de b/java/src/com/google/i18n/phonenumbers/geocoding/data/43_de index 9be50cac6..3143edeb9 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/43_de and b/java/src/com/google/i18n/phonenumbers/geocoding/data/43_de differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/44_en b/java/src/com/google/i18n/phonenumbers/geocoding/data/44_en index ade6ce449..3a2d306ab 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/44_en and b/java/src/com/google/i18n/phonenumbers/geocoding/data/44_en differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/46_sv b/java/src/com/google/i18n/phonenumbers/geocoding/data/46_sv index a8ebc9cf3..016fd627e 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/46_sv and b/java/src/com/google/i18n/phonenumbers/geocoding/data/46_sv differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/48_pl b/java/src/com/google/i18n/phonenumbers/geocoding/data/48_pl index 3e5af2334..717b1ce10 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/48_pl and b/java/src/com/google/i18n/phonenumbers/geocoding/data/48_pl differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/49_de b/java/src/com/google/i18n/phonenumbers/geocoding/data/49_de index 0df583fd3..c37c7366a 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/49_de and b/java/src/com/google/i18n/phonenumbers/geocoding/data/49_de differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/51_en b/java/src/com/google/i18n/phonenumbers/geocoding/data/51_en index beef20663..7f84d3eb7 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/51_en and b/java/src/com/google/i18n/phonenumbers/geocoding/data/51_en differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/54_es b/java/src/com/google/i18n/phonenumbers/geocoding/data/54_es index 5c5f5ec81..7d89c05db 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/54_es and b/java/src/com/google/i18n/phonenumbers/geocoding/data/54_es differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/55_pt b/java/src/com/google/i18n/phonenumbers/geocoding/data/55_pt index 7c2edf977..753576a88 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/55_pt and b/java/src/com/google/i18n/phonenumbers/geocoding/data/55_pt differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/56_es b/java/src/com/google/i18n/phonenumbers/geocoding/data/56_es index deb60d906..9126f783f 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/56_es and b/java/src/com/google/i18n/phonenumbers/geocoding/data/56_es differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/7_en b/java/src/com/google/i18n/phonenumbers/geocoding/data/7_en index b39cd8a72..7ac3c1d84 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/7_en and b/java/src/com/google/i18n/phonenumbers/geocoding/data/7_en differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/82_en b/java/src/com/google/i18n/phonenumbers/geocoding/data/82_en index fdeaf4b5f..cd18ecbf3 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/82_en and b/java/src/com/google/i18n/phonenumbers/geocoding/data/82_en differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/82_ko b/java/src/com/google/i18n/phonenumbers/geocoding/data/82_ko index 5e96f8150..cbc30173d 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/82_ko and b/java/src/com/google/i18n/phonenumbers/geocoding/data/82_ko differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/82_zh b/java/src/com/google/i18n/phonenumbers/geocoding/data/82_zh index f7f64a9a9..d452ab7a2 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/82_zh and b/java/src/com/google/i18n/phonenumbers/geocoding/data/82_zh differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/82_zh_Hant b/java/src/com/google/i18n/phonenumbers/geocoding/data/82_zh_Hant index a2e1825a4..a6a945254 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/82_zh_Hant and b/java/src/com/google/i18n/phonenumbers/geocoding/data/82_zh_Hant differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/84_en b/java/src/com/google/i18n/phonenumbers/geocoding/data/84_en index 393614733..522172954 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/84_en and b/java/src/com/google/i18n/phonenumbers/geocoding/data/84_en differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/84_vi b/java/src/com/google/i18n/phonenumbers/geocoding/data/84_vi index b790b60a9..1b0e2d776 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/84_vi and b/java/src/com/google/i18n/phonenumbers/geocoding/data/84_vi differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/86_zh b/java/src/com/google/i18n/phonenumbers/geocoding/data/86_zh index ec58dc59c..afa8d670e 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/86_zh and b/java/src/com/google/i18n/phonenumbers/geocoding/data/86_zh differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/886_en b/java/src/com/google/i18n/phonenumbers/geocoding/data/886_en index b17f140b1..497c293d9 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/886_en and b/java/src/com/google/i18n/phonenumbers/geocoding/data/886_en differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/886_zh b/java/src/com/google/i18n/phonenumbers/geocoding/data/886_zh index 7b8148334..d04e3abd7 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/886_zh and b/java/src/com/google/i18n/phonenumbers/geocoding/data/886_zh differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/886_zh_Hant b/java/src/com/google/i18n/phonenumbers/geocoding/data/886_zh_Hant index 130d64352..eb259e9ff 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/886_zh_Hant and b/java/src/com/google/i18n/phonenumbers/geocoding/data/886_zh_Hant differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/90_en b/java/src/com/google/i18n/phonenumbers/geocoding/data/90_en index 3efa0e3af..a3dfd8185 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/90_en and b/java/src/com/google/i18n/phonenumbers/geocoding/data/90_en differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/90_tr b/java/src/com/google/i18n/phonenumbers/geocoding/data/90_tr index 741cbd558..7ba238ede 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/90_tr and b/java/src/com/google/i18n/phonenumbers/geocoding/data/90_tr differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/94_en b/java/src/com/google/i18n/phonenumbers/geocoding/data/94_en index f1e31e3a9..0794d2a10 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/94_en and b/java/src/com/google/i18n/phonenumbers/geocoding/data/94_en differ diff --git a/java/src/com/google/i18n/phonenumbers/geocoding/data/config b/java/src/com/google/i18n/phonenumbers/geocoding/data/config index 3d3907ed5..8020cc65f 100644 Binary files a/java/src/com/google/i18n/phonenumbers/geocoding/data/config and b/java/src/com/google/i18n/phonenumbers/geocoding/data/config differ diff --git a/java/test/com/google/i18n/phonenumbers/AsYouTypeFormatterTest.java b/java/test/com/google/i18n/phonenumbers/AsYouTypeFormatterTest.java index 183dc6da3..c6dc09a3b 100644 --- a/java/test/com/google/i18n/phonenumbers/AsYouTypeFormatterTest.java +++ b/java/test/com/google/i18n/phonenumbers/AsYouTypeFormatterTest.java @@ -56,6 +56,23 @@ public class AsYouTypeFormatterTest extends TestCase { assertEquals("650253", formatter.inputDigit('3')); } + public void testInvalidPlusSign() { + AsYouTypeFormatter formatter = phoneUtil.getAsYouTypeFormatter("ZZ"); + assertEquals("+", formatter.inputDigit('+')); + assertEquals("+4", formatter.inputDigit('4')); + assertEquals("+48 ", formatter.inputDigit('8')); + assertEquals("+48 8", formatter.inputDigit('8')); + assertEquals("+48 88", formatter.inputDigit('8')); + assertEquals("+48 88 1", formatter.inputDigit('1')); + assertEquals("+48 88 12", formatter.inputDigit('2')); + assertEquals("+48 88 123", formatter.inputDigit('3')); + assertEquals("+48 88 123 1", formatter.inputDigit('1')); + // A plus sign can only appear at the beginning of the number; otherwise, no formatting is + // applied. + assertEquals("+48881231+", formatter.inputDigit('+')); + assertEquals("+48881231+2", formatter.inputDigit('2')); + } + public void testTooLongNumberMatchingMultipleLeadingDigits() { // See http://code.google.com/p/libphonenumber/issues/detail?id=36 // The bug occurred last time for countries which have two formatting rules with exactly the diff --git a/java/test/com/google/i18n/phonenumbers/PhoneNumberMatcherTest.java b/java/test/com/google/i18n/phonenumbers/PhoneNumberMatcherTest.java index 451ba5ec6..488789276 100644 --- a/java/test/com/google/i18n/phonenumbers/PhoneNumberMatcherTest.java +++ b/java/test/com/google/i18n/phonenumbers/PhoneNumberMatcherTest.java @@ -22,6 +22,7 @@ import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber; import junit.framework.TestCase; import java.util.ArrayList; +import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.NoSuchElementException; @@ -115,6 +116,8 @@ public class PhoneNumberMatcherTest extends TestCase { /** See {@link PhoneNumberUtilTest#testParseWithXInNumber()}. */ public void testFindWithXInNumber() throws Exception { doTestFindInContext("(0xx) 123456789", "AR"); + // A case where x denotes both carrier codes and extension symbol. + doTestFindInContext("(0xx) 123456789 x 1234", "AR"); // This test is intentionally constructed such that the number of digit after xx is larger than // 7, so that the number won't be mistakenly treated as an extension, as we allow extensions up @@ -168,7 +171,9 @@ public class PhoneNumberMatcherTest extends TestCase { doTestFindInContext("(800) 901-3355 x 7246433", "US"); doTestFindInContext("(800) 901-3355 , ext 7246433", "US"); doTestFindInContext("(800) 901-3355 ,extension 7246433", "US"); - doTestFindInContext("(800) 901-3355 , 7246433", "US"); + // The next test differs from PhoneNumberUtil -> when matching we don't consider a lone comma to + // indicate an extension, although we accept it when parsing. + doTestFindInContext("(800) 901-3355 ,x 7246433", "US"); doTestFindInContext("(800) 901-3355 ext: 7246433", "US"); } @@ -199,10 +204,11 @@ public class PhoneNumberMatcherTest extends TestCase { public void testMatchWithSurroundingZipcodes() throws Exception { String number = "415-666-7777"; - String zipPreceding = "My address is CA 34215. " + number + " is my number."; + String zipPreceding = "My address is CA 34215 - " + number + " is my number."; PhoneNumber expectedResult = phoneUtil.parse(number, "US"); - Iterator iterator = phoneUtil.findNumbers(zipPreceding, "US").iterator(); + Iterator iterator = + phoneUtil.findNumbers(zipPreceding, "US").iterator(); PhoneNumberMatch match = iterator.hasNext() ? iterator.next() : null; assertNotNull("Did not find a number in '" + zipPreceding + "'; expected " + number, match); assertEquals(expectedResult, match.number()); @@ -236,24 +242,42 @@ public class PhoneNumberMatcherTest extends TestCase { } public void testMatchesWithSurroundingLatinChars() throws Exception { - ArrayList contextPairs = new ArrayList(5); - contextPairs.add(new NumberContext("abc", "def")); - contextPairs.add(new NumberContext("abc", "")); - contextPairs.add(new NumberContext("", "def")); - // Latin small letter e with an acute accent. - contextPairs.add(new NumberContext("\u00C9", "")); - // Same character decomposed (with combining mark). - contextPairs.add(new NumberContext("e\u0301", "")); + ArrayList possibleOnlyContexts = new ArrayList(); + possibleOnlyContexts.add(new NumberContext("abc", "def")); + possibleOnlyContexts.add(new NumberContext("abc", "")); + possibleOnlyContexts.add(new NumberContext("", "def")); + // Latin capital letter e with an acute accent. + possibleOnlyContexts.add(new NumberContext("\u00C9", "")); + // e with an acute accent decomposed (with combining mark). + possibleOnlyContexts.add(new NumberContext("e\u0301", "")); // Numbers should not be considered valid, if they are surrounded by Latin characters, but // should be considered possible. - findMatchesInContexts(contextPairs, false, true); + findMatchesInContexts(possibleOnlyContexts, false, true); + } + + public void testMoneyNotSeenAsPhoneNumber() throws Exception { + ArrayList possibleOnlyContexts = new ArrayList(); + possibleOnlyContexts.add(new NumberContext("$", "")); + possibleOnlyContexts.add(new NumberContext("", "$")); + possibleOnlyContexts.add(new NumberContext("\u00A3", "")); // Pound sign + possibleOnlyContexts.add(new NumberContext("\u00A5", "")); // Yen sign + findMatchesInContexts(possibleOnlyContexts, false, true); + } + + public void testPhoneNumberWithLeadingOrTrailingMoneyMatches() throws Exception { + // Because of the space after the 20 (or before the 100) these dollar amounts should not stop + // the actual number from being found. + ArrayList contexts = new ArrayList(); + contexts.add(new NumberContext("$20 ", "")); + contexts.add(new NumberContext("", " 100$")); + findMatchesInContexts(contexts, true, true); } public void testMatchesWithSurroundingLatinCharsAndLeadingPunctuation() throws Exception { // Contexts with trailing characters. Leading characters are okay here since the numbers we will // insert start with punctuation, but trailing characters are still not allowed. - ArrayList possibleOnlyContexts = new ArrayList(3); + ArrayList possibleOnlyContexts = new ArrayList(); possibleOnlyContexts.add(new NumberContext("abc", "def")); possibleOnlyContexts.add(new NumberContext("", "def")); possibleOnlyContexts.add(new NumberContext("", "\u00C9")); @@ -265,7 +289,7 @@ public class PhoneNumberMatcherTest extends TestCase { findMatchesInContexts(possibleOnlyContexts, false, true, "US", numberWithPlus); findMatchesInContexts(possibleOnlyContexts, false, true, "US", numberWithBrackets); - ArrayList validContexts = new ArrayList(4); + ArrayList validContexts = new ArrayList(); validContexts.add(new NumberContext("abc", "")); validContexts.add(new NumberContext("\u00C9", "")); validContexts.add(new NumberContext("\u00C9", ".")); // Trailing punctuation. @@ -277,7 +301,7 @@ public class PhoneNumberMatcherTest extends TestCase { } public void testMatchesWithSurroundingChineseChars() throws Exception { - ArrayList validContexts = new ArrayList(3); + ArrayList validContexts = new ArrayList(); validContexts.add(new NumberContext("\u6211\u7684\u7535\u8BDD\u53F7\u7801\u662F", "")); validContexts.add(new NumberContext("", "\u662F\u6211\u7684\u7535\u8BDD\u53F7\u7801")); validContexts.add(new NumberContext("\u8BF7\u62E8\u6253", "\u6211\u5728\u660E\u5929")); @@ -287,7 +311,7 @@ public class PhoneNumberMatcherTest extends TestCase { } public void testMatchesWithSurroundingPunctuation() throws Exception { - ArrayList validContexts = new ArrayList(4); + ArrayList validContexts = new ArrayList(); validContexts.add(new NumberContext("My number-", "")); // At end of text. validContexts.add(new NumberContext("", ".Nice day.")); // At start of text. validContexts.add(new NumberContext("Tel:", ".")); // Punctuation surrounds number. @@ -297,6 +321,184 @@ public class PhoneNumberMatcherTest extends TestCase { findMatchesInContexts(validContexts, true, true); } + public void testMatchesMultiplePhoneNumbersSeparatedByPhoneNumberPunctuation() throws Exception { + String text = "Call 650-253-4561 -- 455-234-3451"; + String region = "US"; + + PhoneNumber number1 = new PhoneNumber(); + number1.setCountryCode(phoneUtil.getCountryCodeForRegion(region)); + number1.setNationalNumber(6502534561L); + PhoneNumberMatch match1 = new PhoneNumberMatch(5, "650-253-4561", number1); + + PhoneNumber number2 = new PhoneNumber(); + number2.setCountryCode(phoneUtil.getCountryCodeForRegion(region)); + number2.setNationalNumber(4552343451L); + PhoneNumberMatch match2 = new PhoneNumberMatch(21, "455-234-3451", number2); + + Iterator matches = phoneUtil.findNumbers(text, region).iterator(); + assertEquals(match1, matches.next()); + assertEquals(match2, matches.next()); + } + + public void testDoesNotMatchMultiplePhoneNumbersSeparatedWithNoWhiteSpace() throws Exception { + // No white-space found between numbers - neither is found. + String text = "Call 650-253-4561--455-234-3451"; + String region = "US"; + + assertTrue(hasNoMatches(phoneUtil.findNumbers(text, region))); + } + + /** + * Strings with number-like things that shouldn't be found under any level. + */ + private static final NumberTest[] IMPOSSIBLE_CASES = { + new NumberTest("12345", "US"), + new NumberTest("23456789", "US"), + new NumberTest("234567890112", "US"), + new NumberTest("650+253+1234", "US"), + new NumberTest("3/10/1984", "CA"), + new NumberTest("03/27/2011", "US"), + new NumberTest("31/8/2011", "US"), + new NumberTest("1/12/2011", "US"), + new NumberTest("10/12/82", "DE"), + }; + + /** + * Strings with number-like things that should only be found under "possible". + */ + private static final NumberTest[] POSSIBLE_ONLY_CASES = { + new NumberTest("abc8002345678", "US"), + // US numbers cannot start with 7 in the test metadata to be valid. + new NumberTest("7121115678", "US"), + // 'X' should not be found in numbers at leniencies stricter than POSSIBLE, unless it represents + // a carrier code or extension. + new NumberTest("1650 x 253 - 1234", "US"), + new NumberTest("650 x 253 - 1234", "US"), + new NumberTest("650x2531234", "US"), + }; + + /** + * Strings with number-like things that should only be found up to and including the "valid" + * leniency level. + */ + private static final NumberTest[] VALID_CASES = { + new NumberTest("65 02 53 00 00.", "US"), + new NumberTest("6502 538365", "US"), + new NumberTest("650//253-1234", "US"), // 2 slashes are illegal at higher levels + new NumberTest("650/253/1234", "US"), + new NumberTest("9002309. 158", "US"), + new NumberTest("21 7/8 - 14 12/34 - 5", "US"), + new NumberTest("12.1 - 23.71 - 23.45", "US"), + new NumberTest("1979-2011 100%", "US"), + new NumberTest("800 234 1 111x1111", "US"), + new NumberTest("+494949-4-94", "DE"), // National number in wrong format + }; + + /** + * Strings with number-like things that should only be found up to and including the + * "strict_grouping" leniency level. + */ + private static final NumberTest[] STRICT_GROUPING_CASES = { + new NumberTest("(415) 6667777", "US"), + new NumberTest("415-6667777", "US"), + // Should be found by strict grouping but not exact grouping, as the last two groups are + // formatted together as a block. + new NumberTest("800-2491234", "DE"), + }; + + /** + * Strings with number-like things that should found at all levels. + */ + private static final NumberTest[] EXACT_GROUPING_CASES = { + new NumberTest("\uFF14\uFF11\uFF15\uFF16\uFF16\uFF16\uFF17\uFF17\uFF17\uFF17", "US"), + new NumberTest("\uFF14\uFF11\uFF15-\uFF16\uFF16\uFF16-\uFF17\uFF17\uFF17\uFF17", "US"), + new NumberTest("4156667777", "US"), + new NumberTest("4156667777 x 123", "US"), + new NumberTest("415-666-7777", "US"), + new NumberTest("415/666-7777", "US"), + new NumberTest("415-666-7777 ext. 503", "US"), + new NumberTest("1 415 666 7777 x 123", "US"), + new NumberTest("+1 415-666-7777", "US"), + new NumberTest("+494949 49", "DE"), + new NumberTest("+49-49-34", "DE"), + new NumberTest("+49-4931-49", "DE"), + new NumberTest("04931-49", "DE"), // With National Prefix + new NumberTest("+49-494949", "DE"), // One group with country code + new NumberTest("+49-494949 ext. 49", "DE"), + new NumberTest("+49494949 ext. 49", "DE"), + new NumberTest("0494949", "DE"), + new NumberTest("0494949 ext. 49", "DE"), + }; + + public void testMatchesWithStrictGroupingLeniency() throws Exception { + int noMatchFoundCount = 0; + int wrongMatchFoundCount = 0; + List testCases = new ArrayList(); + testCases.addAll(Arrays.asList(STRICT_GROUPING_CASES)); + testCases.addAll(Arrays.asList(EXACT_GROUPING_CASES)); + doTestNumberMatchesForLeniency(testCases, Leniency.STRICT_GROUPING); + } + + public void testNonMatchesWithStrictGroupLeniency() throws Exception { + int matchFoundCount = 0; + List testCases = new ArrayList(); + testCases.addAll(Arrays.asList(POSSIBLE_ONLY_CASES)); + testCases.addAll(Arrays.asList(VALID_CASES)); + doTestNumberNonMatchesForLeniency(testCases, Leniency.STRICT_GROUPING); + } + + public void testMatchesWithExactGroupingLeniency() throws Exception { + List testCases = new ArrayList(); + testCases.addAll(Arrays.asList(EXACT_GROUPING_CASES)); + doTestNumberMatchesForLeniency(testCases, Leniency.EXACT_GROUPING); + } + + public void testNonMatchesExactGroupLeniency() throws Exception { + List testCases = new ArrayList(); + testCases.addAll(Arrays.asList(POSSIBLE_ONLY_CASES)); + testCases.addAll(Arrays.asList(VALID_CASES)); + testCases.addAll(Arrays.asList(STRICT_GROUPING_CASES)); + doTestNumberNonMatchesForLeniency(testCases, Leniency.EXACT_GROUPING); + } + + private void doTestNumberMatchesForLeniency(List testCases, + PhoneNumberUtil.Leniency leniency) { + int noMatchFoundCount = 0; + int wrongMatchFoundCount = 0; + for (NumberTest test : testCases) { + Iterator iterator = + findNumbersForLeniency(test.rawString, test.region, leniency); + PhoneNumberMatch match = iterator.hasNext() ? iterator.next() : null; + if (match == null) { + noMatchFoundCount++; + System.err.println("No match found in " + test.toString() + " for leniency: " + leniency); + } else { + if (!test.rawString.equals(match.rawString())) { + wrongMatchFoundCount++; + System.err.println("Found wrong match in test " + test.toString() + + ". Found " + match.rawString()); + } + } + } + assertEquals(0, noMatchFoundCount); + assertEquals(0, wrongMatchFoundCount); + } + + private void doTestNumberNonMatchesForLeniency(List testCases, + PhoneNumberUtil.Leniency leniency) { + int matchFoundCount = 0; + for (NumberTest test : testCases) { + Iterator iterator = + findNumbersForLeniency(test.rawString, test.region, leniency); + PhoneNumberMatch match = iterator.hasNext() ? iterator.next() : null; + if (match != null) { + matchFoundCount++; + System.err.println("Match found in " + test.toString() + " for leniency: " + leniency); + } + } + assertEquals(0, matchFoundCount); + } + /** * Helper method which tests the contexts provided and ensures that: * -- if isValid is true, they all find a test number inserted in the middle when leniency of @@ -445,11 +647,10 @@ public class PhoneNumberMatcherTest extends TestCase { numbers.append("My info: 415-666-7777 123 fake street"); } - // Only matches the first 5 despite there being 100 numbers due to max matches. - // There are two false positives per line as "123" is also tried. + // Only matches the first 10 despite there being 100 numbers due to max matches. List expected = new ArrayList(100); PhoneNumber number = phoneUtil.parse("+14156667777", null); - for (int i = 0; i < 5; i++) { + for (int i = 0; i < 10; i++) { expected.add(number); } @@ -572,7 +773,7 @@ public class PhoneNumberMatcherTest extends TestCase { PhoneNumberMatch match = matches.next(); assertEquals(start - index, match.start()); assertEquals(end - index, match.end()); - assertEquals(match.rawString(), sub.subSequence(match.start(), match.end()).toString()); + assertEquals(sub.subSequence(match.start(), match.end()).toString(), match.rawString()); } /** @@ -594,7 +795,7 @@ public class PhoneNumberMatcherTest extends TestCase { * Tests valid numbers in contexts that should pass for {@link Leniency#POSSIBLE}. */ private void findPossibleInContext(String number, String defaultCountry) { - ArrayList contextPairs = new ArrayList(15); + ArrayList contextPairs = new ArrayList(); contextPairs.add(new NumberContext("", "")); // no context contextPairs.add(new NumberContext(" ", "\t")); // whitespace only contextPairs.add(new NumberContext("Hello ", "")); // no context at end @@ -618,15 +819,9 @@ public class PhoneNumberMatcherTest extends TestCase { // With dates, written in the American style. contextPairs.add(new NumberContext( "As I said on 03/10/2011, you may call me at ", "")); - contextPairs.add(new NumberContext( - "As I said on 03/27/2011, you may call me at ", "")); - contextPairs.add(new NumberContext( - "As I said on 31/8/2011, you may call me at ", "")); - contextPairs.add(new NumberContext( - "As I said on 1/12/2011, you may call me at ", "")); - contextPairs.add(new NumberContext( - "I was born on 10/12/82. Please call me at ", "")); - // With a postfix stripped off as it looks like the start of another number + // With trailing numbers after a comma. The 45 should not be considered an extension. + contextPairs.add(new NumberContext("", ", 45 days a year")); + // With a postfix stripped off as it looks like the start of another number. contextPairs.add(new NumberContext("Call ", "/x12 more")); doTestInContext(number, defaultCountry, contextPairs, Leniency.POSSIBLE); @@ -637,17 +832,18 @@ public class PhoneNumberMatcherTest extends TestCase { * {@link Leniency#VALID}. */ private void findValidInContext(String number, String defaultCountry) { - ArrayList contextPairs = new ArrayList(5); + ArrayList contextPairs = new ArrayList(); // With other small numbers. contextPairs.add(new NumberContext("It's only 9.99! Call ", " to buy")); // With a number Day.Month.Year date. contextPairs.add(new NumberContext("Call me on 21.6.1984 at ", "")); // With a number Month/Day date. contextPairs.add(new NumberContext("Call me on 06/21 at ", "")); - // With a number Day.Month date + // With a number Day.Month date. contextPairs.add(new NumberContext("Call me on 21.6. at ", "")); // With a number Month/Day/Year date. contextPairs.add(new NumberContext("Call me on 06/21/84 at ", "")); + doTestInContext(number, defaultCountry, contextPairs, Leniency.VALID); } @@ -659,10 +855,10 @@ public class PhoneNumberMatcherTest extends TestCase { int start = prefix.length(); int end = start + number.length(); - Iterable iterable = - phoneUtil.findNumbers(text, defaultCountry, leniency, Long.MAX_VALUE); + Iterator iterator = + phoneUtil.findNumbers(text, defaultCountry, leniency, Long.MAX_VALUE).iterator(); - PhoneNumberMatch match = iterable.iterator().hasNext() ? iterable.iterator().next() : null; + PhoneNumberMatch match = iterator.hasNext() ? iterator.next() : null; assertNotNull("Did not find a number in '" + text + "'; expected '" + number + "'", match); CharSequence extracted = text.subSequence(match.start(), match.end()); @@ -691,9 +887,18 @@ public class PhoneNumberMatcherTest extends TestCase { } } + private Iterator findNumbersForLeniency( + String text, String defaultCountry, PhoneNumberUtil.Leniency leniency) { + return phoneUtil.findNumbers(text, defaultCountry, leniency, Long.MAX_VALUE).iterator(); + } + /** * Returns true if there were no matches found. */ + private boolean hasNoMatches(Iterator iterator) { + return !iterator.hasNext(); + } + private boolean hasNoMatches(Iterable iterable) { return !iterable.iterator().hasNext(); } @@ -711,4 +916,22 @@ public class PhoneNumberMatcherTest extends TestCase { this.trailingText = trailingText; } } + + /** + * Small class that holds the number we want to test and the region for which it should be valid. + */ + private static class NumberTest { + final String rawString; + final String region; + + NumberTest(String rawString, String regionCode) { + this.rawString = rawString; + this.region = regionCode; + } + + @Override + public String toString() { + return rawString + " (" + region.toString() + ")"; + } + } } diff --git a/java/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java b/java/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java index 2da773ee8..e31190612 100644 --- a/java/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java +++ b/java/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java @@ -147,7 +147,7 @@ public class PhoneNumberUtilTest extends TestCase { assertEquals("(\\d{3})(\\d{3})(\\d{4})", metadata.getNumberFormat(1).getPattern()); assertEquals("$1 $2 $3", metadata.getNumberFormat(1).getFormat()); - assertEquals("[13-9]\\d{9}|2[0-35-9]\\d{8}", + assertEquals("[13-689]\\d{9}|2[0-35-9]\\d{8}", metadata.getGeneralDesc().getNationalNumberPattern()); assertEquals("\\d{7}(?:\\d{3})?", metadata.getGeneralDesc().getPossibleNumberPattern()); assertTrue(metadata.getGeneralDesc().exactlySameAs(metadata.getFixedLine())); @@ -170,7 +170,7 @@ public class PhoneNumberUtilTest extends TestCase { assertEquals("(\\d{3})(\\d{3,4})(\\d{4})", metadata.getNumberFormat(5).getPattern()); assertEquals("$1 $2 $3", metadata.getNumberFormat(5).getFormat()); - assertEquals("(?:[24-6]\\d{2}|3[03-9]\\d|[789](?:[1-9]\\d|0[2-9]))\\d{3,8}", + assertEquals("(?:[24-6]\\d{2}|3[03-9]\\d|[789](?:[1-9]\\d|0[2-9]))\\d{1,8}", metadata.getFixedLine().getNationalNumberPattern()); assertEquals("\\d{2,14}", metadata.getFixedLine().getPossibleNumberPattern()); assertEquals("30123456", metadata.getFixedLine().getExampleNumber()); @@ -1836,8 +1836,6 @@ public class PhoneNumberUtilTest extends TestCase { // NSN matches. assertEquals(PhoneNumberUtil.MatchType.NSN_MATCH, phoneUtil.isNumberMatch("+64 3 331-6005", "03 331 6005")); - assertEquals(PhoneNumberUtil.MatchType.NSN_MATCH, - phoneUtil.isNumberMatch("3 331-6005", "03 331 6005")); assertEquals(PhoneNumberUtil.MatchType.NSN_MATCH, phoneUtil.isNumberMatch(NZ_NUMBER, "03 331 6005")); // Here the second number possibly starts with the country calling code for New Zealand, @@ -1872,6 +1870,10 @@ public class PhoneNumberUtilTest extends TestCase { // Short NSN matches with the country not specified for either one or both numbers. assertEquals(PhoneNumberUtil.MatchType.SHORT_NSN_MATCH, phoneUtil.isNumberMatch("+64 3 331-6005", "331 6005")); + // We did not know that the "0" was a national prefix since neither number has a country code, + // so this is considered a SHORT_NSN_MATCH. + assertEquals(PhoneNumberUtil.MatchType.SHORT_NSN_MATCH, + phoneUtil.isNumberMatch("3 331-6005", "03 331 6005")); assertEquals(PhoneNumberUtil.MatchType.SHORT_NSN_MATCH, phoneUtil.isNumberMatch("3 331-6005", "331 6005")); assertEquals(PhoneNumberUtil.MatchType.SHORT_NSN_MATCH, diff --git a/java/test/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProtoForTesting_DE b/java/test/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProtoForTesting_DE index 0c785345f..766539fa3 100644 Binary files a/java/test/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProtoForTesting_DE and b/java/test/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProtoForTesting_DE differ diff --git a/java/test/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProtoForTesting_US b/java/test/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProtoForTesting_US index d93e0a221..0630d7753 100644 Binary files a/java/test/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProtoForTesting_US and b/java/test/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProtoForTesting_US differ diff --git a/java/test/com/google/i18n/phonenumbers/geocoding/AreaCodeMapTest.java b/java/test/com/google/i18n/phonenumbers/geocoding/AreaCodeMapTest.java index 7d17975d4..d0da308ec 100644 --- a/java/test/com/google/i18n/phonenumbers/geocoding/AreaCodeMapTest.java +++ b/java/test/com/google/i18n/phonenumbers/geocoding/AreaCodeMapTest.java @@ -33,8 +33,8 @@ import java.util.TreeMap; * @author Shaopeng Jia */ public class AreaCodeMapTest extends TestCase { - private final AreaCodeMap areaCodeMapForUS = new AreaCodeMap(1); - private final AreaCodeMap areaCodeMapForIT = new AreaCodeMap(39); + private final AreaCodeMap areaCodeMapForUS = new AreaCodeMap(); + private final AreaCodeMap areaCodeMapForIT = new AreaCodeMap(); private PhoneNumber number = new PhoneNumber(); public AreaCodeMapTest() { @@ -83,13 +83,13 @@ public class AreaCodeMapTest extends TestCase { public void testGetSmallerMapStorageChoosesDefaultImpl() { AreaCodeMapStorageStrategy mapStorage = - new AreaCodeMap(1).getSmallerMapStorage(createDefaultStorageMapCandidate()); + new AreaCodeMap().getSmallerMapStorage(createDefaultStorageMapCandidate()); assertFalse(mapStorage.isFlyweight()); } public void testGetSmallerMapStorageChoosesFlyweightImpl() { AreaCodeMapStorageStrategy mapStorage = - new AreaCodeMap(1).getSmallerMapStorage(createFlyweightStorageMapCandidate()); + new AreaCodeMap().getSmallerMapStorage(createFlyweightStorageMapCandidate()); assertTrue(mapStorage.isFlyweight()); } @@ -158,21 +158,20 @@ public class AreaCodeMapTest extends TestCase { * this stream. The resulting area code map is expected to be strictly equal to the provided one * from which it was generated. */ - private static AreaCodeMap createNewAreaCodeMap(AreaCodeMap areaCodeMap) - throws IOException { + private static AreaCodeMap createNewAreaCodeMap(AreaCodeMap areaCodeMap) throws IOException { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream); areaCodeMap.writeExternal(objectOutputStream); objectOutputStream.flush(); - AreaCodeMap newAreaCodeMap = new AreaCodeMap(1); + AreaCodeMap newAreaCodeMap = new AreaCodeMap(); newAreaCodeMap.readExternal( new ObjectInputStream(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()))); return newAreaCodeMap; } public void testReadWriteExternalWithDefaultStrategy() throws IOException { - AreaCodeMap localAreaCodeMap = new AreaCodeMap(1); + AreaCodeMap localAreaCodeMap = new AreaCodeMap(); localAreaCodeMap.readAreaCodeMap(createDefaultStorageMapCandidate()); assertFalse(localAreaCodeMap.getAreaCodeMapStorage().isFlyweight()); @@ -182,7 +181,7 @@ public class AreaCodeMapTest extends TestCase { } public void testReadWriteExternalWithFlyweightStrategy() throws IOException { - AreaCodeMap localAreaCodeMap = new AreaCodeMap(1); + AreaCodeMap localAreaCodeMap = new AreaCodeMap(); localAreaCodeMap.readAreaCodeMap(createFlyweightStorageMapCandidate()); assertTrue(localAreaCodeMap.getAreaCodeMapStorage().isFlyweight()); diff --git a/java/test/com/google/i18n/phonenumbers/geocoding/FlyweightMapStorageTest.java b/java/test/com/google/i18n/phonenumbers/geocoding/FlyweightMapStorageTest.java new file mode 100644 index 000000000..c00ae8ddd --- /dev/null +++ b/java/test/com/google/i18n/phonenumbers/geocoding/FlyweightMapStorageTest.java @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2011 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.geocoding; + +import junit.framework.TestCase; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.util.SortedMap; +import java.util.TreeMap; + +/** + * Unittests for FlyweightMapStorage.java + * + * @author Philippe Liard + */ +public class FlyweightMapStorageTest extends TestCase { + private final SortedMap areaCodeMap = new TreeMap(); + + public FlyweightMapStorageTest() { + areaCodeMap.put(331402, "Paris"); + areaCodeMap.put(331434, "Paris"); + areaCodeMap.put(334910, "Marseille"); + areaCodeMap.put(334911, "Marseille"); + } + + public void testReadFromSortedMap() { + FlyweightMapStorage mapStorage = new FlyweightMapStorage(); + mapStorage.readFromSortedMap(areaCodeMap); + + assertEquals(331402, mapStorage.getPrefix(0)); + assertEquals(331434, mapStorage.getPrefix(1)); + assertEquals(334910, mapStorage.getPrefix(2)); + assertEquals(334911, mapStorage.getPrefix(3)); + + String desc = mapStorage.getDescription(0); + assertEquals("Paris", desc); + assertTrue(desc == mapStorage.getDescription(1)); // Same identity. + + desc = mapStorage.getDescription(2); + assertEquals("Marseille", desc); + assertTrue(desc == mapStorage.getDescription(3)); // Same identity. + } + + public void testWriteAndReadExternal() throws IOException { + FlyweightMapStorage mapStorage = new FlyweightMapStorage(); + mapStorage.readFromSortedMap(areaCodeMap); + + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream); + mapStorage.writeExternal(objectOutputStream); + objectOutputStream.flush(); + + FlyweightMapStorage newMapStorage = new FlyweightMapStorage(); + ObjectInputStream objectInputStream = + new ObjectInputStream(new ByteArrayInputStream(byteArrayOutputStream.toByteArray())); + newMapStorage.readExternal(objectInputStream); + + String expected = mapStorage.toString(); + assertFalse(expected.length() == 0); + assertEquals(expected, newMapStorage.toString()); + } +} diff --git a/java/test/com/google/i18n/phonenumbers/geocoding/PhoneNumberOfflineGeocoderTest.java b/java/test/com/google/i18n/phonenumbers/geocoding/PhoneNumberOfflineGeocoderTest.java index ec5f9bca9..73611c5ba 100644 --- a/java/test/com/google/i18n/phonenumbers/geocoding/PhoneNumberOfflineGeocoderTest.java +++ b/java/test/com/google/i18n/phonenumbers/geocoding/PhoneNumberOfflineGeocoderTest.java @@ -95,7 +95,7 @@ public class PhoneNumberOfflineGeocoderTest extends TestCase { geocoder.getDescriptionForNumber(KO_NUMBER3, Locale.KOREAN)); } - public void testGetDescritionForInvaildNumber() { + public void testGetDescriptionForInvalidNumber() { assertEquals("", geocoder.getDescriptionForNumber(KO_INVALID_NUMBER, Locale.ENGLISH)); assertEquals("", geocoder.getDescriptionForNumber(US_INVALID_NUMBER, Locale.ENGLISH)); } diff --git a/java/test/com/google/i18n/phonenumbers/geocoding/testing_data/1_en b/java/test/com/google/i18n/phonenumbers/geocoding/testing_data/1_en index 74ef19cdd..a3850da17 100644 Binary files a/java/test/com/google/i18n/phonenumbers/geocoding/testing_data/1_en and b/java/test/com/google/i18n/phonenumbers/geocoding/testing_data/1_en differ diff --git a/java/test/com/google/i18n/phonenumbers/geocoding/testing_data/82_en b/java/test/com/google/i18n/phonenumbers/geocoding/testing_data/82_en index fdeaf4b5f..cd18ecbf3 100644 Binary files a/java/test/com/google/i18n/phonenumbers/geocoding/testing_data/82_en and b/java/test/com/google/i18n/phonenumbers/geocoding/testing_data/82_en differ diff --git a/java/test/com/google/i18n/phonenumbers/geocoding/testing_data/82_ko b/java/test/com/google/i18n/phonenumbers/geocoding/testing_data/82_ko index 5e96f8150..cbc30173d 100644 Binary files a/java/test/com/google/i18n/phonenumbers/geocoding/testing_data/82_ko and b/java/test/com/google/i18n/phonenumbers/geocoding/testing_data/82_ko differ diff --git a/resources/PhoneNumberMetaData.xml b/resources/PhoneNumberMetaData.xml index b62860f16..fa32c56ba 100644 --- a/resources/PhoneNumberMetaData.xml +++ b/resources/PhoneNumberMetaData.xml @@ -714,7 +714,7 @@ - + @@ -809,16 +809,89 @@ - [1-9]\d{9,11} - \d{6,12} + + [1-8]\d{9}| + 9\d{10} + + \d{6,11} - [1-9]\d{9} + + + 11\d{8}| + (?: + 2(?: + 2(?: + [0139]\d| + 2[13-79]| + 4[1-6]| + 5[2457]| + 6[124-8]| + 7[1-4]| + 8[13-6] + )| + 3(?: + 1[467]| + 2[02-6]| + 3[13-8]| + [49][2-6]| + 5[2-8]| + [067]\d + )| + 47[3-8]| + 6(?: + [01345]\d| + 2[2-7] + )| + 9(?: + [0124789]\d| + 3[1-6]| + 5[234]| + 6[2-6] + ) + )| + 3(?: + 3(?: + 2[79]| + 8[2578] + )| + 4(?: + [78]\d| + 0[0124-9]| + [1-356]\d| + 4[24-7]| + 9[123678] + )| + 5(?: + [138]\d| + 2[1245]| + 4[1-9]| + 6[2-4]| + 7[1-6] + )| + 7(?: + [12468]\d| + 3[1245]| + 5[124-8]| + 7[2-57] + )| + 8(?: + [123578]\d| + 4[13-6] + 6[1-357-9]| + 9[124] + ) + )| + 670\d + )\d{6} + \d{6,10} 1123456789 + + 675\d{7}| 9(?: 11[2-9]\d{7}| (?: @@ -837,24 +910,24 @@ \d{4}[2-9]\d{5} ) - \d{6,12} + \d{6,11} 91123456789 - 80\d{8} + 800\d{7} \d{10} - 8012345678 + 8001234567 - - 6(?: - 0\d| - 10 - )\d{7} - + 60[04579]\d{7} \d{10} 6001234567 + + 810\d{7} + \d{10} + 8101234567 + @@ -978,17 +1051,14 @@ - \d{4,13} + [1-9]\d{3,12} \d{3,13} - + 1\d{3,12}| (?: @@ -1017,7 +1087,7 @@ 8[2457] )| 5(?: - 1[27]| + 12| 2[1-8]| 3[357]| 4[147]| @@ -1040,12 +1110,7 @@ 7[1-6]| 9[45] ) - )\d{3,10}| - 5(?: - 0[1-9]| - [79]\d - )\d{2,10}| - 720\d{6,10} + )\d{3,10} 1234567890 @@ -1094,6 +1159,20 @@ \d{9,13} 780123456 + + + 5(?: + (?: + 0[1-9]| + 17 + )\d{2,10}| + [79]\d{3,11} + )| + 720\d{6, 10} + + \d{5,13} + 50123 + @@ -1110,13 +1189,16 @@ $1 $2 $3 - 4 + pattern="(\d{3})(\d{3})(\d{3})"> + + [45]| + 14 + $1 $2 $3 - 5 + pattern="(16)(\d{3})(\d{2,4})"> + 16 $1 $2 $3 1(?: [38]0| - 9 + 90 ) 1(?: [38]00| - 9 + 90 ) $1 $2 $3 - + pattern="(180)(2\d{3})"> 180 - 180[1-9] + 1802 + $1 $2 + + + 19[13] + $1 $2 + + + 19[67] $1 $2 212345678 + + 14(?: + 5\d| + 71 + )\d{5}| 4(?: [0-2]\d| 3[0-57-9]| @@ -1187,28 +1283,44 @@ \d{9} 412345678 + + 16\d{3,7} + \d{5,9} + 1612345 + - - 1(?: - 80(?: - 0\d{2} - )? | - 3(?: - 00\d{2} - )? - )\d{4} + 180(?: + 0\d{3}| + 2 + )\d{3} - \d{6,10} + \d{7,10} 1800123456 - 190[0126]\d{6} - \d{10} + + 19(?: + 0[0126]\d{6}| + [13-5]\d{3}| + [679]\d{5} + ) + + \d{6,10} 1900123456 + + + + 13(?: + 00\d{2} + )?\d{4} + + \d{6,10} + 1300123456 + @@ -1355,21 +1467,33 @@ nationalPrefix="0" nationalPrefixFormattingRule="($NP$FG)"> - 1[28] + + (?: + 1[28]| + 2(?: + [45]2| + [0-36] + )| + 365 + ) + $1 $2 $3 $4 22 $1 $2 $3 $4 - - 3 + + 36[0-46-9] $1 $2 $3 $4 1[013-79]| - 2[013-9] + 2(?: + [45][13-9]| + [7-9] + ) $1 $2 $3 $4 @@ -1391,7 +1515,9 @@ + "Fixed Network" by the national plan. + The following regexp covers both the pre and post August 1st 2011 plans running in + parallel until December 31st 2011. --> (?: 1(?: @@ -1408,12 +1534,35 @@ 7[0-24-8] )| 2(?: - 16| - 2\d| - 3[0-24]| - 4[1468]| - 55| - 6[56]| + 02\d| + 1(?: + 2[0-8]| + 42| + 6 + )| + 2(?: + 2[0-79]| + 3[0-35]| + 42| + [1-35-9]| + )| + 3(?: + 3[0-58]| + [0-24] + )| + 4(?: + 2[0124579]| + [1468] + )| + 5(?: + 2[0124579]| + 5 + )| + 6(?: + 2\d| + 3[0128]| + [56] + )| 79 )| 365?\d| @@ -1751,9 +1900,6 @@ - @@ -1817,7 +1963,7 @@ 4(?: 7\d| - 8[4-9]| + 8[3-9]| 9[1-9] )\d{6} @@ -1885,12 +2031,10 @@ Including 716 as well since many numbers seem to have this prefix. --> 7(?: - [024-6]\d| + [02-68]\d| 1[0-4689]| - 3[0-6]| - 7[01]| - 8[013-9]| - 9[0-4] + 7[0-3]| + 9[0-6] )\d{5} 70123456 @@ -2014,6 +2158,7 @@ + @@ -2048,7 +2193,7 @@ (?: 3(?: - [369]\d| + [23469]\d| 77| 8[38] )| @@ -2860,7 +3005,7 @@ )| 7(?: 0[059]| - [18]0| + 80| 78 )| 8(?: @@ -2905,7 +3050,7 @@ )| 7(?: 0[059]| - [18]0| + 80| 78 )| 8(?: @@ -3475,9 +3620,12 @@ 3(?: 11| - 7[159] + 7[179] + )| + 4(?: + [15]1| + 3[12] )| - 4[135]1| 5(?: 1| 2[37]| @@ -3488,7 +3636,8 @@ 7(?: 31| 5[457]| - 6[09] + 6[09]| + 91 )| 898 @@ -3509,7 +3658,7 @@ 2[179]| [35][2-9]| 6[4789]| - 7[0-46-9]| + 7\d| 8[23] )| 5(?: @@ -3571,6 +3720,8 @@ \d{4,12} + 21\d{8,10}| (?: @@ -3578,9 +3729,12 @@ 2[02-57-9]| 3(?: 11| - 7[159] + 7[179] + )| + 4(?: + [15]1| + 3[12] )| - 4[135]1| 5(?: 1\d| 2[37]| @@ -3591,7 +3745,8 @@ 7(?: 31| 5[457]| - 6[09] + 6[09]| + 91 )| 898 )\d{8}| @@ -3607,9 +3762,10 @@ 4(?: 1[02-9]| 2[179]| - [35][2-9]| + 3[3-9]| + 5[2-9]| 6[4789]| - 7[0-46-9]| + 7\d| 8[23] )| 5(?: @@ -3701,7 +3857,7 @@ + nationalPrefix="0" nationalPrefixForParsing="0([3579]|4(?:44|56))?"> @@ -3799,7 +3955,7 @@ - [24]| + [245]| 8[3-9] $1 $2 @@ -3810,7 +3966,7 @@ - [2489]\d{7,9} + [24589]\d{7,9} \d{8,10} @@ -3821,7 +3977,10 @@ - 8[36789]\d{6} + + 57[01]\d[01]\d{3}| + 8[36789]\d{6} + \d{8} 83123456 @@ -3837,7 +3996,16 @@ 9001234567 - 40[02]0\d{4} + + 40(?: + 00\d{4}| + 10[0-3]\d{3}| + 2(?: + 00\d| + 900 + )\d{2} + ) + \d{8} 40001234 @@ -3845,7 +4013,10 @@ 1(?: - 02[2-4679]| + 0(?: + 00| + 2[2-4679] + )| 1(?: 1[0-35-9]| 2| @@ -3855,9 +4026,16 @@ 8[79]| 9[0-379] )| - 212| + 2(?: + 12| + 34 + )| 400| - 902 + 7(?: + 00| + 1[78]| + 77 + )| )| 911 @@ -7626,7 +7804,7 @@ (?: - 3[4-9]| + 3[2-9]| 4\d )\d{6} @@ -7672,7 +7850,7 @@ - \d{8,9} + [1-9]\d{7,8} \d{6,9} @@ -9256,7 +9434,10 @@ - [01389]\d{5,10} + + [0189]\d{5,10}| + 3\d{8,9} + \d{6,11} @@ -10702,7 +10883,7 @@ 31[25]| - [5-8] + [5-7] $1 $2 $3 @@ -10715,19 +10896,25 @@ $1 $2 + + 8 + $1 $2 $3 $4 + - [356-8]\d{8} - \d{5,9} + [356-8]\d{8,9} + \d{5,10} + (?: 3(?: 1(?: 2\d| 3[1-9]| - 52| + 47| + 5[02]| 6[1-8] )| 2(?: @@ -10754,14 +10941,14 @@ 7(?: 22| 3[468]| - 4[1-8]| + 4[1-9]| 59| 6\d| 7[5-7] )| 9(?: 22| - 4[1-7]| + 4[1-8]| 6[0-8] ) )| @@ -10788,8 +10975,10 @@ 700123456 - 800\d{6} - \d{9} + + 800\d{6,7} + \d{9,10} 800123456 @@ -10797,11 +10986,11 @@ + - + 1\d[1-9]| [2-9] @@ -10823,35 +11012,40 @@ 2[3-6]| 3[2-6]| 4[2-4]| - [5-7][2-5] - )[2-47-9]\d{5} + [567][2-5] + )[2-46-9]\d{5} \d{6,8} 23456789 - (?: (?: 1[0-35-9]| - 9[1-49] + 6[6-9]| + 7[06-89]| + 9\d )[1-9]| 8(?: 0[89]| - 5[2-689] + 5[2-689]| + 8\d{2}| + [1349]\d| ) )\d{5} - \d{8} + + \d{8,9} 91234567 + 1800(?: 1\d| - 2[09] + 2[019] )\d{4} \d{10} @@ -11708,7 +11902,7 @@ [89][01]| 7(?: [01]| - 6[67]) + 6[167]) $1 $2 $3 @@ -11736,7 +11930,7 @@ 3\d| 7(?: [01]\d| - 6[67] + 6[167] ) )\d{5} @@ -11840,7 +12034,8 @@ - + + @@ -11858,12 +12053,10 @@ [7-9]0 $1 $2 $3 - - + [89]0 - 0$1 $2 $3 $4 + $1 $2 $3 $4 @@ -12759,12 +12952,12 @@ 3(?: 0[2-7]| 1[35-7]| - 2[367]| + 2[3567]| 3[4-7] )| 4(?: 0[237]| - 1[2467] + 1[27] )| 5(?: 0[47]| @@ -12793,7 +12986,7 @@ + digits long, based on the Montenegro document. --> \d{8,9} 67622901 @@ -14362,7 +14555,7 @@ (?: 2[03-9]| - 35| + 3[0-5]| 4[1-7]| 88 )\d{4} @@ -14372,7 +14565,7 @@ (?: - 7[4-9]| + 7[3-9]| 8[0-79]| 9\d )\d{4} @@ -16532,10 +16725,11 @@ + - + (?: 2[389]| @@ -16544,7 +16738,7 @@ $1 $2 - + 1| 2(?: @@ -16554,49 +16748,71 @@ 3(?: [0-8]| 9[1-9] - )| - 42 + ) $1 $2 - + 6 $1 $2 - + [89] $1 $2 + + 7[26] + $1 $2 + + + 7[08] + $1 $2 + - [1-46-9]\d{4,11} + [1-36-9]\d{4,11} \d{5,12} - [1-3]\d{6,9} - \d{5,10} - 1012345 + [1-3]\d{6,11} + \d{5,12} + 101234567 - 6[0-689]\d{3,10} - \d{5,12} - 6012345 + + 6(?: + [0-689]| + 7\d + )\d{6,7} + + \d{8,10} + 601234567 - 800\d{3,6} - \d{6,9} + 800\d{3,9} + \d{6,12} 80012345 (?: - 9[0-2]| - 42 - )\d{4,7} + 90[0169]| + 78\d + )\d{3,7} - \d{6,9} + \d{6,12} 90012345 + + 7[06]\d{4,10} + \d{6,12} + 700123456 + + + 1[189]\d{1,4} + \d{3,6} + 12345 + @@ -17094,7 +17310,7 @@ - \d{7,10} + [1-9]\d{6,9} \d{5,10} @@ -18644,7 +18860,7 @@ 868(?: 2(?: 01| - 2[1-4] + 2[1-5] )| 6(?: 07| @@ -19192,7 +19408,7 @@ )| 7(?: 0[1-46-8]| - 1[2-9]| + 1[02-9]| 2[047]| 3[124]| 4[07]| @@ -19284,7 +19500,7 @@ )| 7(?: 0[1-46-8]| - 1[2-9]| + 1[02-9]| 2[047]| 3[124]| 4[07]| @@ -20173,7 +20389,7 @@ - \d{9} + [1-578]\d{8} \d{8,9} diff --git a/resources/PhoneNumberMetaDataForTesting.xml b/resources/PhoneNumberMetaDataForTesting.xml index cc74b7d38..b67444cd5 100644 --- a/resources/PhoneNumberMetaDataForTesting.xml +++ b/resources/PhoneNumberMetaDataForTesting.xml @@ -205,7 +205,7 @@ \d{2,14} - (?:[24-6]\d{2}|3[03-9]\d|[789](?:[1-9]\d|0[2-9]))\d{3,8} + (?:[24-6]\d{2}|3[03-9]\d|[789](?:[1-9]\d|0[2-9]))\d{1,8} 30123456 @@ -685,7 +685,8 @@ - [13-9]\d{9}|2[0-35-9]\d{8} + + [13-689]\d{9}|2[0-35-9]\d{8} \d{7}(?:\d{3})? 1234567890 diff --git a/resources/geocoding/de/352.txt b/resources/geocoding/de/352.txt new file mode 100644 index 000000000..dbe36d808 --- /dev/null +++ b/resources/geocoding/de/352.txt @@ -0,0 +1,59 @@ +# Copyright (C) 2011 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. + +# Generated from: +# Internal statistical data (2011-08-08) and translated with Freebase. + +35222|Luxemburg +35223|Bad Mondorf +35224|Luxemburg +35225|Luxemburg +35226|Luxemburg +35227|Luxemburg +35229|Luxemburg +35230|Kanton Capellen +35231|Bertrange +35232|Kanton Mersch +35233|Walferdingen +35234|Senningerberg +35235|Sandweiler +35236|Hesperingen +35237|Leudelange +35239|Steinfort +3524|Luxemburg +35250|Bascharage +35251|Dudelange +35252|Dudelange +35253|Esch-sur-Alzette +35254|Esch-sur-Alzette +35255|Esch-sur-Alzette +35256|Rumelange +35257|Esch-sur-Alzette +35258|Differdange +35259|Soleuvre +35271|Betzdorf +35272|Echternach +35274|Wasserbillig +35275|Distrikt Grevenmacher +35276|Wormeldange +35278|Junglinster +35279|Berdorf +35280|Kanton Diekirch +35281|Ettelbrück +35283|Kanton Vianden +35287|Larochette +35292|Kanton Clerf +35295|Kanton Wiltz +35297|Huldange +35299|Troisvierges diff --git a/resources/geocoding/de/43.txt b/resources/geocoding/de/43.txt index 21fa3fc14..d1fb4c770 100644 --- a/resources/geocoding/de/43.txt +++ b/resources/geocoding/de/43.txt @@ -16,11 +16,6 @@ # http://www.rtr.at/en/tk/E129/Austrian_Numbering_Plan_2011-03-30.pdf [2011-03-30] 431|Wien -43316|Graz -43463|Klagenfurt -43512|Innsbruck -43662|Salzburg -43732|Linz 432142|Gattendorf 432143|Kittsee 432144|Deutsch Jahrndorf @@ -338,6 +333,7 @@ 433157|Kapfenstein 433158|Sankt Anna am Aigen 433159|Bad Gleichenberg +43316|Graz 433170|Fischbach 433171|Gasen 433172|Weiz @@ -568,6 +564,7 @@ 434357|Sankt Paul im Lavanttal 434358|Sankt Andrä 434359|Reichenfels +43463|Klagenfurt 434710|Oberdrauburg 434712|Greifenburg 434713|Techendorf @@ -612,6 +609,7 @@ 434876|Kals am Großglockner 434877|Prägraten am Großvenediger 434879|Sankt Veit in Defereggen +43512|Innsbruck 435212|Seefeld in Tirol 435213|Scharnitz 435214|Leutasch @@ -837,6 +835,7 @@ 436584|Maria Alm am Steinernen Meer 436588|Lofer 436589|Unken +43662|Salzburg 437211|Reichenau im Mühlkreis 437212|Zwettl an der Rodl 437213|Bad Leonfelden @@ -911,6 +910,7 @@ 437287|Peilstein im Mühlviertel 437288|Ulrichsberg 437289|Rohrbach in Oberösterreich +43732|Linz 437353|Gaflenz 437355|Weyer 437357|Kleinreifling diff --git a/resources/geocoding/de/49.txt b/resources/geocoding/de/49.txt index a3ef4d933..ecb582599 100644 --- a/resources/geocoding/de/49.txt +++ b/resources/geocoding/de/49.txt @@ -15,95 +15,9 @@ # Generated from: # http://www.itu.int/oth/T0202000051/en [2010-09-16] -4930|Berlin -4940|Hamburg -4969|Frankfurt am Main -4989|München 49201|Essen 49202|Wuppertal 49203|Duisburg -49208|Oberhausen Rheinland -49209|Gelsenkirchen -49211|Düsseldorf -49212|Solingen -49214|Leverkusen -49221|Köln -49228|Bonn -49231|Dortmund -49234|Bochum -49241|Aachen -49251|Münster -49261|Koblenz am Rhein -49271|Siegen -49281|Wesel -49291|Meschede -49331|Potsdam -49335|Frankfurt (Oder) -49340|Dessau Anh -49341|Leipzig -49345|Halle Saale -49351|Dresden -49355|Cottbus -49361|Erfurt -49365|Gera -49371|Chemnitz Sachsen -49375|Zwickau -49381|Rostock -49385|Schwerin -49391|Magdeburg -49395|Neubrandenburg -49421|Bremen -49431|Kiel -49441|Oldenburg (Oldb) -49451|Lübeck -49461|Flensburg -49471|Bremerhaven -49481|Heide Holstein -49491|Leer Ostfriesland -49511|Hannover -49521|Bielefeld -49531|Braunschweig -49541|Osnabrück -49551|Göttingen -49561|Kassel -49571|Minden Westfalen -49581|Uelzen -49591|Lingen (Ems) -49611|Wiesbaden -49621|Mannheim -49631|Kaiserslautern -49641|Giessen -49651|Trier -49661|Fulda -49671|Bad Kreuznach -49681|Saarbrücken -49711|Stuttgart -49721|Karlsruhe -49731|Ulm Donau -49741|Rottweil -49751|Ravensburg -49761|Freiburg im Breisgau -49771|Donaueschingen -49781|Offenburg -49791|Schwäbisch Hall -49811|Hallbergmoos -49821|Augsburg -49831|Kempten Allgäu -49841|Ingolstadt Donau -49851|Passau -49861|Traunstein -49871|Landshut -49881|Weilheim in Oberbayern -49906|Donauwörth -49911|Nürnberg -49921|Bayreuth -49931|Würzburg -49941|Regensburg -49951|Bamberg -49961|Weiden in der Oberpfalz -49971|Bad Kissingen -49981|Ansbach -49991|Deggendorf 492041|Bottrop 492043|Gladbeck 492045|Bottrop-Kirchhellen @@ -116,14 +30,19 @@ 492064|Dinslaken 492065|Duisburg-Rheinhausen 492066|Duisburg-Homberg +49208|Oberhausen Rheinland +49209|Gelsenkirchen 492102|Ratingen 492103|Hilden 492104|Mettmann +49211|Düsseldorf +49212|Solingen 492129|Haan Rheinland 492131|Neuss 492132|Meerbusch-Büderich 492133|Dormagen 492137|Neuss-Norf +49214|Leverkusen 492150|Meerbusch-Lank 492151|Krefeld 492152|Kempen @@ -158,6 +77,7 @@ 492206|Overath 492207|Kürten-Dürscheid 492208|Niederkassel +49221|Köln 492222|Bornheim Rheinland 492223|Königswinter 492224|Bad Honnef @@ -201,6 +121,7 @@ 492273|Kerpen-Horrem 492274|Elsdorf Rheinland 492275|Kerpen-Buir +49228|Bonn 492291|Waldbröl 492292|Windeck Sieg 492293|Nümbrecht @@ -217,6 +138,7 @@ 492307|Kamen 492308|Unna-Hemmerde 492309|Waltrop +49231|Dortmund 492323|Herne 492324|Hattingen Ruhr 492325|Wanne-Eickel @@ -231,6 +153,7 @@ 492337|Hagen-Dahl 492338|Breckerfeld 492339|Sprockhövel-Haßlinghausen +49234|Bochum 492351|Lüdenscheid 492352|Altena Westfalen 492353|Halver @@ -279,6 +202,7 @@ 492407|Herzogenrath-Kohlscheid 492408|Aachen-Kornelimünster 492409|Stolberg-Gressenich +49241|Aachen 492421|Düren 492422|Kreuzau 492423|Langerwehe @@ -330,6 +254,7 @@ 492507|Havixbeck 492508|Drensteinfurt 492509|Nottuln-Appelhülsen +49251|Münster 492520|Wadersloh-Diestedde 492521|Beckum 492522|Oelde @@ -400,6 +325,7 @@ 492606|Winningen Mosel 492607|Kobern-Gondorf 492608|Welschneudorf +49261|Koblenz am Rhein 492620|Neuhäusel Westerwald 492621|Lahnstein 492622|Bendorf am Rhein @@ -464,6 +390,7 @@ 492695|Insul 492696|Nohn Eifel 492697|Blankenheim-Ahrhütte +49271|Siegen 492721|Lennestadt 492722|Attendorn 492723|Kirchhundem @@ -509,6 +436,7 @@ 492802|Alpen 492803|Wesel-Büderich 492804|Xanten-Marienbaum +49281|Wesel 492821|Kleve Niederrhein 492822|Emmerich 492823|Goch @@ -555,6 +483,7 @@ 492903|Meschede-Freienohl 492904|Bestwig 492905|Bestwig-Ramsbeck +49291|Meschede 492921|Soest 492922|Werl 492923|Lippetal-Herzfeld @@ -602,12 +531,14 @@ 492992|Marsberg 492993|Marsberg-Canstein 492994|Marsberg-Westheim +4930|Berlin 493301|Oranienburg 493302|Hennigsdorf 493303|Birkenwerder 493304|Velten 493306|Gransee 493307|Zehdenick +49331|Potsdam 493321|Nauen Brandenburg 493322|Falkensee 493327|Werder Havel @@ -623,6 +554,7 @@ 493342|Neuenhagen bei Berlin 493344|Bad Freienwalde 493346|Seelow +49335|Frankfurt (Oder) 493361|Fürstenwalde Spree 493362|Erkner 493364|Eisenhüttenstadt @@ -640,6 +572,8 @@ 493391|Neuruppin 493394|Wittstock Dosse 493395|Pritzwalk +49340|Dessau Anh +49341|Leipzig 493421|Torgau 493423|Eilenburg 493425|Wurzen @@ -652,6 +586,7 @@ 493445|Naumburg Saale 493447|Altenburg Thüringen 493448|Meuselwitz Thüringen +49345|Halle Saale 493461|Merseburg Saale 493462|Bad Dürrenberg 493464|Sangerhausen @@ -666,6 +601,7 @@ 493496|Köthen Anhalt 493501|Pirna 493504|Dippoldiswalde +49351|Dresden 493521|Meissen 493522|Grossenhain Sachsen 493523|Coswig bei Dresden @@ -680,6 +616,7 @@ 493542|Lübbenau Spreewald 493544|Luckau Brandenburg 493546|Lübben Spreewald +49355|Cottbus 493561|Guben 493562|Forst Lausitz 493563|Spremberg @@ -702,6 +639,7 @@ 493603|Bad Langensalza 493605|Leinefelde 493606|Heiligenstadt Heilbad +49361|Erfurt 493621|Gotha Thüringen 493622|Waltershausen Thüringen 493623|Friedrichroda @@ -717,6 +655,7 @@ 493643|Weimar Thüringen 493644|Apolda 493647|Pößneck +49365|Gera 493661|Greiz 493663|Schleiz 493671|Saalfeld Saale @@ -732,6 +671,7 @@ 493691|Eisenach Thüringen 493693|Meiningen 493695|Bad Salzungen +49371|Chemnitz Sachsen 493721|Meinersdorf 493722|Limbach-Oberfrohna 493723|Hohenstein-Ernstthal @@ -746,6 +686,7 @@ 493741|Plauen 493744|Auerbach Vogtland 493745|Falkenstein Vogtland +49375|Zwickau 493761|Werdau Sachsen 493762|Crimmitschau 493763|Glauchau @@ -755,6 +696,7 @@ 493772|Schneeberg Erzgebirge 493773|Johanngeorgenstadt 493774|Schwarzenberg +49381|Rostock 493821|Ribnitz-Damgarten 493831|Stralsund 493834|Greifswald @@ -764,6 +706,7 @@ 493843|Güstrow 493844|Schwaan 493847|Sternberg +49385|Schwerin 493860|Raben Steinfeld 493861|Plate 493863|Crivitz @@ -784,6 +727,7 @@ 493904|Haldensleben 493907|Gardelegen 493909|Klötze Altmark +49391|Magdeburg 493921|Burg bei Magdeburg 493923|Zerbst 493925|Stassfurt @@ -798,6 +742,7 @@ 493946|Quedlinburg 493947|Thale 493949|Oschersleben Bode +49395|Neubrandenburg 493961|Altentreptow 493962|Penzlin bei Waren 493963|Woldegk @@ -817,6 +762,7 @@ 493994|Malchin 493996|Teterow 493998|Demmin +4940|Hamburg 494101|Pinneberg 494102|Ahrensburg 494103|Wedel @@ -902,6 +848,7 @@ 494207|Oyten 494208|Grasberg 494209|Schwanewede +49421|Bremen 494221|Delmenhorst 494222|Ganderkesee 494223|Ganderkesee-Bookholzberg @@ -972,6 +919,7 @@ 494305|Westensee 494307|Raisdorf 494308|Schwedeneck +49431|Kiel 494320|Heidmühlen 494321|Neumünster 494322|Bordesholm @@ -1033,6 +981,7 @@ 494407|Wardenburg 494408|Hude Oldenburg 494409|Westerstede-Ocholt +49441|Oldenburg (Oldb) 494421|Wilhelmshaven 494422|Sande Kreis Friesl 494423|Fedderwarden @@ -1101,6 +1050,7 @@ 494506|Stockelsdorf-Krumbeck 494508|Krummesse 494509|Groß Grönau +49451|Lübeck 494521|Eutin 494522|Plön 494523|Malente @@ -1147,6 +1097,7 @@ 494607|Janneby 494608|Handewitt 494609|Eggebek +49461|Flensburg 494621|Schleswig 494622|Taarstedt 494623|Böklund @@ -1193,6 +1144,7 @@ 494706|Schiffdorf 494707|Langen-Neuenwalde 494708|Ringstedt +49471|Bremerhaven 494721|Cuxhaven 494722|Cuxhaven-Altenbruch 494723|Cuxhaven-Altenwalde @@ -1253,6 +1205,7 @@ 494804|Nordhastedt 494805|Schafstedt 494806|Sarzbüttel +49481|Heide Holstein 494821|Itzehoe 494822|Kellinghusen 494823|Wilster @@ -1310,6 +1263,7 @@ 494893|Hohenaspe 494902|Jemgum-Ditzum 494903|Wymeer +49491|Leer Ostfriesland 494920|Wirdum 494921|Emden Stadt 494922|Borkum @@ -1411,6 +1365,7 @@ 495105|Barsinghausen 495108|Gehrden Han 495109|Ronnenberg +49511|Hannover 495121|Hildesheim 495123|Schellerten 495126|Algermissen @@ -1484,6 +1439,7 @@ 495207|Schloss Holte-Stukenbrock 495208|Leopoldshöhe 495209|Gütersloh-Friedrichsdorf +49521|Bielefeld 495221|Herford 495222|Bad Salzuflen 495223|Bünde @@ -1549,6 +1505,7 @@ 495307|Braunschweig-Wenden 495308|Lehre 495309|Lehre-Wendhausen +49531|Braunschweig 495320|Torfhaus 495321|Goslar 495322|Bad Harzburg @@ -1609,6 +1566,7 @@ 495406|Belm 495407|Wallenhorst 495409|Hilter am Teutoburger Wald +49541|Osnabrück 495421|Dissen am Teutoburger Wald 495422|Melle 495423|Versmold @@ -1675,6 +1633,7 @@ 495507|Ebergötzen 495508|Gleichen-Rittmarshausen 495509|Rosdorf Kreis Göttingen +49551|Göttingen 495520|Braunlage 495521|Herzberg am Harz 495522|Osterode am Harz @@ -1728,6 +1687,7 @@ 495607|Fuldatal 495608|Söhrewald 495609|Ahnatal +49561|Kassel 495621|Bad Wildungen 495622|Fritzlar 495623|Edertal @@ -1788,6 +1748,7 @@ 495705|Petershagen-Windheim 495706|Porta Westfalica 495707|Petershagen Weser +49571|Minden Westfalen 495721|Stadthagen 495722|Bückeburg 495723|Bad Nenndorf @@ -1831,6 +1792,7 @@ 495806|Barum bei Bad Bevensen 495807|Altenmedingen 495808|Gerdau +49581|Uelzen 495820|Suhlendorf 495821|Bad Bevensen 495822|Ebstorf @@ -1888,6 +1850,7 @@ 495907|Geeste 495908|Wietmarschen-Lohne 495909|Wettrup +49591|Lingen (Ems) 495921|Nordhorn 495922|Bad Bentheim 495923|Schüttorf @@ -1999,6 +1962,7 @@ 496107|Kelsterbach 496108|Mühlheim am Main 496109|Frankfurt-Bergen-Enkheim +49611|Wiesbaden 496120|Aarbergen 496122|Hofheim-Wallau 496123|Eltville am Rhein @@ -2062,6 +2026,7 @@ 496206|Lampertheim 496207|Wald-Michelbach 496209|Mörlenbach +49621|Mannheim 496220|Wilhelmsfeld 496221|Heidelberg 496222|Wiesloch @@ -2133,6 +2098,7 @@ 496306|Trippstadt 496307|Schopp 496308|Olsbrücken +49631|Kaiserslautern 496321|Neustadt an der Weinstraße 496322|Bad Dürkheim 496323|Edenkoben @@ -2203,6 +2169,7 @@ 496407|Rabenau Hessen 496408|Buseck 496409|Biebertal +49641|Giessen 496420|Lahntal 496421|Marburg 496422|Kirchhain @@ -2270,6 +2237,7 @@ 496507|Neumagen-Dhron 496508|Hetzerath Mosel 496509|Büdlich +49651|Trier 496522|Mettendorf 496523|Holsthum 496524|Rodershausen @@ -2330,6 +2298,7 @@ 496596|Üdersdorf 496597|Jünkerath 496599|Weidenbach bei Gerolstein +49661|Fulda 496620|Philippsthal Werra 496621|Bad Hersfeld 496622|Bebra @@ -2403,6 +2372,7 @@ 496707|Windesheim 496708|Bad Münster am Stein-Ebernburg 496709|Fürfeld Kreis Bad Kreuznach +49671|Bad Kreuznach 496721|Bingen am Rhein 496722|Rüdesheim am Rhein 496723|Oestrich-Winkel @@ -2460,6 +2430,7 @@ 496805|Kleinblittersdorf 496806|Heusweiler 496809|Grossrosseln +49681|Saarbrücken 496821|Neunkirchen Saar 496824|Ottweiler 496825|Illingen Saar @@ -2507,6 +2478,7 @@ 496894|St Ingbert 496897|Sulzbach Saar 496898|Völklingen +4969|Frankfurt am Main 497021|Kirchheim unter Teck 497022|Nürtingen 497023|Weilheim an der Teck @@ -2540,6 +2512,7 @@ 497083|Bad Herrenalb 497084|Schömberg bei Neuenbürg 497085|Enzklösterle +49711|Stuttgart 497121|Reutlingen 497122|St Johann Württemberg 497123|Metzingen Württemberg @@ -2599,6 +2572,7 @@ 497202|Karlsbad 497203|Walzbachtal 497204|Malsch-Völkersbach +49721|Karlsruhe 497220|Forbach-Hundsbach 497221|Baden-Baden 497222|Rastatt @@ -2661,6 +2635,7 @@ 497307|Senden Iller 497308|Nersingen 497309|Weissenhorn +49731|Ulm Donau 497321|Heidenheim an der Brenz 497322|Giengen an der Brenz 497323|Gerstetten @@ -2721,6 +2696,7 @@ 497402|Fluorn-Winzeln 497403|Dunningen 497404|Epfendorf +49741|Rottweil 497420|Deisslingen 497422|Schramberg 497423|Oberndorf am Neckar @@ -2780,6 +2756,7 @@ 497504|Horgenzell 497505|Fronreute 497506|Wangen-Leupolz +49751|Ravensburg 497520|Bodnegg 497522|Wangen im Allgäu 497524|Bad Waldsee @@ -2832,6 +2809,7 @@ 497586|Herbertingen 497587|Hosskirch 497602|Oberried Breisgau +49761|Freiburg im Breisgau 497620|Schopfheim-Gersbach 497621|Lörrach 497622|Schopfheim @@ -2890,6 +2868,7 @@ 497707|Bräunlingen 497708|Geisingen-Leipferdingen 497709|Wutach +49771|Donaueschingen 497720|Schwenningen am Neckar 497721|Villingen im Schwarzwald 497722|Triberg im Schwarzwald @@ -2937,6 +2916,7 @@ 497806|Bad Peterstal-Griesbach 497807|Neuried Ortenaukreis 497808|Hohberg bei Offenburg +49781|Offenburg 497821|Lahr Schwarzwald 497822|Ettenheim 497823|Seelbach Schutter @@ -2965,6 +2945,7 @@ 497905|Langenburg 497906|Braunsbach 497907|Schwäbisch Hall-Sulzdorf +49791|Schwäbisch Hall 497930|Boxberg Baden 497931|Bad Mergentheim 497932|Niederstetten Württemberg @@ -3066,6 +3047,7 @@ 498104|Sauerlach 498105|Gilching 498106|Vaterstetten +49811|Hallbergmoos 498121|Markt Schwaben 498122|Erding 498123|Moosinning @@ -3113,6 +3095,7 @@ 498206|Egling an der Paar 498207|Affing 498208|Eurasburg bei Augsburg +49821|Augsburg 498221|Günzburg 498222|Burgau Schwaben 498223|Ichenhausen @@ -3171,6 +3154,7 @@ 498303|Waltenhofen 498304|Wildpoldsried 498306|Ronsberg +49831|Kempten Allgäu 498320|Missen-Wilhams 498321|Sonthofen 498322|Oberstdorf @@ -3237,6 +3221,7 @@ 498405|Stammham bei Ingolstadt 498406|Böhmfeld 498407|Grossmehring +49841|Ingolstadt Donau 498421|Eichstätt Bayern 498422|Dollnstein 498423|Titting @@ -3280,6 +3265,7 @@ 498506|Bad Höhenstadt 498507|Neuburg am Inn 498509|Ruderting +49851|Passau 498531|Pocking 498532|Griesbach im Rottal 498533|Rotthalmünster @@ -3324,6 +3310,7 @@ 498591|Obernzell 498592|Wegscheid Niederbayern 498593|Untergriesbach +49861|Traunstein 498621|Trostberg 498622|Tacherting-Peterskirchen 498623|Kirchweidach @@ -3377,6 +3364,7 @@ 498707|Adlkofen 498708|Weihmichl-Unterneuhausen 498709|Eching Niederbayern +49871|Landshut 498721|Eggenfelden 498722|Gangkofen 498723|Arnstorf @@ -3422,6 +3410,7 @@ 498807|Dießen am Ammersee 498808|Pähl 498809|Wessobrunn +49881|Weilheim in Oberbayern 498821|Garmisch-Partenkirchen 498822|Oberammergau 498823|Mittenwald @@ -3441,6 +3430,8 @@ 498867|Rottenbuch Oberbayern 498868|Schwabsoien 498869|Kinsau +4989|München +49906|Donauwörth 499070|Tapfheim 499071|Dillingen an der Donau 499072|Lauingen Donau @@ -3474,6 +3465,7 @@ 499105|Grosshabersdorf 499106|Markt Erlbach 499107|Trautskirchen +49911|Nürnberg 499120|Leinburg 499122|Schwabach 499123|Lauf an der Pegnitz @@ -3526,3 +3518,11 @@ 499183|Burgthann 499184|Deining Oberpfalz 499185|Mühlhausen Oberpfalz +49921|Bayreuth +49931|Würzburg +49941|Regensburg +49951|Bamberg +49961|Weiden in der Oberpfalz +49971|Bad Kissingen +49981|Ansbach +49991|Deggendorf diff --git a/resources/geocoding/el/30.txt b/resources/geocoding/el/30.txt new file mode 100644 index 000000000..47864a09b --- /dev/null +++ b/resources/geocoding/el/30.txt @@ -0,0 +1,256 @@ +# Copyright (C) 2011 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. + +# Generated from: +# http://el.wikipedia.org/wiki/Τηλεφωνικοί_κωδικοί_της_Ελλάδας + +3021|Αθήνα/Πειραιάς/Σαλαμίνα +302221|Χαλκίδα +302222|Κύμη +302223|Αλιβέρι +302224|Κάρυστος +302226|Αιδηψός +302227|Μαντούδι +302228|Ψαχνά +302229|Ερέτρια +302231|Λαμία +302232|Δομοκός +302233|Αταλάντη +302234|Αμφίκλεια +302235|Καμμένα Βούρλα +302236|Μακρακώμη +302237|Καρπενήσι +302238|Στυλίδα +302241|Ρόδος +302242|Κως +302243|Κάλυμνος +302244|Αρχάγγελος +302245|Κάρπαθος +302246|Τήλος/Σύμη/Χάλκη/Μεγίστη +302247|Λέρος +302251|Μυτιλήνη +302252|Αγιάσος/Πλωμάρι +302253|Καλλονή/Μήθυμνα +302254|Άγιος Ευστράτιος/Μούδρος/Μύρινα +302261|Λειβαδιά +302262|Θήβα +302263|Βίλια +302264|Δόμβραινα +302265|Άμφισσα +302266|Λιδορίκι +302267|Δίστομο +302268|Αλίαρτος +302271|Χίος +302272|Καρδάμυλα +302273|Σάμος +302274|Βολισσός +302275|Άγιος Κήρυκος +302281|Σύρος +302282|Άνδρος +302283|Τήνος +302284|Πάρος +302285|Νάξος +302286|Θήρα +302287|Μήλος +302288|Κέα +302289|Μύκονος +302291|Λαγονήσι +302292|Λαύριο +302293|Άγιος Σωτήρας +302294|Ραφήνα +302295|Αφίδναι +302296|Μέγαρα/Νέα Πέραμος +302297|Αίγινα +302298|Μέθανα/Πόρος/Σπέτσες +302299|Μαρκόπουλο +30231|Θεσσαλονίκη +302321|Σέρρες +302322|Νιγρίτα +302323|Σιδηρόκαστρο +302324|Νέα Ζίχνη +3023250|Ηράκλεια +302327|Ροδόπολη Σερρών +302331|Βέροια +302332|Νάουσα +302333|Αλεξάνδρεια +302341|Κιλκίς +302343|Πολύκαστρο +302351|Κατερίνη +302352|Λιτόχωρο +302353|Αιγίνιο +302371|Πολύγυρος +302372|Αρναία +302373|Νέα Μουδανιά +302374|Κασσάνδρεια +302375|Νικήτη +302376|Στρατώνι +302377|Άγιον Όρος/Ιερισσός +302381|Έδεσσα +302382|Γιαννιτσά +302384|Αριδαία +302385|Φλώρινα +302386|Αμύνταιο +302391|Χαλκηδόνα +302392|Περαία +302393|Λαγκαδίκια +302394|Λαγκαδάς +302395|Σοχός +302396|Βασιλικά +302397|Ασπροβάλτα +302399|Καλλικράτεια +30241|Λάρισα +302421|Βόλος +302422|Αλμυρός +302423|Καλά Νερά +302424|Σκόπελος +302425|Βελεστίνο +302426|Ζαγορά +302427|Σκιάθος +302431|Τρίκαλα +302432|Καλαμπάκα +302433|Φαρκαδόνα +302434|Πύλη +302441|Καρδίτσα +302443|Σοφάδες +302444|Παλαμάς +302445|Μουζάκι +302461|Κοζάνη +302462|Γρεβενά +302463|Πτολεμαΐδα +302464|Σέρβια +302465|Σιάτιστα +302467|Καστοριά +302468|Νεάπολη +3024910|Φάρσαλα +302492|Τύρναβος +302493|Ελασσόνα +302494|Αγιά +302495|Γόννοι/Μακρυχώρι +30251|Καβάλα +302521|Δράμα +302522|Προσοτσάνη +302523|Κάτω Νευροκόπι +302524|Παρανέστι +302531|Κομοτηνή +302532|Σάπες +302533|Ξυλαγανή +302534|Ίασμος +302535|Νέα Καλλίστη +302541|Ξάνθη +302542|Σταυρούπολη +302544|Εχίνος +302551|Αλεξανδρούπολη +302552|Ορεστιάδα +302553|Διδυμότειχο +302554|Σουφλί +302555|Φέρες +302556|Κυπρίνος +302591|Χρυσούπολη +302592|Ελευθερούπολη +302593|Θάσος +302594|Νέα Πέραμος Καβάλας +30261|Πάτρα +302621|Πύργος +302622|Αμαλιάδα +302623|Λεχαινά +302624|Αρχαία Ολυμπία +302625|Κρέστενα +302626|Ανδρίτσαινα +302631|Μεσολόγγι +302632|Αιτωλικό +302634|Ναύπακτος +302635|Ματαράγκα +302641|Αγρίνιο +302642|Αμφιλοχία +302643|Βόνιτσα +302644|Θερμό +302645|Λευκάδα +302647|Νέο Χαλκιόπουλο/Φυτείες +302651|Ιωάννινα +302653|Καρυές Ασπραγγέλων +302655|Κόνιτσα/Πέρδικα Δωδώνης +302656|Μέτσοβο +302657|Δελβινάκι +302658|Ζίτσα +302659|Καλέντζι Δωδώνης +302661|Κέρκυρα +302662|Λευκίμμη +302663|Σκριπερό +302664|Φιλιάτες +302665|Ηγουμενίτσα +302666|Παραμυθιά +302671|Αργοστόλι +302674|Σάμη +302681|Άρτα +302682|Πρέβεζα +302683|Φιλιππιάδα +302684|Καναλλάκι +302685|Βουργαρέλι +302691|Αίγιο +302692|Καλάβρυτα +302693|Κάτω Αχαΐα +302694|Χαλανδρίτσα +302695|Ζάκυνθος +302696|Ακράτα +30271|Τρίπολη +302721|Καλαμάτα +302722|Μεσσήνη +302723|Πύλος +302724|Μελιγαλάς +302725|Κορώνη Πυλίας +302731|Σπάρτη +302732|Μολάοι +302733|Γύθειο +302734|Νεάπολη +302735|Σκάλα +302741|Κόρινθος +302742|Κιάτο +302743|Ξυλόκαστρο +302744|Λουτράκι +302746|Νεμέα +302747|Καλιανοί +302751|Άργος +302752|Ναύπλιο +302753|Λυγουριό +302754|Κρανίδι +302755|Άστρος +302757|Λεωνίδιο +302761|Κυπαρισσία +302763|Γαργαλιάνοι +302765|Κοπανάκι +302791|Μεγαλόπολη +302792|Καστρί Κυνουρίας +302795|Βυτίνα +302796|Λεβίδι +302797|Τροπαία +30281|Ηράκλειο +302821|Χανιά +302822|Κίσσαμος +302823|Κάντανος +302824|Κολυμβάρι +302825|Βάμος +302831|Ρέθυμνο +302832|Σπήλι +302833|Αμάρι +302834|Πέραμα Μυλοποτάμου +302841|Άγιος Νικόλαος +302842|Ιεράπετρα +302843|Σητεία +302844|Τζερμιάδο +302891|Αρκαλοχώρι +302892|Μοίρες (Ηρακλειο) +302893|Πύργος (Μονοφάτσι) +302894|Αγία Βαρβάρα (Ηράκλειο Κρήτης) +302895|Άνω Βιάννος +302897|Λιμένας Χερσονήσου diff --git a/resources/geocoding/en/27.txt b/resources/geocoding/en/27.txt new file mode 100644 index 000000000..4274f532c --- /dev/null +++ b/resources/geocoding/en/27.txt @@ -0,0 +1,55 @@ +# Copyright (C) 2011 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. + +# Generated from: +# Internal statistical data (2011-08-05). + +2710|Johannesburg +2711|Johannesburg +2712|Pretoria +2713|Mbombela +2714|Rustenburg +2715|Polokwane +2716|Vereeniging +2717|Ermelo +2718|Klerksdorp +2721|Cape Town +2722|Malmesbury +2723|Worcester +2724|Cape Town +2727|Vredendal +2728|Hermanus +2731|Durban +2732|KwaDukuza +2733|Pietermaritzburg +2734|Newcastle +2735|Richards Bay +2736|Ladysmith +2739|Port Shepstone +2740|Bisho +2741|Port Elizabeth +2742|Jeffrey's Bay +2743|East London +2744|George +2745|Queenstown +2746|Grahamstown +2747|Umtata +2748|Cradock +2749|Graaff-Reinet +2751|Bloemfontein +2753|Kimberley +2754|Upington +2756|Kroonstad +2757|Welkom +2758|Bethlehem diff --git a/resources/geocoding/en/352.txt b/resources/geocoding/en/352.txt new file mode 100644 index 000000000..b58799058 --- /dev/null +++ b/resources/geocoding/en/352.txt @@ -0,0 +1,59 @@ +# Copyright (C) 2011 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. + +# Generated from: +# Internal statistical data (2011-08-08) and translated with Freebase. + +35222|Luxembourg +35223|Mondorf-les-Bains +35224|Luxembourg +35225|Luxembourg +35226|Luxembourg +35227|Luxembourg +35229|Luxembourg +35230|Capellen +35231|Bertrange +35232|Mersch +35233|Walferdange +35234|Senningerberg +35235|Sandweiler +35236|Hesperange +35237|Leudelange +35239|Steinfort +3524|Luxembourg +35250|Bascharage +35251|Dudelange +35252|Dudelange +35253|Esch-sur-Alzette +35254|Esch-sur-Alzette +35255|Esch-sur-Alzette +35256|Rumelange +35257|Esch-sur-Alzette +35258|Differdange +35259|Soleuvre +35271|Betzdorf +35272|Echternach +35274|Wasserbillig +35275|Grevenmacher +35276|Wormeldange +35278|Junglinster +35279|Berdorf +35280|Diekirch +35281|Ettelbruck +35283|Vianden +35287|Larochette +35292|Clervaux +35295|Wiltz +35297|Huldange +35299|Troisvierges diff --git a/resources/geocoding/en/39.txt b/resources/geocoding/en/39.txt index f780589bf..5fcfd661d 100644 --- a/resources/geocoding/en/39.txt +++ b/resources/geocoding/en/39.txt @@ -15,39 +15,13 @@ # Generated from: # http://en.wikipedia.org/wiki/Area_codes_in_Italy [426029162] -3902|Milan -3906|Rome 39010|Genoa 39011|Turin -39015|Biella -39030|Brescia -39031|Como -39035|Bergamo -39039|Monza -39040|Trieste -39041|Venice -39045|Verona -39049|Padova -39050|Pisa -39051|Bologna -39055|Florence -39059|Modena -39070|Cagliari -39071|Ancona -39075|Perugia -39079|Sassari -39080|Bari -39081|Naples -39085|Pescara -39089|Salerno -39090|Messina -39091|Palermo -39095|Catania -39099|Taranto 390122|Turin 390125|Turin 390131|Alessandria 390141|Asti +39015|Biella 390161|Vercelli 390165|Aosta Valley 390166|Aosta Valley @@ -55,6 +29,9 @@ 390183|Imperia 390185|Genoa 390187|La Spezia +3902|Milan +39030|Brescia +39031|Como 390321|Novara 390322|Novara 390324|Verbano-Cusio-Ossola @@ -65,6 +42,7 @@ 390343|Sondrio 390344|Como 390346|Bergamo +39035|Bergamo 390362|Cremona/Monza 390363|Bergamo 390364|Brescia @@ -74,6 +52,9 @@ 390373|Cremona 390376|Mantua 390382|Pavia +39039|Monza +39040|Trieste +39041|Venice 390421|Venice 390422|Treviso 390423|Treviso @@ -83,9 +64,13 @@ 390432|Udine 390444|Vicenza 390445|Vicenza +39045|Verona 390461|Trento 390471|Bolzano/Bozen 390481|Gorizia +39049|Padova +39050|Pisa +39051|Bologna 390521|Parma 390522|Reggio Emilia 390523|Piacenza @@ -94,6 +79,7 @@ 390543|Forlì-Cesena 390545|Ravenna 390549|San Marino +39055|Florence 390565|Livorno 390574|Prato 390575|Arezzo @@ -101,20 +87,29 @@ 390583|Lucca 390585|Massa-Carrara 390586|Livorno +39059|Modena +3906|Rome +39070|Cagliari +39071|Ancona 390731|Ancona 390732|Ancona 390733|Macerata 390734|Fermo 390735|Ascoli Piceno 390737|Macerata +39075|Perugia 390774|Rome 390776|Frosinone 390783|Oristano 390789|Sassari +39079|Sassari +39080|Bari +39081|Naples 390823|Caserta 390824|Benevento 390825|Avellino 390832|Lecce +39085|Pescara 390862|L'Aquila 390865|Isernia 390874|Campobasso @@ -122,6 +117,9 @@ 390882|Foggia 390883|Andria Barletta Trani 390884|Foggia +39089|Salerno +39090|Messina +39091|Palermo 390921|Palermo 390922|Agrigento 390924|Trapani @@ -129,9 +127,11 @@ 390933|Caltanissetta 390934|Caltanissetta and Enna 390942|Catania +39095|Catania 390961|Catanzaro 390962|Crotone 390963|Vibo Valentia 390965|Reggio Calabria 390974|Salerno 390975|Potenza +39099|Taranto diff --git a/resources/geocoding/en/886.txt b/resources/geocoding/en/886.txt index 97f82e26a..7c07ae95d 100644 --- a/resources/geocoding/en/886.txt +++ b/resources/geocoding/en/886.txt @@ -17,14 +17,14 @@ 8862|Taipei 8863|Taoyuan, Hsinchu, Yilan, Hualien +88637|Miaoli 8864|Taichung, Changhua +88649|Nantou 8865|Chiayi, Yunlin 8866|Tainan, Penghu 8867|Kaohsiung 8868|Pingtung -88637|Miaoli -88649|Nantou 88682|Kinmen -88689|Taitung 886826|Wuqiu 886836|Matsu +88689|Taitung diff --git a/resources/geocoding/es/34.txt b/resources/geocoding/es/34.txt index 8e0c1651f..a26034ab5 100644 --- a/resources/geocoding/es/34.txt +++ b/resources/geocoding/es/34.txt @@ -15,8 +15,6 @@ # Generated from: # http://www.mityc.es/telecomunicaciones/es-ES/Servicios/Numeracion/Documents/Presentation_E164_Numbering_Plan_20101118_%20English.pdf [2011-11-18] -3491|Madrid -3493|Barcelona 34810|Madrid 34820|Ávila 34822|Tenerife @@ -43,6 +41,7 @@ 34881|La Coruña 34884|Asturias 34888|Orense +3491|Madrid 34920|Ávila 34922|Tenerife 34923|Salamanca @@ -51,6 +50,7 @@ 34926|Ciudad Real 34927|Cáceres 34928|Las Palmas +3493|Barcelona 34941|La Rioja 34942|Cantabria 34943|Guipúzcoa diff --git a/resources/geocoding/es/54.txt b/resources/geocoding/es/54.txt index 024aaaf01..73515380e 100644 --- a/resources/geocoding/es/54.txt +++ b/resources/geocoding/es/54.txt @@ -18,24 +18,6 @@ 5411|Ciudad Autónoma de Buenos Aires 54220|Merlo 54221|La Plata -54223|Mar del Plata, General Pueyrredón -54237|Moreno -54261|Mendoza, Capital -54264|San Juan, Capital -54291|Bahía Blanca -54297|Comodoro Rivadavia, Escalante -54299|Neuquén, Confluencia -54341|Rosario -54342|Santa Fe, La Capital -54343|Paraná -54345|Concordia, Entre Ríos -54351|Córdoba, Capital -54353|Villa María, General San Martin -54358|Río Cuarto -54381|San Miguel de Tucumán, Capital -54385|Santiago del Estero, Capital -54387|Salta, Capital -54388|San Salvador de Jujuy, Doctor Manuel Belgrano 542221|Verónica, Buenos Aires 542223|Coronel Brandsen 542224|Buenos Aires @@ -43,6 +25,7 @@ 542226|Cañuelas 542227|Lobos 542229|Buenos Aires +54223|Mar del Plata, General Pueyrredón 542241|Buenos Aires 542243|General Belgrano, Buenos Aires 542244|Las Flores @@ -97,6 +80,7 @@ 542356|General Pinto, Buenos Aires 542358|Buenos Aires 542362|Junín, Buenos Aires +54237|Moreno 542392|Buenos Aires 542394|Salliqueló, Buenos Aires 542395|La Matanza @@ -106,15 +90,18 @@ 542475|Rojas, Buenos Aires 542477|Pergamino 542478|Arrecifes, Buenos Aires +54261|Mendoza, Capital 542622|Tunuyán, Mendoza 542623|San Martin 542625|General Alvear, Mendoza 542627|San Rafael +54264|San Juan, Capital 542652|San Luis, La Capital 542656|Merlo, San Luis 542657|Villa Mercedes, General Pedernera 542901|Ushuaia 542902|El Calafate, Lago Argentino +54291|Bahía Blanca 542920|Viedma, Adolfo Alsina 542921|Coronel Dorrego, Buenos Aires 542922|Coronel Pringles, Buenos Aires @@ -140,7 +127,9 @@ 542964|Río Grande 542965|Trelew, Rawson 542966|Río Gallegos, Ger Aike +54297|Comodoro Rivadavia, Escalante 542983|Tres Arroyos +54299|Neuquén, Confluencia 543327|López Camelo, Buenos Aires 543329|Buenos Aires 543382|Rufino, Santa Fe @@ -154,11 +143,15 @@ 543406|San Jorge, Santa Fe 543407|Ramallo 543408|San Cristóbal, Santa Fe +54341|Rosario +54342|Santa Fe, La Capital +54343|Paraná 543442|Concepción del Uruguay, Entre Ríos 543444|Gualeguay, Entre Ríos 543445|Rosario del Tala, Entre Ríos 543446|Gualeguaychú 543447|Colón +54345|Concordia, Entre Ríos 543460|Santa Teresa, Santa Fe 543461|San Nicolás de Los Arroyos, San Nicolás 543462|Venado Tuerto, General López @@ -180,8 +173,10 @@ 543493|Sunchales, Santa Fe 543496|Esperanza, Santa Fe 543498|San Justo, Santa Fe +54351|Córdoba, Capital 543521|Capital 543525|Jesús María, Córdoba +54353|Villa María, General San Martin 543541|Villa Carlos Paz, Córdoba 543543|Córdoba, Capital 543544|Villa Dolores, Córdoba @@ -196,6 +191,7 @@ 543572|Capital 543573|Villa del Rosario, Córdoba 543576|Córdoba +54358|Río Cuarto 543717|Formosa 543718|Clorinda, Formosa 543722|Resistencia, San Fernando @@ -218,11 +214,15 @@ 543775|Monte Caseros, Corrientes 543777|Goya, Corrientes 543783|Corrientes, Capital +54381|San Miguel de Tucumán, Capital 543822|La Rioja, Capital 543825|Chilecito, La Rioja 543833|San Fernando del Valle de Catamarca, Catamarca 543835|Andalgalá, Catamarca 543844|Añatuya, Santiago del Estero +54385|Santiago del Estero, Capital 543863|Monteros, Tucumán 543865|Concepción, Tucumán 543868|Cafayate, Salta +54387|Salta, Capital +54388|San Salvador de Jujuy, Doctor Manuel Belgrano diff --git a/resources/geocoding/fr/33.txt b/resources/geocoding/fr/33.txt index 07287294f..077cc5568 100644 --- a/resources/geocoding/fr/33.txt +++ b/resources/geocoding/fr/33.txt @@ -15,17 +15,6 @@ # Generated from: # Internal statistical data (2011-06-02) -331402|Paris -331434|Paris -331447|Paris -331458|Paris -334910|Marseille -334911|Marseille -334914|Marseille -334915|Marseille -334917|Marseille -334918|Marseille -334938|Nice 3310000|Paris 3313004|Ecquevilly 3313005|Coignières @@ -291,6 +280,7 @@ 3314017|Paris 3314018|Paris 3314019|Paris +331402|Paris 3314030|Paris 3314031|Paris 3314033|Paris @@ -539,6 +529,7 @@ 3314337|Paris 3314338|Paris 3314339|Créteil +331434|Paris 3314350|Sceaux 3314351|Montfermeil 3314352|Aubervilliers @@ -632,6 +623,7 @@ 3314467|Paris 3314468|Paris 3314469|Paris +331447|Paris 3314482|Paris 3314483|Paris 3314484|Paris @@ -721,6 +713,7 @@ 3314577|Paris 3314578|Paris 3314579|Paris +331458|Paris 3314590|Sucy-en-Brie 3314591|Aulnay-sous-Bois 3314592|Noisy-le-Grand @@ -5027,6 +5020,8 @@ 3349096|Arles 3349097|Saintes-Mariés-de-la-Mer 3349098|Arles +334910|Marseille +334911|Marseille 3349121|Marseille 3349122|Marseille 3349123|Marseille @@ -5043,6 +5038,8 @@ 3349135|Marseille 3349136|Marseille 3349137|Marseille +334914|Marseille +334915|Marseille 3349160|Marseille 3349161|Marseille 3349162|Marseille @@ -5053,6 +5050,8 @@ 3349167|Marseille 3349168|Allauch 3349169|Marseille +334917|Marseille +334918|Marseille 3349190|Marseille 3349191|Marseille 3349192|Marseille @@ -5210,6 +5209,7 @@ 3349377|Roquefort-les-Pins 3349378|Beausoleil 3349379|Contes +334938|Nice 3349390|Cannes 3349391|Tourrette-Levens 3349392|Nice diff --git a/resources/geocoding/hu/36.txt b/resources/geocoding/hu/36.txt new file mode 100644 index 000000000..7a2a6060d --- /dev/null +++ b/resources/geocoding/hu/36.txt @@ -0,0 +1,71 @@ +# Copyright (C) 2011 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. + +# Generated from: +# http://en.wikipedia.org/wiki/Telephone_numbers_in_Hungary + +361|Budapest +3622|Székesfehérvár +3623|Biatorbágy +3624|Szigetszentmiklós +3625|Dunaújváros +3626|Szentendre +3627|Vác +3628|Gödöllő +3629|Monor +3632|Salgótarján +3633|Esztergom +3634|Tatabánya +3635|Balassagyarmat +3636|Eger +3637|Gyöngyös +3642|Nyíregyháza +3644|Mátészalka +3645|Kisvárda +3646|Miskolc +3647|Szerencs +3648|Ózd +3649|Mezőkövesd +3652|Debrecen +3653|Cegléd +3654|Berettyóújfalu +3656|Szolnok +3657|Jászberény +3659|Karcag +3662|Szeged +3663|Szentes +3666|Békéscsaba +3668|Orosháza +3669|Mohács +3672|Pécs +3673|Szigetvár +3674|Szekszárd +3675|Paks +3676|Kecskemét +3677|Kiskunhalas +3678|Kiskőrös +3679|Baja +3682|Kaposvár +3683|Keszthely +3684|Siófok +3685|Marcali +3687|Tapolca +3688|Veszprém +3689|Pápa +3692|Zalaegerszeg +3693|Nagykanizsa +3694|Szombathely +3695|Sárvár +3696|Győr +3699|Sopron diff --git a/resources/geocoding/it/39.txt b/resources/geocoding/it/39.txt index 396b590c3..4c0acb467 100644 --- a/resources/geocoding/it/39.txt +++ b/resources/geocoding/it/39.txt @@ -15,36 +15,8 @@ # Generated from: # http://it.wikipedia.org/wiki/Elenco_degli_indicativi_geografici_in_Italia [41442199] -3902|Milano -3906|Roma 39010|Genova 39011|Torino -39015|Biella -39019|Savona -39030|Brescia -39031|Como -39035|Bergamo -39039|Monza -39040|Trieste -39041|Venezia -39045|Verona -39049|Padova -39050|Pisa -39051|Bologna -39055|Firenze -39059|Modena -39070|Cagliari -39071|Ancona -39075|Perugia -39079|Sassari -39080|Bari -39081|Napoli -39085|Pescara -39089|Salerno -39090|Messina -39091|Palermo -39095|Catania -39099|Taranto 390121|Pinerolo 390122|Susa 390123|Lanzo Torinese @@ -55,6 +27,7 @@ 390142|Casale Monferrato 390143|Novi Ligure 390144|Acqui Terme +39015|Biella 390161|Vercelli 390163|Borgosesia 390165|Aosta @@ -69,6 +42,10 @@ 390184|Sanremo 390185|Rapallo 390187|La Spezia +39019|Savona +3902|Milano +39030|Brescia +39031|Como 390321|Novara 390322|Arona 390323|Baveno @@ -81,6 +58,7 @@ 390344|Menaggio 390345|San Pellegrino Terme 390346|Clusone +39035|Bergamo 390362|Seregno 390363|Treviglio 390364|Breno @@ -98,6 +76,9 @@ 390384|Mortara 390385|Stradella 390386|Ostiglia +39039|Monza +39040|Trieste +39041|Venezia 390421|San Donà di Piave 390422|Treviso 390423|Montebelluna @@ -119,6 +100,7 @@ 390442|Legnago 390444|Vicenza 390445|Schio +39045|Verona 390461|Trento 390462|Cavalese 390463|Cles @@ -129,6 +111,9 @@ 390473|Merano 390474|Brunico 390481|Gorizia +39049|Padova +39050|Pisa +39051|Bologna 390521|Parma 390522|Reggio nell'Emilia 390523|Piacenza @@ -147,6 +132,7 @@ 390546|Faenza 390547|Cesena 390549|Repubblica di San Marino +39055|Firenze 390564|Grosseto 390565|Piombino 390566|Follonica @@ -163,6 +149,10 @@ 390586|Livorno 390587|Pontedera 390588|Volterra +39059|Modena +3906|Roma +39070|Cagliari +39071|Ancona 390721|Pesaro 390722|Urbino 390731|Jesi @@ -176,6 +166,7 @@ 390743|Spoleto 390744|Terni 390746|Rieti +39075|Perugia 390761|Viterbo 390763|Orvieto 390765|Poggio Mirteto @@ -191,6 +182,9 @@ 390784|Nuoro 390785|Macomer 390789|Olbia +39079|Sassari +39080|Bari +39081|Napoli 390823|Caserta 390824|Benevento 390825|Avellino @@ -201,6 +195,7 @@ 390833|Gallipoli 390835|Matera 390836|Maglie +39085|Pescara 390861|Teramo 390862|L'Aquila 390863|Avezzano @@ -216,6 +211,9 @@ 390883|Andria 390884|Manfredonia 390885|Cerignola +39089|Salerno +39090|Messina +39091|Palermo 390921|Cefalù 390922|Agrigento 390923|Trapani @@ -228,6 +226,7 @@ 390935|Enna 390941|Patti 390942|Taormina +39095|Catania 390961|Catanzaro 390962|Crotone 390963|Vibo Valentia diff --git a/resources/geocoding/nl/31.txt b/resources/geocoding/nl/31.txt index b35431857..4a24e8fe6 100644 --- a/resources/geocoding/nl/31.txt +++ b/resources/geocoding/nl/31.txt @@ -16,39 +16,13 @@ # Internal statistical data (2011-06-01) 3110|Rotterdam -3113|Tilburg -3115|Delft -3120|Amsterdam -3123|Haarlem -3124|Nijmegen -3126|Arnhem -3130|Utrecht -3133|Amersfoort -3135|Hilversum -3136|Almere -3138|Zwolle -3140|Eindhoven -3143|Maastricht -3145|Heerlen -3146|Sittard -3150|Groningen -3153|Enschede -3155|Apeldoorn -3158|Leeuwarden -3170|Den Haag -3171|Leiden -3172|Alkmaar -3173|'s-Hertogenbosch -3175|Zaandam -3176|Breda -3177|Venlo -3178|Dordrecht -3179|Zoetermeer 31111|Zierikzee 31113|Goes 31114|Hulst 31115|Terneuzen 31118|Middelburg +3113|Tilburg +3115|Delft 31161|Rijen 31164|Bergen op Zoom 31165|Roosendaal @@ -61,17 +35,22 @@ 31183|Gorinchem 31184|Sliedrecht 31186|Oud-Beijerland +3120|Amsterdam 31222|Den Burg 31223|Den Helder 31224|Schagen 31227|Medemblik 31228|Enkhuizen +3123|Haarlem +3124|Nijmegen 31251|Beverwijk 31252|Nieuw-Vennep 31255|IJmuiden +3126|Arnhem 31294|Weesp 31297|Aalsmeer 31299|Purmerend +3130|Utrecht 31313|Dieren 31314|Doetinchem 31316|Zevenaar @@ -79,6 +58,7 @@ 31318|Veenendaal 31320|Lelystad 31321|Dronten +3133|Amersfoort 31341|Harderwijk 31342|Barneveld 31343|Driebergen-Rijsenburg @@ -86,11 +66,18 @@ 31345|Culemborg 31346|Maarssen 31348|Woerden +3135|Hilversum +3136|Almere +3138|Zwolle +3140|Eindhoven 31411|Boxtel 31412|Oss 31413|Uden 31416|Waalwijk 31418|Zaltbommel +3143|Maastricht +3145|Heerlen +3146|Sittard 31475|Roermond 31478|Venray 31487|Druten @@ -98,6 +85,7 @@ 31493|Deurne 31495|Weert 31499|Best +3150|Groningen 31512|Drachten 31513|Heerenveen 31514|Lemmer @@ -112,6 +100,7 @@ 31527|Emmeloord 31528|Hoogeveen 31529|Dalfsen +3153|Enschede 31541|Oldenzaal 31543|Winterswijk 31544|Lichtenvoorde @@ -119,6 +108,7 @@ 31546|Almelo 31547|Goor 31548|Rijssen +3155|Apeldoorn 31561|Wolvega 31562|West-Terschelling 31566|Grou @@ -129,6 +119,7 @@ 31575|Zutphen 31577|Elspeet 31578|Epe +3158|Leeuwarden 31591|Emmen 31592|Assen 31593|Beilen @@ -136,3 +127,12 @@ 31597|Winschoten 31598|Veendam 31599|Stadskanaal +3170|Den Haag +3171|Leiden +3172|Alkmaar +3173|'s-Hertogenbosch +3175|Zaandam +3176|Breda +3177|Venlo +3178|Dordrecht +3179|Zoetermeer diff --git a/resources/geocoding/sv/46.txt b/resources/geocoding/sv/46.txt index f0fe53c6f..0a837a985 100644 --- a/resources/geocoding/sv/46.txt +++ b/resources/geocoding/sv/46.txt @@ -15,31 +15,13 @@ # Generated from: # http://www.pts.se/upload/Ovrigt/Tele/Nummerfragor/Sv_nrplan_telefoni_enl_TU-T_rek_E.164.pdf [2011-02-25] -468|Stockholm 4611|Norrköping -4613|Linköping -4616|Eskilstuna-Torshälla -4618|Uppsala -4619|Örebro-Kumla -4621|Västerås -4626|Gävle-Sandviken -4631|Göteborg -4633|Borås -4635|Halmstad -4636|Jönköping-Huskvarna -4640|Malmö -4642|Helsingborg-Höganäs -4644|Kristianstad -4646|Lund -4654|Karlstad -4660|Sundsval-Timrå -4663|Östersund -4690|Umeå 46120|Åtvidaberg 46121|Söderköping 46122|Finspång 46123|Valdemarsvik 46125|Vikbolandet +4613|Linköping 46140|Tranås 46141|Motala 46142|Mjölby-Skänninge-Boxholm @@ -53,10 +35,14 @@ 46157|Flen-Malmköping 46158|Gnesta 46159|Mariefred +4616|Eskilstuna-Torshälla 46171|Enköping 46174|Alunda 46175|Hallstavik-Rimbo 46176|Norrtälje +4618|Uppsala +4619|Örebro-Kumla +4621|Västerås 46220|Hallstahammar-Surahammar 46221|Köping 46222|Skinnskatteberg @@ -73,6 +59,7 @@ 46250|Mora-Orsa 46251|Älvdalen 46253|Idre-Särna +4626|Gävle-Sandviken 46270|Söderhamn 46271|Alfta-Edsbyn 46278|Bollnäs @@ -88,13 +75,17 @@ 46300|Kungsbacka 46301|Hindås 46303|Kungälv +4631|Göteborg 46320|Kinna 46321|Ulricehamn 46322|Alingsås-Vårgårda 46325|Svenljunga-Tranemo +4633|Borås 46340|Varberg 46345|Hyltebruk-Torup 46346|Falkenberg +4635|Halmstad +4636|Jönköping-Huskvarna 46370|Värnamo 46371|Gislaved-Anderstorp 46372|Ljungby @@ -105,6 +96,7 @@ 46390|Gränna 46392|Mullsjö 46393|Vaggeryd +4640|Malmö 46410|Trelleborg 46411|Ystad 46413|Eslöv-Höör @@ -113,16 +105,19 @@ 46416|Sjöbo 46417|Tomelilla 46418|Landskrona-Svalöv +4642|Helsingborg-Höganäs 46430|Laholm 46431|Ängelholm-Båstad 46433|Markaryd-Strömsnäsbruk 46435|Klippan-Perstorp +4644|Kristianstad 46451|Hässleholm 46454|Karlshamn-Olofström 46455|Karlskrona 46456|Sölvesborg-Bromölla 46457|Ronneby 46459|Ryd +4646|Lund 46470|Växjö 46471|Emmaboda 46472|Alvesta-Rydaholm @@ -168,6 +163,7 @@ 46532|Åmål 46533|Säffle 46534|Ed +4654|Karlstad 46550|Kristinehamn 46551|Gullspång 46552|Deje @@ -190,6 +186,7 @@ 46589|Arboga 46590|Filipstad 46591|Hällefors-Grythyttan +4660|Sundsval-Timrå 46611|Härnösand 46612|Kramfors 46613|Ullånger @@ -198,6 +195,7 @@ 46622|Näsåker 46623|Ramsele 46624|Backe +4663|Östersund 46640|Krokom 46642|Lit 46643|Hallen-Oviken @@ -225,6 +223,8 @@ 46692|Liden 46693|Bräcke-Gällö 46696|Hammarstrand +468|Stockholm +4690|Umeå 46910|Skellefteå 46911|Piteå 46912|Byske diff --git a/resources/geocoding/zh/886.txt b/resources/geocoding/zh/886.txt index 47e4a3670..198cb8216 100644 --- a/resources/geocoding/zh/886.txt +++ b/resources/geocoding/zh/886.txt @@ -17,14 +17,14 @@ 8862|台北 8863|桃园、新竹、花莲、宜兰 +88637|苗栗 8864|台中、彰化 +88649|南投 8865|嘉义、云林 8866|台南、澎湖 8867|高雄 8868|屏东 -88637|苗栗 -88649|南投 88682|金门 -88689|台东 886826|乌丘 886836|马祖 +88689|台东 diff --git a/resources/geocoding/zh_Hant/886.txt b/resources/geocoding/zh_Hant/886.txt index f62cfbad1..672fe48a8 100644 --- a/resources/geocoding/zh_Hant/886.txt +++ b/resources/geocoding/zh_Hant/886.txt @@ -17,14 +17,14 @@ 8862|臺北 8863|桃園、新竹、花蓮、宜蘭 +88637|苗栗 8864|臺中、彰化 +88649|南投 8865|嘉義、雲林 8866|臺南、澎湖 8867|高雄 8868|屏東 -88637|苗栗 -88649|南投 88682|金門 -88689|臺東 886826|烏坵 886836|馬祖 +88689|臺東 diff --git a/resources/test/geocoding/en/1.txt b/resources/test/geocoding/en/1.txt index 642efaad6..cd3604ca8 100644 --- a/resources/test/geocoding/en/1.txt +++ b/resources/test/geocoding/en/1.txt @@ -14,8 +14,8 @@ 1201|NJ 1212|NY -1650|CA -1989|MA 1212812|New York, NY 1617423|Boston, MA +1650|CA 1650960|Mountain View, CA +1989|MA diff --git a/tools/java/cpp-build/target/cpp-build-1.0-SNAPSHOT-jar-with-dependencies.jar b/tools/java/cpp-build/target/cpp-build-1.0-SNAPSHOT-jar-with-dependencies.jar index c727b9960..429c22213 100644 Binary files a/tools/java/cpp-build/target/cpp-build-1.0-SNAPSHOT-jar-with-dependencies.jar and b/tools/java/cpp-build/target/cpp-build-1.0-SNAPSHOT-jar-with-dependencies.jar differ diff --git a/tools/java/java-build/src/com/google/i18n/phonenumbers/tools/GenerateAreaCodeData.java b/tools/java/java-build/src/com/google/i18n/phonenumbers/tools/GenerateAreaCodeData.java index a5effcf11..11e65c4a6 100644 --- a/tools/java/java-build/src/com/google/i18n/phonenumbers/tools/GenerateAreaCodeData.java +++ b/tools/java/java-build/src/com/google/i18n/phonenumbers/tools/GenerateAreaCodeData.java @@ -68,8 +68,7 @@ public class GenerateAreaCodeData extends Command { outputPath = null; } - public GenerateAreaCodeData(File inputPath, File outputPath) - throws IOException { + public GenerateAreaCodeData(File inputPath, File outputPath) throws IOException { if (!inputPath.isDirectory()) { throw new IOException("The provided input path does not exist: " + inputPath.getAbsolutePath()); @@ -104,11 +103,10 @@ public class GenerateAreaCodeData extends Command { /** * Converts the text data read from the provided input stream to the Java binary serialization * format. The resulting data is written to the provided output stream. - * - * @VisibleForTesting */ + // @VisibleForTesting static void convertData( - InputStream input, OutputStream output, int countryCallingCode) throws IOException { + InputStream input, OutputStream output) throws IOException { SortedMap areaCodeMapTemp = new TreeMap(); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader( @@ -135,7 +133,7 @@ public class GenerateAreaCodeData extends Command { } } // Build the corresponding area code map and serialize it to the binary format. - AreaCodeMap areaCodeMap = new AreaCodeMap(countryCallingCode); + AreaCodeMap areaCodeMap = new AreaCodeMap(); areaCodeMap.readAreaCodeMap(areaCodeMapTemp); ObjectOutputStream objectOutputStream = new ObjectOutputStream(output); areaCodeMap.writeExternal(objectOutputStream); @@ -194,11 +192,10 @@ public class GenerateAreaCodeData extends Command { * Adds a country code/language mapping to the provided map. The country code and language are * generated from the provided file name previously used to output the area code/location mappings * for the given country. - * - * @VisibleForTesting */ - static int addConfigurationMapping(SortedMap> availableDataFiles, - File outputAreaCodeMappingsFile) { + // @VisibleForTesting + static void addConfigurationMapping(SortedMap> availableDataFiles, + File outputAreaCodeMappingsFile) { String outputAreaCodeMappingsFileName = outputAreaCodeMappingsFile.getName(); int indexOfUnderscore = outputAreaCodeMappingsFileName.indexOf('_'); int countryCode = Integer.parseInt( @@ -211,14 +208,12 @@ public class GenerateAreaCodeData extends Command { availableDataFiles.put(countryCode, languageSet); } languageSet.add(language); - return countryCode; } /** * Outputs the binary configuration file mapping country codes to language strings. - * - * @VisibleForTesting */ + // @VisibleForTesting static void outputBinaryConfiguration(SortedMap> availableDataFiles, OutputStream outputStream) throws IOException { MappingFileProvider mappingFileProvider = new MappingFileProvider(); @@ -234,7 +229,7 @@ public class GenerateAreaCodeData extends Command { * @throws IOException * @throws FileNotFoundException */ - public void run() throws FileNotFoundException, IOException { + public void run() throws IOException { List> inputOutputMappings = createInputOutputFileMappings(); SortedMap> availableDataFiles = new TreeMap>(); @@ -247,12 +242,14 @@ public class GenerateAreaCodeData extends Command { File binaryFile = inputOutputMapping.second; fileInputStream = new FileInputStream(textFile); fileOutputStream = new FileOutputStream(binaryFile); - int countryCallingCode = - addConfigurationMapping(availableDataFiles, inputOutputMapping.second); - convertData(fileInputStream, fileOutputStream, countryCallingCode); + convertData(fileInputStream, fileOutputStream); + addConfigurationMapping(availableDataFiles, inputOutputMapping.second); + } catch (RuntimeException e) { + LOGGER.log(Level.SEVERE, + "Error processing file " + inputOutputMapping.first.getAbsolutePath()); + throw e; } catch (IOException e) { LOGGER.log(Level.SEVERE, e.getMessage()); - continue; } finally { closeFile(fileInputStream); closeFile(fileOutputStream); diff --git a/tools/java/java-build/target/java-build-1.0-SNAPSHOT-jar-with-dependencies.jar b/tools/java/java-build/target/java-build-1.0-SNAPSHOT-jar-with-dependencies.jar index 0e38e71f4..423e861bf 100644 Binary files a/tools/java/java-build/target/java-build-1.0-SNAPSHOT-jar-with-dependencies.jar and b/tools/java/java-build/target/java-build-1.0-SNAPSHOT-jar-with-dependencies.jar differ diff --git a/tools/java/java-build/test/com/google/i18n/phonenumbers/tools/GenerateAreaCodeDataTest.java b/tools/java/java-build/test/com/google/i18n/phonenumbers/tools/GenerateAreaCodeDataTest.java index 49d2eec20..43a283c78 100644 --- a/tools/java/java-build/test/com/google/i18n/phonenumbers/tools/GenerateAreaCodeDataTest.java +++ b/tools/java/java-build/test/com/google/i18n/phonenumbers/tools/GenerateAreaCodeDataTest.java @@ -84,15 +84,14 @@ public class GenerateAreaCodeDataTest extends TestCase { assertEquals("1|en,en_US,es,\n33|en,fr,\n86|zh_Hans,\n", mappingFileProvider.toString()); } - private static String convertData(String input, int countryCallingCode) throws IOException { + private static String convertData(String input) throws IOException { ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(input.getBytes()); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - GenerateAreaCodeData.convertData( - byteArrayInputStream, byteArrayOutputStream, countryCallingCode); + GenerateAreaCodeData.convertData(byteArrayInputStream, byteArrayOutputStream); // The byte array output stream now contains the corresponding serialized area code map. Try // to deserialize it and compare it with the initial input. - AreaCodeMap areaCodeMap = new AreaCodeMap(countryCallingCode); + AreaCodeMap areaCodeMap = new AreaCodeMap(); areaCodeMap.readExternal( new ObjectInputStream(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()))); @@ -102,16 +101,16 @@ public class GenerateAreaCodeDataTest extends TestCase { public void testConvertData() throws IOException { String input = "331|Paris\n334|Marseilles\n"; - String dataAfterDeserialization = convertData(input, 33); + String dataAfterDeserialization = convertData(input); assertEquals(input, dataAfterDeserialization); // Make sure convertData() ignores comments. - dataAfterDeserialization = convertData(" # Comment.\n" + input, 33); + dataAfterDeserialization = convertData(" # Comment.\n" + input); assertEquals(input, dataAfterDeserialization); // Make sure convertData() ignores blank lines. - dataAfterDeserialization = convertData("\n" + input, 33); + dataAfterDeserialization = convertData("\n" + input); assertEquals(input, dataAfterDeserialization); // Make sure convertData() ignores trailing white spaces. - dataAfterDeserialization = convertData(" \n" + input, 33); + dataAfterDeserialization = convertData(" \n" + input); assertEquals(input, dataAfterDeserialization); } @@ -119,7 +118,7 @@ public class GenerateAreaCodeDataTest extends TestCase { String input = "331"; try { - convertData(input, 33); + convertData(input); fail(); } catch (RuntimeException e) { // Expected. @@ -130,7 +129,7 @@ public class GenerateAreaCodeDataTest extends TestCase { String input = "331|"; try { - convertData(input, 33); + convertData(input); fail(); } catch (RuntimeException e) { // Expected. @@ -141,7 +140,7 @@ public class GenerateAreaCodeDataTest extends TestCase { String input = "331|Paris\n331|Marseilles\n"; try { - convertData(input, 33); + convertData(input); fail(); } catch (RuntimeException e) { // Expected.