1 /*
2  * Copyright (c) 2023 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_PHONE_NUMBER_RULE_H
16 #define OHOS_GLOBAL_PHONE_NUMBER_RULE_H
17 
18 #include <string>
19 #include <unicode/regex.h>
20 #include <vector>
21 #include "regex_rule.h"
22 #include "negative_rule.h"
23 #include "border_rule.h"
24 #include "code_rule.h"
25 #include "positive_rule.h"
26 #include "find_rule.h"
27 #include "libxml/globals.h"
28 #include "libxml/tree.h"
29 #include "libxml/xmlstring.h"
30 
31 namespace OHOS {
32 namespace Global {
33 namespace I18n {
34 class PhoneNumberRule {
35 public:
36     PhoneNumberRule(std::string& country);
37     ~PhoneNumberRule();
38     void Init();
39 
40     std::vector<BorderRule*> GetBorderRules();
41     std::vector<CodeRule*> GetCodesRules();
42     std::vector<PositiveRule*> GetPositiveRules();
43     std::vector<NegativeRule*> GetNegativeRules();
44     std::vector<FindRule*> GetFindRules();
45     // Indicates whether the rules of the country are optimized
46     bool isFixed;
47 
48 private:
49     void InitRule(std::string& xmlPath);
50     void SetRules(std::string& category, icu::UnicodeString& content, std::string& valid,
51         std::string& handle, std::string& insensitive, std::string& type);
52     void ParseXmlNode(xmlNodePtr cur, std::string& category);
53     std::string XmlNodePtrToString(xmlNodePtr valuePtr);
54     bool IsXmlNodeValueEmpty(const std::string& insensitive, const std::string& type,
55         const std::string& valid, const std::string& handle);
56 
57     std::vector<NegativeRule*> negativeRules;
58     std::vector<PositiveRule*> positiveRules;
59     std::vector<BorderRule*> borderRules;
60     std::vector<CodeRule*> codesRules;
61     std::vector<FindRule*> findRules;
62     std::string country;
63     std::string xmlPath;
64     bool commonExit;
65     static std::string xmlCommonPath;
66 };
67 } // namespace I18n
68 } // namespace Global
69 } // namespace OHOS
70 #endif