diff --git a/cpp/src/phonenumbers/phonenumberutil.h b/cpp/src/phonenumbers/phonenumberutil.h index 3f539c8fa..4750eb430 100644 --- a/cpp/src/phonenumbers/phonenumberutil.h +++ b/cpp/src/phonenumbers/phonenumberutil.h @@ -579,6 +579,13 @@ class PhoneNumberUtil : public Singleton { const string& number, const string& region_dialing_from) const; + // Returns true if the number can be dialled from outside the region, or + // unknown. If the number can only be dialled from within the region, returns + // false. Does not check the number is a valid number. Note that, at the + // moment, this method does not handle short numbers (which are currently all + // presumed to not be diallable from outside their country). + bool CanBeInternationallyDialled(const PhoneNumber& number) const; + // Tests whether a phone number has a geographical association. It checks if // the number is associated to a certain region in the country where it // belongs to. Note that this doesn't verify if the number is actually in use. @@ -940,12 +947,6 @@ class PhoneNumberUtil : public Singleton { bool IsShorterThanPossibleNormalNumber(const PhoneMetadata* country_metadata, const string& number) const; - // Returns true if the number can be dialled from outside the region, or - // unknown. If the number can only be dialled from within the region, returns - // false. Does not check the number is a valid number. Note that, at the - // moment, this method does not handle short numbers. - bool CanBeInternationallyDialled(const PhoneNumber& number) const; - DISALLOW_COPY_AND_ASSIGN(PhoneNumberUtil); }; diff --git a/cpp/test/phonenumbers/phonenumberutil_test.cc b/cpp/test/phonenumbers/phonenumberutil_test.cc index aee8fa659..bc7890a69 100644 --- a/cpp/test/phonenumbers/phonenumberutil_test.cc +++ b/cpp/test/phonenumbers/phonenumberutil_test.cc @@ -67,10 +67,6 @@ class PhoneNumberUtilTest : public testing::Test { phone_util_.ExtractPossibleNumber(number, extracted_number); } - bool CanBeInternationallyDialled(const PhoneNumber& number) const { - return phone_util_.CanBeInternationallyDialled(number); - } - bool IsViablePhoneNumber(const string& number) const { return phone_util_.IsViablePhoneNumber(number); } @@ -4443,24 +4439,24 @@ TEST_F(PhoneNumberUtilTest, CanBeInternationallyDialled) { // We have no-international-dialling rules for the US in our test metadata // that say that toll-free numbers cannot be dialled internationally. test_number.set_national_number(8002530000ULL); - EXPECT_FALSE(CanBeInternationallyDialled(test_number)); + EXPECT_FALSE(phone_util_.CanBeInternationallyDialled(test_number)); // Normal US numbers can be internationally dialled. test_number.set_national_number(6502530000ULL); - EXPECT_TRUE(CanBeInternationallyDialled(test_number)); + EXPECT_TRUE(phone_util_.CanBeInternationallyDialled(test_number)); // Invalid number. test_number.set_national_number(2530000ULL); - EXPECT_TRUE(CanBeInternationallyDialled(test_number)); + EXPECT_TRUE(phone_util_.CanBeInternationallyDialled(test_number)); // We have no data for NZ - should return true. test_number.set_country_code(64); test_number.set_national_number(33316005ULL); - EXPECT_TRUE(CanBeInternationallyDialled(test_number)); + EXPECT_TRUE(phone_util_.CanBeInternationallyDialled(test_number)); test_number.set_country_code(800); test_number.set_national_number(12345678ULL); - EXPECT_TRUE(CanBeInternationallyDialled(test_number)); + EXPECT_TRUE(phone_util_.CanBeInternationallyDialled(test_number)); } TEST_F(PhoneNumberUtilTest, IsAlphaNumber) { diff --git a/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java b/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java index 6d678f8a6..2b2eab6e5 100644 --- a/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java +++ b/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java @@ -3491,14 +3491,13 @@ public class PhoneNumberUtil { /** * Returns true if the number can be dialled from outside the region, or unknown. If the number * can only be dialled from within the region, returns false. Does not check the number is a valid - * number. Note that, at the moment, this method does not handle short numbers. - * TODO: Make this method public when we have enough metadata to make it worthwhile. + * number. Note that, at the moment, this method does not handle short numbers (which are + * currently all presumed to not be diallable from outside their country). * * @param number the phone-number for which we want to know whether it is diallable from * outside the region */ - // @VisibleForTesting - boolean canBeInternationallyDialled(PhoneNumber number) { + public boolean canBeInternationallyDialled(PhoneNumber number) { PhoneMetadata metadata = getMetadataForRegion(getRegionCodeForNumber(number)); if (metadata == null) { // Note numbers belonging to non-geographical entities (e.g. +800 numbers) are always diff --git a/javascript/i18n/phonenumbers/phonenumberutil.js b/javascript/i18n/phonenumbers/phonenumberutil.js index e2086dba4..28d8e3533 100644 --- a/javascript/i18n/phonenumbers/phonenumberutil.js +++ b/javascript/i18n/phonenumbers/phonenumberutil.js @@ -4530,9 +4530,9 @@ i18n.phonenumbers.PhoneNumberUtil.prototype.isNationalNumberSuffixOfTheOther_ = /** * Returns true if the number can be dialled from outside the region, or * unknown. If the number can only be dialled from within the region, returns - * false. Does not check the number is a valid number. - * TODO: Make this method public when we have enough metadata to make it - * worthwhile. Currently visible for testing purposes only. + * false. Does not check the number is a valid number. Note that, at the + * moment, this method does not handle short numbers (which are currently + * all presumed to not be diallable from outside their country). * * @param {i18n.phonenumbers.PhoneNumber} number the phone-number for which we * want to know whether it is diallable from outside the region. diff --git a/pending_code_changes.txt b/pending_code_changes.txt index 8b1378917..2557ee5ff 100644 --- a/pending_code_changes.txt +++ b/pending_code_changes.txt @@ -1 +1,5 @@ - +Code changes: + - PhoneNumberUtil.canBeInternationallyDialled() API is made public (in + Java and CPP) now as it is useful for clients if they want to make + sure they only allow internationally-accessible numbers for a + particular use-case. In JS this API is already public. 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 240d88dae..0fd11159f 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/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 bca87669b..a72a1c2b3 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