diff --git a/cpp/src/phonenumbers/shortnumberinfo.cc b/cpp/src/phonenumbers/shortnumberinfo.cc index 98fe8e033..afe69d5a4 100644 --- a/cpp/src/phonenumbers/shortnumberinfo.cc +++ b/cpp/src/phonenumbers/shortnumberinfo.cc @@ -108,19 +108,6 @@ bool ShortNumberInfo::RegionDialingFromMatchesNumber(const PhoneNumber& number, region_dialing_from) != region_codes.end(); } -bool ShortNumberInfo::IsPossibleShortNumberForRegion( - const string& short_number, const string& region_dialing_from) const { - const PhoneMetadata* phone_metadata = - GetMetadataForRegion(region_dialing_from); - if (!phone_metadata) { - return false; - } - const RepeatedField& lengths = - phone_metadata->general_desc().possible_length(); - return std::find(lengths.begin(), lengths.end(), short_number.length()) != - lengths.end(); -} - bool ShortNumberInfo::IsPossibleShortNumberForRegion(const PhoneNumber& number, const string& region_dialing_from) const { if (!RegionDialingFromMatchesNumber(number, region_dialing_from)) { @@ -161,23 +148,6 @@ bool ShortNumberInfo::IsPossibleShortNumber(const PhoneNumber& number) const { return false; } -bool ShortNumberInfo::IsValidShortNumberForRegion( - const string& short_number, const string& region_dialing_from) const { - const PhoneMetadata* phone_metadata = - GetMetadataForRegion(region_dialing_from); - if (!phone_metadata) { - return false; - } - const PhoneNumberDesc& general_desc = phone_metadata->general_desc(); - if (!MatchesPossibleNumberAndNationalNumber(*matcher_api_, short_number, - general_desc)) { - return false; - } - const PhoneNumberDesc& short_number_desc = phone_metadata->short_code(); - return MatchesPossibleNumberAndNationalNumber(*matcher_api_, short_number, - short_number_desc); -} - bool ShortNumberInfo::IsValidShortNumberForRegion( const PhoneNumber& number, const string& region_dialing_from) const { if (!RegionDialingFromMatchesNumber(number, region_dialing_from)) { @@ -212,44 +182,6 @@ bool ShortNumberInfo::IsValidShortNumber(const PhoneNumber& number) const { return IsValidShortNumberForRegion(number, region_code); } -ShortNumberInfo::ShortNumberCost ShortNumberInfo::GetExpectedCostForRegion( - const string& short_number, const string& region_dialing_from) const { - const PhoneMetadata* phone_metadata = - GetMetadataForRegion(region_dialing_from); - if (!phone_metadata) { - return ShortNumberInfo::UNKNOWN_COST; - } - - // The possible lengths are not present for a particular sub-type if they - // match the general description; for this reason, we check the possible - // lengths against the general description first to allow an early exit if - // possible. - const RepeatedField& lengths = - phone_metadata->general_desc().possible_length(); - if (std::find(lengths.begin(), lengths.end(), short_number.length()) == - lengths.end()) { - return ShortNumberInfo::UNKNOWN_COST; - } - - if (MatchesPossibleNumberAndNationalNumber(*matcher_api_, short_number, - phone_metadata->premium_rate())) { - return ShortNumberInfo::PREMIUM_RATE; - } - if (MatchesPossibleNumberAndNationalNumber(*matcher_api_, short_number, - phone_metadata->standard_rate())) { - return ShortNumberInfo::STANDARD_RATE; - } - if (MatchesPossibleNumberAndNationalNumber(*matcher_api_, short_number, - phone_metadata->toll_free())) { - return ShortNumberInfo::TOLL_FREE; - } - if (IsEmergencyNumber(short_number, region_dialing_from)) { - // Emergency numbers are implicitly toll-free. - return ShortNumberInfo::TOLL_FREE; - } - return ShortNumberInfo::UNKNOWN_COST; -} - ShortNumberInfo::ShortNumberCost ShortNumberInfo::GetExpectedCostForRegion( const PhoneNumber& number, const string& region_dialing_from) const { if (!RegionDialingFromMatchesNumber(number, region_dialing_from)) { diff --git a/cpp/src/phonenumbers/shortnumberinfo.h b/cpp/src/phonenumbers/shortnumberinfo.h index 5cb80761e..aae16161d 100644 --- a/cpp/src/phonenumbers/shortnumberinfo.h +++ b/cpp/src/phonenumbers/shortnumberinfo.h @@ -53,20 +53,6 @@ class ShortNumberInfo { UNKNOWN_COST }; - // DEPRECATED: Anyone who was using it and passing in a string with whitespace - // (or other formatting characters) would have been getting the wrong result. - // You should parse the string to PhoneNumber and use the method - // IsPossibleShortNumberForRegion(PhoneNumber, String). This method will be - // removed in the next release. - // - // Check whether a short number is a possible number when dialled from a - // region, given the number in the form of a string, and the region where the - // number is dialed from. This provides a more lenient check than - // IsValidShortNumberForRegion. - bool IsPossibleShortNumberForRegion( - const string& short_number, - const string& region_dialing_from) const; - // Check whether a short number is a possible number when dialled from a // region, given the number in the form of a string, and the region where the // number is dialed from. This provides a more lenient check than @@ -81,19 +67,6 @@ class ShortNumberInfo { // See IsPossibleShortNumberForRegion for details. bool IsPossibleShortNumber(const PhoneNumber& number) const; - // DEPRECATED: Anyone who was using it and passing in a string with whitespace - // (or other formatting characters) would have been getting the wrong result. - // You should parse the string to PhoneNumber and use the method - // IsValidShortNumberForRegion(PhoneNumber, String). This method will be - // removed in the next release. - // - // Tests whether a short number matches a valid pattern in a region. Note - // that this doesn't verify the number is actually in use, which is - // impossible to tell by just looking at the number itself. - bool IsValidShortNumberForRegion( - const string& short_number, - const string& region_dialing_from) const; - // Tests whether a short number matches a valid pattern in a region. Note // that this doesn't verify the number is actually in use, which is // impossible to tell by just looking at the number itself. @@ -108,30 +81,6 @@ class ShortNumberInfo { // IsValidShortNumberForRegion for details. bool IsValidShortNumber(const PhoneNumber& number) const; - // DEPRECATED: Anyone who was using it and passing in a string with whitespace - // (or other formatting characters) would have been getting the wrong result. - // You should parse the string to PhoneNumber and use the method - // GetExpectedCostForRegion(PhoneNumber, String). This method will be - // removed in the next release. - // - // Gets the expected cost category of a short number when dialled from a - // region (however, nothing is implied about its validity). If it is - // important that the number is valid, then its validity must first be - // checked using IsValidShortNumberForRegion. Note that emergency numbers are - // always considered toll-free. Example usage: - // - // ShortNumberInfo short_info; - // string short_number("110"); - // RegionCode region_code = RegionCode::FR(); - // if (short_info.IsValidShortNumberForRegion(short_number, region_code)) { - // ShortNumberInfo::ShortNumberCost cost = - // short_info.GetExpectedCostForRegion(short_number, region_code); - // // Do something with the cost information here. - // } - ShortNumberCost GetExpectedCostForRegion( - const string& short_number, - const string& region_dialing_from) const; - // Gets the expected cost category of a short number when dialled from a // region (however, nothing is implied about its validity). If it is // important that the number is valid, then its validity must first be diff --git a/java/libphonenumber/src/com/google/i18n/phonenumbers/ShortNumberInfo.java b/java/libphonenumber/src/com/google/i18n/phonenumbers/ShortNumberInfo.java index 64c15341d..5e2950f1c 100644 --- a/java/libphonenumber/src/com/google/i18n/phonenumbers/ShortNumberInfo.java +++ b/java/libphonenumber/src/com/google/i18n/phonenumbers/ShortNumberInfo.java @@ -108,30 +108,6 @@ public class ShortNumberInfo { return regionCodes.contains(regionDialingFrom); } - /** - * Check whether a short number is a possible number when dialled from a region, given the number - * in the form of a string, and the region where the number is dialed from. This provides a more - * lenient check than {@link #isValidShortNumberForRegion}. - * - * @param shortNumber the short number to check as a string - * @param regionDialingFrom the region from which the number is dialed - * @return whether the number is a possible short number - * @deprecated Anyone who was using it and passing in a string with whitespace (or other - * formatting characters) would have been getting the wrong result. You should parse - * the string to PhoneNumber and use the method - * {@code #isPossibleShortNumberForRegion(PhoneNumber, String)}. This method will be - * removed in the next release. - */ - @Deprecated - public boolean isPossibleShortNumberForRegion(String shortNumber, String regionDialingFrom) { - PhoneMetadata phoneMetadata = - MetadataManager.getShortNumberMetadataForRegion(regionDialingFrom); - if (phoneMetadata == null) { - return false; - } - return phoneMetadata.getGeneralDesc().getPossibleLengthList().contains(shortNumber.length()); - } - /** * Check whether a short number is a possible number when dialed from the given region. This * provides a more lenient check than {@link #isValidShortNumberForRegion}. @@ -177,35 +153,6 @@ public class ShortNumberInfo { return false; } - /** - * Tests whether a short number matches a valid pattern in a region. Note that this doesn't verify - * the number is actually in use, which is impossible to tell by just looking at the number - * itself. - * - * @param shortNumber the short number to check as a string - * @param regionDialingFrom the region from which the number is dialed - * @return whether the short number matches a valid pattern - * @deprecated Anyone who was using it and passing in a string with whitespace (or other - * formatting characters) would have been getting the wrong result. You should parse - * the string to PhoneNumber and use the method - * {@code #isValidShortNumberForRegion(PhoneNumber, String)}. This method will be - * removed in the next release. - */ - @Deprecated - public boolean isValidShortNumberForRegion(String shortNumber, String regionDialingFrom) { - PhoneMetadata phoneMetadata = - MetadataManager.getShortNumberMetadataForRegion(regionDialingFrom); - if (phoneMetadata == null) { - return false; - } - PhoneNumberDesc generalDesc = phoneMetadata.getGeneralDesc(); - if (!matchesPossibleNumberAndNationalNumber(shortNumber, generalDesc)) { - return false; - } - PhoneNumberDesc shortNumberDesc = phoneMetadata.getShortCode(); - return matchesPossibleNumberAndNationalNumber(shortNumber, shortNumberDesc); - } - /** * Tests whether a short number matches a valid pattern in a region. Note that this doesn't verify * the number is actually in use, which is impossible to tell by just looking at the number @@ -253,67 +200,6 @@ public class ShortNumberInfo { return isValidShortNumberForRegion(number, regionCode); } - /** - * Gets the expected cost category of a short number when dialled from a region (however, nothing - * is implied about its validity). If it is important that the number is valid, then its validity - * must first be checked using {@link isValidShortNumberForRegion}. Note that emergency numbers - * are always considered toll-free. Example usage: - *
{@code
-   * ShortNumberInfo shortInfo = ShortNumberInfo.getInstance();
-   * String shortNumber = "110";
-   * String regionCode = "FR";
-   * if (shortInfo.isValidShortNumberForRegion(shortNumber, regionCode)) {
-   *   ShortNumberInfo.ShortNumberCost cost = shortInfo.getExpectedCostForRegion(shortNumber,
-   *       regionCode);
-   *   // Do something with the cost information here.
-   * }}
- * - * @param shortNumber the short number for which we want to know the expected cost category, - * as a string - * @param regionDialingFrom the region from which the number is dialed - * @return the expected cost category for that region of the short number. Returns UNKNOWN_COST if - * the number does not match a cost category. Note that an invalid number may match any cost - * category. - * @deprecated Anyone who was using it and passing in a string with whitespace (or other - * formatting characters) would have been getting the wrong result. You should parse - * the string to PhoneNumber and use the method - * {@code #getExpectedCostForRegion(PhoneNumber, String)}. This method will be - * removed in the next release. - */ - @Deprecated - public ShortNumberCost getExpectedCostForRegion(String shortNumber, String regionDialingFrom) { - // Note that regionDialingFrom may be null, in which case phoneMetadata will also be null. - PhoneMetadata phoneMetadata = MetadataManager.getShortNumberMetadataForRegion( - regionDialingFrom); - if (phoneMetadata == null) { - return ShortNumberCost.UNKNOWN_COST; - } - - // The possible lengths are not present for a particular sub-type if they match the general - // description; for this reason, we check the possible lengths against the general description - // first to allow an early exit if possible. - if (!phoneMetadata.getGeneralDesc().getPossibleLengthList().contains(shortNumber.length())) { - return ShortNumberCost.UNKNOWN_COST; - } - - // The cost categories are tested in order of decreasing expense, since if for some reason the - // patterns overlap the most expensive matching cost category should be returned. - if (matchesPossibleNumberAndNationalNumber(shortNumber, phoneMetadata.getPremiumRate())) { - return ShortNumberCost.PREMIUM_RATE; - } - if (matchesPossibleNumberAndNationalNumber(shortNumber, phoneMetadata.getStandardRate())) { - return ShortNumberCost.STANDARD_RATE; - } - if (matchesPossibleNumberAndNationalNumber(shortNumber, phoneMetadata.getTollFree())) { - return ShortNumberCost.TOLL_FREE; - } - if (isEmergencyNumber(shortNumber, regionDialingFrom)) { - // Emergency numbers are implicitly toll-free. - return ShortNumberCost.TOLL_FREE; - } - return ShortNumberCost.UNKNOWN_COST; - } - /** * Gets the expected cost category of a short number when dialed from a region (however, nothing * is implied about its validity). If it is important that the number is valid, then its validity diff --git a/java/pending_code_changes.txt b/java/pending_code_changes.txt index 8b1378917..c1d6ecf04 100644 --- a/java/pending_code_changes.txt +++ b/java/pending_code_changes.txt @@ -1 +1,5 @@ - +Code changes: + - Deleting deprecated methods in ShortNumberInfo that work on strings, instead + of phone number objects. These have been marked deprecated for months. Any + users of these methods should call PhoneNumberUtil.parse first to create a + PhoneNumber object, and pass this in.