From eca651e6c02af0207aba2f5be4abc13510a13c7e Mon Sep 17 00:00:00 2001 From: Cory Kramer Date: Thu, 14 Dec 2023 16:17:13 +0000 Subject: [PATCH] Replace usage of deprecated Callback4 with std::function. --- cpp/src/phonenumbers/phonenumbermatcher.cc | 43 +++++++++------------- cpp/src/phonenumbers/phonenumbermatcher.h | 10 ++--- 2 files changed, 23 insertions(+), 30 deletions(-) diff --git a/cpp/src/phonenumbers/phonenumbermatcher.cc b/cpp/src/phonenumbers/phonenumbermatcher.cc index 2d60ceb4d..eca0a25ea 100644 --- a/cpp/src/phonenumbers/phonenumbermatcher.cc +++ b/cpp/src/phonenumbers/phonenumbermatcher.cc @@ -26,14 +26,15 @@ #endif // I18N_PHONENUMBERS_USE_ICU_REGEXP #include -#include +#include #include #include #include +#include #include +#include #include #include -#include #include "phonenumbers/alternate_format.h" #include "phonenumbers/base/logging.h" @@ -409,7 +410,7 @@ PhoneNumberMatcher::PhoneNumberMatcher(const PhoneNumberUtil& util, last_match_(NULL), search_index_(0), is_input_valid_utf8_(true) { - is_input_valid_utf8_ = IsInputUtf8(); + is_input_valid_utf8_ = IsInputUtf8(); } PhoneNumberMatcher::PhoneNumberMatcher(const string& text, @@ -541,12 +542,8 @@ bool PhoneNumberMatcher::VerifyAccordingToLeniency( !IsNationalPrefixPresentIfRequired(number)) { return false; } - ResultCallback4&>* callback = - NewPermanentCallback(&AllNumberGroupsRemainGrouped); - bool is_valid = CheckNumberGroupingIsValid(number, candidate, callback); - delete(callback); - return is_valid; + return CheckNumberGroupingIsValid(number, candidate, + &AllNumberGroupsRemainGrouped); } case PhoneNumberMatcher::EXACT_GROUPING: { if (!phone_util_.IsValidNumber(number) || @@ -556,13 +553,10 @@ bool PhoneNumberMatcher::VerifyAccordingToLeniency( !IsNationalPrefixPresentIfRequired(number)) { return false; } - ResultCallback4&>* callback = - NewPermanentCallback( - this, &PhoneNumberMatcher::AllNumberGroupsAreExactlyPresent); - bool is_valid = CheckNumberGroupingIsValid(number, candidate, callback); - delete(callback); - return is_valid; + return CheckNumberGroupingIsValid( + number, candidate, + std::bind_front(&PhoneNumberMatcher::AllNumberGroupsAreExactlyPresent, + this)); } default: LOG(ERROR) << "No implementation defined for verification for leniency " @@ -691,17 +685,16 @@ bool PhoneNumberMatcher::Find(int index, PhoneNumberMatch* match) { } bool PhoneNumberMatcher::CheckNumberGroupingIsValid( - const PhoneNumber& phone_number, - const string& candidate, - ResultCallback4&>* checker) const { - DCHECK(checker); + const PhoneNumber &phone_number, const string &candidate, + std::function &)> + checker) const { string normalized_candidate = NormalizeUTF8::NormalizeDecimalDigits(candidate); std::vector formatted_number_groups; GetNationalNumberGroups(phone_number, &formatted_number_groups); - if (checker->Run(phone_util_, phone_number, normalized_candidate, - formatted_number_groups)) { + if (checker(phone_util_, phone_number, normalized_candidate, + formatted_number_groups)) { return true; } // If this didn't pass, see if there are any alternate formats that match, and @@ -730,8 +723,8 @@ bool PhoneNumberMatcher::CheckNumberGroupingIsValid( formatted_number_groups.clear(); GetNationalNumberGroupsForPattern(phone_number, &*it, &formatted_number_groups); - if (checker->Run(phone_util_, phone_number, normalized_candidate, - formatted_number_groups)) { + if (checker(phone_util_, phone_number, normalized_candidate, + formatted_number_groups)) { return true; } } diff --git a/cpp/src/phonenumbers/phonenumbermatcher.h b/cpp/src/phonenumbers/phonenumbermatcher.h index b680d1b07..b4cfb7d75 100644 --- a/cpp/src/phonenumbers/phonenumbermatcher.h +++ b/cpp/src/phonenumbers/phonenumbermatcher.h @@ -22,12 +22,12 @@ #ifndef I18N_PHONENUMBERS_PHONENUMBERMATCHER_H_ #define I18N_PHONENUMBERS_PHONENUMBERMATCHER_H_ +#include #include #include #include "phonenumbers/base/basictypes.h" #include "phonenumbers/base/memory/scoped_ptr.h" -#include "phonenumbers/callback.h" #include "phonenumbers/regexp_adapter.h" namespace i18n { @@ -134,10 +134,10 @@ class PhoneNumberMatcher { PhoneNumberMatch* match); bool CheckNumberGroupingIsValid( - const PhoneNumber& phone_number, - const string& candidate, - ResultCallback4&>* checker) const; + const PhoneNumber &phone_number, const string &candidate, + std::function &)> + checker) const; // 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