Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 18 additions & 25 deletions cpp/src/phonenumbers/phonenumbermatcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@
#endif // I18N_PHONENUMBERS_USE_ICU_REGEXP

#include <ctype.h>
#include <stddef.h>
#include <functional>
#include <limits>
#include <map>
#include <memory>
#include <stddef.h>
#include <string>
#include <unicode/uchar.h>
#include <utility>
#include <vector>
#include <unicode/uchar.h>

#include "phonenumbers/alternate_format.h"
#include "phonenumbers/base/logging.h"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -541,12 +542,8 @@ bool PhoneNumberMatcher::VerifyAccordingToLeniency(
!IsNationalPrefixPresentIfRequired(number)) {
return false;
}
ResultCallback4<bool, const PhoneNumberUtil&, const PhoneNumber&,
const string&, const std::vector<string>&>* 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) ||
Expand All @@ -556,13 +553,10 @@ bool PhoneNumberMatcher::VerifyAccordingToLeniency(
!IsNationalPrefixPresentIfRequired(number)) {
return false;
}
ResultCallback4<bool, const PhoneNumberUtil&, const PhoneNumber&,
const string&, const std::vector<string>&>* 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 "
Expand Down Expand Up @@ -691,17 +685,16 @@ bool PhoneNumberMatcher::Find(int index, PhoneNumberMatch* match) {
}

bool PhoneNumberMatcher::CheckNumberGroupingIsValid(
const PhoneNumber& phone_number,
const string& candidate,
ResultCallback4<bool, const PhoneNumberUtil&, const PhoneNumber&,
const string&, const std::vector<string>&>* checker) const {
DCHECK(checker);
const PhoneNumber &phone_number, const string &candidate,
std::function<bool(const PhoneNumberUtil &, const PhoneNumber &,
const std::string &, const std::vector<std::string> &)>
checker) const {
string normalized_candidate =
NormalizeUTF8::NormalizeDecimalDigits(candidate);
std::vector<string> 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
Expand Down Expand Up @@ -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;
}
}
Expand Down
10 changes: 5 additions & 5 deletions cpp/src/phonenumbers/phonenumbermatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
#ifndef I18N_PHONENUMBERS_PHONENUMBERMATCHER_H_
#define I18N_PHONENUMBERS_PHONENUMBERMATCHER_H_

#include <functional>
#include <string>
#include <vector>

#include "phonenumbers/base/basictypes.h"
#include "phonenumbers/base/memory/scoped_ptr.h"
#include "phonenumbers/callback.h"
#include "phonenumbers/regexp_adapter.h"

namespace i18n {
Expand Down Expand Up @@ -134,10 +134,10 @@ class PhoneNumberMatcher {
PhoneNumberMatch* match);

bool CheckNumberGroupingIsValid(
const PhoneNumber& phone_number,
const string& candidate,
ResultCallback4<bool, const PhoneNumberUtil&, const PhoneNumber&,
const string&, const vector<string>&>* checker) const;
const PhoneNumber &phone_number, const string &candidate,
std::function<bool(const PhoneNumberUtil &, const PhoneNumber &,
const std::string &, const std::vector<std::string> &)>
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
Expand Down