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
|
Oniguruma API 2003/07/04
declared in regex.h.
# int regex_init(void)
Initialize library.
You don't have to call it explicitly, because it is called in regex_new().
# int regex_error_code_to_str(UChar* err_buf, int err_code, ...)
Return error message string length.
arguments
1 err_buf: error message buffer.
(required size: REG_MAX_ERROR_MESSAGE_LEN)
2 err_code: error code returned from other API functions.
3 err_info (optional): error info returned from regex_new()
and regex_recompile().
# int regex_new(regex_t** reg, UChar* pattern, UChar* pattern_end,
RegOptionType option, RegCharEncoding code, RegSyntaxType* syntax,
RegErrorInfo* err_info)
Create new regex object(regex_t).
normal return: REG_NORMAL
arguments
1 reg: return regex object's address.
2 pattern: regex pattern string.
3 pattern_end: terminate address of pattern. (pattern + pattern length)
4 option: compile time options.
REG_OPTION_NONE no option
REG_OPTION_SINGLELINE '^' -> '\A', '$' -> '\z', '\Z' -> '\z'
REG_OPTION_MULTILINE '.' match with newline
REG_OPTION_IGNORECASE ignore case (case-insensitive)
REG_OPTION_EXTEND extended pattern form
REG_OPTION_FIND_LONGEST find longest match
REG_OPTION_FIND_NOT_EMPTY ignore empty match
REG_OPTION_NEGATE_SINGLELINE
clear REG_OPTION_SINGLELINE which is default on
in REG_SYNTAX_POSIX_XXX, REG_SYNTAX_PERL and REG_SYNTAX_JAVA.
REG_OPTION_CAPTURE_ONLY_NAMED_GROUP named group only captured.
5 code: character encoding.
REGCODE_ASCII ASCII
REGCODE_UTF8 UTF-8
REGCODE_EUCJP EUC-JP
REGCODE_SJIS Shift_JIS
REGCODE_DEFAULT ASCII
6 syntax: pointer to pattern syntax definition.
REG_SYNTAX_POSIX_BASIC POSIX Basic RE
REG_SYNTAX_POSIX_EXTENDED POSIX Extended RE
REG_SYNTAX_EMACS Emacs
REG_SYNTAX_GREP grep
REG_SYNTAX_GNU_REGEX GNU regex
REG_SYNTAX_JAVA Java (Sun java.util.regex)
REG_SYNTAX_PERL Perl
REG_SYNTAX_RUBY Ruby
REG_SYNTAX_DEFAULT default (== Ruby)
regex_set_default_syntax()
or any RegSyntaxType data pointer defined by user.
7 err_info: address for return optional error info.
use this value as 3rd argument of regex_error_code_to_str().
# void regex_free(regex_t* reg)
Free memory used by regex object.
arguments
1 reg: regex object.
# int regex_recompile(regex_t* reg, UChar* pattern, UChar* pattern_end,
RegOptionType option, RegCharEncoding code, RegSyntaxType* syntax,
RegErrorInfo* err_info)
Recompile regex object.
normal return: REG_NORMAL
arguments
1 reg: regex object.
Another arguments are same with regex_new().
# int regex_search(regex_t* reg, UChar* str, UChar* end, UChar* start,
UChar* range, RegRegion* region, RegOptionType option)
Search string and return search result and matching region.
normal return: match position offset (i.e. p - str >= 0)
not found: REG_MISMATCH (< 0)
arguments
1 reg: regex object
2 str: target string
3 end: terminate address of target string
4 start: search start address of target string
5 range: search terminate address of target string
6 region: address for return group match range info (NULL is allowed)
7 option: search time option
REG_OPTION_NOTBOL string head(str) isn't considered as begin of line
REG_OPTION_NOTEOL string end (end) isn't considered as end of line
REG_OPTION_POSIX_REGION region argument is regmatch_t[] of POSIX API.
# int regex_match(regex_t* reg, UChar* str, UChar* end, UChar* at,
RegRegion* region, RegOptionType option)
Match string and return result and matching region.
normal return: match length (i.e. p - at >= 0)
not match: REG_MISMATCH (< 0)
arguments
1 reg: regex object
2 str: target string
3 end: terminate address of target string
4 at: match address of target string
5 region: address for return group match range info (NULL is allowed)
6 option: search time option
REG_OPTION_NOTBOL string head(str) isn't considered as begin of line
REG_OPTION_NOTEOL string end (end) isn't considered as end of line
REG_OPTION_POSIX_REGION region argument is regmatch_t[] of POSIX API.
# RegRegion* regex_region_new(void)
Create a region.
# void regex_region_free(RegRegion* region, int free_self)
Free memory used by region.
arguments
1 region: target region
2 free_self: [1: free all, 0: free memory used in region but not self]
# void regex_region_copy(RegRegion* to, RegRegion* from)
Copy contents of region.
arguments
1 to: target region
2 from: source region
# void regex_region_clear(RegRegion* region)
Clear contents of region.
arguments
1 region: target region
# int regex_region_resize(RegRegion* region, int n)
Resize group range area of region.
normal return: REG_NORMAL
arguments
1 region: target region
2 n: new size
# int regex_name_to_group_numbers(regex_t* reg, UChar* name, UChar* name_end,
int** num_list)
Return group number list of name.
Named subexp is defined by (?<name>....).
normal return: number of groups for the name.
(ex. /(?<x>..)...(?<x>..)/ ==> 2)
name not found: -1
arguments
1 reg: regex object.
2 name: subexp-name.
3 name_end: terminate address of subexp-name.
4 num_list: return list of group number.
# int regex_foreach_names(regex_t* reg, int (*func)(UChar*,int,int*,void*),
void* arg)
Iterate function call for all names.
normal return: 0
error: func's return value.
arguments
1 reg: regex object.
2 func: called function.
func(name, <number of groups>, <group number's list>, arg);
if func return non 0 value, iteration is stopped.
3 arg: argument for func.
# UChar* regex_get_prev_char_head(RegCharEncoding code, UChar* start, UChar* s)
Return previous character head address.
arguments
1 code: character encoding
2 start: string address
3 s: target address of string
# UChar* regex_get_left_adjust_char_head(RegCharEncoding code,
UChar* start, UChar* s)
Return left-adjusted head address of a character.
arguments
1 code: character encoding
2 start: string address
3 s: target address of string
# UChar* regex_get_right_adjust_char_head(RegCharEncoding code,
UChar* start, UChar* s)
Return right-adjusted head address of a character.
arguments
1 code: character encoding
2 start: string address
3 s: target address of string
# int regex_set_default_syntax(RegSyntaxType* syntax)
Set default syntax.
arguments
1 syntax: pointer to pattern syntax definition.
# void regex_set_default_trans_table(UChar* table)
Set default case transformation table.
arguments
1 table: case transformation table
(* this function will be obsoleted in future version)
# int regex_end(void)
The use of this library is finished.
normal return: REG_NORMAL
# const char* regex_version(void)
Return version string. (ex. "1.8.6")
// END
|