-
Notifications
You must be signed in to change notification settings - Fork 5
/
comelang-str.h
339 lines (271 loc) · 11.9 KB
/
comelang-str.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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
#ifndef COMELANG_STR_H
#define COMELANG_STR_H
using comelang-str;
#include <pcre.h>
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE
#endif
#include <wchar.h>
#include <libgen.h>
typedef wchar_t*% wstring;
struct come_regex
{
string str;
pcre* regex;
bool ignore_case;
bool multiline;
bool global;
bool extended;
bool dotall;
bool anchored;
bool dollar_endonly;
bool ungreedy;
int options;
pcre* re;
};
come_regex*% come_regex*::initialize(come_regex*% self, char* str, bool ignore_case=false, bool multiline=false, bool global=false, bool extended=false, bool dotall=false, bool anchored=false, bool dollar_endonly=false, bool ungreedy=false);
come_regex*% char*::to_regex(char* self, bool ignore_case=false, bool multiline=false, bool global=false, bool extended=false, bool dotall=false, bool anchored=false, bool dollar_endonly=false, bool ungreedy=false);
come_regex*% string::to_regex(char* self, bool ignore_case=false, bool multiline=false, bool global=false, bool extended=false, bool dotall=false, bool anchored=false, bool dollar_endonly=false, bool ungreedy=false);
void come_regex*::finalize(come_regex* reg);
come_regex*% come_regex*::clone(come_regex* reg);
bool come_regex*::equals(come_regex* left, come_regex* right);
unsigned int come_regex*::get_hash_key(come_regex* reg);
string come_regex*::to_string(come_regex* regex);
string string::lower_case(char* str);
string string::upper_case(char* str);
wstring wchar_t*::substring(wchar_t* str, int head, int tail);
static inline wstring wstring::substring(wchar_t* str, int head, int tail)
{
return wchar_t*::substring(str, head, tail);
}
int char*::index_count(char* str, char* search_str, int count=1, int default_value=-1);
static inline int string::index_count(char* str, char* search_str, int count=1, int default_value=-1)
{
return char*::index_count(str, search_str, count, default_value);
}
int char*::index_regex_count(char* self, come_regex* reg, int count=1, int default_value);
static inline int string::index_regex_count(char* self, come_regex* reg, int count=1, int default_value=-1)
{
return char*::index_regex_count(self, reg, count, default_value);
}
int char*::rindex(char* str, char* search_str, int default_value=-1);
static inline int string::rindex(char* str, char* search_str, int default_value=-1)
{
return char*::rindex(str, search_str, default_value);
}
int char*::rindex_regex(char* self, come_regex* reg, int default_value=-1);
static inline int string::rindex_regex(char* self, come_regex* reg, int default_value=-1)
{
return char*::rindex_regex(self, reg, default_value);
}
int char*::rindex_count(char* str, char* search_str, int count=1, int default_value=-1);
static inline int string::rindex_count(char* str, char* search_str, int count=1, int default_value=-1)
{
return char*::rindex_count(str, search_str, default_value);
}
list<string>*% char*::scan_block(char* self, come_regex* reg, void* parent, string (*block)(void* parent, char* match_string, list<string>* group_strings));
static inline list<string>*% string::scan_block(char* self, come_regex* reg, void* parent, string (*block)(void* parent, char* match_string, list<string>* group_strings))
{
return char*::scan_block(self, reg, parent, block);
}
list<string>*% char*::scan_block_count(char* self, come_regex* reg, int count, void* parent, string (*block)(void* parent, char* match_string, list<string>* group_strings));
static inline list<string>*% string::scan_block_count(char* self, come_regex* reg, int count, void* parent, string (*block)(void* parent, char* match_string, list<string>* group_strings))
{
return char*::scan_block_count(self, reg, count, parent, block);
}
list<string>*% char*::split_block(char* self, come_regex* reg, void* parent, string (*block)(void* parent, char* match_string, list<string>* group_strings));
static inline list<string>*% string::split_block(char* self, come_regex* reg, void* parent, string (*block)(void* parent, char* match_string, list<string>* group_strings))
{
return char*::split_block(self, reg, parent, block);
}
list<string>*% char*::split_block_count(char* self, come_regex* reg, int count, void* parent, string (*block)(void* parent, char* match_string, list<string>* group_strings));
static inline list<string>*% string::split_block_count(char* self, come_regex* reg, int count, void* parent, string (*block)(void* parent, char* match_string, list<string>* group_strings))
{
return char*::split_block_count(self, reg, count, parent, block);
}
list<string>*% char*::scan_group_strings(char* self, come_regex* reg, list<string>* group_strings, int* num_group_string_in_regex);
static inline list<string>*% string::scan_group_strings(char* self, come_regex* reg, list<string>* group_strings, int* num_group_string_in_regex)
{
return char*::scan_group_strings(self, reg, group_strings, num_group_string_in_regex);
}
string char*::strip(char* self);
static inline string string::strip(char* self)
{
return char*::strip(self);
}
string char*::printable(char* str);
static inline string string::printable(char* str)
{
return string::printable(str);
}
wstring char*::to_wstring(char* str);
static inline wstring string::to_wstring(char* str)
{
return char*::to_wstring(str);
}
string wchar_t::to_string(wchar_t wc);
string wchar_t*::to_string(wchar_t* wstr);
static inline string wstring::to_string(wchar_t* wstr)
{
return wchar_t*::to_string(wstr);
}
static inline wstring int::to_wstring(int self)
{
return xsprintf("%d", self).to_wstring();
}
int wchar_t*::length(wchar_t* str);
static inline int wstring::length(wchar_t* str)
{
return wchar_t*::length(str);
}
wstring wchar_t*::delete(wchar_t* str, int head, int tail) ;
static inline wstring wstring::delete(wchar_t* str, int head, int tail)
{
return wchar_t*::delete(str, head, tail);
}
int wchar_t*::index(wchar_t* str, wchar_t* search_str, int default_value=-1);
static inline int wstring::index(wchar_t* str, wchar_t* search_str, int default_value=1)
{
return wchar_t*::index(str, search_str, default_value);
}
int wchar_t*::rindex(wchar_t* str, wchar_t* search_str, int default_value=-1);
static inline int wstring::rindex(wchar_t* str, wchar_t* search_str, int default_value=-1)
{
return wchar_t*::rindex(str, search_str, default_value);
}
wstring wchar_t*::reverse(wchar_t* str);
static inline wstring wstring::reverse(wchar_t* str)
{
return wchar_t*::reverse(str);
}
wstring wchar_t*::multiply(wchar_t* str, int n);
static inline wstring wstring::multiply(wchar_t* str, int n)
{
return wchar_t*::multiply(str, n);
}
wstring wchar_t*::printable(wchar_t* str);
static inline wstring wstring::printable(wchar_t* str)
{
return wchar_t*::printable(str);
}
int wchar_t*::compare(wchar_t* left, wchar_t* right);
int wstring::compare(wchar_t* left, wchar_t* right);
bool wchar_t::operator_equals(wchar_t left, wchar_t right);
bool wchar_t::operator_not_equals(wchar_t left, wchar_t right);
bool wchar_t*::operator_equals(wchar_t* left, wchar_t* right);
bool wstring::operator_equals(wchar_t* left, wchar_t* right);
bool wchar_t*::operator_not_equals(wchar_t* left, wchar_t* right);
bool wstring::operator_not_equals(wchar_t* left, wchar_t* right);
wstring wchar_t*::operator_add(wchar_t* left, wchar_t* right);
wstring wstring::operator_add(wchar_t* left, wchar_t* right);
wstring wchar_t*::operator_mult(wchar_t* str, int n);
wstring wstring::operator_mult(wchar_t* str, int n);
unsigned int wchar_t::get_hash_key(wchar_t value);
unsigned int wchar_t*::get_hash_key(wchar_t* value);
static inline unsigned int wstring::get_hash_key(wchar_t* value)
{
return wchar_t*::get_hash_key(value);
}
bool wchar_t::equals(wchar_t left, wchar_t right);
bool wchar_t*::equals(wchar_t* left, wchar_t* right);
bool wstring::equals(wchar_t* left, wchar_t* right);
bool char*::match_group_strings(char* self, come_regex* reg, int count, list<string>* group_strings);
static inline bool string::match_group_strings(char* self, come_regex* reg, int count, list<string>* group_strings)
{
return char*::match_group_strings(self, reg, count, group_strings);
}
int char*::index(char* str, char* search_str, int default_value=-1);
static inline int string::index(char* str, char* search_str, int default_value=-1)
{
return char*::index(str, search_str, default_value);
}
int char*::index_regex(char* self, come_regex* reg, int default_value=-1);
static inline int string::index_regex(char* self, come_regex* reg, int default_value=-1)
{
return char*::index_regex(self, reg, default_value);
}
string char*::replace(char* self, int index, char c);
static inline string string::replace(char* self, int index, char c)
{
return char*::replace(self, index, c);
}
string char*::multiply(char* str, int n);
static inline string string::multiply(char* str, int n)
{
return char*::multiply(str, n);
}
string char*::sub(char* self, come_regex* reg, char* replace);
static inline string string::sub(char* self, come_regex* reg, char* replace)
{
return char*::sub(self, reg, replace);
}
string char*::sub_count(char* self, come_regex* reg, char* replace, int count=1);
static inline string string::sub_count(char* self, come_regex* reg, char* replace, int count=1)
{
return char*::sub_count(self, reg, replace, count);
}
list<string>*% char*::split_str(char* self, char* str);
static inline list<string>*% string::split_str(char* self, char* str)
{
return char*::split_str(self, str);
}
list<string>*% char*::scan(char* self, come_regex* reg);
static inline list<string>*% string::scan(char* self, come_regex* reg)
{
return char*::scan(self, reg);
}
list<string>*% char*::split(char* self, come_regex* reg);
static inline list<string>*% string::split(char* self, come_regex* reg)
{
return char*::split(self, reg);
}
bool char*::match(char* self, come_regex* reg);
static inline bool string::match(char* self, come_regex* reg)
{
return char*::match(self, reg);
}
list<string>*% char*::split_maxsplit(char* self, come_regex* reg, int maxsplit);
static inline list<string>*% string::split_maxsplit(char* self, come_regex* reg, int maxsplit)
{
return char*::split_maxsplit(self, reg, maxsplit);
}
int char*::rindex_regex_count(char* self, come_regex* reg, int count=1, int default_value=-1);
static inline int string::rindex_regex_count(char* self, come_regex* reg, int count=1, int default_value=-1)
{
return char*::rindex_regex_count(self, reg, count, default_value);
}
bool char*::match_count(char* self, come_regex* reg, int count=1);
static inline bool string::match_count(char* self, come_regex* reg, int count=1)
{
return char*::match_count(self, reg, count);
}
string char*::sub_block(char* self, come_regex* reg, void* parent, string (*block)(void* parent, char* match_string, list<string>* group_strings));
static inline string string::sub_block(char* self, come_regex* reg, void* parent, string (*block)(void* parent, char* match_string, list<string>* group_strings))
{
return char*::sub_block(self, reg, parent, block);
}
string char*::sub_block_count(char* self, come_regex* reg, int count, void* parent, string (*block)(void* parent, char* match_string, list<string>* group_strings));
static inline string string::sub_block_count(char* self, come_regex* reg, int count, void* parent, string (*block)(void* parent, char* match_string, list<string>* group_strings))
{
return char*::sub_block_count(self, reg, count, parent, block);
}
bool come_regex*::operator_not_equals(come_regex* left, come_regex* right);
bool come_regex*::operator_equals(come_regex* left, come_regex* right);
wstring char*::to_wstring(char* str);
static inline wstring string::to_wstring(char* str)
{
return char*::to_wstring(str);
}
wstring __builtin_wstring(char* str);
string string::chomp(char* str);
static inline string char*::chomp(char* str)
{
return string::chomp(str);
}
string xrealpath(char* path);
string xdirname(char* path);
size_t xwcslen(wchar_t* wstr); // for debian, ubuntu
#ifdef __DEBIAN__
#define wcslen(o) xwcslen(o)
#endif
#endif