]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/RegularExpressionDxe/Oniguruma/regenc.h
MdeModulePkg RegularExpressionDxe: Update Oniguruma to 6.9.0
[mirror_edk2.git] / MdeModulePkg / Universal / RegularExpressionDxe / Oniguruma / regenc.h
1 #ifndef REGENC_H
2 #define REGENC_H
3 /**********************************************************************
4 regenc.h - Oniguruma (regular expression library)
5 **********************************************************************/
6 /*-
7 * Copyright (c) 2002-2018 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
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.
18 *
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
29 * SUCH DAMAGE.
30 */
31
32 #ifndef ONIGURUMA_EXPORT
33 #define ONIGURUMA_EXPORT
34 #endif
35
36 //#include "config.h"
37 //#include <stddef.h>
38
39 #ifdef ONIG_ESCAPE_UCHAR_COLLISION
40 #undef ONIG_ESCAPE_UCHAR_COLLISION
41 #endif
42
43 #include "oniguruma.h"
44
45 typedef struct {
46 OnigCodePoint from;
47 OnigCodePoint to;
48 } OnigPairCaseFoldCodes;
49
50
51 #ifndef NULL
52 #define NULL ((void* )0)
53 #endif
54
55 #ifndef TRUE
56 #define TRUE 1
57 #endif
58
59 #ifndef FALSE
60 #define FALSE 0
61 #endif
62
63 #ifndef ARG_UNUSED
64 #if defined(__GNUC__)
65 # define ARG_UNUSED __attribute__ ((unused))
66 #else
67 # define ARG_UNUSED
68 #endif
69 #endif
70
71 #define ONIG_IS_NULL(p) (((void*)(p)) == (void*)0)
72 #define ONIG_IS_NOT_NULL(p) (((void*)(p)) != (void*)0)
73 #define ONIG_CHECK_NULL_RETURN(p) if (ONIG_IS_NULL(p)) return NULL
74 #define ONIG_CHECK_NULL_RETURN_VAL(p,val) if (ONIG_IS_NULL(p)) return (val)
75
76 #define MAX_CODE_POINT (~((OnigCodePoint )0))
77
78 #define enclen(enc,p) ONIGENC_MBC_ENC_LEN(enc,p)
79
80 /* character types bit flag */
81 #define BIT_CTYPE_NEWLINE (1<< ONIGENC_CTYPE_NEWLINE)
82 #define BIT_CTYPE_ALPHA (1<< ONIGENC_CTYPE_ALPHA)
83 #define BIT_CTYPE_BLANK (1<< ONIGENC_CTYPE_BLANK)
84 #define BIT_CTYPE_CNTRL (1<< ONIGENC_CTYPE_CNTRL)
85 #define BIT_CTYPE_DIGIT (1<< ONIGENC_CTYPE_DIGIT)
86 #define BIT_CTYPE_GRAPH (1<< ONIGENC_CTYPE_GRAPH)
87 #define BIT_CTYPE_LOWER (1<< ONIGENC_CTYPE_LOWER)
88 #define BIT_CTYPE_PRINT (1<< ONIGENC_CTYPE_PRINT)
89 #define BIT_CTYPE_PUNCT (1<< ONIGENC_CTYPE_PUNCT)
90 #define BIT_CTYPE_SPACE (1<< ONIGENC_CTYPE_SPACE)
91 #define BIT_CTYPE_UPPER (1<< ONIGENC_CTYPE_UPPER)
92 #define BIT_CTYPE_XDIGIT (1<< ONIGENC_CTYPE_XDIGIT)
93 #define BIT_CTYPE_WORD (1<< ONIGENC_CTYPE_WORD)
94 #define BIT_CTYPE_ALNUM (1<< ONIGENC_CTYPE_ALNUM)
95 #define BIT_CTYPE_ASCII (1<< ONIGENC_CTYPE_ASCII)
96
97 #define CTYPE_TO_BIT(ctype) (1<<(ctype))
98 #define CTYPE_IS_WORD_GRAPH_PRINT(ctype) \
99 ((ctype) == ONIGENC_CTYPE_WORD || (ctype) == ONIGENC_CTYPE_GRAPH ||\
100 (ctype) == ONIGENC_CTYPE_PRINT)
101
102
103 typedef struct {
104 UChar *name;
105 int ctype;
106 short int len;
107 } PosixBracketEntryType;
108
109 struct PropertyNameCtype {
110 char *name;
111 int ctype;
112 };
113
114 /* #define USE_CRNL_AS_LINE_TERMINATOR */
115 #define USE_UNICODE_PROPERTIES
116 #define USE_UNICODE_EXTENDED_GRAPHEME_CLUSTER
117 /* #define USE_UNICODE_CASE_FOLD_TURKISH_AZERI */
118 /* #define USE_UNICODE_ALL_LINE_TERMINATORS */ /* see Unicode.org UTS #18 */
119
120
121 #define ONIG_ENCODING_INIT_DEFAULT ONIG_ENCODING_ASCII
122
123
124 #define ENC_FLAG_ASCII_COMPATIBLE (1<<0)
125 #define ENC_FLAG_UNICODE (1<<1)
126
127
128 /* for encoding system implementation (internal) */
129 extern int onigenc_end(void);
130 extern int onigenc_ascii_apply_all_case_fold P_((OnigCaseFoldType flag, OnigApplyAllCaseFoldFunc f, void* arg));
131 extern int onigenc_ascii_get_case_fold_codes_by_str P_((OnigCaseFoldType flag, const OnigUChar* p, const OnigUChar* end, OnigCaseFoldCodeItem items[]));
132 extern int onigenc_apply_all_case_fold_with_map P_((int map_size, const OnigPairCaseFoldCodes map[], int ess_tsett_flag, OnigCaseFoldType flag, OnigApplyAllCaseFoldFunc f, void* arg));
133 extern int onigenc_get_case_fold_codes_by_str_with_map P_((int map_size, const OnigPairCaseFoldCodes map[], int ess_tsett_flag, OnigCaseFoldType flag, const OnigUChar* p, const OnigUChar* end, OnigCaseFoldCodeItem items[]));
134 extern int onigenc_not_support_get_ctype_code_range P_((OnigCtype ctype, OnigCodePoint* sb_out, const OnigCodePoint* ranges[]));
135 extern int onigenc_is_mbc_newline_0x0a P_((const UChar* p, const UChar* end));
136
137
138 /* methods for single byte encoding */
139 extern int onigenc_ascii_mbc_case_fold P_((OnigCaseFoldType flag, const UChar** p, const UChar* end, UChar* lower));
140 extern int onigenc_single_byte_mbc_enc_len P_((const UChar* p));
141 extern OnigCodePoint onigenc_single_byte_mbc_to_code P_((const UChar* p, const UChar* end));
142 extern int onigenc_single_byte_code_to_mbclen P_((OnigCodePoint code));
143 extern int onigenc_single_byte_code_to_mbc P_((OnigCodePoint code, UChar *buf));
144 extern UChar* onigenc_single_byte_left_adjust_char_head P_((const UChar* start, const UChar* s));
145 extern int onigenc_always_true_is_allowed_reverse_match P_((const UChar* s, const UChar* end));
146 extern int onigenc_always_false_is_allowed_reverse_match P_((const UChar* s, const UChar* end));
147 extern int onigenc_always_true_is_valid_mbc_string P_((const UChar* s, const UChar* end));
148 extern int onigenc_length_check_is_valid_mbc_string P_((OnigEncoding enc, const UChar* s, const UChar* end));
149
150 /* methods for multi byte encoding */
151 extern OnigCodePoint onigenc_mbn_mbc_to_code P_((OnigEncoding enc, const UChar* p, const UChar* end));
152 extern int onigenc_mbn_mbc_case_fold P_((OnigEncoding enc, OnigCaseFoldType flag, const UChar** p, const UChar* end, UChar* lower));
153 extern int onigenc_mb2_code_to_mbclen P_((OnigCodePoint code));
154 extern int onigenc_mb2_code_to_mbc P_((OnigEncoding enc, OnigCodePoint code, UChar *buf));
155 extern int onigenc_minimum_property_name_to_ctype P_((OnigEncoding enc, UChar* p, UChar* end));
156 extern int onigenc_unicode_property_name_to_ctype P_((OnigEncoding enc, UChar* p, UChar* end));
157 extern int onigenc_is_mbc_word_ascii P_((OnigEncoding enc, UChar* s, const UChar* end));
158 extern int onigenc_mb2_is_code_ctype P_((OnigEncoding enc, OnigCodePoint code, unsigned int ctype));
159 extern int onigenc_mb4_code_to_mbclen P_((OnigCodePoint code));
160 extern int onigenc_mb4_code_to_mbc P_((OnigEncoding enc, OnigCodePoint code, UChar *buf));
161 extern int onigenc_mb4_is_code_ctype P_((OnigEncoding enc, OnigCodePoint code, unsigned int ctype));
162 extern struct PropertyNameCtype* onigenc_euc_jp_lookup_property_name P_((register const char *str, register size_t len));
163 extern struct PropertyNameCtype* onigenc_sjis_lookup_property_name P_((register const char *str, register size_t len));
164
165 /* in enc/unicode.c */
166 extern int onigenc_unicode_is_code_ctype P_((OnigCodePoint code, unsigned int ctype));
167 extern int onigenc_utf16_32_get_ctype_code_range P_((OnigCtype ctype, OnigCodePoint *sb_out, const OnigCodePoint* ranges[]));
168 extern int onigenc_unicode_ctype_code_range P_((OnigCtype ctype, const OnigCodePoint* ranges[]));
169 extern int onigenc_unicode_get_case_fold_codes_by_str P_((OnigEncoding enc, OnigCaseFoldType flag, const OnigUChar* p, const OnigUChar* end, OnigCaseFoldCodeItem items[]));
170 extern int onigenc_unicode_mbc_case_fold P_((OnigEncoding enc, OnigCaseFoldType flag, const UChar** pp, const UChar* end, UChar* fold));
171 extern int onigenc_unicode_apply_all_case_fold P_((OnigCaseFoldType flag, OnigApplyAllCaseFoldFunc f, void* arg));
172 extern int onigenc_egcb_is_break_position P_((OnigEncoding enc, UChar* p, UChar* prev, const UChar* start, const UChar* end));
173
174
175 #define UTF16_IS_SURROGATE_FIRST(c) (((c) & 0xfc) == 0xd8)
176 #define UTF16_IS_SURROGATE_SECOND(c) (((c) & 0xfc) == 0xdc)
177
178 /* from unicode generated codes */
179 #define FOLDS1_FOLD(i) (OnigUnicodeFolds1 + (i))
180 #define FOLDS2_FOLD(i) (OnigUnicodeFolds2 + (i))
181 #define FOLDS3_FOLD(i) (OnigUnicodeFolds3 + (i))
182 #define FOLDS1_UNFOLDS_NUM(i) (OnigUnicodeFolds1[(i)+1])
183 #define FOLDS2_UNFOLDS_NUM(i) (OnigUnicodeFolds2[(i)+2])
184 #define FOLDS3_UNFOLDS_NUM(i) (OnigUnicodeFolds3[(i)+3])
185 #define FOLDS1_UNFOLDS(i) (OnigUnicodeFolds1 + (i) + 2)
186 #define FOLDS2_UNFOLDS(i) (OnigUnicodeFolds2 + (i) + 3)
187 #define FOLDS3_UNFOLDS(i) (OnigUnicodeFolds3 + (i) + 4)
188 #define FOLDS1_NEXT_INDEX(i) ((i) + 2 + OnigUnicodeFolds1[(i)+1])
189 #define FOLDS2_NEXT_INDEX(i) ((i) + 3 + OnigUnicodeFolds2[(i)+2])
190 #define FOLDS3_NEXT_INDEX(i) ((i) + 4 + OnigUnicodeFolds3[(i)+3])
191
192 #define FOLDS_FOLD_ADDR_BUK(buk, addr) do {\
193 if ((buk)->fold_len == 1)\
194 addr = OnigUnicodeFolds1 + (buk)->index;\
195 else if ((buk)->fold_len == 2)\
196 addr = OnigUnicodeFolds2 + (buk)->index;\
197 else if ((buk)->fold_len == 3)\
198 addr = OnigUnicodeFolds3 + (buk)->index;\
199 else\
200 addr = 0;\
201 } while (0)
202
203 extern OnigCodePoint OnigUnicodeFolds1[];
204 extern OnigCodePoint OnigUnicodeFolds2[];
205 extern OnigCodePoint OnigUnicodeFolds3[];
206
207 struct ByUnfoldKey {
208 OnigCodePoint code;
209 short int index;
210 short int fold_len;
211 };
212
213 extern const struct ByUnfoldKey* onigenc_unicode_unfold_key(OnigCodePoint code);
214 extern int onigenc_unicode_fold1_key(OnigCodePoint code[]);
215 extern int onigenc_unicode_fold2_key(OnigCodePoint code[]);
216 extern int onigenc_unicode_fold3_key(OnigCodePoint code[]);
217
218 extern int onig_codes_cmp(OnigCodePoint a[], OnigCodePoint b[], int n);
219 extern int onig_codes_byte_at(OnigCodePoint code[], int at);
220
221
222
223 #define ONIGENC_ISO_8859_1_TO_LOWER_CASE(c) \
224 OnigEncISO_8859_1_ToLowerCaseTable[c]
225 #define ONIGENC_ISO_8859_1_TO_UPPER_CASE(c) \
226 OnigEncISO_8859_1_ToUpperCaseTable[c]
227
228 extern const UChar OnigEncISO_8859_1_ToLowerCaseTable[];
229 extern const UChar OnigEncISO_8859_1_ToUpperCaseTable[];
230
231 extern int
232 onigenc_with_ascii_strncmp P_((OnigEncoding enc, const UChar* p, const UChar* end, const UChar* sascii /* ascii */, int n));
233 extern UChar*
234 onigenc_step P_((OnigEncoding enc, const UChar* p, const UChar* end, int n));
235
236 /* defined in regexec.c, but used in enc/xxx.c */
237 extern int onig_is_in_code_range P_((const UChar* p, OnigCodePoint code));
238
239 extern OnigEncoding OnigEncDefaultCharEncoding;
240 extern const UChar OnigEncAsciiToLowerCaseTable[];
241 extern const UChar OnigEncAsciiToUpperCaseTable[];
242 extern const unsigned short OnigEncAsciiCtypeTable[];
243
244
245 #define ONIGENC_IS_ASCII_CODE(code) ((code) < 0x80)
246 #define ONIGENC_ASCII_CODE_TO_LOWER_CASE(c) OnigEncAsciiToLowerCaseTable[c]
247 #define ONIGENC_ASCII_CODE_TO_UPPER_CASE(c) OnigEncAsciiToUpperCaseTable[c]
248 #define ONIGENC_IS_ASCII_CODE_CTYPE(code,ctype) \
249 ((OnigEncAsciiCtypeTable[code] & CTYPE_TO_BIT(ctype)) != 0)
250 #define ONIGENC_IS_ASCII_CODE_WORD(code) \
251 ((OnigEncAsciiCtypeTable[code] & CTYPE_TO_BIT(ONIGENC_CTYPE_WORD)) != 0)
252 #define ONIGENC_IS_ASCII_CODE_CASE_AMBIG(code) \
253 (ONIGENC_IS_ASCII_CODE_CTYPE(code, ONIGENC_CTYPE_UPPER) ||\
254 ONIGENC_IS_ASCII_CODE_CTYPE(code, ONIGENC_CTYPE_LOWER))
255
256 #define ONIGENC_IS_UNICODE_ENCODING(enc) \
257 (((enc)->flag & ENC_FLAG_UNICODE) != 0)
258
259 #define ONIGENC_IS_ASCII_COMPATIBLE_ENCODING(enc) \
260 (((enc)->flag & ENC_FLAG_ASCII_COMPATIBLE) != 0)
261
262 #endif /* REGENC_H */