3 /**********************************************************************
4 regint.h - Oniguruma (regular expression library)
5 **********************************************************************/
7 * Copyright (c) 2002-2018 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 /* #define ONIG_DEBUG_PARSE */
34 /* #define ONIG_DEBUG_COMPILE */
35 /* #define ONIG_DEBUG_SEARCH */
36 /* #define ONIG_DEBUG_MATCH */
37 /* #define ONIG_DONT_OPTIMIZE */
39 /* for byte-code statistical data. */
40 /* #define ONIG_DEBUG_STATISTICS */
42 #if defined(ONIG_DEBUG_PARSE) || defined(ONIG_DEBUG_MATCH) || \
43 defined(ONIG_DEBUG_SEARCH) || defined(ONIG_DEBUG_COMPILE) || \
44 defined(ONIG_DEBUG_STATISTICS)
50 #if defined(__i386) || defined(__i386__) || defined(_M_IX86) || \
51 (defined(__ppc__) && defined(__APPLE__)) || \
52 defined(__x86_64) || defined(__x86_64__) || \
54 #define PLATFORM_UNALIGNED_WORD_ACCESS
61 #define USE_BACKREF_WITH_LEVEL /* \k<name+n>, \k<name-n> */
62 #define USE_INSISTENT_CHECK_CAPTURES_IN_EMPTY_REPEAT /* /(?:()|())*\2/ */
63 #define USE_NEWLINE_AT_END_OF_STRING_HAS_EMPTY_LINE /* /\n$/ =~ "\n" */
64 #define USE_WARNING_REDUNDANT_NESTED_REPEAT_OPERATOR
66 #define USE_RETRY_LIMIT_IN_MATCH
69 #define USE_OP_PUSH_OR_JUMP_EXACT
70 #define USE_QUANT_PEEK_NEXT
71 #define USE_ST_LIBRARY
76 # ifndef HAVE_STDARG_PROTOTYPES
77 # define HAVE_STDARG_PROTOTYPES 1
81 /* escape Mac OS X/Xcode 2.4/gcc 4.0.1 problem */
82 #if defined(__APPLE__) && defined(__GNUC__) && __GNUC__ >= 4
83 # ifndef HAVE_STDARG_PROTOTYPES
84 # define HAVE_STDARG_PROTOTYPES 1
89 # ifndef HAVE_STDARG_PROTOTYPES
90 # define HAVE_STDARG_PROTOTYPES 1
95 #define INIT_MATCH_STACK_SIZE 160
96 #define DEFAULT_MATCH_STACK_LIMIT_SIZE 0 /* unlimited */
97 #define DEFAULT_RETRY_LIMIT_IN_MATCH 10000000
98 #define DEFAULT_PARSE_DEPTH_LIMIT 4096
101 /* escape other system UChar definition */
102 #ifdef ONIG_ESCAPE_UCHAR_COLLISION
103 #undef ONIG_ESCAPE_UCHAR_COLLISION
106 #define USE_WORD_BEGIN_END /* "\<", "\>" */
107 #define USE_CAPTURE_HISTORY
108 #define USE_VARIABLE_META_CHARS
109 #define USE_POSIX_API_REGION_OPTION
110 #define USE_FIND_LONGEST_SEARCH_ALL_OF_RANGE
112 #define xmalloc malloc
113 #define xrealloc realloc
114 #define xcalloc calloc
117 #define st_init_table onig_st_init_table
118 #define st_init_table_with_size onig_st_init_table_with_size
119 #define st_init_numtable onig_st_init_numtable
120 #define st_init_numtable_with_size onig_st_init_numtable_with_size
121 #define st_init_strtable onig_st_init_strtable
122 #define st_init_strtable_with_size onig_st_init_strtable_with_size
123 #define st_delete onig_st_delete
124 #define st_delete_safe onig_st_delete_safe
125 #define st_insert onig_st_insert
126 #define st_lookup onig_st_lookup
127 #define st_foreach onig_st_foreach
128 #define st_add_direct onig_st_add_direct
129 #define st_free_table onig_st_free_table
130 #define st_cleanup_safe onig_st_cleanup_safe
131 #define st_copy onig_st_copy
132 #define st_nothing_key_clone onig_st_nothing_key_clone
133 #define st_nothing_key_free onig_st_nothing_key_free
135 #define onig_st_is_member st_is_member
137 //#define xmemset memset
138 //#define xmemcpy memcpy
139 //#define xmemmove memmove
141 #if defined(_WIN32) && !defined(__GNUC__)
142 #define xalloca _alloca
143 #define xvsnprintf(buf,size,fmt,args) _vsnprintf_s(buf,size,_TRUNCATE,fmt,args)
144 #define xsnprintf sprintf_s
145 #define xstrcat(dest,src,size) strcat_s(dest,size,src)
147 #define xalloca alloca
148 #define xvsnprintf vsnprintf
149 #define xsnprintf snprintf
150 #define xstrcat(dest,src,size) strcat(dest,src)
154 // #include <stddef.h>
169 #if defined(HAVE_ALLOCA_H) && !defined(__GNUC__)
176 # include <strings.h>
180 #ifdef HAVE_SYS_TYPES_H
182 #include <sys/types.h>
186 #ifdef HAVE_INTTYPES_H
187 #include <inttypes.h>
200 #if defined(_MSC_VER) && (_MSC_VER < 1300)
201 typedef int intptr_t;
202 typedef unsigned int uintptr_t;
206 typedef INTN
intptr_t;
207 typedef UINTN
uintptr_t;
210 #define offsetof OFFSET_OF
220 #define MIN(a,b) (((a)>(b))?(b):(a))
221 #define MAX(a,b) (((a)<(b))?(b):(a))
223 #define IS_NULL(p) (((void*)(p)) == (void*)0)
224 #define IS_NOT_NULL(p) (((void*)(p)) != (void*)0)
225 #define CHECK_NULL_RETURN(p) if (IS_NULL(p)) return NULL
226 #define CHECK_NULL_RETURN_MEMERR(p) if (IS_NULL(p)) return ONIGERR_MEMORY
227 #define NULL_UCHARP ((UChar* )0)
229 #define INFINITE_LEN ONIG_INFINITE_DISTANCE
231 #ifdef PLATFORM_UNALIGNED_WORD_ACCESS
233 #define PLATFORM_GET_INC(val,p,type) do{\
235 (p) += sizeof(type);\
240 #define PLATFORM_GET_INC(val,p,type) do{\
241 xmemcpy(&val, (p), sizeof(type));\
242 (p) += sizeof(type);\
245 /* sizeof(OnigCodePoint) */
247 # define WORD_ALIGNMENT_SIZE SIZEOF_SIZE_T
249 # define WORD_ALIGNMENT_SIZE SIZEOF_LONG
252 #define GET_ALIGNMENT_PAD_SIZE(addr,pad_size) do {\
253 (pad_size) = WORD_ALIGNMENT_SIZE - ((uintptr_t )(addr) % WORD_ALIGNMENT_SIZE);\
254 if ((pad_size) == WORD_ALIGNMENT_SIZE) (pad_size) = 0;\
257 #define ALIGNMENT_RIGHT(addr) do {\
258 (addr) += (WORD_ALIGNMENT_SIZE - 1);\
259 (addr) -= ((uintptr_t )(addr) % WORD_ALIGNMENT_SIZE);\
262 #endif /* PLATFORM_UNALIGNED_WORD_ACCESS */
272 const UChar
* tag_start
;
273 const UChar
* tag_end
;
274 OnigCalloutType type
;
275 OnigCalloutFunc start_func
;
276 OnigCalloutFunc end_func
;
285 OnigType types
[ONIG_CALLOUT_MAX_ARGS_NUM
];
286 OnigValue vals
[ONIG_CALLOUT_MAX_ARGS_NUM
];
294 const UChar
* pattern
;
295 const UChar
* pattern_end
;
299 int callout_list_alloc
;
300 CalloutListEntry
* callout_list
; /* index: callout num */
304 #define REG_EXTP(reg) ((RegexExt* )((reg)->chain))
305 #define REG_EXTPL(reg) ((reg)->chain)
307 struct re_pattern_buffer
{
308 /* common members of BBuf(bytes-buffer) */
309 unsigned char* p
; /* compiled pattern */
310 unsigned int used
; /* used space for p */
311 unsigned int alloc
; /* allocated space for p */
313 int num_mem
; /* used memory(...) num counted from 1 */
314 int num_repeat
; /* OP_REPEAT/OP_REPEAT_NG id-counter */
315 int num_null_check
; /* OP_EMPTY_CHECK_START/END id counter */
316 int num_comb_exp_check
; /* no longer used (combination explosion check) */
317 int num_call
; /* number of subexp call */
318 unsigned int capture_history
; /* (?@...) flag (1-31) */
319 unsigned int bt_mem_start
; /* need backtrack flag */
320 unsigned int bt_mem_end
; /* need backtrack flag */
322 int repeat_range_alloc
;
323 OnigRepeatRange
* repeat_range
;
326 OnigOptionType options
;
327 OnigSyntaxType
* syntax
;
328 OnigCaseFoldType case_fold_flag
;
331 /* optimization info (string search, char-map and anchors) */
332 int optimize
; /* optimize flag */
333 int threshold_len
; /* search str-length for apply optimize */
334 int anchor
; /* BEGIN_BUF, BEGIN_POS, (SEMI_)END_BUF */
335 OnigLen anchor_dmin
; /* (SEMI_)END_BUF anchor distance */
336 OnigLen anchor_dmax
; /* (SEMI_)END_BUF anchor distance */
337 int sub_anchor
; /* start-anchor for exact or map */
338 unsigned char *exact
;
339 unsigned char *exact_end
;
340 unsigned char map
[ONIG_CHAR_TABLE_SIZE
]; /* used as BM skip or char-map */
341 int *int_map
; /* BM skip for exact_len > 255 */
342 int *int_map_backward
; /* BM skip for backward search */
343 OnigLen dmin
; /* min-distance of exact or map */
344 OnigLen dmax
; /* max-distance of exact or map */
346 /* regex_t link chain */
347 struct re_pattern_buffer
* chain
; /* escape compile-conflict */
351 /* stack pop level */
353 STACK_POP_LEVEL_FREE
= 0,
354 STACK_POP_LEVEL_MEM_START
= 1,
355 STACK_POP_LEVEL_ALL
= 2
361 OPTIMIZE_EXACT
= 1, /* Slow Search */
362 OPTIMIZE_EXACT_BM
= 2, /* Boyer Moore Search */
363 OPTIMIZE_EXACT_BM_NO_REV
= 3, /* BM (but not simple match) */
364 OPTIMIZE_EXACT_IC
= 4, /* Slow Search (ignore case) */
365 OPTIMIZE_MAP
= 5 /* char map */
369 typedef unsigned int MemStatusType
;
371 #define MEM_STATUS_BITS_NUM (sizeof(MemStatusType) * 8)
372 #define MEM_STATUS_CLEAR(stats) (stats) = 0
373 #define MEM_STATUS_ON_ALL(stats) (stats) = ~((MemStatusType )0)
374 #define MEM_STATUS_AT(stats,n) \
375 ((n) < (int )MEM_STATUS_BITS_NUM ? ((stats) & ((MemStatusType )1 << n)) : ((stats) & 1))
376 #define MEM_STATUS_AT0(stats,n) \
377 ((n) > 0 && (n) < (int )MEM_STATUS_BITS_NUM ? ((stats) & ((MemStatusType )1 << n)) : ((stats) & 1))
379 #define MEM_STATUS_ON(stats,n) do {\
380 if ((n) < (int )MEM_STATUS_BITS_NUM) {\
382 (stats) |= ((MemStatusType )1 << (n));\
388 #define MEM_STATUS_ON_SIMPLE(stats,n) do {\
389 if ((n) < (int )MEM_STATUS_BITS_NUM)\
390 (stats) |= ((MemStatusType )1 << (n));\
394 #define INT_MAX_LIMIT ((1UL << (SIZEOF_INT * 8 - 1)) - 1)
396 #define IS_CODE_WORD_ASCII(enc,code) \
397 (ONIGENC_IS_CODE_ASCII(code) && ONIGENC_IS_CODE_WORD(enc,code))
398 #define IS_CODE_DIGIT_ASCII(enc, code) \
399 (ONIGENC_IS_CODE_ASCII(code) && ONIGENC_IS_CODE_DIGIT(enc,code))
400 #define IS_CODE_XDIGIT_ASCII(enc, code) \
401 (ONIGENC_IS_CODE_ASCII(code) && ONIGENC_IS_CODE_XDIGIT(enc,code))
403 #define DIGITVAL(code) ((code) - '0')
404 #define ODIGITVAL(code) DIGITVAL(code)
405 #define XDIGITVAL(enc,code) \
406 (IS_CODE_DIGIT_ASCII(enc,code) ? DIGITVAL(code) \
407 : (ONIGENC_IS_CODE_UPPER(enc,code) ? (code) - 'A' + 10 : (code) - 'a' + 10))
409 #define IS_SINGLELINE(option) ((option) & ONIG_OPTION_SINGLELINE)
410 #define IS_MULTILINE(option) ((option) & ONIG_OPTION_MULTILINE)
411 #define IS_IGNORECASE(option) ((option) & ONIG_OPTION_IGNORECASE)
412 #define IS_EXTEND(option) ((option) & ONIG_OPTION_EXTEND)
413 #define IS_FIND_LONGEST(option) ((option) & ONIG_OPTION_FIND_LONGEST)
414 #define IS_FIND_NOT_EMPTY(option) ((option) & ONIG_OPTION_FIND_NOT_EMPTY)
415 #define IS_FIND_CONDITION(option) ((option) & \
416 (ONIG_OPTION_FIND_LONGEST | ONIG_OPTION_FIND_NOT_EMPTY))
417 #define IS_NOTBOL(option) ((option) & ONIG_OPTION_NOTBOL)
418 #define IS_NOTEOL(option) ((option) & ONIG_OPTION_NOTEOL)
419 #define IS_POSIX_REGION(option) ((option) & ONIG_OPTION_POSIX_REGION)
421 #define IS_WORD_ASCII(option) \
422 ((option) & (ONIG_OPTION_WORD_IS_ASCII | ONIG_OPTION_POSIX_IS_ASCII))
423 #define IS_DIGIT_ASCII(option) \
424 ((option) & (ONIG_OPTION_DIGIT_IS_ASCII | ONIG_OPTION_POSIX_IS_ASCII))
425 #define IS_SPACE_ASCII(option) \
426 ((option) & (ONIG_OPTION_SPACE_IS_ASCII | ONIG_OPTION_POSIX_IS_ASCII))
427 #define IS_POSIX_ASCII(option) ((option) & ONIG_OPTION_POSIX_IS_ASCII)
429 #define IS_ASCII_MODE_CTYPE_OPTION(ctype, options) \
431 (((ctype) < ONIGENC_CTYPE_ASCII && IS_POSIX_ASCII(options)) ||\
432 ((ctype) == ONIGENC_CTYPE_WORD && IS_WORD_ASCII(options)) ||\
433 ((ctype) == ONIGENC_CTYPE_DIGIT && IS_DIGIT_ASCII(options)) ||\
434 ((ctype) == ONIGENC_CTYPE_SPACE && IS_SPACE_ASCII(options))))
436 #define DISABLE_CASE_FOLD_MULTI_CHAR(case_fold_flag) \
437 ((case_fold_flag) & ~INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR)
439 #define REPEAT_INFINITE -1
440 #define IS_REPEAT_INFINITE(n) ((n) == REPEAT_INFINITE)
443 #define BITS_PER_BYTE 8
444 #define SINGLE_BYTE_SIZE (1 << BITS_PER_BYTE)
445 #define BITS_IN_ROOM (sizeof(Bits) * BITS_PER_BYTE)
446 #define BITSET_SIZE (SINGLE_BYTE_SIZE / BITS_IN_ROOM)
448 #ifdef PLATFORM_UNALIGNED_WORD_ACCESS
449 typedef unsigned int Bits
;
451 typedef unsigned char Bits
;
453 typedef Bits BitSet
[BITSET_SIZE
];
454 typedef Bits
* BitSetRef
;
456 #define SIZE_BITSET sizeof(BitSet)
458 #define BITSET_CLEAR(bs) do {\
460 for (i = 0; i < (int )BITSET_SIZE; i++) { (bs)[i] = 0; } \
463 #define BS_ROOM(bs,pos) (bs)[pos / BITS_IN_ROOM]
464 #define BS_BIT(pos) (1 << (pos % BITS_IN_ROOM))
466 #define BITSET_AT(bs, pos) (BS_ROOM(bs,pos) & BS_BIT(pos))
467 #define BITSET_SET_BIT(bs, pos) BS_ROOM(bs,pos) |= BS_BIT(pos)
468 #define BITSET_CLEAR_BIT(bs, pos) BS_ROOM(bs,pos) &= ~(BS_BIT(pos))
469 #define BITSET_INVERT_BIT(bs, pos) BS_ROOM(bs,pos) ^= BS_BIT(pos)
472 typedef struct _BBuf
{
478 #define BB_INIT(buf,size) onig_bbuf_init((BBuf* )(buf), (size))
480 #define BB_SIZE_INC(buf,inc) do{\
481 (buf)->alloc += (inc);\
482 (buf)->p = (UChar* )xrealloc((buf)->p, (buf)->alloc);\
483 if (IS_NULL((buf)->p)) return(ONIGERR_MEMORY);\
486 #define BB_EXPAND(buf,low) do{\
487 unsigned int OldSize_ = (buf)->alloc * sizeof((buf)->p[0]);\
488 do { (buf)->alloc *= 2; } while ((buf)->alloc < (unsigned int )low);\
489 (buf)->p = (UChar* )xrealloc((buf)->p, (buf)->alloc, OldSize_);\
490 if (IS_NULL((buf)->p)) return(ONIGERR_MEMORY);\
493 #define BB_ENSURE_SIZE(buf,size) do{\
494 unsigned int new_alloc = (buf)->alloc;\
495 while (new_alloc < (unsigned int )(size)) { new_alloc *= 2; }\
496 if ((buf)->alloc != new_alloc) {\
497 (buf)->p = (UChar* )xrealloc((buf)->p, new_alloc, (buf)->alloc);\
498 if (IS_NULL((buf)->p)) return(ONIGERR_MEMORY);\
499 (buf)->alloc = new_alloc;\
503 #define BB_WRITE(buf,pos,bytes,n) do{\
504 int used = (pos) + (n);\
505 if ((buf)->alloc < (unsigned int )used) BB_EXPAND((buf),used);\
506 xmemcpy((buf)->p + (pos), (bytes), (n));\
507 if ((buf)->used < (unsigned int )used) (buf)->used = used;\
510 #define BB_WRITE1(buf,pos,byte) do{\
511 int used = (pos) + 1;\
512 if ((buf)->alloc < (unsigned int )used) BB_EXPAND((buf),used);\
513 (buf)->p[(pos)] = (byte);\
514 if ((buf)->used < (unsigned int )used) (buf)->used = used;\
517 #define BB_ADD(buf,bytes,n) BB_WRITE((buf),(buf)->used,(bytes),(n))
518 #define BB_ADD1(buf,byte) BB_WRITE1((buf),(buf)->used,(byte))
519 #define BB_GET_ADD_ADDRESS(buf) ((buf)->p + (buf)->used)
520 #define BB_GET_OFFSET_POS(buf) ((buf)->used)
523 #define BB_MOVE_RIGHT(buf,from,to,n) do {\
524 if ((unsigned int )((to)+(n)) > (buf)->alloc) BB_EXPAND((buf),(to) + (n));\
525 xmemmove((buf)->p + (to), (buf)->p + (from), (n));\
526 if ((unsigned int )((to)+(n)) > (buf)->used) (buf)->used = (to) + (n);\
530 #define BB_MOVE_LEFT(buf,from,to,n) do {\
531 xmemmove((buf)->p + (to), (buf)->p + (from), (n));\
535 #define BB_MOVE_LEFT_REDUCE(buf,from,to) do {\
536 xmemmove((buf)->p + (to), (buf)->p + (from), (buf)->used - (from));\
537 (buf)->used -= (from - to);\
540 #define BB_INSERT(buf,pos,bytes,n) do {\
541 if (pos >= (buf)->used) {\
542 BB_WRITE(buf,pos,bytes,n);\
545 BB_MOVE_RIGHT((buf),(pos),(pos) + (n),((buf)->used - (pos)));\
546 xmemcpy((buf)->p + (pos), (bytes), (n));\
550 #define BB_GET_BYTE(buf, pos) (buf)->p[(pos)]
554 #define ANCHOR_PREC_READ (1<<0)
555 #define ANCHOR_PREC_READ_NOT (1<<1)
556 #define ANCHOR_LOOK_BEHIND (1<<2)
557 #define ANCHOR_LOOK_BEHIND_NOT (1<<3)
559 #define ANCHOR_BEGIN_BUF (1<<4)
560 #define ANCHOR_BEGIN_LINE (1<<5)
561 #define ANCHOR_BEGIN_POSITION (1<<6)
562 #define ANCHOR_END_BUF (1<<7)
563 #define ANCHOR_SEMI_END_BUF (1<<8)
564 #define ANCHOR_END_LINE (1<<9)
565 #define ANCHOR_WORD_BOUNDARY (1<<10)
566 #define ANCHOR_NO_WORD_BOUNDARY (1<<11)
567 #define ANCHOR_WORD_BEGIN (1<<12)
568 #define ANCHOR_WORD_END (1<<13)
569 #define ANCHOR_ANYCHAR_INF (1<<14)
570 #define ANCHOR_ANYCHAR_INF_ML (1<<15)
571 #define ANCHOR_EXTENDED_GRAPHEME_CLUSTER_BOUNDARY (1<<16)
572 #define ANCHOR_NO_EXTENDED_GRAPHEME_CLUSTER_BOUNDARY (1<<17)
575 #define ANCHOR_HAS_BODY(a) ((a)->type < ANCHOR_BEGIN_BUF)
577 #define IS_WORD_ANCHOR_TYPE(type) \
578 ((type) == ANCHOR_WORD_BOUNDARY || (type) == ANCHOR_NO_WORD_BOUNDARY || \
579 (type) == ANCHOR_WORD_BEGIN || (type) == ANCHOR_WORD_END)
583 OP_FINISH
= 0, /* matching process terminator (no more alternative) */
584 OP_END
= 1, /* pattern code terminator (success end) */
586 OP_EXACT1
= 2, /* single byte, N = 1 */
587 OP_EXACT2
, /* single byte, N = 2 */
588 OP_EXACT3
, /* single byte, N = 3 */
589 OP_EXACT4
, /* single byte, N = 4 */
590 OP_EXACT5
, /* single byte, N = 5 */
591 OP_EXACTN
, /* single byte */
592 OP_EXACTMB2N1
, /* mb-length = 2 N = 1 */
593 OP_EXACTMB2N2
, /* mb-length = 2 N = 2 */
594 OP_EXACTMB2N3
, /* mb-length = 2 N = 3 */
595 OP_EXACTMB2N
, /* mb-length = 2 */
596 OP_EXACTMB3N
, /* mb-length = 3 */
597 OP_EXACTMBN
, /* other length */
599 OP_EXACT1_IC
, /* single byte, N = 1, ignore case */
600 OP_EXACTN_IC
, /* single byte, ignore case */
608 #ifdef USE_OP_CCLASS_NODE
609 OP_CCLASS_NODE
, /* pointer to CClassNode node */
612 OP_ANYCHAR
, /* "." */
613 OP_ANYCHAR_ML
, /* "." multi-line */
614 OP_ANYCHAR_STAR
, /* ".*" */
615 OP_ANYCHAR_ML_STAR
, /* ".*" multi-line */
616 OP_ANYCHAR_STAR_PEEK_NEXT
,
617 OP_ANYCHAR_ML_STAR_PEEK_NEXT
,
628 OP_EXTENDED_GRAPHEME_CLUSTER_BOUNDARY
,
629 OP_NO_EXTENDED_GRAPHEME_CLUSTER_BOUNDARY
,
644 OP_BACKREF_WITH_LEVEL
, /* \k<xxx+n>, \k<xxx-n> */
645 OP_BACKREF_CHECK
, /* (?(n)), (?('name')) */
646 OP_BACKREF_CHECK_WITH_LEVEL
, /* (?(n-level)), (?('name-level')) */
649 OP_MEMORY_START_PUSH
, /* push back-tracker to stack */
650 OP_MEMORY_END_PUSH
, /* push back-tracker to stack */
651 OP_MEMORY_END_PUSH_REC
, /* push back-tracker to stack */
653 OP_MEMORY_END_REC
, /* push marker to stack */
655 OP_FAIL
, /* pop stack and move */
660 OP_PUSH_OR_JUMP_EXACT1
, /* if match exact then push, else jump. */
661 OP_PUSH_IF_PEEK_NEXT
, /* if match exact then push, else none. */
662 OP_REPEAT
, /* {n,m} */
663 OP_REPEAT_NG
, /* {n,m}? (non greedy) */
665 OP_REPEAT_INC_NG
, /* non greedy */
666 OP_REPEAT_INC_SG
, /* search and get in stack */
667 OP_REPEAT_INC_NG_SG
, /* search and get in stack (non greedy) */
668 OP_EMPTY_CHECK_START
, /* null loop checker start */
669 OP_EMPTY_CHECK_END
, /* null loop checker end */
670 OP_EMPTY_CHECK_END_MEMST
, /* null loop checker end (with capture status) */
671 OP_EMPTY_CHECK_END_MEMST_PUSH
, /* with capture status and push check-end */
673 OP_PREC_READ_START
, /* (?=...) start */
674 OP_PREC_READ_END
, /* (?=...) end */
675 OP_PREC_READ_NOT_START
, /* (?!...) start */
676 OP_PREC_READ_NOT_END
, /* (?!...) end */
677 OP_ATOMIC_START
, /* (?>...) start */
678 OP_ATOMIC_END
, /* (?>...) end */
679 OP_LOOK_BEHIND
, /* (?<=...) start (no needs end opcode) */
680 OP_LOOK_BEHIND_NOT_START
, /* (?<!...) start */
681 OP_LOOK_BEHIND_NOT_END
, /* (?<!...) end */
683 OP_CALL
, /* \g<name> */
688 OP_CALLOUT_CONTENTS
, /* (?{...}) (?{{...}}) */
689 OP_CALLOUT_NAME
, /* (*name) (*name[tag](args...)) */
694 SAVE_KEEP
= 0, /* SAVE S */
696 SAVE_RIGHT_RANGE
= 2,
700 UPDATE_VAR_KEEP_FROM_STACK_LAST
= 0,
701 UPDATE_VAR_S_FROM_STACK
= 1,
702 UPDATE_VAR_RIGHT_RANGE_FROM_STACK
= 2,
703 UPDATE_VAR_RIGHT_RANGE_FROM_S_STACK
= 3,
704 UPDATE_VAR_RIGHT_RANGE_INIT
= 4,
707 typedef int RelAddrType
;
708 typedef int AbsAddrType
;
709 typedef int LengthType
;
710 typedef int RepeatNumType
;
711 typedef int MemNumType
;
712 typedef void* PointerType
;
713 typedef int SaveType
;
714 typedef int UpdateVarType
;
715 typedef int ModeType
;
717 #define SIZE_OPCODE 1
718 #define SIZE_RELADDR sizeof(RelAddrType)
719 #define SIZE_ABSADDR sizeof(AbsAddrType)
720 #define SIZE_LENGTH sizeof(LengthType)
721 #define SIZE_MEMNUM sizeof(MemNumType)
722 #define SIZE_REPEATNUM sizeof(RepeatNumType)
723 #define SIZE_OPTION sizeof(OnigOptionType)
724 #define SIZE_CODE_POINT sizeof(OnigCodePoint)
725 #define SIZE_POINTER sizeof(PointerType)
726 #define SIZE_SAVE_TYPE sizeof(SaveType)
727 #define SIZE_UPDATE_VAR_TYPE sizeof(UpdateVarType)
728 #define SIZE_MODE sizeof(ModeType)
730 #define GET_RELADDR_INC(addr,p) PLATFORM_GET_INC(addr, p, RelAddrType)
731 #define GET_ABSADDR_INC(addr,p) PLATFORM_GET_INC(addr, p, AbsAddrType)
732 #define GET_LENGTH_INC(len,p) PLATFORM_GET_INC(len, p, LengthType)
733 #define GET_MEMNUM_INC(num,p) PLATFORM_GET_INC(num, p, MemNumType)
734 #define GET_REPEATNUM_INC(num,p) PLATFORM_GET_INC(num, p, RepeatNumType)
735 #define GET_OPTION_INC(option,p) PLATFORM_GET_INC(option, p, OnigOptionType)
736 #define GET_POINTER_INC(ptr,p) PLATFORM_GET_INC(ptr, p, PointerType)
737 #define GET_SAVE_TYPE_INC(type,p) PLATFORM_GET_INC(type, p, SaveType)
738 #define GET_UPDATE_VAR_TYPE_INC(type,p) PLATFORM_GET_INC(type, p, UpdateVarType)
739 #define GET_MODE_INC(mode,p) PLATFORM_GET_INC(mode, p, ModeType)
741 /* code point's address must be aligned address. */
742 #define GET_CODE_POINT(code,p) code = *((OnigCodePoint* )(p))
743 #define GET_BYTE_INC(byte,p) do{\
749 /* op-code + arg size */
750 #define SIZE_OP_ANYCHAR_STAR SIZE_OPCODE
751 #define SIZE_OP_ANYCHAR_STAR_PEEK_NEXT (SIZE_OPCODE + 1)
752 #define SIZE_OP_JUMP (SIZE_OPCODE + SIZE_RELADDR)
753 #define SIZE_OP_PUSH (SIZE_OPCODE + SIZE_RELADDR)
754 #define SIZE_OP_PUSH_SUPER (SIZE_OPCODE + SIZE_RELADDR)
755 #define SIZE_OP_POP_OUT SIZE_OPCODE
756 #define SIZE_OP_PUSH_OR_JUMP_EXACT1 (SIZE_OPCODE + SIZE_RELADDR + 1)
757 #define SIZE_OP_PUSH_IF_PEEK_NEXT (SIZE_OPCODE + SIZE_RELADDR + 1)
758 #define SIZE_OP_REPEAT_INC (SIZE_OPCODE + SIZE_MEMNUM)
759 #define SIZE_OP_REPEAT_INC_NG (SIZE_OPCODE + SIZE_MEMNUM)
760 #define SIZE_OP_WORD_BOUNDARY (SIZE_OPCODE + SIZE_MODE)
761 #define SIZE_OP_PREC_READ_START SIZE_OPCODE
762 #define SIZE_OP_PREC_READ_NOT_START (SIZE_OPCODE + SIZE_RELADDR)
763 #define SIZE_OP_PREC_READ_END SIZE_OPCODE
764 #define SIZE_OP_PREC_READ_NOT_END SIZE_OPCODE
765 #define SIZE_OP_FAIL SIZE_OPCODE
766 #define SIZE_OP_MEMORY_START (SIZE_OPCODE + SIZE_MEMNUM)
767 #define SIZE_OP_MEMORY_START_PUSH (SIZE_OPCODE + SIZE_MEMNUM)
768 #define SIZE_OP_MEMORY_END_PUSH (SIZE_OPCODE + SIZE_MEMNUM)
769 #define SIZE_OP_MEMORY_END_PUSH_REC (SIZE_OPCODE + SIZE_MEMNUM)
770 #define SIZE_OP_MEMORY_END (SIZE_OPCODE + SIZE_MEMNUM)
771 #define SIZE_OP_MEMORY_END_REC (SIZE_OPCODE + SIZE_MEMNUM)
772 #define SIZE_OP_ATOMIC_START SIZE_OPCODE
773 #define SIZE_OP_ATOMIC_END SIZE_OPCODE
774 #define SIZE_OP_EMPTY_CHECK_START (SIZE_OPCODE + SIZE_MEMNUM)
775 #define SIZE_OP_EMPTY_CHECK_END (SIZE_OPCODE + SIZE_MEMNUM)
776 #define SIZE_OP_LOOK_BEHIND (SIZE_OPCODE + SIZE_LENGTH)
777 #define SIZE_OP_LOOK_BEHIND_NOT_START (SIZE_OPCODE + SIZE_RELADDR + SIZE_LENGTH)
778 #define SIZE_OP_LOOK_BEHIND_NOT_END SIZE_OPCODE
779 #define SIZE_OP_CALL (SIZE_OPCODE + SIZE_ABSADDR)
780 #define SIZE_OP_RETURN SIZE_OPCODE
781 #define SIZE_OP_PUSH_SAVE_VAL (SIZE_OPCODE + SIZE_SAVE_TYPE + SIZE_MEMNUM)
782 #define SIZE_OP_UPDATE_VAR (SIZE_OPCODE + SIZE_UPDATE_VAR_TYPE + SIZE_MEMNUM)
785 #define SIZE_OP_CALLOUT_CONTENTS (SIZE_OPCODE + SIZE_MEMNUM)
786 #define SIZE_OP_CALLOUT_NAME (SIZE_OPCODE + SIZE_MEMNUM + SIZE_MEMNUM)
789 #define MC_ESC(syn) (syn)->meta_char_table.esc
790 #define MC_ANYCHAR(syn) (syn)->meta_char_table.anychar
791 #define MC_ANYTIME(syn) (syn)->meta_char_table.anytime
792 #define MC_ZERO_OR_ONE_TIME(syn) (syn)->meta_char_table.zero_or_one_time
793 #define MC_ONE_OR_MORE_TIME(syn) (syn)->meta_char_table.one_or_more_time
794 #define MC_ANYCHAR_ANYTIME(syn) (syn)->meta_char_table.anychar_anytime
796 #define IS_MC_ESC_CODE(code, syn) \
797 ((code) == MC_ESC(syn) && \
798 !IS_SYNTAX_OP2((syn), ONIG_SYN_OP2_INEFFECTIVE_ESCAPE))
801 #define SYN_POSIX_COMMON_OP \
802 ( ONIG_SYN_OP_DOT_ANYCHAR | ONIG_SYN_OP_POSIX_BRACKET | \
803 ONIG_SYN_OP_DECIMAL_BACKREF | \
804 ONIG_SYN_OP_BRACKET_CC | ONIG_SYN_OP_ASTERISK_ZERO_INF | \
805 ONIG_SYN_OP_LINE_ANCHOR | \
806 ONIG_SYN_OP_ESC_CONTROL_CHARS )
808 #define SYN_GNU_REGEX_OP \
809 ( ONIG_SYN_OP_DOT_ANYCHAR | ONIG_SYN_OP_BRACKET_CC | \
810 ONIG_SYN_OP_POSIX_BRACKET | ONIG_SYN_OP_DECIMAL_BACKREF | \
811 ONIG_SYN_OP_BRACE_INTERVAL | ONIG_SYN_OP_LPAREN_SUBEXP | \
812 ONIG_SYN_OP_VBAR_ALT | \
813 ONIG_SYN_OP_ASTERISK_ZERO_INF | ONIG_SYN_OP_PLUS_ONE_INF | \
814 ONIG_SYN_OP_QMARK_ZERO_ONE | \
815 ONIG_SYN_OP_ESC_AZ_BUF_ANCHOR | ONIG_SYN_OP_ESC_CAPITAL_G_BEGIN_ANCHOR | \
816 ONIG_SYN_OP_ESC_W_WORD | \
817 ONIG_SYN_OP_ESC_B_WORD_BOUND | ONIG_SYN_OP_ESC_LTGT_WORD_BEGIN_END | \
818 ONIG_SYN_OP_ESC_S_WHITE_SPACE | ONIG_SYN_OP_ESC_D_DIGIT | \
819 ONIG_SYN_OP_LINE_ANCHOR )
821 #define SYN_GNU_REGEX_BV \
822 ( ONIG_SYN_CONTEXT_INDEP_ANCHORS | ONIG_SYN_CONTEXT_INDEP_REPEAT_OPS | \
823 ONIG_SYN_CONTEXT_INVALID_REPEAT_OPS | ONIG_SYN_ALLOW_INVALID_INTERVAL | \
824 ONIG_SYN_BACKSLASH_ESCAPE_IN_CC | ONIG_SYN_ALLOW_DOUBLE_RANGE_OP_IN_CC )
827 #define NCCLASS_FLAGS(cc) ((cc)->flags)
828 #define NCCLASS_FLAG_SET(cc,flag) (NCCLASS_FLAGS(cc) |= (flag))
829 #define NCCLASS_FLAG_CLEAR(cc,flag) (NCCLASS_FLAGS(cc) &= ~(flag))
830 #define IS_NCCLASS_FLAG_ON(cc,flag) ((NCCLASS_FLAGS(cc) & (flag)) != 0)
833 #define FLAG_NCCLASS_NOT (1<<0)
834 #define FLAG_NCCLASS_SHARE (1<<1)
836 #define NCCLASS_SET_NOT(nd) NCCLASS_FLAG_SET(nd, FLAG_NCCLASS_NOT)
837 #define NCCLASS_CLEAR_NOT(nd) NCCLASS_FLAG_CLEAR(nd, FLAG_NCCLASS_NOT)
838 #define IS_NCCLASS_NOT(nd) IS_NCCLASS_FLAG_ON(nd, FLAG_NCCLASS_NOT)
840 extern void onig_add_end_call(void (*func
)(void));
845 #ifdef ONIG_DEBUG_COMPILE
846 extern void onig_print_compiled_byte_code_list(FILE* f
, regex_t
* reg
);
849 #ifdef ONIG_DEBUG_STATISTICS
850 extern void onig_statistics_init
P_((void));
851 extern int onig_print_statistics
P_((FILE* f
));
855 extern void onig_warning(const char* s
);
856 extern UChar
* onig_error_code_to_format
P_((int code
));
857 extern void EFIAPI onig_snprintf_with_pattern
PV_((UChar buf
[], int bufsize
, OnigEncoding enc
, UChar
* pat
, UChar
* pat_end
, const UChar
*fmt
, ...));
858 extern int onig_bbuf_init
P_((BBuf
* buf
, int size
));
859 extern int onig_compile
P_((regex_t
* reg
, const UChar
* pattern
, const UChar
* pattern_end
, OnigErrorInfo
* einfo
));
860 extern void onig_transfer
P_((regex_t
* to
, regex_t
* from
));
861 extern int onig_is_code_in_cc_len
P_((int enclen
, OnigCodePoint code
, void* /* CClassNode* */ cc
));
862 extern RegexExt
* onig_get_regex_ext(regex_t
* reg
);
863 extern int onig_ext_set_pattern(regex_t
* reg
, const UChar
* pattern
, const UChar
* pattern_end
);
867 extern OnigCalloutType
onig_get_callout_type_by_name_id(int name_id
);
868 extern OnigCalloutFunc
onig_get_callout_start_func_by_name_id(int id
);
869 extern OnigCalloutFunc
onig_get_callout_end_func_by_name_id(int id
);
870 extern int onig_callout_tag_table_free(void* table
);
871 extern void onig_free_reg_callout_list(int n
, CalloutListEntry
* list
);
872 extern CalloutListEntry
* onig_reg_callout_list_at(regex_t
* reg
, int num
);
873 extern OnigCalloutFunc
onig_get_callout_start_func(regex_t
* reg
, int callout_num
);
875 /* for definition of builtin callout */
876 #define BC0_P(name, func) do {\
877 int len = onigenc_str_bytelen_null(enc, (UChar* )name);\
878 id = onig_set_callout_of_name(enc, ONIG_CALLOUT_TYPE_SINGLE,\
879 (UChar* )(name), (UChar* )((name) + len),\
880 ONIG_CALLOUT_IN_PROGRESS,\
881 onig_builtin_ ## func, 0, 0, 0, 0, 0);\
882 if (id < 0) return id;\
885 #define BC0_R(name, func) do {\
886 int len = onigenc_str_bytelen_null(enc, (UChar* )name);\
887 id = onig_set_callout_of_name(enc, ONIG_CALLOUT_TYPE_SINGLE,\
888 (UChar* )(name), (UChar* )((name) + len),\
889 ONIG_CALLOUT_IN_RETRACTION,\
890 onig_builtin_ ## func, 0, 0, 0, 0, 0);\
891 if (id < 0) return id;\
894 #define BC0_B(name, func) do {\
895 int len = onigenc_str_bytelen_null(enc, (UChar* )name);\
896 id = onig_set_callout_of_name(enc, ONIG_CALLOUT_TYPE_SINGLE,\
897 (UChar* )(name), (UChar* )((name) + len),\
898 ONIG_CALLOUT_IN_BOTH,\
899 onig_builtin_ ## func, 0, 0, 0, 0, 0);\
900 if (id < 0) return id;\
903 #define BC_P(name, func, na, ts) do {\
904 int len = onigenc_str_bytelen_null(enc, (UChar* )name);\
905 id = onig_set_callout_of_name(enc, ONIG_CALLOUT_TYPE_SINGLE,\
906 (UChar* )(name), (UChar* )((name) + len),\
907 ONIG_CALLOUT_IN_PROGRESS,\
908 onig_builtin_ ## func, 0, (na), (ts), 0, 0); \
909 if (id < 0) return id;\
912 #define BC_P_O(name, func, nts, ts, nopts, opts) do {\
913 int len = onigenc_str_bytelen_null(enc, (UChar* )name);\
914 id = onig_set_callout_of_name(enc, ONIG_CALLOUT_TYPE_SINGLE,\
915 (UChar* )(name), (UChar* )((name) + len),\
916 ONIG_CALLOUT_IN_PROGRESS,\
917 onig_builtin_ ## func, 0, (nts), (ts), (nopts), (opts));\
918 if (id < 0) return id;\
921 #define BC_B(name, func, na, ts) do {\
922 int len = onigenc_str_bytelen_null(enc, (UChar* )name);\
923 id = onig_set_callout_of_name(enc, ONIG_CALLOUT_TYPE_SINGLE,\
924 (UChar* )(name), (UChar* )((name) + len),\
925 ONIG_CALLOUT_IN_BOTH,\
926 onig_builtin_ ## func, 0, (na), (ts), 0, 0);\
927 if (id < 0) return id;\
930 #define BC_B_O(name, func, nts, ts, nopts, opts) do {\
931 int len = onigenc_str_bytelen_null(enc, (UChar* )name);\
932 id = onig_set_callout_of_name(enc, ONIG_CALLOUT_TYPE_SINGLE,\
933 (UChar* )(name), (UChar* )((name) + len),\
934 ONIG_CALLOUT_IN_BOTH,\
935 onig_builtin_ ## func, 0, (nts), (ts), (nopts), (opts));\
936 if (id < 0) return id;\
939 #endif /* USE_CALLOUT */
943 typedef void hash_table_type
;
946 # include <windows.h>
947 typedef ULONG_PTR hash_data_type
;
949 //typedef unsigned long hash_data_type;
952 typedef UINTN hash_data_type
;
954 extern hash_table_type
* onig_st_init_strend_table_with_size
P_((int size
));
955 extern int onig_st_lookup_strend
P_((hash_table_type
* table
, const UChar
* str_key
, const UChar
* end_key
, hash_data_type
*value
));
956 extern int onig_st_insert_strend
P_((hash_table_type
* table
, const UChar
* str_key
, const UChar
* end_key
, hash_data_type value
));
958 typedef int (*ONIGENC_INIT_PROPERTY_LIST_FUNC_TYPE
)(void);
960 #endif /* REGINT_H */
961 #include <ProcessorBind.h>
962 #define INT_MAX MAX_INTN
963 #define LONG_MAX MAX_UINTN