1 /**********************************************************************
2 regenc.c - Oniguruma (regular expression library)
3 **********************************************************************/
5 * Copyright (c) 2002-2007 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
8 * (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>
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
34 OnigEncoding OnigEncDefaultCharEncoding
= ONIG_ENCODING_INIT_DEFAULT
;
43 onigenc_get_default_encoding(void)
45 return OnigEncDefaultCharEncoding
;
49 onigenc_set_default_encoding(OnigEncoding enc
)
51 OnigEncDefaultCharEncoding
= enc
;
56 onigenc_get_right_adjust_char_head(OnigEncoding enc
, const UChar
* start
, const UChar
* s
)
58 UChar
* p
= ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc
, start
, s
);
66 onigenc_get_right_adjust_char_head_with_prev(OnigEncoding enc
,
67 const UChar
* start
, const UChar
* s
, const UChar
** prev
)
69 UChar
* p
= ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc
, start
, s
);
72 if (prev
) *prev
= (const UChar
* )p
;
76 if (prev
) *prev
= (const UChar
* )NULL
; /* Sorry */
82 onigenc_get_prev_char_head(OnigEncoding enc
, const UChar
* start
, const UChar
* s
)
87 return ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc
, start
, s
- 1);
91 onigenc_step_back(OnigEncoding enc
, const UChar
* start
, const UChar
* s
, int n
)
93 while (ONIG_IS_NOT_NULL(s
) && n
-- > 0) {
97 s
= ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc
, start
, s
- 1);
103 onigenc_step(OnigEncoding enc
, const UChar
* p
, const UChar
* end
, int n
)
105 UChar
* q
= (UChar
* )p
;
107 q
+= ONIGENC_MBC_ENC_LEN(enc
, q
);
109 return (q
<= end
? q
: NULL
);
113 onigenc_strlen(OnigEncoding enc
, const UChar
* p
, const UChar
* end
)
116 UChar
* q
= (UChar
* )p
;
119 q
+= ONIGENC_MBC_ENC_LEN(enc
, q
);
126 onigenc_strlen_null(OnigEncoding enc
, const UChar
* s
)
129 UChar
* p
= (UChar
* )s
;
134 int len
= ONIGENC_MBC_MINLEN(enc
);
136 if (len
== 1) return n
;
139 if (*q
!= '\0') break;
143 if (len
== 1) return n
;
145 p
+= ONIGENC_MBC_ENC_LEN(enc
, p
);
151 onigenc_str_bytelen_null(OnigEncoding enc
, const UChar
* s
)
153 UChar
* start
= (UChar
* )s
;
154 UChar
* p
= (UChar
* )s
;
159 int len
= ONIGENC_MBC_MINLEN(enc
);
161 if (len
== 1) return (int )(p
- start
);
164 if (*q
!= '\0') break;
168 if (len
== 1) return (int )(p
- start
);
170 p
+= ONIGENC_MBC_ENC_LEN(enc
, p
);
174 const UChar OnigEncAsciiToLowerCaseTable
[] = {
175 0000, 0001, 0002, 0003, 0004, 0005, 0006, 0007,
176 0010, 0011, 0012, 0013, 0014, 0015, 0016, 0017,
177 0020, 0021, 0022, 0023, 0024, 0025, 0026, 0027,
178 0030, 0031, 0032, 0033, 0034, 0035, 0036, 0037,
179 0040, 0041, 0042, 0043, 0044, 0045, 0046, 0047,
180 0050, 0051, 0052, 0053, 0054, 0055, 0056, 0057,
181 0060, 0061, 0062, 0063, 0064, 0065, 0066, 0067,
182 0070, 0071, 0072, 0073, 0074, 0075, 0076, 0077,
183 0100, 0141, 0142, 0143, 0144, 0145, 0146, 0147,
184 0150, 0151, 0152, 0153, 0154, 0155, 0156, 0157,
185 0160, 0161, 0162, 0163, 0164, 0165, 0166, 0167,
186 0170, 0171, 0172, 0133, 0134, 0135, 0136, 0137,
187 0140, 0141, 0142, 0143, 0144, 0145, 0146, 0147,
188 0150, 0151, 0152, 0153, 0154, 0155, 0156, 0157,
189 0160, 0161, 0162, 0163, 0164, 0165, 0166, 0167,
190 0170, 0171, 0172, 0173, 0174, 0175, 0176, 0177,
191 0200, 0201, 0202, 0203, 0204, 0205, 0206, 0207,
192 0210, 0211, 0212, 0213, 0214, 0215, 0216, 0217,
193 0220, 0221, 0222, 0223, 0224, 0225, 0226, 0227,
194 0230, 0231, 0232, 0233, 0234, 0235, 0236, 0237,
195 0240, 0241, 0242, 0243, 0244, 0245, 0246, 0247,
196 0250, 0251, 0252, 0253, 0254, 0255, 0256, 0257,
197 0260, 0261, 0262, 0263, 0264, 0265, 0266, 0267,
198 0270, 0271, 0272, 0273, 0274, 0275, 0276, 0277,
199 0300, 0301, 0302, 0303, 0304, 0305, 0306, 0307,
200 0310, 0311, 0312, 0313, 0314, 0315, 0316, 0317,
201 0320, 0321, 0322, 0323, 0324, 0325, 0326, 0327,
202 0330, 0331, 0332, 0333, 0334, 0335, 0336, 0337,
203 0340, 0341, 0342, 0343, 0344, 0345, 0346, 0347,
204 0350, 0351, 0352, 0353, 0354, 0355, 0356, 0357,
205 0360, 0361, 0362, 0363, 0364, 0365, 0366, 0367,
206 0370, 0371, 0372, 0373, 0374, 0375, 0376, 0377,
209 #ifdef USE_UPPER_CASE_TABLE
210 const UChar OnigEncAsciiToUpperCaseTable
[256] = {
211 0000, 0001, 0002, 0003, 0004, 0005, 0006, 0007,
212 0010, 0011, 0012, 0013, 0014, 0015, 0016, 0017,
213 0020, 0021, 0022, 0023, 0024, 0025, 0026, 0027,
214 0030, 0031, 0032, 0033, 0034, 0035, 0036, 0037,
215 0040, 0041, 0042, 0043, 0044, 0045, 0046, 0047,
216 0050, 0051, 0052, 0053, 0054, 0055, 0056, 0057,
217 0060, 0061, 0062, 0063, 0064, 0065, 0066, 0067,
218 0070, 0071, 0072, 0073, 0074, 0075, 0076, 0077,
219 0100, 0101, 0102, 0103, 0104, 0105, 0106, 0107,
220 0110, 0111, 0112, 0113, 0114, 0115, 0116, 0117,
221 0120, 0121, 0122, 0123, 0124, 0125, 0126, 0127,
222 0130, 0131, 0132, 0133, 0134, 0135, 0136, 0137,
223 0140, 0101, 0102, 0103, 0104, 0105, 0106, 0107,
224 0110, 0111, 0112, 0113, 0114, 0115, 0116, 0117,
225 0120, 0121, 0122, 0123, 0124, 0125, 0126, 0127,
226 0130, 0131, 0132, 0173, 0174, 0175, 0176, 0177,
227 0200, 0201, 0202, 0203, 0204, 0205, 0206, 0207,
228 0210, 0211, 0212, 0213, 0214, 0215, 0216, 0217,
229 0220, 0221, 0222, 0223, 0224, 0225, 0226, 0227,
230 0230, 0231, 0232, 0233, 0234, 0235, 0236, 0237,
231 0240, 0241, 0242, 0243, 0244, 0245, 0246, 0247,
232 0250, 0251, 0252, 0253, 0254, 0255, 0256, 0257,
233 0260, 0261, 0262, 0263, 0264, 0265, 0266, 0267,
234 0270, 0271, 0272, 0273, 0274, 0275, 0276, 0277,
235 0300, 0301, 0302, 0303, 0304, 0305, 0306, 0307,
236 0310, 0311, 0312, 0313, 0314, 0315, 0316, 0317,
237 0320, 0321, 0322, 0323, 0324, 0325, 0326, 0327,
238 0330, 0331, 0332, 0333, 0334, 0335, 0336, 0337,
239 0340, 0341, 0342, 0343, 0344, 0345, 0346, 0347,
240 0350, 0351, 0352, 0353, 0354, 0355, 0356, 0357,
241 0360, 0361, 0362, 0363, 0364, 0365, 0366, 0367,
242 0370, 0371, 0372, 0373, 0374, 0375, 0376, 0377,
246 const unsigned short OnigEncAsciiCtypeTable
[256] = {
247 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008,
248 0x4008, 0x420c, 0x4209, 0x4208, 0x4208, 0x4208, 0x4008, 0x4008,
249 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008,
250 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008,
251 0x4284, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0,
252 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0,
253 0x78b0, 0x78b0, 0x78b0, 0x78b0, 0x78b0, 0x78b0, 0x78b0, 0x78b0,
254 0x78b0, 0x78b0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0,
255 0x41a0, 0x7ca2, 0x7ca2, 0x7ca2, 0x7ca2, 0x7ca2, 0x7ca2, 0x74a2,
256 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2,
257 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2,
258 0x74a2, 0x74a2, 0x74a2, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x51a0,
259 0x41a0, 0x78e2, 0x78e2, 0x78e2, 0x78e2, 0x78e2, 0x78e2, 0x70e2,
260 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2,
261 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2,
262 0x70e2, 0x70e2, 0x70e2, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x4008,
263 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
264 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
265 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
266 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
267 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
268 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
269 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
270 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
271 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
272 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
273 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
274 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
275 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
276 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
277 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
278 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000
281 const UChar OnigEncISO_8859_1_ToLowerCaseTable
[256] = {
282 0000, 0001, 0002, 0003, 0004, 0005, 0006, 0007,
283 0010, 0011, 0012, 0013, 0014, 0015, 0016, 0017,
284 0020, 0021, 0022, 0023, 0024, 0025, 0026, 0027,
285 0030, 0031, 0032, 0033, 0034, 0035, 0036, 0037,
286 0040, 0041, 0042, 0043, 0044, 0045, 0046, 0047,
287 0050, 0051, 0052, 0053, 0054, 0055, 0056, 0057,
288 0060, 0061, 0062, 0063, 0064, 0065, 0066, 0067,
289 0070, 0071, 0072, 0073, 0074, 0075, 0076, 0077,
290 0100, 0141, 0142, 0143, 0144, 0145, 0146, 0147,
291 0150, 0151, 0152, 0153, 0154, 0155, 0156, 0157,
292 0160, 0161, 0162, 0163, 0164, 0165, 0166, 0167,
293 0170, 0171, 0172, 0133, 0134, 0135, 0136, 0137,
294 0140, 0141, 0142, 0143, 0144, 0145, 0146, 0147,
295 0150, 0151, 0152, 0153, 0154, 0155, 0156, 0157,
296 0160, 0161, 0162, 0163, 0164, 0165, 0166, 0167,
297 0170, 0171, 0172, 0173, 0174, 0175, 0176, 0177,
298 0200, 0201, 0202, 0203, 0204, 0205, 0206, 0207,
299 0210, 0211, 0212, 0213, 0214, 0215, 0216, 0217,
300 0220, 0221, 0222, 0223, 0224, 0225, 0226, 0227,
301 0230, 0231, 0232, 0233, 0234, 0235, 0236, 0237,
302 0240, 0241, 0242, 0243, 0244, 0245, 0246, 0247,
303 0250, 0251, 0252, 0253, 0254, 0255, 0256, 0257,
304 0260, 0261, 0262, 0263, 0264, 0265, 0266, 0267,
305 0270, 0271, 0272, 0273, 0274, 0275, 0276, 0277,
306 0340, 0341, 0342, 0343, 0344, 0345, 0346, 0347,
307 0350, 0351, 0352, 0353, 0354, 0355, 0356, 0357,
308 0360, 0361, 0362, 0363, 0364, 0365, 0366, 0327,
309 0370, 0371, 0372, 0373, 0374, 0375, 0376, 0337,
310 0340, 0341, 0342, 0343, 0344, 0345, 0346, 0347,
311 0350, 0351, 0352, 0353, 0354, 0355, 0356, 0357,
312 0360, 0361, 0362, 0363, 0364, 0365, 0366, 0367,
313 0370, 0371, 0372, 0373, 0374, 0375, 0376, 0377
316 #ifdef USE_UPPER_CASE_TABLE
317 const UChar OnigEncISO_8859_1_ToUpperCaseTable
[256] = {
318 0000, 0001, 0002, 0003, 0004, 0005, 0006, 0007,
319 0010, 0011, 0012, 0013, 0014, 0015, 0016, 0017,
320 0020, 0021, 0022, 0023, 0024, 0025, 0026, 0027,
321 0030, 0031, 0032, 0033, 0034, 0035, 0036, 0037,
322 0040, 0041, 0042, 0043, 0044, 0045, 0046, 0047,
323 0050, 0051, 0052, 0053, 0054, 0055, 0056, 0057,
324 0060, 0061, 0062, 0063, 0064, 0065, 0066, 0067,
325 0070, 0071, 0072, 0073, 0074, 0075, 0076, 0077,
326 0100, 0101, 0102, 0103, 0104, 0105, 0106, 0107,
327 0110, 0111, 0112, 0113, 0114, 0115, 0116, 0117,
328 0120, 0121, 0122, 0123, 0124, 0125, 0126, 0127,
329 0130, 0131, 0132, 0133, 0134, 0135, 0136, 0137,
330 0140, 0101, 0102, 0103, 0104, 0105, 0106, 0107,
331 0110, 0111, 0112, 0113, 0114, 0115, 0116, 0117,
332 0120, 0121, 0122, 0123, 0124, 0125, 0126, 0127,
333 0130, 0131, 0132, 0173, 0174, 0175, 0176, 0177,
334 0200, 0201, 0202, 0203, 0204, 0205, 0206, 0207,
335 0210, 0211, 0212, 0213, 0214, 0215, 0216, 0217,
336 0220, 0221, 0222, 0223, 0224, 0225, 0226, 0227,
337 0230, 0231, 0232, 0233, 0234, 0235, 0236, 0237,
338 0240, 0241, 0242, 0243, 0244, 0245, 0246, 0247,
339 0250, 0251, 0252, 0253, 0254, 0255, 0256, 0257,
340 0260, 0261, 0262, 0263, 0264, 0265, 0266, 0267,
341 0270, 0271, 0272, 0273, 0274, 0275, 0276, 0277,
342 0300, 0301, 0302, 0303, 0304, 0305, 0306, 0307,
343 0310, 0311, 0312, 0313, 0314, 0315, 0316, 0317,
344 0320, 0321, 0322, 0323, 0324, 0325, 0326, 0327,
345 0330, 0331, 0332, 0333, 0334, 0335, 0336, 0337,
346 0300, 0301, 0302, 0303, 0304, 0305, 0306, 0307,
347 0310, 0311, 0312, 0313, 0314, 0315, 0316, 0317,
348 0320, 0321, 0322, 0323, 0324, 0325, 0326, 0367,
349 0330, 0331, 0332, 0333, 0334, 0335, 0336, 0377,
354 onigenc_set_default_caseconv_table(const UChar
* table ARG_UNUSED
)
361 onigenc_get_left_adjust_char_head(OnigEncoding enc
, const UChar
* start
, const UChar
* s
)
363 return ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc
, start
, s
);
366 const OnigPairCaseFoldCodes OnigAsciiLowerMap
[] = {
396 onigenc_ascii_apply_all_case_fold(OnigCaseFoldType flag ARG_UNUSED
,
397 OnigApplyAllCaseFoldFunc f
, void* arg
)
403 i
< (int )(sizeof(OnigAsciiLowerMap
)/sizeof(OnigPairCaseFoldCodes
));
405 code
= OnigAsciiLowerMap
[i
].to
;
406 r
= (*f
)(OnigAsciiLowerMap
[i
].from
, &code
, 1, arg
);
407 if (r
!= 0) return r
;
409 code
= OnigAsciiLowerMap
[i
].from
;
410 r
= (*f
)(OnigAsciiLowerMap
[i
].to
, &code
, 1, arg
);
411 if (r
!= 0) return r
;
418 onigenc_ascii_get_case_fold_codes_by_str(OnigCaseFoldType flag ARG_UNUSED
,
419 const OnigUChar
* p
, const OnigUChar
* end ARG_UNUSED
,
420 OnigCaseFoldCodeItem items
[])
422 if (0x41 <= *p
&& *p
<= 0x5a) {
423 items
[0].byte_len
= 1;
424 items
[0].code_len
= 1;
425 items
[0].code
[0] = (OnigCodePoint
)(*p
+ 0x20);
428 else if (0x61 <= *p
&& *p
<= 0x7a) {
429 items
[0].byte_len
= 1;
430 items
[0].code_len
= 1;
431 items
[0].code
[0] = (OnigCodePoint
)(*p
- 0x20);
439 ss_apply_all_case_fold(OnigCaseFoldType flag ARG_UNUSED
,
440 OnigApplyAllCaseFoldFunc f
, void* arg
)
442 static OnigCodePoint ss
[] = { 0x73, 0x73 };
444 return (*f
)((OnigCodePoint
)0xdf, ss
, 2, arg
);
448 onigenc_apply_all_case_fold_with_map(int map_size
,
449 const OnigPairCaseFoldCodes map
[],
450 int ess_tsett_flag
, OnigCaseFoldType flag
,
451 OnigApplyAllCaseFoldFunc f
, void* arg
)
456 r
= onigenc_ascii_apply_all_case_fold(flag
, f
, arg
);
457 if (r
!= 0) return r
;
459 for (i
= 0; i
< map_size
; i
++) {
461 r
= (*f
)(map
[i
].from
, &code
, 1, arg
);
462 if (r
!= 0) return r
;
465 r
= (*f
)(map
[i
].to
, &code
, 1, arg
);
466 if (r
!= 0) return r
;
469 if (ess_tsett_flag
!= 0)
470 return ss_apply_all_case_fold(flag
, f
, arg
);
476 onigenc_get_case_fold_codes_by_str_with_map(int map_size
,
477 const OnigPairCaseFoldCodes map
[],
478 int ess_tsett_flag
, OnigCaseFoldType flag ARG_UNUSED
,
479 const OnigUChar
* p
, const OnigUChar
* end
, OnigCaseFoldCodeItem items
[])
481 if (0x41 <= *p
&& *p
<= 0x5a) {
482 items
[0].byte_len
= 1;
483 items
[0].code_len
= 1;
484 items
[0].code
[0] = (OnigCodePoint
)(*p
+ 0x20);
485 if (*p
== 0x53 && ess_tsett_flag
!= 0 && end
> p
+ 1
486 && (*(p
+1) == 0x53 || *(p
+1) == 0x73)) {
488 items
[1].byte_len
= 2;
489 items
[1].code_len
= 1;
490 items
[1].code
[0] = (OnigCodePoint
)0xdf;
496 else if (0x61 <= *p
&& *p
<= 0x7a) {
497 items
[0].byte_len
= 1;
498 items
[0].code_len
= 1;
499 items
[0].code
[0] = (OnigCodePoint
)(*p
- 0x20);
500 if (*p
== 0x73 && ess_tsett_flag
!= 0 && end
> p
+ 1
501 && (*(p
+1) == 0x73 || *(p
+1) == 0x53)) {
503 items
[1].byte_len
= 2;
504 items
[1].code_len
= 1;
505 items
[1].code
[0] = (OnigCodePoint
)0xdf;
511 else if (*p
== 0xdf && ess_tsett_flag
!= 0) {
512 items
[0].byte_len
= 1;
513 items
[0].code_len
= 2;
514 items
[0].code
[0] = (OnigCodePoint
)'s';
515 items
[0].code
[1] = (OnigCodePoint
)'s';
517 items
[1].byte_len
= 1;
518 items
[1].code_len
= 2;
519 items
[1].code
[0] = (OnigCodePoint
)'S';
520 items
[1].code
[1] = (OnigCodePoint
)'S';
522 items
[2].byte_len
= 1;
523 items
[2].code_len
= 2;
524 items
[2].code
[0] = (OnigCodePoint
)'s';
525 items
[2].code
[1] = (OnigCodePoint
)'S';
527 items
[3].byte_len
= 1;
528 items
[3].code_len
= 2;
529 items
[3].code
[0] = (OnigCodePoint
)'S';
530 items
[3].code
[1] = (OnigCodePoint
)'s';
537 for (i
= 0; i
< map_size
; i
++) {
538 if (*p
== map
[i
].from
) {
539 items
[0].byte_len
= 1;
540 items
[0].code_len
= 1;
541 items
[0].code
[0] = map
[i
].to
;
544 else if (*p
== map
[i
].to
) {
545 items
[0].byte_len
= 1;
546 items
[0].code_len
= 1;
547 items
[0].code
[0] = map
[i
].from
;
558 onigenc_not_support_get_ctype_code_range(OnigCtype ctype ARG_UNUSED
,
559 OnigCodePoint
* sb_out ARG_UNUSED
,
560 const OnigCodePoint
* ranges
[] ARG_UNUSED
)
562 return ONIG_NO_SUPPORT_CONFIG
;
566 onigenc_is_mbc_newline_0x0a(const UChar
* p
, const UChar
* end
)
569 if (*p
== 0x0a) return 1;
574 /* for single byte encodings */
576 onigenc_ascii_mbc_case_fold(OnigCaseFoldType flag ARG_UNUSED
, const UChar
** p
,
577 const UChar
*end ARG_UNUSED
, UChar
* lower
)
579 *lower
= ONIGENC_ASCII_CODE_TO_LOWER_CASE(**p
);
582 return 1; /* return byte length of converted char to lower */
587 onigenc_ascii_is_mbc_ambiguous(OnigCaseFoldType flag
,
588 const UChar
** pp
, const UChar
* end
)
590 const UChar
* p
= *pp
;
593 return ONIGENC_IS_ASCII_CODE_CASE_AMBIG(*p
);
598 onigenc_single_byte_mbc_enc_len(const UChar
* p ARG_UNUSED
)
604 onigenc_single_byte_mbc_to_code(const UChar
* p
, const UChar
* end ARG_UNUSED
)
606 return (OnigCodePoint
)(*p
);
610 onigenc_single_byte_code_to_mbclen(OnigCodePoint code ARG_UNUSED
)
612 return (code
< 0x100 ? 1 : ONIGERR_INVALID_CODE_POINT_VALUE
);
616 onigenc_single_byte_code_to_mbc(OnigCodePoint code
, UChar
*buf
)
618 *buf
= (UChar
)(code
& 0xff);
623 onigenc_single_byte_left_adjust_char_head(const UChar
* start ARG_UNUSED
,
630 onigenc_always_true_is_allowed_reverse_match(const UChar
* s ARG_UNUSED
,
631 const UChar
* end ARG_UNUSED
)
637 onigenc_always_false_is_allowed_reverse_match(const UChar
* s ARG_UNUSED
,
638 const UChar
* end ARG_UNUSED
)
644 onigenc_mbn_mbc_to_code(OnigEncoding enc
, const UChar
* p
, const UChar
* end
)
649 len
= enclen(enc
, p
);
650 n
= (OnigCodePoint
)(*p
++);
651 if (len
== 1) return n
;
653 for (i
= 1; i
< len
; i
++) {
662 onigenc_mbn_mbc_case_fold(OnigEncoding enc
, OnigCaseFoldType flag ARG_UNUSED
,
663 const UChar
** pp
, const UChar
* end ARG_UNUSED
,
667 const UChar
*p
= *pp
;
669 if (ONIGENC_IS_MBC_ASCII(p
)) {
670 *lower
= ONIGENC_ASCII_CODE_TO_LOWER_CASE(*p
);
677 len
= enclen(enc
, p
);
678 for (i
= 0; i
< len
; i
++) {
682 return len
; /* return byte length of converted to lower char */
688 onigenc_mbn_is_mbc_ambiguous(OnigEncoding enc
, OnigCaseFoldType flag
,
689 const UChar
** pp
, const UChar
* end
)
691 const UChar
* p
= *pp
;
693 if (ONIGENC_IS_MBC_ASCII(p
)) {
695 return ONIGENC_IS_ASCII_CODE_CASE_AMBIG(*p
);
698 (*pp
) += enclen(enc
, p
);
704 onigenc_mb2_code_to_mbclen(OnigCodePoint code
)
706 if ((code
& 0xff00) != 0) return 2;
711 onigenc_mb4_code_to_mbclen(OnigCodePoint code
)
713 if ((code
& 0xff000000) != 0) return 4;
714 else if ((code
& 0xff0000) != 0) return 3;
715 else if ((code
& 0xff00) != 0) return 2;
720 onigenc_mb2_code_to_mbc(OnigEncoding enc
, OnigCodePoint code
, UChar
*buf
)
724 if ((code
& 0xff00) != 0) {
725 *p
++ = (UChar
)((code
>> 8) & 0xff);
727 *p
++ = (UChar
)(code
& 0xff);
730 if (enclen(enc
, buf
) != (p
- buf
))
731 return ONIGERR_INVALID_CODE_POINT_VALUE
;
733 return (int)(p
- buf
);
737 onigenc_mb4_code_to_mbc(OnigEncoding enc
, OnigCodePoint code
, UChar
*buf
)
741 if ((code
& 0xff000000) != 0) {
742 *p
++ = (UChar
)((code
>> 24) & 0xff);
744 if ((code
& 0xff0000) != 0 || p
!= buf
) {
745 *p
++ = (UChar
)((code
>> 16) & 0xff);
747 if ((code
& 0xff00) != 0 || p
!= buf
) {
748 *p
++ = (UChar
)((code
>> 8) & 0xff);
750 *p
++ = (UChar
)(code
& 0xff);
753 if (enclen(enc
, buf
) != (p
- buf
))
754 return ONIGERR_INVALID_CODE_POINT_VALUE
;
756 return (int)(p
- buf
);
760 onigenc_minimum_property_name_to_ctype(OnigEncoding enc
, UChar
* p
, UChar
* end
)
762 static PosixBracketEntryType PBS
[] = {
763 { (UChar
* )"Alnum", ONIGENC_CTYPE_ALNUM
, 5 },
764 { (UChar
* )"Alpha", ONIGENC_CTYPE_ALPHA
, 5 },
765 { (UChar
* )"Blank", ONIGENC_CTYPE_BLANK
, 5 },
766 { (UChar
* )"Cntrl", ONIGENC_CTYPE_CNTRL
, 5 },
767 { (UChar
* )"Digit", ONIGENC_CTYPE_DIGIT
, 5 },
768 { (UChar
* )"Graph", ONIGENC_CTYPE_GRAPH
, 5 },
769 { (UChar
* )"Lower", ONIGENC_CTYPE_LOWER
, 5 },
770 { (UChar
* )"Print", ONIGENC_CTYPE_PRINT
, 5 },
771 { (UChar
* )"Punct", ONIGENC_CTYPE_PUNCT
, 5 },
772 { (UChar
* )"Space", ONIGENC_CTYPE_SPACE
, 5 },
773 { (UChar
* )"Upper", ONIGENC_CTYPE_UPPER
, 5 },
774 { (UChar
* )"XDigit", ONIGENC_CTYPE_XDIGIT
, 6 },
775 { (UChar
* )"ASCII", ONIGENC_CTYPE_ASCII
, 5 },
776 { (UChar
* )"Word", ONIGENC_CTYPE_WORD
, 4 },
777 { (UChar
* )NULL
, -1, 0 }
780 PosixBracketEntryType
*pb
;
783 len
= onigenc_strlen(enc
, p
, end
);
784 for (pb
= PBS
; IS_NOT_NULL(pb
->name
); pb
++) {
785 if (len
== pb
->len
&&
786 onigenc_with_ascii_strncmp(enc
, p
, end
, pb
->name
, pb
->len
) == 0)
790 return ONIGERR_INVALID_CHAR_PROPERTY_NAME
;
794 onigenc_mb2_is_code_ctype(OnigEncoding enc
, OnigCodePoint code
,
798 return ONIGENC_IS_ASCII_CODE_CTYPE(code
, ctype
);
800 if (CTYPE_IS_WORD_GRAPH_PRINT(ctype
)) {
801 return (ONIGENC_CODE_TO_MBCLEN(enc
, code
) > 1 ? TRUE
: FALSE
);
809 onigenc_mb4_is_code_ctype(OnigEncoding enc
, OnigCodePoint code
,
813 return ONIGENC_IS_ASCII_CODE_CTYPE(code
, ctype
);
815 if (CTYPE_IS_WORD_GRAPH_PRINT(ctype
)) {
816 return (ONIGENC_CODE_TO_MBCLEN(enc
, code
) > 1 ? TRUE
: FALSE
);
824 onigenc_with_ascii_strncmp(OnigEncoding enc
, const UChar
* p
, const UChar
* end
,
825 const UChar
* sascii
/* ascii */, int n
)
830 if (p
>= end
) return (int )(*sascii
);
832 c
= (int )ONIGENC_MBC_TO_CODE(enc
, p
, end
);
842 /* Property management */
844 resize_property_list(int new_size
, const OnigCodePoint
*** plist
, int* psize
)
847 const OnigCodePoint
**list
= *plist
;
849 size
= sizeof(OnigCodePoint
*) * new_size
;
851 list
= (const OnigCodePoint
** )xmalloc(size
);
854 list
= (const OnigCodePoint
** )xrealloc((void* )list
, size
, *psize
* sizeof(OnigCodePoint
*));
857 if (IS_NULL(list
)) return ONIGERR_MEMORY
;
866 onigenc_property_list_add_property(UChar
* name
, const OnigCodePoint
* prop
,
867 hash_table_type
**table
, const OnigCodePoint
*** plist
, int *pnum
,
870 #define PROP_INIT_SIZE 16
874 if (*psize
<= *pnum
) {
875 int new_size
= (*psize
== 0 ? PROP_INIT_SIZE
: *psize
* 2);
876 r
= resize_property_list(new_size
, plist
, psize
);
877 if (r
!= 0) return r
;
880 (*plist
)[*pnum
] = prop
;
882 if (ONIG_IS_NULL(*table
)) {
883 *table
= onig_st_init_strend_table_with_size(PROP_INIT_SIZE
);
884 if (ONIG_IS_NULL(*table
)) return ONIGERR_MEMORY
;
888 onig_st_insert_strend(*table
, name
, name
+ strlen_s((char* )name
, MAX_STRING_SIZE
),
889 (hash_data_type
)(*pnum
+ ONIGENC_MAX_STD_CTYPE
));
894 onigenc_property_list_init(int (*f
)(void))