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_MATCHED_DATE_TIME_INFO_H
16 #define OHOS_GLOBAL_MATCHED_DATE_TIME_INFO_H
17 
18 #include <string>
19 #include <unicode/regex.h>
20 #include "utils.h"
21 
22 namespace OHOS {
23 namespace Global {
24 namespace I18n {
25 class MatchedDateTimeInfo {
26 public:
MatchedDateTimeInfo()27     MatchedDateTimeInfo() : _begin(-1), _end(-1), type(0), isTimePeriod(false) {}
MatchedDateTimeInfo(int begin,int end,std::string & regex)28     MatchedDateTimeInfo(int begin, int end, std::string& regex)
29         : _begin(begin), _end(end), regex(regex), type(0), isTimePeriod(false) {}
~MatchedDateTimeInfo()30     ~MatchedDateTimeInfo() {}
31 
SetIsTimePeriod(bool is)32     void SetIsTimePeriod(bool is)
33     {
34         isTimePeriod = is;
35     }
36 
IsTimePeriod()37     bool IsTimePeriod()
38     {
39         if (isTimePeriod) {
40             return isTimePeriod;
41         }
42         if (regex == "") {
43             return false;
44         }
45         int32_t status = 0;
46         int key = ConvertString2Int(regex, status);
47         // 49999 and 60000 are rules number.
48         return key > 49999 && key < 60000;
49     }
50 
SetBegin(int begin)51     void SetBegin(int begin)
52     {
53         this->_begin = begin;
54     }
55 
GetBegin()56     int GetBegin()
57     {
58         return _begin;
59     }
60 
SetEnd(int end)61     void SetEnd(int end)
62     {
63         this->_end = end;
64     }
65 
GetEnd()66     int GetEnd()
67     {
68         return _end;
69     }
70 
GetRegex()71     std::string GetRegex()
72     {
73         return regex;
74     }
75 
GetType()76     int GetType()
77     {
78         return type;
79     }
80 
SetType(int type)81     void SetType(int type)
82     {
83         this->type = type;
84     }
85 
86     bool operator<(const MatchedDateTimeInfo& info) const
87     {
88         if (_begin < info._begin) {
89             return true;
90         }
91         return false;
92     }
93 
94 private:
95     // Start position of the phone number
96     int _begin;
97     // End position of the phone number
98     int _end;
99     // Date rule key
100     std::string regex;
101     int type;
102     bool isTimePeriod;
103 };
104 } // namespace I18n
105 } // namespace Global
106 } // namespace OHOS
107 #endif