2626#endif // I18N_PHONENUMBERS_USE_ICU_REGEXP
2727
2828#include < ctype.h>
29- #include < stddef.h >
29+ #include < functional >
3030#include < limits>
3131#include < map>
3232#include < memory>
33+ #include < stddef.h>
3334#include < string>
35+ #include < unicode/uchar.h>
3436#include < utility>
3537#include < vector>
36- #include < unicode/uchar.h>
3738
3839#include " phonenumbers/alternate_format.h"
3940#include " phonenumbers/base/logging.h"
@@ -409,7 +410,7 @@ PhoneNumberMatcher::PhoneNumberMatcher(const PhoneNumberUtil& util,
409410 last_match_(NULL ),
410411 search_index_(0 ),
411412 is_input_valid_utf8_(true ) {
412- is_input_valid_utf8_ = IsInputUtf8 ();
413+ is_input_valid_utf8_ = IsInputUtf8 ();
413414}
414415
415416PhoneNumberMatcher::PhoneNumberMatcher (const string& text,
@@ -541,12 +542,8 @@ bool PhoneNumberMatcher::VerifyAccordingToLeniency(
541542 !IsNationalPrefixPresentIfRequired (number)) {
542543 return false ;
543544 }
544- ResultCallback4<bool , const PhoneNumberUtil&, const PhoneNumber&,
545- const string&, const std::vector<string>&>* callback =
546- NewPermanentCallback (&AllNumberGroupsRemainGrouped);
547- bool is_valid = CheckNumberGroupingIsValid (number, candidate, callback);
548- delete (callback);
549- return is_valid;
545+ return CheckNumberGroupingIsValid (number, candidate,
546+ &AllNumberGroupsRemainGrouped);
550547 }
551548 case PhoneNumberMatcher::EXACT_GROUPING : {
552549 if (!phone_util_.IsValidNumber (number) ||
@@ -556,13 +553,10 @@ bool PhoneNumberMatcher::VerifyAccordingToLeniency(
556553 !IsNationalPrefixPresentIfRequired (number)) {
557554 return false ;
558555 }
559- ResultCallback4<bool , const PhoneNumberUtil&, const PhoneNumber&,
560- const string&, const std::vector<string>&>* callback =
561- NewPermanentCallback (
562- this , &PhoneNumberMatcher::AllNumberGroupsAreExactlyPresent);
563- bool is_valid = CheckNumberGroupingIsValid (number, candidate, callback);
564- delete (callback);
565- return is_valid;
556+ return CheckNumberGroupingIsValid (
557+ number, candidate,
558+ std::bind_front (&PhoneNumberMatcher::AllNumberGroupsAreExactlyPresent,
559+ this ));
566560 }
567561 default :
568562 LOG (ERROR ) << " No implementation defined for verification for leniency "
@@ -691,17 +685,16 @@ bool PhoneNumberMatcher::Find(int index, PhoneNumberMatch* match) {
691685}
692686
693687bool PhoneNumberMatcher::CheckNumberGroupingIsValid (
694- const PhoneNumber& phone_number,
695- const string& candidate,
696- ResultCallback4<bool , const PhoneNumberUtil&, const PhoneNumber&,
697- const string&, const std::vector<string>&>* checker) const {
698- DCHECK (checker);
688+ const PhoneNumber &phone_number, const string &candidate,
689+ std::function<bool (const PhoneNumberUtil &, const PhoneNumber &,
690+ const std::string &, const std::vector<std::string> &)>
691+ checker) const {
699692 string normalized_candidate =
700693 NormalizeUTF8::NormalizeDecimalDigits (candidate);
701694 std::vector<string> formatted_number_groups;
702695 GetNationalNumberGroups (phone_number, &formatted_number_groups);
703- if (checker-> Run (phone_util_, phone_number, normalized_candidate,
704- formatted_number_groups)) {
696+ if (checker (phone_util_, phone_number, normalized_candidate,
697+ formatted_number_groups)) {
705698 return true ;
706699 }
707700 // If this didn't pass, see if there are any alternate formats that match, and
@@ -730,8 +723,8 @@ bool PhoneNumberMatcher::CheckNumberGroupingIsValid(
730723 formatted_number_groups.clear ();
731724 GetNationalNumberGroupsForPattern (phone_number, &*it,
732725 &formatted_number_groups);
733- if (checker-> Run (phone_util_, phone_number, normalized_candidate,
734- formatted_number_groups)) {
726+ if (checker (phone_util_, phone_number, normalized_candidate,
727+ formatted_number_groups)) {
735728 return true ;
736729 }
737730 }
0 commit comments