1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef OHOS_GLOBAL_I18N_POSITIVE_RULE_H
16 #define OHOS_GLOBAL_I18N_POSITIVE_RULE_H
17 
18 #include <unicode/regex.h>
19 #include "matched_number_info.h"
20 #include "phonenumbers/phonenumbermatch.h"
21 
22 namespace OHOS {
23 namespace Global {
24 namespace I18n {
25 using i18n::phonenumbers::PhoneNumberMatch;
26 class PositiveRule {
27 public:
28     PositiveRule(icu::UnicodeString& regex, std::string& HandleType, std::string& insensitive);
29     icu::RegexPattern* GetPattern();
30     std::vector<MatchedNumberInfo> HandleInner(PhoneNumberMatch* possibleNumber, icu::UnicodeString& message);
31     std::vector<MatchedNumberInfo> Handle(PhoneNumberMatch* match, icu::UnicodeString& message);
32 
33 private:
34     static std::vector<MatchedNumberInfo> GetNumbersWithSlant(icu::UnicodeString& testStr);
35     std::vector<MatchedNumberInfo> HandlePossibleNumberWithPattern(PhoneNumberMatch* possibleNumber,
36         icu::UnicodeString& message, bool isStartsWithNumber);
37 
38     std::vector<MatchedNumberInfo> HandleDefault(PhoneNumberMatch* possibleNumber, icu::UnicodeString& message);
39     std::vector<MatchedNumberInfo> HandleOperator(PhoneNumberMatch* possibleNumber, icu::UnicodeString& message);
40     std::vector<MatchedNumberInfo> HandleBlank(PhoneNumberMatch* possibleNumber, icu::UnicodeString& message);
41     std::vector<MatchedNumberInfo> HandleSlant(PhoneNumberMatch* possibleNumber, icu::UnicodeString& message);
42     std::vector<MatchedNumberInfo> HandleStartWithMobile(PhoneNumberMatch* possibleNumber, icu::UnicodeString& message);
43     std::vector<MatchedNumberInfo> HandleEndWithMobile(PhoneNumberMatch* possibleNumber, icu::UnicodeString& message);
44 
45     icu::UnicodeString DealStringWithOneBracket(icu::UnicodeString& message);
46     bool IsNumberWithOneBracket(icu::UnicodeString& message);
47     icu::UnicodeString regex;
48     UErrorCode status;
49     std::string handleType;
50     std::string insensitive;
51 };
52 } // namespace I18n
53 } // namespace Global
54 } // namespace OHOS
55 #endif