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_RULES_ENGINE_H 16 #define OHOS_GLOBAL_RULES_ENGINE_H 17 18 #include <string> 19 #include <unicode/regex.h> 20 #include <unordered_map> 21 #include <vector> 22 #include "date_time_rule.h" 23 #include "matched_date_time_info.h" 24 25 namespace OHOS { 26 namespace Global { 27 namespace I18n { 28 struct RulesSet { 29 public: RulesSetRulesSet30 RulesSet (std::unordered_map<std::string, std::string> rulesMap, 31 std::unordered_map<std::string, std::string> subRules, 32 std::unordered_map<std::string, std::string> param, 33 std::unordered_map<std::string, std::string> paramBackup) 34 { 35 this->rulesMap = rulesMap; 36 this->subRules = subRules; 37 this->param = param; 38 this->paramBackup = paramBackup; 39 } 40 std::unordered_map<std::string, std::string> rulesMap; 41 std::unordered_map<std::string, std::string> subRules; 42 std::unordered_map<std::string, std::string> param; 43 std::unordered_map<std::string, std::string> paramBackup; 44 }; 45 46 class RulesEngine { 47 public: 48 RulesEngine(); 49 RulesEngine(DateTimeRule* dateTimeRule, RulesSet& rulesSet); 50 ~RulesEngine(); 51 std::vector<MatchedDateTimeInfo> Match(icu::UnicodeString& message); 52 53 private: 54 void Init(); 55 std::string InitOptRules(std::string& rule); 56 std::string InitSubRules(std::string& rule); 57 bool InitRules(std::string& rulesValue); 58 DateTimeRule* dateTimeRule = nullptr; 59 std::unordered_map<std::string, std::string> rulesMap; 60 std::unordered_map<std::string, std::string> subRules; 61 std::unordered_map<std::string, std::string> param; 62 std::unordered_map<std::string, std::string> paramBackup; 63 std::unordered_map<std::string, icu::UnicodeString> patterns; 64 }; 65 } // namespace I18n 66 } // namespace Global 67 } // namespace OHOS 68 #endif