forked from ElektraInitiative/libelektra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtype.h
236 lines (209 loc) · 5.59 KB
/
type.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/**
* @file type.h
*
* @brief Used for validating types.
*
* @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
*
*/
#ifndef ELEKTRA_PLUGIN_TOML_TYPE_H
#define ELEKTRA_PLUGIN_TOML_TYPE_H
#include <regex.h>
#include <stdbool.h>
typedef struct
{
regex_t regexBin;
regex_t regexOct;
regex_t regexDec;
regex_t regexHex;
regex_t regexFloat;
regex_t regexFloatSpecial;
// regex_t regexBare;
regex_t regexOffsetDt;
regex_t regexLocalDt;
regex_t regexLocalDate;
regex_t regexLocalTime;
} TypeChecker;
/*
* @brief Creates a new type checker.
*
* The type checker compiles different regular expressions, used for the validation of types.
* If one of the regular expressions can not be compiled, an assertion will be thrown, as long
* as assertions are enabled. If not enabled, regex compilation may silently fail.
*
* @retval Pointer The created type checker.
* @retval NULL When out-of-memory
*/
TypeChecker * createTypeChecker (void);
/*
* @brief Frees the type checker and all resources allocation within it.
*
* @param checker TypeChecker to be freed.
*/
void destroyTypeChecker (TypeChecker * checker);
/*
* @brief Checks if string is any number.
*
* Checks if the given number is binary, octal, decimal, hexadecimal or float.
*
* @param str String to be checked.
*
* @retval True If string is a number.
* @retval False Otherwise.
*/
bool isNumber (TypeChecker * checker, const char * str);
/*
* @brief Checks if string is binary.
*
* @param str String to be checked.
*
* @retval True If string is binary.
* @retval False Otherwise.
*/
bool isBinary (TypeChecker * checker, const char * str);
/*
* @brief Checks if string is octal.
*
* @param str String to be checked.
*
* @retval True If string is octal.
* @retval False Otherwise.
*/
bool isOctal (TypeChecker * checker, const char * str);
/*
* @brief Checks if string is decimal.
*
* @param str String to be checked.
*
* @retval True If string is decimal.
* @retval False Otherwise.
*/
bool isDecimal (TypeChecker * checker, const char * str);
/*
* @brief Checks if string is hexadecimal
*
* @param str String to be checked.
*
* @retval True If string is hexadecimal.
* @retval False Otherwise.
*/
bool isHexadecimal (TypeChecker * checker, const char * str);
/*
* @brief Checks if string is floating point.
*
* Considers +/- nan and +/- inf as floats.
*
* @param str String to be checked.
*
* @retval True If string is float.
* @retval False Otherwise.
*/
bool isFloat (TypeChecker * checker, const char * str);
// bool isBareString(TypeChecker * checker, const char * str);
/*
* @brief Checks if string is a datetime.
*
* Checks if the syntax matches a RFC3339 datetime.
*
* @param str String to be checked.
*
* @retval True If string is a datetime.
* @retval False Otherwise.
*/
bool isDateTime (TypeChecker * checker, const char * str);
/*
* @brief Checks if string could be an offset datetime.
*
* Checks only syntax.
*
* @param str String to be checked.
*
* @retval True If string is syntactically an offset datetime.
* @retval False Otherwise.
*/
bool isOffsetDatetime (TypeChecker * checker, const char * str);
/*
* @brief Checks if string is a local datetime.
*
* @param str String to be checked.
*
* @retval True If string is an local datetime.
* @retval False Otherwise.
*/
bool isLocalDateTime (TypeChecker * checker, const char * str);
/*
* @brief Checks if string is a date.
*
* @param str String to be checked.
*
* @retval True If string is a date.
* @retval False Otherwise.
*/
bool isLocalDate (TypeChecker * checker, const char * str);
/*
* @brief Checks if string is a local time.
*
* @param str String to be checked.
*
* @retval True If string is a local time.
* @retval False Otherwise.
*/
bool isLocalTime (TypeChecker * checker, const char * str);
/*
* @brief Checks the validity of datetime values.
*
* The supplied string must already be matched as a datetime,
* otherwise invalid values may be returned or invalid memory accesses may happen.
*
* Will check for leap years. Ignores leap seconds, so a second value of 60 is always valid.
*
* @param str A datetime string.
*
* @retval True If Values are valid.
* @retval False Otherwise.
*/
bool validOffsetDateTimeValues (const char * str);
/*
* @brief Checks the validity of local datetime values.
*
* The supplied string must already be matched as a local datetime,
* otherwise invalid values may be returned or invalid memory accesses may happen.
*
* Will check for leap years. Ignores leap seconds, so a second value of 60 is always valid.
*
* @param str A datetime string.
*
* @retval True If Values are valid.
* @retval False Otherwise.
*/
bool validLocalDateTimeValues (const char * str);
/*
* @brief Checks the validity of local date values.
*
* The supplied string must already be matched as a local date,
* otherwise invalid values may be returned or invalid memory accesses may happen.
*
* Will check for leap years.
*
* @param str A datetime string.
*
* @retval True If Values are valid.
* @retval False Otherwise.
*/
bool validLocalDateValues (const char * str);
/*
* @brief Checks the validity of local time values.
*
* The supplied string must already be matched as a local time,
* otherwise invalid values may be returned or invalid memory accesses may happen.
*
* Ignores leap seconds, so a second value of 60 is always valid.
*
* @param str A datetime string.
*
* @retval True If Values are valid.
* @retval False Otherwise.
*/
bool validLocalTimeValues (const char * str);
bool isValidNumberBase (const char * str, unsigned long long base);
#endif // ELEKTRA_PLUGIN_TOML_TYPE_H