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_CODE_RULE_H
16 #define OHOS_GLOBAL_I18N_CODE_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 CodeRule {
27 public:
28     CodeRule(std::string& IsValidType);
29     PhoneNumberMatch* IsValid(PhoneNumberMatch* possibleNumber, icu::UnicodeString& message);
30     PhoneNumberMatch* Handle(PhoneNumberMatch* phoneNumberMatch, icu::UnicodeString& message);
31 
32 private:
33     static int CountDigits(icu::UnicodeString& str);
34     void StartWithBrackets(icu::UnicodeString& phone);
35     bool NumberValid(icu::UnicodeString& number);
36     bool PrefixValid(icu::UnicodeString& number, int length);
37     PhoneNumberMatch* IsValidEnd(PhoneNumberMatch* possibleNumber, icu::UnicodeString& message);
38     PhoneNumberMatch* IsValidStart(PhoneNumberMatch* possibleNumber, icu::UnicodeString& message);
39     PhoneNumberMatch* IsValidDefault(PhoneNumberMatch* possibleNumber, icu::UnicodeString& message);
40     PhoneNumberMatch* IsValidPreSuf(PhoneNumberMatch* possibleNumber, icu::UnicodeString& message);
41     PhoneNumberMatch* IsValidCode(PhoneNumberMatch* possibleNumber, icu::UnicodeString& message);
42     PhoneNumberMatch* IsValidRawstr(PhoneNumberMatch* possibleNumber, icu::UnicodeString& message);
43     // Decide which IsValid function to use
44     std::string isValidType;
45 };
46 } // namespace I18n
47 } // namespace Global
48 } // namespace OHOS
49 #endif