Browse Source

CPP: libphonenumber 4.2.

Review URL: http://codereview.appspot.com/5372051
pull/567/head
Philippe Liard 14 years ago
committed by Mihaela Rosca
parent
commit
39890054ff
12 changed files with 19889 additions and 19305 deletions
  1. +1
    -1
      cpp/CMakeLists.txt
  2. +9195
    -9002
      cpp/src/phonenumbers/lite_metadata.cc
  3. +9844
    -9608
      cpp/src/phonenumbers/metadata.cc
  4. +71
    -5
      cpp/src/phonenumbers/phonenumbermatcher.cc
  5. +10
    -2
      cpp/src/phonenumbers/phonenumbermatcher.h
  6. +122
    -98
      cpp/src/phonenumbers/phonenumberutil.cc
  7. +29
    -8
      cpp/src/phonenumbers/phonenumberutil.h
  8. +588
    -579
      cpp/src/phonenumbers/test_metadata.cc
  9. +6
    -2
      cpp/test/phonenumbers/phonenumbermatcher_test.cc
  10. +12
    -0
      cpp/test/phonenumbers/phonenumberutil_test.cc
  11. +5
    -0
      cpp/test/phonenumbers/test_util.h
  12. +6
    -0
      debian/changelog

+ 1
- 1
cpp/CMakeLists.txt View File

@ -18,7 +18,7 @@ cmake_minimum_required (VERSION 2.8)
project (libphonenumber)
set (libphonenumber_VERSION_MAJOR 4)
set (libphonenumber_VERSION_MINOR 1)
set (libphonenumber_VERSION_MINOR 2)
# Helper functions dealing with finding libraries and programs this library
# depends on.


+ 9195
- 9002
cpp/src/phonenumbers/lite_metadata.cc
File diff suppressed because it is too large
View File


+ 9844
- 9608
cpp/src/phonenumbers/metadata.cc
File diff suppressed because it is too large
View File


+ 71
- 5
cpp/src/phonenumbers/phonenumbermatcher.cc View File

@ -38,6 +38,7 @@
#include "phonenumbers/default_logger.h"
#include "phonenumbers/encoding_utils.h"
#include "phonenumbers/normalize_utf8.h"
#include "phonenumbers/phonemetadata.pb.h"
#include "phonenumbers/phonenumber.pb.h"
#include "phonenumbers/phonenumbermatch.h"
#include "phonenumbers/phonenumberutil.h"
@ -359,13 +360,20 @@ bool PhoneNumberMatcher::ParseAndVerify(const string& candidate, int offset,
}
PhoneNumber number;
if (phone_util_.Parse(candidate, preferred_region_, &number) !=
if (phone_util_.ParseAndKeepRawInput(candidate, preferred_region_, &number) !=
PhoneNumberUtil::NO_PARSING_ERROR) {
return false;
}
if (VerifyAccordingToLeniency(leniency_, number, candidate)) {
match->set_start(offset);
match->set_raw_string(candidate);
// We used ParseAndKeepRawInput to create this number, but for now we don't
// return the extra values parsed. TODO: stop clearing all values here and
// switch all users over to using raw_input() rather than the raw_string()
// of PhoneNumberMatch.
number.clear_country_code_source();
number.clear_preferred_domestic_carrier_code();
number.clear_raw_input();
match->set_number(number);
return true;
}
@ -381,15 +389,17 @@ bool PhoneNumberMatcher::VerifyAccordingToLeniency(
case PhoneNumberMatcher::POSSIBLE:
return phone_util_.IsPossibleNumber(number);
case PhoneNumberMatcher::VALID:
if (!phone_util_.IsValidNumber(number)) {
if (!phone_util_.IsValidNumber(number) ||
!ContainsOnlyValidXChars(number, candidate, phone_util_)) {
return false;
}
return ContainsOnlyValidXChars(number, candidate, phone_util_);
return IsNationalPrefixPresentIfRequired(number);
case PhoneNumberMatcher::STRICT_GROUPING: {
if (!phone_util_.IsValidNumber(number) ||
!ContainsOnlyValidXChars(number, candidate, phone_util_) ||
// Two or more slashes were present.
FindNth(candidate, '/', 2) != string::npos) {
(FindNth(candidate, '/', 2) != string::npos) ||
!IsNationalPrefixPresentIfRequired(number)) {
return false;
}
// TODO(lararennie,shaopengjia): Evaluate how this works for other locales
@ -440,7 +450,8 @@ bool PhoneNumberMatcher::VerifyAccordingToLeniency(
if (!phone_util_.IsValidNumber(number) ||
!ContainsOnlyValidXChars(number, candidate, phone_util_) ||
// Two or more slashes were present.
FindNth(candidate, '/', 2) != string::npos) {
(FindNth(candidate, '/', 2) != string::npos) ||
!IsNationalPrefixPresentIfRequired(number)) {
return false;
}
// TODO(lararennie,shaopengjia): Evaluate how this works for other locales
@ -626,5 +637,60 @@ bool PhoneNumberMatcher::Find(int index, PhoneNumberMatch* match) {
return false;
}
bool PhoneNumberMatcher::IsNationalPrefixPresentIfRequired(
const PhoneNumber& number) const {
// First, check how we deduced the country code. If it was written in
// international format, then the national prefix is not required.
if (number.country_code_source() != PhoneNumber::FROM_DEFAULT_COUNTRY) {
return true;
}
string phone_number_region;
phone_util_.GetRegionCodeForCountryCode(
number.country_code(), &phone_number_region);
const PhoneMetadata* metadata =
phone_util_.GetMetadataForRegion(phone_number_region);
if (!metadata) {
return true;
}
// Check if a national prefix should be present when formatting this number.
string national_number;
phone_util_.GetNationalSignificantNumber(number, &national_number);
const NumberFormat* format_rule =
phone_util_.ChooseFormattingPatternForNumber(metadata->number_format(),
national_number,
national_number);
// To do this, we check that a national prefix formatting rule was present and
// that it wasn't just the first-group symbol ($1) with punctuation.
if (format_rule && !format_rule->national_prefix_formatting_rule().empty()) {
if (format_rule->national_prefix_optional_when_formatting()) {
// The national-prefix is optional in these cases, so we don't need to
// check if it was present.
return true;
}
// Remove the first-group symbol.
string candidate_national_prefix_rule(
format_rule->national_prefix_formatting_rule());
// We assume that the first-group symbol will never be _before_ the national
// prefix.
candidate_national_prefix_rule.erase(
candidate_national_prefix_rule.find("$1"));
phone_util_.NormalizeDigitsOnly(&candidate_national_prefix_rule);
if (candidate_national_prefix_rule.empty()) {
// National Prefix not needed for this number.
return true;
}
// Normalize the remainder.
string raw_input_copy(number.raw_input());
// Check if we found a national prefix and/or carrier code at the start of
// the raw input, and return the result.
phone_util_.NormalizeDigitsOnly(&raw_input_copy);
return phone_util_.MaybeStripNationalPrefixAndCarrierCode(
*metadata,
&raw_input_copy,
NULL); // Don't need to keep the stripped carrier code.
}
return true;
}
} // namespace phonenumbers
} // namespace i18n

+ 10
- 2
cpp/src/phonenumbers/phonenumbermatcher.h View File

@ -53,8 +53,10 @@ class PhoneNumberMatcher {
// 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 and the next level might result in lower coverage
// especially for regions outside of country code "+1".
// Warning: The next two levels might result in lower coverage especially
// for regions outside of country code "+1". If you are not sure about which
// level to use, you can send an e-mail to the discussion group
// http://groups.google.com/group/libphonenumber-discuss/
STRICT_GROUPING,
// Phone numbers accepted are valid and are grouped in the same way that we
// would have formatted it, or as a single block. For example, a US number
@ -96,6 +98,12 @@ class PhoneNumberMatcher {
// start index of the candidate string within the overall text.
bool Find(int index, PhoneNumberMatch* match);
// Checks a number was formatted with a national prefix, if the number was
// found in national format, and a national prefix is required for that
// number. Returns false if the number needed to have a national prefix and
// none was found.
bool IsNationalPrefixPresentIfRequired(const PhoneNumber& number) const;
// Attempts to extract a match from candidate. Returns true if the match was
// found, otherwise returns false.
bool ExtractMatch(const string& candidate, int offset,


+ 122
- 98
cpp/src/phonenumbers/phonenumberutil.cc View File

@ -269,83 +269,6 @@ void FormatNumberByFormat(int country_calling_code,
}
}
// The number_for_leading_digits_match is a separate parameter, because for
// alpha numbers we want to pass in the numeric version to select the right
// formatting rule, but then we actually apply the formatting pattern to the
// national_number (which in this case has alpha characters in it).
//
// Note that carrier_code is optional - if an empty string, no carrier code
// replacement will take place.
void FormatAccordingToFormatsWithCarrier(
const string& number_for_leading_digits_match,
const RepeatedPtrField<NumberFormat>& available_formats,
PhoneNumberUtil::PhoneNumberFormat number_format,
const string& national_number,
const string& carrier_code,
string* formatted_number) {
DCHECK(formatted_number);
for (RepeatedPtrField<NumberFormat>::const_iterator
it = available_formats.begin(); it != available_formats.end(); ++it) {
int size = it->leading_digits_pattern_size();
if (size > 0) {
const scoped_ptr<RegExpInput> number_copy(
regexp_factory->CreateInput(number_for_leading_digits_match));
// We always use the last leading_digits_pattern, as it is the most
// detailed.
if (!regexp_cache->GetRegExp(it->leading_digits_pattern(size - 1))
.Consume(number_copy.get())) {
continue;
}
}
const RegExp& pattern_to_match(regexp_cache->GetRegExp(it->pattern()));
if (pattern_to_match.FullMatch(national_number)) {
string formatting_pattern(it->format());
if (number_format == PhoneNumberUtil::NATIONAL &&
carrier_code.length() > 0 &&
it->domestic_carrier_code_formatting_rule().length() > 0) {
// Replace the $CC in the formatting rule with the desired carrier code.
string carrier_code_formatting_rule =
it->domestic_carrier_code_formatting_rule();
carrier_code_pattern->Replace(&carrier_code_formatting_rule,
carrier_code);
first_group_capturing_pattern->Replace(&formatting_pattern,
carrier_code_formatting_rule);
} else {
// Use the national prefix formatting rule instead.
string national_prefix_formatting_rule =
it->national_prefix_formatting_rule();
if (number_format == PhoneNumberUtil::NATIONAL &&
national_prefix_formatting_rule.length() > 0) {
// Apply the national_prefix_formatting_rule as the formatting_pattern
// contains only information on how the national significant number
// should be formatted at this point.
first_group_capturing_pattern->Replace(
&formatting_pattern, national_prefix_formatting_rule);
}
}
formatted_number->assign(national_number);
pattern_to_match.GlobalReplace(formatted_number, formatting_pattern);
return;
}
}
// If no pattern above is matched, we format the number as a whole.
formatted_number->assign(national_number);
}
// Simple wrapper of FormatAccordingToFormatsWithCarrier for the common case of
// no carrier code.
void FormatAccordingToFormats(
const string& number_for_leading_digits_match,
const RepeatedPtrField<NumberFormat>& available_formats,
PhoneNumberUtil::PhoneNumberFormat number_format,
const string& national_number,
string* formatted_number) {
DCHECK(formatted_number);
FormatAccordingToFormatsWithCarrier(number_for_leading_digits_match,
available_formats, number_format,
national_number, "", formatted_number);
}
// Returns true when one national number is the suffix of the other or both are
// the same.
bool IsNationalNumberSuffixOfTheOther(const PhoneNumber& first_number,
@ -691,6 +614,15 @@ PhoneNumberUtil::~PhoneNumberUtil() {
country_calling_code_to_region_code_map_->end());
}
void PhoneNumberUtil::GetSupportedRegions(set<string>* regions) const {
DCHECK(regions);
for (map<string, PhoneMetadata>::const_iterator it =
region_to_metadata_map_->begin(); it != region_to_metadata_map_->end();
++it) {
regions->insert(it->first);
}
}
// Public wrapper function to get a PhoneNumberUtil instance with the default
// metadata file.
// static
@ -790,15 +722,6 @@ bool PhoneNumberUtil::IsFormatEligibleForAsYouTypeFormatter(
return eligible_format_pattern.FullMatch(format);
}
void PhoneNumberUtil::GetSupportedRegions(set<string>* regions) const {
DCHECK(regions);
for (map<string, PhoneMetadata>::const_iterator it =
region_to_metadata_map_->begin(); it != region_to_metadata_map_->end();
++it) {
regions->insert(it->first);
}
}
void PhoneNumberUtil::GetNddPrefixForRegion(const string& region_code,
bool strip_non_digits,
string* national_prefix) const {
@ -997,7 +920,7 @@ void PhoneNumberUtil::FormatNumberForMobileDialing(
bool with_formatting,
string* formatted_number) const {
string region_code;
GetRegionCodeForNumber(number, &region_code);
GetRegionCodeForCountryCode(number.country_code(), &region_code);
if (!IsValidRegionCode(region_code)) {
formatted_number->assign(number.has_raw_input() ? number.raw_input() : "");
return;
@ -1008,12 +931,17 @@ void PhoneNumberUtil::FormatNumberForMobileDialing(
PhoneNumber number_no_extension(number);
number_no_extension.clear_extension();
PhoneNumberType number_type = GetNumberType(number_no_extension);
if ((region_code == "CO") && (calling_from == "CO") &&
(number_type == FIXED_LINE)) {
if ((region_code == "CO") && (calling_from == "CO")) {
if (number_type == FIXED_LINE) {
FormatNationalNumberWithCarrierCode(
number_no_extension, kColombiaMobileToFixedLinePrefix,
formatted_number);
} else if ((region_code == "BR") && (calling_from == "BR") &&
} else {
// E164 doesn't work at all when dialing within Colombia.
Format(number_no_extension, NATIONAL, formatted_number);
}
} else if ((region_code == "BR") &&
(calling_from == "BR") &&
((number_type == FIXED_LINE) || (number_type == MOBILE) ||
(number_type == FIXED_LINE_OR_MOBILE))) {
if (number_no_extension.has_preferred_domestic_carrier_code()) {
@ -1047,8 +975,9 @@ void PhoneNumberUtil::FormatOutOfCountryCallingNumber(
string* formatted_number) const {
DCHECK(formatted_number);
if (!IsValidRegionCode(calling_from)) {
VLOG(1) << "Trying to format number from invalid region. International"
<< " formatting applied.";
VLOG(1) << "Trying to format number from invalid region "
<< calling_from
<< ". International formatting applied.";
Format(number, INTERNATIONAL, formatted_number);
return;
}
@ -1229,6 +1158,98 @@ void PhoneNumberUtil::FormatOutOfCountryKeepingAlphaChars(
}
}
const NumberFormat* PhoneNumberUtil::ChooseFormattingPatternForNumber(
const RepeatedPtrField<NumberFormat>& available_formats,
const string& number_for_leading_digits_match,
const string& national_number) const {
for (RepeatedPtrField<NumberFormat>::const_iterator
it = available_formats.begin(); it != available_formats.end(); ++it) {
int size = it->leading_digits_pattern_size();
if (size > 0) {
const scoped_ptr<RegExpInput> number_copy(
regexp_factory->CreateInput(number_for_leading_digits_match));
// We always use the last leading_digits_pattern, as it is the most
// detailed.
if (!regexp_cache->GetRegExp(it->leading_digits_pattern(size - 1))
.Consume(number_copy.get())) {
continue;
}
}
const RegExp& pattern_to_match(regexp_cache->GetRegExp(it->pattern()));
if (pattern_to_match.FullMatch(national_number)) {
return &(*it);
}
}
return NULL;
}
// The number_for_leading_digits_match is a separate parameter, because for
// alpha numbers we want to pass in the numeric version to select the right
// formatting rule, but then we actually apply the formatting pattern to the
// national_number (which in this case has alpha characters in it).
//
// Note that carrier_code is optional - if an empty string, no carrier code
// replacement will take place.
void PhoneNumberUtil::FormatAccordingToFormatsWithCarrier(
const string& number_for_leading_digits_match,
const RepeatedPtrField<NumberFormat>& available_formats,
PhoneNumberUtil::PhoneNumberFormat number_format,
const string& national_number,
const string& carrier_code,
string* formatted_number) const {
DCHECK(formatted_number);
const NumberFormat* format = ChooseFormattingPatternForNumber(
available_formats,
number_for_leading_digits_match,
national_number);
if (!format) {
// If no pattern above is matched, we format the number as a whole.
formatted_number->assign(national_number);
return;
}
string formatting_pattern(format->format());
if (number_format == PhoneNumberUtil::NATIONAL &&
carrier_code.length() > 0 &&
format->domestic_carrier_code_formatting_rule().length() > 0) {
// Replace the $CC in the formatting rule with the desired carrier code.
string carrier_code_formatting_rule =
format->domestic_carrier_code_formatting_rule();
carrier_code_pattern->Replace(&carrier_code_formatting_rule,
carrier_code);
first_group_capturing_pattern->Replace(&formatting_pattern,
carrier_code_formatting_rule);
} else {
// Use the national prefix formatting rule instead.
string national_prefix_formatting_rule =
format->national_prefix_formatting_rule();
if (number_format == PhoneNumberUtil::NATIONAL &&
national_prefix_formatting_rule.length() > 0) {
// Apply the national_prefix_formatting_rule as the formatting_pattern
// contains only information on how the national significant number
// should be formatted at this point.
first_group_capturing_pattern->Replace(
&formatting_pattern, national_prefix_formatting_rule);
}
}
formatted_number->assign(national_number);
const RegExp& pattern_to_match(regexp_cache->GetRegExp(format->pattern()));
pattern_to_match.GlobalReplace(formatted_number, formatting_pattern);
}
// Simple wrapper of FormatAccordingToFormatsWithCarrier for the common case of
// no carrier code.
void PhoneNumberUtil::FormatAccordingToFormats(
const string& number_for_leading_digits_match,
const RepeatedPtrField<NumberFormat>& available_formats,
PhoneNumberUtil::PhoneNumberFormat number_format,
const string& national_number,
string* formatted_number) const {
DCHECK(formatted_number);
FormatAccordingToFormatsWithCarrier(number_for_leading_digits_match,
available_formats, number_format,
national_number, "", formatted_number);
}
void PhoneNumberUtil::FormatNationalNumber(
const string& number,
const string& region_code,
@ -1794,7 +1815,7 @@ int PhoneNumberUtil::GetLengthOfNationalDestinationCode(
}
}
string region_code;
GetRegionCodeForNumber(number, &region_code);
GetRegionCodeForCountryCode(number.country_code(), &region_code);
if (region_code == "AR" &&
GetNumberType(number) == MOBILE) {
// Argentinian mobile numbers, when formatted in the international format,
@ -1930,8 +1951,9 @@ PhoneNumberUtil::MaybeStripInternationalPrefixAndNormalize(
// Strips any national prefix (such as 0, 1) present in the number provided.
// The number passed in should be the normalized telephone number that we wish
// to strip any national dialing prefix from. The metadata should be for the
// region that we think this number is from.
void PhoneNumberUtil::MaybeStripNationalPrefixAndCarrierCode(
// region that we think this number is from. Returns true if a national prefix
// and/or carrier code was stripped.
bool PhoneNumberUtil::MaybeStripNationalPrefixAndCarrierCode(
const PhoneMetadata& metadata,
string* number,
string* carrier_code) const {
@ -1942,7 +1964,7 @@ void PhoneNumberUtil::MaybeStripNationalPrefixAndCarrierCode(
if (number->empty() || possible_national_prefix.empty()) {
// Early return for numbers of zero length or with no national prefix
// possible.
return;
return false;
}
// We use two copies here since Consume modifies the phone number, and if the
// first if-clause fails the number will already be changed.
@ -1975,7 +1997,7 @@ void PhoneNumberUtil::MaybeStripNationalPrefixAndCarrierCode(
transform_rule);
if (is_viable_original_number &&
!national_number_rule.FullMatch(number_string_copy)) {
return;
return false;
}
number->assign(number_string_copy);
if (carrier_code) {
@ -1993,15 +2015,17 @@ void PhoneNumberUtil::MaybeStripNationalPrefixAndCarrierCode(
number_copy_without_transform->ToString();
if (is_viable_original_number &&
!national_number_rule.FullMatch(number_copy_as_string)) {
return;
return false;
}
number->assign(number_copy_as_string);
if (carrier_code) {
carrier_code->assign(carrier_code_temp);
}
} else {
return false;
VLOG(4) << "The first digits did not match the national prefix.";
}
return true;
}
// Strips any extension (as in, the part of the number dialled after the call is


+ 29
- 8
cpp/src/phonenumbers/phonenumberutil.h View File

@ -147,6 +147,10 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> {
TOO_LONG,
};
// Convenience method to get a list of what regions the library has metadata
// for.
void GetSupportedRegions(set<string>* regions) const;
// Gets a PhoneNumberUtil instance to carry out international phone number
// formatting, parsing, or validation. The instance is loaded with phone
// number metadata for a number of most commonly used regions, as specified by
@ -201,8 +205,8 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> {
//
// int area_code_length = phone_util.GetLengthOfGeographicalAreaCode(number);
// if (area_code_length > 0) {
// area_code = national_significant_number.substring(0, area_code_length);
// subscriber_number = national_significant_number.substring(
// area_code = national_significant_number.substr(0, area_code_length);
// subscriber_number = national_significant_number.substr(
// area_code_length, string::npos);
// else {
// area_code = "";
@ -244,9 +248,9 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> {
// int national_destination_code_length =
// phone_util.GetLengthOfGeographicalAreaCode(number);
// if (national_destination_code_length > 0) {
// national_destination_code = national_significant_number.substring(
// national_destination_code = national_significant_number.substr(
// 0, national_destination_code_length);
// subscriber_number = national_significant_number.substring(
// subscriber_number = national_significant_number.substr(
// national_destination_code_length, string::npos);
// else {
// national_destination_code = "";
@ -604,9 +608,6 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> {
// Trims unwanted end characters from a phone number string.
void TrimUnwantedEndChars(string* number) const;
// Gets all the supported regions.
void GetSupportedRegions(set<string>* regions) const;
// Helper function to check region code is not unknown or null.
bool IsValidRegionCode(const string& region_code) const;
@ -624,6 +625,26 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> {
int country_calling_code,
list<string>* region_codes) const;
const NumberFormat* ChooseFormattingPatternForNumber(
const RepeatedPtrField<NumberFormat>& available_formats,
const string& number_for_leading_digits_match,
const string& national_number) const;
void FormatAccordingToFormatsWithCarrier(
const string& number_for_leading_digits_match,
const RepeatedPtrField<NumberFormat>& available_formats,
PhoneNumberUtil::PhoneNumberFormat number_format,
const string& national_number,
const string& carrier_code,
string* formatted_number) const;
void FormatAccordingToFormats(
const string& number_for_leading_digits_match,
const RepeatedPtrField<NumberFormat>& available_formats,
PhoneNumberUtil::PhoneNumberFormat number_format,
const string& national_number,
string* formatted_number) const;
// Simple wrapper of FormatNationalNumberWithCarrier for the common case of
// no carrier code.
void FormatNationalNumber(const string& number,
@ -660,7 +681,7 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> {
const string& possible_idd_prefix,
string* number) const;
void MaybeStripNationalPrefixAndCarrierCode(
bool MaybeStripNationalPrefixAndCarrierCode(
const PhoneMetadata& metadata,
string* number,
string* carrier_code) const;


+ 588
- 579
cpp/src/phonenumbers/test_metadata.cc
File diff suppressed because it is too large
View File


+ 6
- 2
cpp/test/phonenumbers/phonenumbermatcher_test.cc View File

@ -326,7 +326,8 @@ class PhoneNumberMatcherTest : public testing::Test {
TEST_F(PhoneNumberMatcherTest, FindNationalNumber) {
// Same cases as in ParseNationalNumber.
DoTestFindInContext("033316005", RegionCode::NZ());
DoTestFindInContext("33316005", RegionCode::NZ());
// "33316005", RegionCode::NZ() is omitted since the national-prefix is
// obligatory for these types of numbers in New Zealand.
// National prefix attached and some formatting present.
DoTestFindInContext("03-331 6005", RegionCode::NZ());
DoTestFindInContext("03 331 6005", RegionCode::NZ());
@ -697,6 +698,7 @@ static const NumberTest POSSIBLE_ONLY_CASES[] = {
NumberTest("1650 x 253 - 1234", RegionCode::US()),
NumberTest("650 x 253 - 1234", RegionCode::US()),
NumberTest("650x2531234", RegionCode::US()),
NumberTest("(20) 3346 1234", RegionCode::GB()), // Non-optional NP omitted
};
// Strings with number-like things that should only be found up to and including
@ -727,7 +729,7 @@ static const NumberTest STRICT_GROUPING_CASES[] = {
NumberTest("415-6667777", RegionCode::US()),
// Should be found by strict grouping but not exact grouping, as the last two
// groups are formatted together as a block.
NumberTest("800-2491234", RegionCode::DE()),
NumberTest("0800-2491234", RegionCode::DE()),
};
// Strings with number-like things that should found at all levels.
@ -757,6 +759,8 @@ static const NumberTest EXACT_GROUPING_CASES[] = {
NumberTest("+49494949 ext. 49", RegionCode::DE()),
NumberTest("0494949", RegionCode::DE()),
NumberTest("0494949 ext. 49", RegionCode::DE()),
NumberTest("01 (33) 3461 2234", RegionCode::MX()), // Optional NP present
NumberTest("(33) 3461 2234", RegionCode::MX()), // Optional NP omitted
};
TEST_F(PhoneNumberMatcherTest, MatchesWithStrictGroupingLeniency) {


+ 12
- 0
cpp/test/phonenumbers/phonenumberutil_test.cc View File

@ -601,6 +601,18 @@ TEST_F(PhoneNumberUtilTest, FormatOutOfCountryCallingNumber) {
EXPECT_EQ("011 15 8765-4321 ext. 1234", formatted_number);
}
TEST_F(PhoneNumberUtilTest, FormatOutOfCountryWithInvalidRegion) {
PhoneNumber test_number;
string formatted_number;
test_number.set_country_code(1);
test_number.set_national_number(6502530000ULL);
// AQ/Antarctica isn't a valid region code for phone number formatting,
// so this falls back to intl formatting.
phone_util_.FormatOutOfCountryCallingNumber(test_number, RegionCode::AQ(),
&formatted_number);
EXPECT_EQ("+1 650 253 0000", formatted_number);
}
TEST_F(PhoneNumberUtilTest, FormatOutOfCountryWithPreferredIntlPrefix) {
PhoneNumber test_number;
string formatted_number;


+ 5
- 0
cpp/test/phonenumbers/test_util.h View File

@ -57,6 +57,11 @@ class RegionCode {
return s;
}
static const string& AQ() {
static const string s = "AQ";
return s;
}
static const string& AR() {
static const string s = "AR";
return s;


+ 6
- 0
debian/changelog View File

@ -1,3 +1,9 @@
libphonenumber (4.2) lucid; urgency=low
* Version update.
-- Fredrik Roubert <roubert@google.com> Mon, 14 Nov 2011 14:30:28 +0200
libphonenumber (4.1) lucid; urgency=low
* Version update.


Loading…
Cancel
Save