Skip to content

Commit eca651e

Browse files
committed
Replace usage of deprecated Callback4 with std::function.
1 parent 87612bf commit eca651e

2 files changed

Lines changed: 23 additions & 30 deletions

File tree

cpp/src/phonenumbers/phonenumbermatcher.cc

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@
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

415416
PhoneNumberMatcher::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

693687
bool 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
}

cpp/src/phonenumbers/phonenumbermatcher.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
#ifndef I18N_PHONENUMBERS_PHONENUMBERMATCHER_H_
2323
#define I18N_PHONENUMBERS_PHONENUMBERMATCHER_H_
2424

25+
#include <functional>
2526
#include <string>
2627
#include <vector>
2728

2829
#include "phonenumbers/base/basictypes.h"
2930
#include "phonenumbers/base/memory/scoped_ptr.h"
30-
#include "phonenumbers/callback.h"
3131
#include "phonenumbers/regexp_adapter.h"
3232

3333
namespace i18n {
@@ -134,10 +134,10 @@ class PhoneNumberMatcher {
134134
PhoneNumberMatch* match);
135135

136136
bool CheckNumberGroupingIsValid(
137-
const PhoneNumber& phone_number,
138-
const string& candidate,
139-
ResultCallback4<bool, const PhoneNumberUtil&, const PhoneNumber&,
140-
const string&, const vector<string>&>* checker) const;
137+
const PhoneNumber &phone_number, const string &candidate,
138+
std::function<bool(const PhoneNumberUtil &, const PhoneNumber &,
139+
const std::string &, const std::vector<std::string> &)>
140+
checker) const;
141141

142142
// Helper method to get the national-number part of a number, formatted
143143
// without any national prefix, and return it as a set of digit blocks that

0 commit comments

Comments
 (0)