• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 The Libphonenumber Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef I18N_PHONENUMBERS_REGEX_BASED_MATCHER_H_
18 #define I18N_PHONENUMBERS_REGEX_BASED_MATCHER_H_
19 
20 #include <string>
21 
22 #include "phonenumbers/base/basictypes.h"
23 #include "phonenumbers/base/memory/scoped_ptr.h"
24 #include "phonenumbers/matcher_api.h"
25 
26 namespace i18n {
27 namespace phonenumbers {
28 
29 class AbstractRegExpFactory;
30 class PhoneNumberDesc;
31 class RegExpCache;
32 
33 // Implementation of the matcher API using the regular expressions in the
34 // PhoneNumberDesc proto message to match numbers.
35 class RegexBasedMatcher : public MatcherApi {
36  public:
37   RegexBasedMatcher();
38 
39   // This type is neither copyable nor movable.
40   RegexBasedMatcher(const RegexBasedMatcher&) = delete;
41   RegexBasedMatcher& operator=(const RegexBasedMatcher&) = delete;
42 
43   ~RegexBasedMatcher();
44 
45   bool MatchNationalNumber(const string& number,
46                            const PhoneNumberDesc& number_desc,
47                            bool allow_prefix_match) const;
48 
49  private:
50   bool Match(const string& number, const string& number_pattern,
51              bool allow_prefix_match) const;
52 
53   const scoped_ptr<const AbstractRegExpFactory> regexp_factory_;
54   const scoped_ptr<RegExpCache> regexp_cache_;
55 
56 };
57 
58 }  // namespace phonenumbers
59 }  // namespace i18n
60 
61 #endif  // I18N_PHONENUMBERS_REGEX_BASED_MATCHER_H_
62