-
Notifications
You must be signed in to change notification settings - Fork 94
/
API
702 lines (466 loc) · 21 KB
/
API
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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
Onigmo (Oniguruma-mod) API Version 6.1.2 2017/05/10
#include <onigmo.h>
# int onig_initialize(OnigEncoding use_encodings[], int num_encodings)
Initialize library.
This is added for compatibility to Oniguruma 6.0.
Currently this is same as onig_init().
arguments
1 use_encodings: array of encodings used in application.
2 num_encodings: number of encodings.
# int onig_init(void)
Initialize library.
Single thread program:
You don't have to call it explicitly, because it is called in onig_new().
However calling it is preferred.
Multi thread program:
You have to call it explicitly from a specific thread (normally the main
thread) before you use onig_new(), because onig_init() is not thread safe.
# int onig_error_code_to_str(UChar* err_buf, OnigPosition err_code, ...)
Get error message string.
If this function is used for onig_new(),
don't call this after the pattern argument of onig_new() is freed.
normal return: error message string length
arguments
1 err_buf: error message string buffer.
(required size: ONIG_MAX_ERROR_MESSAGE_LEN)
2 err_code: error code returned by other API functions.
3 err_info (optional): error info returned by onig_new().
# void onig_set_warn_func(OnigWarnFunc func)
Set warning function.
WARNING:
'[', '-', ']' in character class without escape.
']' in pattern without escape.
arguments
1 func: function pointer. void (*func)(char* warning_message)
# void onig_set_verb_warn_func(OnigWarnFunc func)
Set verbose warning function.
WARNING:
redundant nested repeat operator.
arguments
1 func: function pointer. void (*func)(char* warning_message)
# int onig_new(regex_t** reg, const UChar* pattern, const UChar* pattern_end,
OnigOptionType option, OnigEncoding enc,
const OnigSyntaxType* syntax, OnigErrorInfo* err_info)
Create a regex object.
normal return: ONIG_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.
ONIG_OPTION_NONE no option
ONIG_OPTION_SINGLELINE '^' -> '\A', '$' -> '\Z'
ONIG_OPTION_DOTALL '.' match with newline
ONIG_OPTION_MULTILINE same as ONIG_OPTION_DOTALL
ONIG_OPTION_IGNORECASE ambiguity match on
ONIG_OPTION_EXTEND extended pattern form
ONIG_OPTION_FIND_LONGEST find longest match
ONIG_OPTION_FIND_NOT_EMPTY ignore empty match
ONIG_OPTION_NEGATE_SINGLELINE
clear ONIG_OPTION_SINGLELINE which is enabled on
ONIG_SYNTAX_POSIX_BASIC, ONIG_SYNTAX_POSIX_EXTENDED,
ONIG_SYNTAX_PERL, ONIG_SYNTAX_PERL58, ONIG_SYNTAX_PERL58_NG,
ONIG_SYNTAX_JAVA, ONIG_SYNTAX_PYTHON
ONIG_OPTION_DONT_CAPTURE_GROUP only named group captured.
ONIG_OPTION_CAPTURE_GROUP named and no-named group captured.
ONIG_OPTION_NEWLINE_CRLF
Treat CR+LF as a newline too. (default: LF only)
To use this option, you must enable the following line in regenc.h.
/* #define USE_CRNL_AS_LINE_TERMINATOR */
5 enc: character encoding.
ONIG_ENCODING_ASCII ASCII
ONIG_ENCODING_ISO_8859_1 ISO 8859-1
ONIG_ENCODING_ISO_8859_2 ISO 8859-2
ONIG_ENCODING_ISO_8859_3 ISO 8859-3
ONIG_ENCODING_ISO_8859_4 ISO 8859-4
ONIG_ENCODING_ISO_8859_5 ISO 8859-5
ONIG_ENCODING_ISO_8859_6 ISO 8859-6
ONIG_ENCODING_ISO_8859_7 ISO 8859-7
ONIG_ENCODING_ISO_8859_8 ISO 8859-8
ONIG_ENCODING_ISO_8859_9 ISO 8859-9
ONIG_ENCODING_ISO_8859_10 ISO 8859-10
ONIG_ENCODING_ISO_8859_11 ISO 8859-11
ONIG_ENCODING_ISO_8859_13 ISO 8859-13
ONIG_ENCODING_ISO_8859_14 ISO 8859-14
ONIG_ENCODING_ISO_8859_15 ISO 8859-15
ONIG_ENCODING_ISO_8859_16 ISO 8859-16
ONIG_ENCODING_UTF_8 UTF-8
ONIG_ENCODING_UTF_16BE UTF-16BE
ONIG_ENCODING_UTF_16LE UTF-16LE
ONIG_ENCODING_UTF_32BE UTF-32BE
ONIG_ENCODING_UTF_32LE UTF-32LE
ONIG_ENCODING_EUC_JP EUC-JP
ONIG_ENCODING_EUC_TW EUC-TW
ONIG_ENCODING_EUC_KR EUC-KR
ONIG_ENCODING_EUC_CN EUC-CN
ONIG_ENCODING_SHIFT_JIS Shift_JIS
ONIG_ENCODING_WINDOWS_31J Windows-31J (CP932)
ONIG_ENCODING_KOI8_R KOI8-R
ONIG_ENCODING_KOI8_U KOI8-U
ONIG_ENCODING_WINDOWS_1250 Windows-1250 (CP1250)
ONIG_ENCODING_WINDOWS_1251 Windows-1251 (CP1251)
ONIG_ENCODING_WINDOWS_1252 Windows-1252 (CP1252)
ONIG_ENCODING_WINDOWS_1253 Windows-1253 (CP1253)
ONIG_ENCODING_WINDOWS_1254 Windows-1254 (CP1254)
ONIG_ENCODING_WINDOWS_1257 Windows-1257 (CP1257)
ONIG_ENCODING_BIG5 Big5
ONIG_ENCODING_GB18030 GB18030
or any OnigEncodingType data address defined by user.
The following encoding names can be also used for backward compatibility:
ONIG_ENCODING_UTF8 UTF-8
ONIG_ENCODING_UTF16_BE UTF-16BE
ONIG_ENCODING_UTF16_LE UTF-16LE
ONIG_ENCODING_UTF32_BE UTF-32BE
ONIG_ENCODING_UTF32_LE UTF-32LE
ONIG_ENCODING_SJIS Shift_JIS
ONIG_ENCODING_CP932 Windows-31J (CP932)
ONIG_ENCODING_CP1250 Windows-1250 (CP1250)
ONIG_ENCODING_CP1251 Windows-1251 (CP1251)
ONIG_ENCODING_CP1252 Windows-1252 (CP1252)
ONIG_ENCODING_CP1253 Windows-1253 (CP1253)
ONIG_ENCODING_CP1254 Windows-1254 (CP1254)
ONIG_ENCODING_CP1257 Windows-1257 (CP1257)
6 syntax: address of pattern syntax definition.
ONIG_SYNTAX_ASIS plain text
ONIG_SYNTAX_POSIX_BASIC POSIX Basic RE
ONIG_SYNTAX_POSIX_EXTENDED POSIX Extended RE
ONIG_SYNTAX_EMACS Emacs
ONIG_SYNTAX_GREP grep
ONIG_SYNTAX_GNU_REGEX GNU regex
ONIG_SYNTAX_JAVA Java (Sun java.util.regex)
ONIG_SYNTAX_PERL58 Perl 5.8
ONIG_SYNTAX_PERL58_NG Perl 5.8 + named group
ONIG_SYNTAX_PERL Perl 5.10+
ONIG_SYNTAX_PYTHON Python
ONIG_SYNTAX_RUBY Ruby
ONIG_SYNTAX_DEFAULT default (== Ruby)
onig_set_default_syntax()
or any OnigSyntaxType data address defined by user.
7 err_info: address for return optional error info.
Use this value as 3rd argument of onig_error_code_to_str().
# int onig_new_without_alloc(regex_t* reg, const UChar* pattern,
const UChar* pattern_end,
OnigOptionType option, OnigEncoding enc,
const OnigSyntaxType* syntax, OnigErrorInfo* err_info)
Create a regex object.
reg object area is not allocated in this function.
normal return: ONIG_NORMAL
# int onig_new_deluxe(regex_t** reg, const UChar* pattern, const UChar* pattern_end,
OnigCompileInfo* ci, OnigErrorInfo* einfo)
Create a regex object.
This function is deluxe version of onig_new().
normal return: ONIG_NORMAL
arguments
1 reg: return address of regex object.
2 pattern: regex pattern string.
3 pattern_end: terminate address of pattern. (pattern + pattern length)
4 ci: compile time info.
ci->num_of_elements: number of elements in ci. (current version: 5)
ci->pattern_enc: pattern string character encoding.
ci->target_enc: target string character encoding.
ci->syntax: address of pattern syntax definition.
ci->option: compile time option.
ci->case_fold_flag: character matching case fold bit flag for
ONIG_OPTION_IGNORECASE mode.
ONIGENC_CASE_FOLD_MIN: minimum
ONIGENC_CASE_FOLD_DEFAULT: minimum
onig_set_default_case_fold_flag()
5 err_info: address for return optional error info.
Use this value as 3rd argument of onig_error_code_to_str().
Different character encoding combination is allowed for
the following cases only.
pattern_enc: ASCII, ISO_8859_1
target_enc: UTF_16BE, UTF_16LE, UTF_32BE, UTF_32LE
pattern_enc: UTF_16BE/LE
target_enc: UTF_16LE/BE
pattern_enc: UTF_32BE/LE
target_enc: UTF_32LE/BE
# void onig_free(regex_t* reg)
Free memory used by regex object.
arguments
1 reg: regex object.
# void onig_free_body(regex_t* reg)
Free memory used by regex object. (Except reg oneself.)
arguments
1 reg: regex object.
# OnigPosition onig_search(regex_t* reg, const UChar* str, const UChar* end,
const UChar* start, const UChar* range, OnigRegion* region,
OnigOptionType option)
# OnigPosition onig_search_gpos(regex_t* reg, const UChar* str, const UChar* end,
const UChar* global_pos,
const UChar* start, const UChar* range, OnigRegion* region,
OnigOptionType option)
Search string and return search result and matching region.
normal return: match position offset (i.e. p - str >= 0)
not found: ONIG_MISMATCH (< 0)
arguments
1 reg: regex object
2 str: target string
3 end: terminate address of target string
4 global_pos: position of \G
if not need, set same value as str.
5 start: search start address of target string
6 range: search terminate address of target string
in forward search (start <= searched string < range)
in backward search (range <= searched string <= start)
7 region: address for return group match range info (NULL is allowed)
8 option: search time option
ONIG_OPTION_NOTBOL string head(str) isn't considered as begin of line
ONIG_OPTION_NOTEOL string end (end) isn't considered as end of line
ONIG_OPTION_NOTBOS string head(str) isn't considered as begin of string (\A)
ONIG_OPTION_NOTEOS string end (end) isn't considered as end of string (\z)
# OnigPosition onig_match(regex_t* reg, const UChar* str, const UChar* end,
const UChar* at, OnigRegion* region, OnigOptionType option)
Match string and return result and matching region.
normal return: match length (>= 0)
not match: ONIG_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
ONIG_OPTION_NOTBOL string head(str) isn't considered as begin of line
ONIG_OPTION_NOTEOL string end (end) isn't considered as end of line
ONIG_OPTION_NOTBOS string head(str) isn't considered as begin of string (\A)
ONIG_OPTION_NOTEOS string end (end) isn't considered as end of string (\z)
# OnigPosition onig_scan(regex_t* reg, const UChar* str, const UChar* end,
OnigRegion* region, OnigOptionType option,
int (*scan_callback)(OnigPosition, OnigPosition, OnigRegion*, void*),
void* callback_arg)
Scan string and callback with matching region.
normal return: number of matching times
error: error code
interruption: return value of callback function (!= 0)
arguments
1 reg: regex object
2 str: target string
3 end: terminate address of target string
4 region: address for return group match range info (NULL is allowed)
5 option: search time option
6 scan_callback: callback function (defined by user)
7 callback_arg: optional argument passed to callback
# OnigRegion* onig_region_new(void)
Create a region.
# void onig_region_free(OnigRegion* 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 onig_region_copy(OnigRegion* to, const OnigRegion* from)
Copy contents of region.
arguments
1 to: target region
2 from: source region
# void onig_region_clear(OnigRegion* region)
Clear contents of region.
arguments
1 region: target region
# int onig_region_resize(OnigRegion* region, int n)
Resize group range area of region.
normal return: ONIG_NORMAL
arguments
1 region: target region
2 n: new size
# int onig_name_to_group_numbers(regex_t* reg, const UChar* name, const UChar* name_end,
int** num_list)
Return the group number list of the 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: group name.
3 name_end: terminate address of group name.
4 num_list: return list of group number.
# int onig_name_to_backref_number(regex_t* reg, const UChar* name, const UChar* name_end,
const OnigRegion *region)
Return the group number corresponding to the named backref (\k<name>).
If two or more regions for the groups of the name are effective,
the greatest number in it is obtained.
normal return: group number.
arguments
1 reg: regex object.
2 name: group name.
3 name_end: terminate address of group name.
4 region: search/match result region.
# int onig_foreach_name(regex_t* reg,
int (*func)(const UChar*, const UChar*, int,int*,regex_t*,void*),
void* arg)
Iterate function call for all names.
normal return: 0
error: func's return value.
arguments
1 reg: regex object.
2 func: callback function.
func(name, name_end, <number of groups>, <group number's list>,
reg, arg);
if func does not return 0, then iteration is stopped.
3 arg: argument for func.
# int onig_number_of_names(const regex_t* reg)
Return the number of names defined in the pattern.
Multiple definitions of one name is counted as one.
arguments
1 reg: regex object.
# OnigEncoding onig_get_encoding(const regex_t* reg)
# OnigOptionType onig_get_options(const regex_t* reg)
# OnigCaseFoldType onig_get_case_fold_flag(const regex_t* reg)
# const OnigSyntaxType* onig_get_syntax(const regex_t* reg)
Return a value of the regex object.
arguments
1 reg: regex object.
# int onig_number_of_captures(const regex_t* reg)
Return the number of capture group in the pattern.
arguments
1 reg: regex object.
# int onig_number_of_capture_histories(const regex_t* reg)
Return the number of capture history defined in the pattern.
You can't use capture history if ONIG_SYN_OP2_ATMARK_CAPTURE_HISTORY
is disabled in the pattern syntax.(disabled in the default syntax)
arguments
1 reg: regex object.
# OnigCaptureTreeNode* onig_get_capture_tree(OnigRegion* region)
Return the root node of capture history data tree.
This value is undefined if matching has failed.
arguments
1 region: matching result.
# int onig_capture_tree_traverse(OnigRegion* region, int at,
int(*func)(int,OnigPosition,OnigPosition,int,int,void*),
void* arg)
Traverse and callback in capture history data tree.
normal return: 0
error: callback func's return value.
arguments
1 region: match region data.
2 at: callback position.
ONIG_TRAVERSE_CALLBACK_AT_FIRST: callback first, then traverse children.
ONIG_TRAVERSE_CALLBACK_AT_LAST: traverse children first, then callback.
ONIG_TRAVERSE_CALLBACK_AT_BOTH: callback first, then traverse children,
and at last callback again.
3 func: callback function.
if func does not return 0, then traverse is stopped.
int func(int group, OnigPosition beg, OnigPosition end,
int level, int at, void* arg)
group: group number
beg: capture start position
end: capture end position
level: nest level (from 0)
at: callback position
ONIG_TRAVERSE_CALLBACK_AT_FIRST
ONIG_TRAVERSE_CALLBACK_AT_LAST
arg: optional callback argument
4 arg; optional callback argument.
# int onig_noname_group_capture_is_active(const regex_t* reg)
Return noname group capture activity.
active: 1
inactive: 0
arguments
1 reg: regex object.
if option ONIG_OPTION_DONT_CAPTURE_GROUP == ON
--> inactive
if the regex pattern have named group
and syntax ONIG_SYN_CAPTURE_ONLY_NAMED_GROUP == ON
and option ONIG_OPTION_CAPTURE_GROUP == OFF
--> inactive
else --> active
# UChar* onigenc_get_prev_char_head(OnigEncoding enc, const UChar* start,
const UChar* s, const UChar* end)
Return previous character head address.
arguments
1 enc: character encoding
2 start: string address
3 s: target address of string
4 end: end of string
# UChar* onigenc_get_left_adjust_char_head(OnigEncoding enc,
const UChar* start, const UChar* s, const UChar* end)
Return left-adjusted head address of a character.
arguments
1 enc: character encoding
2 start: string address
3 s: target address of string
4 end: end of string
# UChar* onigenc_get_right_adjust_char_head(OnigEncoding enc,
const UChar* start, const UChar* s, const UChar* end)
Return right-adjusted head address of a character.
arguments
1 enc: character encoding
2 start: string address
3 s: target address of string
4 end: end of string
# int onigenc_strlen(OnigEncoding enc, const UChar* s, const UChar* end)
# int onigenc_strlen_null(OnigEncoding enc, const UChar* s)
Return number of characters in the string.
# int onigenc_str_bytelen_null(OnigEncoding enc, const UChar* s)
Return number of bytes in the string.
# int onig_set_default_syntax(const OnigSyntaxType* syntax)
Set default syntax.
arguments
1 syntax: address of pattern syntax definition.
# void onig_copy_syntax(OnigSyntaxType* to, const OnigSyntaxType* from)
Copy syntax.
arguments
1 to: destination address.
2 from: source address.
# unsigned int onig_get_syntax_op(const OnigSyntaxType* syntax)
# unsigned int onig_get_syntax_op2(const OnigSyntaxType* syntax)
# unsigned int onig_get_syntax_behavior(const OnigSyntaxType* syntax)
# OnigOptionType onig_get_syntax_options(const OnigSyntaxType* syntax)
# void onig_set_syntax_op(OnigSyntaxType* syntax, unsigned int op)
# void onig_set_syntax_op2(OnigSyntaxType* syntax, unsigned int op2)
# void onig_set_syntax_behavior(OnigSyntaxType* syntax, unsigned int behavior)
# void onig_set_syntax_options(OnigSyntaxType* syntax, OnigOptionType options)
Get/Set elements of the syntax.
arguments
1 syntax: syntax
2 op, op2, behavior, options: value of element.
# void onig_copy_encoding(OnigEncodingType *to, OnigEncoding from)
Copy encoding.
arguments
1 to: destination address.
2 from: source address.
# int onig_set_meta_char(OnigSyntaxType* syntax, unsigned int what,
OnigCodePoint code)
Set a variable meta character to the code point value.
Except for an escape character, this meta characters specification
is not work, if ONIG_SYN_OP_VARIABLE_META_CHARACTERS is not effective
by the syntax. (Build-in syntaxes are not effective.)
normal return: ONIG_NORMAL
arguments
1 syntax: target syntax
2 what: specifies which meta character it is.
ONIG_META_CHAR_ESCAPE
ONIG_META_CHAR_ANYCHAR
ONIG_META_CHAR_ANYTIME
ONIG_META_CHAR_ZERO_OR_ONE_TIME
ONIG_META_CHAR_ONE_OR_MORE_TIME
ONIG_META_CHAR_ANYCHAR_ANYTIME
3 code: meta character or ONIG_INEFFECTIVE_META_CHAR.
# OnigCaseFoldType onig_get_default_case_fold_flag(void)
Get default case fold flag.
# int onig_set_default_case_fold_flag(OnigCaseFoldType case_fold_flag)
Set default case fold flag.
1 case_fold_flag: case fold flag
# unsigned int onig_get_match_stack_limit_size(void)
Return the maximum number of stack size.
(default: 0 == unlimited)
# int onig_set_match_stack_limit_size(unsigned int size)
Set the maximum number of stack size.
(size = 0: unlimited)
normal return: ONIG_NORMAL
# unsigned int onig_get_parse_depth_limit(void)
Return the maximum depth of parser recursion.
(default: DEFAULT_PARSE_DEPTH_LIMIT defined in regint.h. Currently 4096.)
# int onig_set_parse_depth_limit(unsigned int depth)
Set the maximum depth of parser recursion.
(depth = 0: Set to the default value defined in regint.h.)
normal return: ONIG_NORMAL
# int onig_end(void)
The use of this library is finished.
normal return: ONIG_NORMAL
It is not allowed to use regex objects which created
before onig_end() call.
# const char* onig_version(void)
Return version string. (ex. "5.0.3")
// END