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_DATE_RULE_INIT_H
16 #define OHOS_GLOBAL_DATE_RULE_INIT_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 "date_time_filter.h"
24 #include "matched_date_time_info.h"
25 #include "rules_engine.h"
26 
27 namespace OHOS {
28 namespace Global {
29 namespace I18n {
30 class DateRuleInit {
31 public:
32     DateRuleInit(std::string& locale);
33     ~DateRuleInit();
34 
35     std::vector<MatchedDateTimeInfo> Detect(icu::UnicodeString& message);
36 
37 private:
38     void Init();
39     std::vector<MatchedDateTimeInfo> GetMatches(icu::UnicodeString& message);
40     std::vector<MatchedDateTimeInfo> ClearFind(icu::UnicodeString& message);
41     std::vector<MatchedDateTimeInfo> PastFind(icu::UnicodeString& message);
42     void GetMatchedInfo(std::vector<MatchedDateTimeInfo>& matches, MatchedDateTimeInfo& match,
43         icu::UnicodeString& message);
44 
45     std::string locale;
46     DateTimeRule* dateTimeRule;
47     DateTimeFilter* filter;
48     std::vector<RulesEngine> universalAndLocaleRules;
49     std::unordered_map<std::string, RulesEngine> subDetectsMap;
50     RulesEngine clearRulesEngine;
51     RulesEngine pastRulesEngine;
52 };
53 } // namespace I18n
54 } // namespace Global
55 } // namespace OHOS
56 #endif