[rubygems/rubygems] Use a constant empty tar header to avoid extra allocations
[ruby.git] / enc / euc_jp.c
blobd283bf4ebb12086afc9627decb9ff0b673ff4030
1 /**********************************************************************
2 euc_jp.c - Onigmo (Oniguruma-mod) (regular expression library)
3 **********************************************************************/
4 /*-
5 * Copyright (c) 2002-2008 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
6 * Copyright (c) 2011 K.Takata <kentkt AT csc DOT jp>
7 * All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
31 #include "regenc.h"
33 #define eucjp_islead(c) ((UChar )((c) - 0xa1) > 0xfe - 0xa1)
35 static const int EncLen_EUCJP[] = {
36 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
37 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
38 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
39 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
40 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
41 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
42 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
43 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
44 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
45 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
46 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
47 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
48 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
49 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
50 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
51 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1
54 typedef enum { FAILURE = -2, ACCEPT = -1, S0 = 0, S1, S2 } state_t;
55 #define A ACCEPT
56 #define F FAILURE
57 static const signed char trans[][0x100] = {
58 { /* S0 0 1 2 3 4 5 6 7 8 9 a b c d e f */
59 /* 0 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
60 /* 1 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
61 /* 2 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
62 /* 3 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
63 /* 4 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
64 /* 5 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
65 /* 6 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
66 /* 7 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
67 /* 8 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, 1, 2,
68 /* 9 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
69 /* a */ F, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
70 /* b */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
71 /* c */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
72 /* d */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
73 /* e */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
74 /* f */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, F
76 { /* S1 0 1 2 3 4 5 6 7 8 9 a b c d e f */
77 /* 0 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
78 /* 1 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
79 /* 2 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
80 /* 3 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
81 /* 4 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
82 /* 5 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
83 /* 6 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
84 /* 7 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
85 /* 8 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
86 /* 9 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
87 /* a */ F, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
88 /* b */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
89 /* c */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
90 /* d */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
91 /* e */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
92 /* f */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, F
94 { /* S2 0 1 2 3 4 5 6 7 8 9 a b c d e f */
95 /* 0 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
96 /* 1 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
97 /* 2 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
98 /* 3 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
99 /* 4 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
100 /* 5 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
101 /* 6 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
102 /* 7 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
103 /* 8 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
104 /* 9 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
105 /* a */ F, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
106 /* b */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
107 /* c */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
108 /* d */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
109 /* e */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
110 /* f */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, F
114 #undef A
115 #undef F
117 static const OnigPairCaseFoldCodes CaseFoldMap[] = {
118 /* Fullwidth Alphabet */
119 { 0xa3c1, 0xa3e1 },
120 { 0xa3c2, 0xa3e2 },
121 { 0xa3c3, 0xa3e3 },
122 { 0xa3c4, 0xa3e4 },
123 { 0xa3c5, 0xa3e5 },
124 { 0xa3c6, 0xa3e6 },
125 { 0xa3c7, 0xa3e7 },
126 { 0xa3c8, 0xa3e8 },
127 { 0xa3c9, 0xa3e9 },
128 { 0xa3ca, 0xa3ea },
129 { 0xa3cb, 0xa3eb },
130 { 0xa3cc, 0xa3ec },
131 { 0xa3cd, 0xa3ed },
132 { 0xa3ce, 0xa3ee },
133 { 0xa3cf, 0xa3ef },
134 { 0xa3d0, 0xa3f0 },
135 { 0xa3d1, 0xa3f1 },
136 { 0xa3d2, 0xa3f2 },
137 { 0xa3d3, 0xa3f3 },
138 { 0xa3d4, 0xa3f4 },
139 { 0xa3d5, 0xa3f5 },
140 { 0xa3d6, 0xa3f6 },
141 { 0xa3d7, 0xa3f7 },
142 { 0xa3d8, 0xa3f8 },
143 { 0xa3d9, 0xa3f9 },
144 { 0xa3da, 0xa3fa },
146 /* Greek */
147 { 0xa6a1, 0xa6c1 },
148 { 0xa6a2, 0xa6c2 },
149 { 0xa6a3, 0xa6c3 },
150 { 0xa6a4, 0xa6c4 },
151 { 0xa6a5, 0xa6c5 },
152 { 0xa6a6, 0xa6c6 },
153 { 0xa6a7, 0xa6c7 },
154 { 0xa6a8, 0xa6c8 },
155 { 0xa6a9, 0xa6c9 },
156 { 0xa6aa, 0xa6ca },
157 { 0xa6ab, 0xa6cb },
158 { 0xa6ac, 0xa6cc },
159 { 0xa6ad, 0xa6cd },
160 { 0xa6ae, 0xa6ce },
161 { 0xa6af, 0xa6cf },
162 { 0xa6b0, 0xa6d0 },
163 { 0xa6b1, 0xa6d1 },
164 { 0xa6b2, 0xa6d2 },
165 { 0xa6b3, 0xa6d3 },
166 { 0xa6b4, 0xa6d4 },
167 { 0xa6b5, 0xa6d5 },
168 { 0xa6b6, 0xa6d6 },
169 { 0xa6b7, 0xa6d7 },
170 { 0xa6b8, 0xa6d8 },
172 /* Cyrillic */
173 { 0xa7a1, 0xa7d1 },
174 { 0xa7a2, 0xa7d2 },
175 { 0xa7a3, 0xa7d3 },
176 { 0xa7a4, 0xa7d4 },
177 { 0xa7a5, 0xa7d5 },
178 { 0xa7a6, 0xa7d6 },
179 { 0xa7a7, 0xa7d7 },
180 { 0xa7a8, 0xa7d8 },
181 { 0xa7a9, 0xa7d9 },
182 { 0xa7aa, 0xa7da },
183 { 0xa7ab, 0xa7db },
184 { 0xa7ac, 0xa7dc },
185 { 0xa7ad, 0xa7dd },
186 { 0xa7ae, 0xa7de },
187 { 0xa7af, 0xa7df },
188 { 0xa7b0, 0xa7e0 },
189 { 0xa7b1, 0xa7e1 },
190 { 0xa7b2, 0xa7e2 },
191 { 0xa7b3, 0xa7e3 },
192 { 0xa7b4, 0xa7e4 },
193 { 0xa7b5, 0xa7e5 },
194 { 0xa7b6, 0xa7e6 },
195 { 0xa7b7, 0xa7e7 },
196 { 0xa7b8, 0xa7e8 },
197 { 0xa7b9, 0xa7e9 },
198 { 0xa7ba, 0xa7ea },
199 { 0xa7bb, 0xa7eb },
200 { 0xa7bc, 0xa7ec },
201 { 0xa7bd, 0xa7ed },
202 { 0xa7be, 0xa7ee },
203 { 0xa7bf, 0xa7ef },
204 { 0xa7c0, 0xa7f0 },
205 { 0xa7c1, 0xa7f1 },
208 static int
209 mbc_enc_len(const UChar* p, const UChar* e, OnigEncoding enc ARG_UNUSED)
211 int firstbyte = *p++;
212 state_t s;
213 s = trans[0][firstbyte];
214 if (s < 0) return s == ACCEPT ? ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(1) :
215 ONIGENC_CONSTRUCT_MBCLEN_INVALID();
216 if (p == e) return ONIGENC_CONSTRUCT_MBCLEN_NEEDMORE(EncLen_EUCJP[firstbyte]-1);
217 s = trans[s][*p++];
218 if (s < 0) return s == ACCEPT ? ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(2) :
219 ONIGENC_CONSTRUCT_MBCLEN_INVALID();
220 if (p == e) return ONIGENC_CONSTRUCT_MBCLEN_NEEDMORE(EncLen_EUCJP[firstbyte]-2);
221 s = trans[s][*p++];
222 return s == ACCEPT ? ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(3) :
223 ONIGENC_CONSTRUCT_MBCLEN_INVALID();
226 static OnigCodePoint
227 mbc_to_code(const UChar* p, const UChar* end, OnigEncoding enc)
229 int c, i, len;
230 OnigCodePoint n;
232 len = mbc_enc_len(p, end, enc);
233 n = (OnigCodePoint )*p++;
234 if (len == 1) return n;
236 for (i = 1; i < len; i++) {
237 if (p >= end) break;
238 c = *p++;
239 n <<= 8; n += c;
241 return n;
244 static int
245 code_to_mbclen(OnigCodePoint code, OnigEncoding enc ARG_UNUSED)
247 if (ONIGENC_IS_CODE_ASCII(code)) return 1;
248 else if (code > 0x00ffffff)
249 return ONIGERR_TOO_BIG_WIDE_CHAR_VALUE;
250 else if ((code & 0xff808080) == 0x00808080) return 3;
251 else if ((code & 0xffff8080) == 0x00008080) return 2;
252 else
253 return ONIGERR_INVALID_CODE_POINT_VALUE;
256 #if 0
257 static int
258 code_to_mbc_first(OnigCodePoint code)
260 int first;
262 if ((code & 0xff0000) != 0) {
263 first = (code >> 16) & 0xff;
265 else if ((code & 0xff00) != 0) {
266 first = (code >> 8) & 0xff;
268 else {
269 return (int )code;
271 return first;
273 #endif
275 static int
276 code_to_mbc(OnigCodePoint code, UChar *buf, OnigEncoding enc)
278 UChar *p = buf;
280 if ((code & 0xff0000) != 0) *p++ = (UChar )(((code >> 16) & 0xff));
281 if ((code & 0xff00) != 0) *p++ = (UChar )(((code >> 8) & 0xff));
282 *p++ = (UChar )(code & 0xff);
284 #if 1
285 if (mbc_enc_len(buf, p, enc) != (p - buf))
286 return ONIGERR_INVALID_CODE_POINT_VALUE;
287 #endif
288 return (int )(p - buf);
291 static int
292 apply_all_case_fold(OnigCaseFoldType flag,
293 OnigApplyAllCaseFoldFunc f, void* arg, OnigEncoding enc)
295 return onigenc_apply_all_case_fold_with_map(
296 numberof(CaseFoldMap), CaseFoldMap, 0,
297 flag, f, arg);
300 static OnigCodePoint
301 get_lower_case(OnigCodePoint code)
303 if (ONIGENC_IS_IN_RANGE(code, 0xa3c1, 0xa3da)) {
304 /* Fullwidth Alphabet */
305 return (OnigCodePoint )(code + 0x0020);
307 else if (ONIGENC_IS_IN_RANGE(code, 0xa6a1, 0xa6b8)) {
308 /* Greek */
309 return (OnigCodePoint )(code + 0x0020);
311 else if (ONIGENC_IS_IN_RANGE(code, 0xa7a1, 0xa7c1)) {
312 /* Cyrillic */
313 return (OnigCodePoint )(code + 0x0030);
315 return code;
318 static OnigCodePoint
319 get_upper_case(OnigCodePoint code)
321 if (ONIGENC_IS_IN_RANGE(code, 0xa3e1, 0xa3fa)) {
322 /* Fullwidth Alphabet */
323 return (OnigCodePoint )(code - 0x0020);
325 else if (ONIGENC_IS_IN_RANGE(code, 0xa6c1, 0xa6d8)) {
326 /* Greek */
327 return (OnigCodePoint )(code - 0x0020);
329 else if (ONIGENC_IS_IN_RANGE(code, 0xa7d1, 0xa7f1)) {
330 /* Cyrillic */
331 return (OnigCodePoint )(code - 0x0030);
333 return code;
336 static int
337 get_case_fold_codes_by_str(OnigCaseFoldType flag,
338 const OnigUChar* p, const OnigUChar* end,
339 OnigCaseFoldCodeItem items[], OnigEncoding enc)
341 int len;
342 OnigCodePoint code, code_lo, code_up;
344 code = mbc_to_code(p, end, enc);
345 if (ONIGENC_IS_ASCII_CODE(code))
346 return onigenc_ascii_get_case_fold_codes_by_str(flag, p, end, items, enc);
348 len = mbc_enc_len(p, end, enc);
349 code_lo = get_lower_case(code);
350 code_up = get_upper_case(code);
352 if (code != code_lo) {
353 items[0].byte_len = len;
354 items[0].code_len = 1;
355 items[0].code[0] = code_lo;
356 return 1;
358 else if (code != code_up) {
359 items[0].byte_len = len;
360 items[0].code_len = 1;
361 items[0].code[0] = code_up;
362 return 1;
365 return 0;
368 static int
369 mbc_case_fold(OnigCaseFoldType flag,
370 const UChar** pp, const UChar* end, UChar* lower,
371 OnigEncoding enc)
373 const UChar* p = *pp;
375 if (ONIGENC_IS_MBC_ASCII(p)) {
376 *lower = ONIGENC_ASCII_CODE_TO_LOWER_CASE(*p);
377 (*pp)++;
378 return 1;
380 else {
381 OnigCodePoint code;
382 int len;
384 len = mbc_enc_len(p, end, enc);
385 code = get_lower_case(mbc_to_code(p, end, enc));
386 len = code_to_mbc(code, lower, enc);
387 if (len == ONIGERR_INVALID_CODE_POINT_VALUE) len = 1;
388 (*pp) += len;
389 return len; /* return byte length of converted char to lower */
393 static UChar*
394 left_adjust_char_head(const UChar* start, const UChar* s, const UChar* end, OnigEncoding enc)
396 /* In this encoding
397 mb-trail bytes doesn't mix with single bytes.
399 const UChar *p;
400 int len;
402 if (s <= start) return (UChar* )s;
403 p = s;
405 while (!eucjp_islead(*p) && p > start) p--;
406 len = mbc_enc_len(p, end, enc);
407 if (p + len > s) return (UChar* )p;
408 p += len;
409 return (UChar* )(p + ((s - p) & ~1));
412 static int
413 is_allowed_reverse_match(const UChar* s, const UChar* end, OnigEncoding enc ARG_UNUSED)
415 const UChar c = *s;
416 if (c <= 0x7e || c == 0x8e || c == 0x8f)
417 return TRUE;
418 else
419 return FALSE;
423 static const OnigCodePoint CR_Hiragana[] = {
425 #ifdef ENC_EUC_JIS_2004
426 0xa4a1, 0xa4fb
427 #else
428 0xa4a1, 0xa4f3
429 #endif
430 }; /* CR_Hiragana */
432 #ifdef ENC_EUC_JIS_2004
433 static const OnigCodePoint CR_Katakana[] = {
435 0x8ea6, 0x8eaf, /* JIS X 0201 Katakana */
436 0x8eb1, 0x8edd, /* JIS X 0201 Katakana */
437 0xa5a1, 0xa5fe,
438 0xa6ee, 0xa6fe,
439 0xa7f2, 0xa7f5,
440 }; /* CR_Katakana */
441 #else
442 static const OnigCodePoint CR_Katakana[] = {
444 0x8ea6, 0x8eaf, /* JIS X 0201 Katakana */
445 0x8eb1, 0x8edd, /* JIS X 0201 Katakana */
446 0xa5a1, 0xa5f6,
447 }; /* CR_Katakana */
448 #endif
450 #ifdef ENC_EUC_JIS_2004
451 static const OnigCodePoint CR_Han[] = {
452 /* EUC-JIS-2004 (JIS X 0213:2004) */
454 /* plane 1 */
455 0xa1b8, 0xa1b8,
456 0xaea1, 0xfefe, /* Kanji level 1, 2 and 3 */
457 /* plane 2 */
458 0x8fa1a1, 0x8fa1fe, /* row 1 */
459 0x8fa3a1, 0x8fa5fe, /* row 3 .. 5 */
460 0x8fa8a1, 0x8fa8fe, /* row 8 */
461 0x8faca1, 0x8faffe, /* row 12 .. 15 */
462 0x8feea1, 0x8ffef6, /* row 78 .. 94 */
463 }; /* CR_Han */
464 #else
465 static const OnigCodePoint CR_Han[] = {
466 /* EUC-JP (JIS X 0208 based) */
468 0xa1b8, 0xa1b8,
469 0xb0a1, 0xcfd3, /* Kanji level 1 */
470 0xd0a1, 0xf4a6, /* Kanji level 2 */
471 0x8fb0a1, 0x8fedf3 /* JIS X 0212 Supplemental Kanji (row 16 .. 77) */
472 }; /* CR_Han */
473 #endif
475 static const OnigCodePoint CR_Latin[] = {
477 0x0041, 0x005a,
478 0x0061, 0x007a,
479 0xa3c1, 0xa3da,
480 0xa3e1, 0xa3fa,
481 /* TODO: add raw 8 .. 11 to support EUC-JIS-2004 */
482 /* TODO: add JIS X 0212 row 9 .. 11 */
483 }; /* CR_Latin */
485 static const OnigCodePoint CR_Greek[] = {
487 0xa6a1, 0xa6b8,
488 #ifdef ENC_EUC_JIS_2004
489 0xa6c1, 0xa6d9,
490 #else
491 0xa6c1, 0xa6d8,
492 /* TODO: add JIS X 0212 row 6 */
493 #endif
494 }; /* CR_Greek */
496 static const OnigCodePoint CR_Cyrillic[] = {
498 0xa7a1, 0xa7c1,
499 0xa7d1, 0xa7f1,
500 /* TODO: add JIS X 0212 row 7 */
501 }; /* CR_Cyrillic */
503 #include "enc/jis/props.h"
505 static int
506 property_name_to_ctype(OnigEncoding enc, const UChar* p, const UChar* end)
508 const UChar *s = p, *e = end;
509 const struct enc_property *prop =
510 onig_jis_property((const char* )s, (unsigned int )(e - s));
512 if (!prop) {
513 return onigenc_minimum_property_name_to_ctype(enc, s, e);
516 return (int )prop->ctype;
519 static int
520 is_code_ctype(OnigCodePoint code, unsigned int ctype, OnigEncoding enc ARG_UNUSED)
522 if (ctype <= ONIGENC_MAX_STD_CTYPE) {
523 if (code < 128)
524 return ONIGENC_IS_ASCII_CODE_CTYPE(code, ctype);
525 else {
526 if (CTYPE_IS_WORD_GRAPH_PRINT(ctype)) {
527 return (code_to_mbclen(code, enc) > 1 ? TRUE : FALSE);
531 else {
532 ctype -= (ONIGENC_MAX_STD_CTYPE + 1);
533 if (ctype >= (unsigned int )PropertyListNum)
534 return ONIGERR_TYPE_BUG;
536 return onig_is_in_code_range((UChar* )PropertyList[ctype], code);
539 return FALSE;
542 static int
543 get_ctype_code_range(OnigCtype ctype, OnigCodePoint* sb_out,
544 const OnigCodePoint* ranges[], OnigEncoding enc ARG_UNUSED)
546 if (ctype <= ONIGENC_MAX_STD_CTYPE) {
547 return ONIG_NO_SUPPORT_CONFIG;
549 else {
550 *sb_out = 0x80;
552 ctype -= (ONIGENC_MAX_STD_CTYPE + 1);
553 if (ctype >= (OnigCtype )PropertyListNum)
554 return ONIGERR_TYPE_BUG;
556 *ranges = PropertyList[ctype];
557 return 0;
562 OnigEncodingDefine(euc_jp, EUC_JP) = {
563 mbc_enc_len,
564 "EUC-JP", /* name */
565 3, /* max enc length */
566 1, /* min enc length */
567 onigenc_is_mbc_newline_0x0a,
568 mbc_to_code,
569 code_to_mbclen,
570 code_to_mbc,
571 mbc_case_fold,
572 apply_all_case_fold,
573 get_case_fold_codes_by_str,
574 property_name_to_ctype,
575 is_code_ctype,
576 get_ctype_code_range,
577 left_adjust_char_head,
578 is_allowed_reverse_match,
579 onigenc_ascii_only_case_map,
581 ONIGENC_FLAG_NONE,
584 * Name: EUC-JP
585 * MIBenum: 18
586 * Link: http://www.iana.org/assignments/character-sets
587 * Link: http://home.m05.itscom.net/numa/cde/sjis-euc/sjis-euc.html
588 * Link: http://home.m05.itscom.net/numa/uocjleE.pdf
590 ENC_ALIAS("eucJP", "EUC-JP") /* UI-OSF Application Platform Profile for Japanese Environment Version 1.1 */
593 * Name: eucJP-ms
594 * Link: http://home.m05.itscom.net/numa/cde/ucs-conv/ucs-conv.html
595 * Link: http://www2d.biglobe.ne.jp/~msyk/charcode/cp932/eucJP-ms.html
596 * Link: https://ja.wikipedia.org/wiki/EUC-JP
598 ENC_REPLICATE("eucJP-ms", "EUC-JP") /* TOG/JVC CDE/Motif Technical WG */
599 ENC_ALIAS("euc-jp-ms", "eucJP-ms")
602 * Name: CP51932
603 * MIBenum: 2108
604 * Link: http://www.iana.org/assignments/charset-reg/CP51932
605 * Link: http://search.cpan.org/src/NARUSE/Encode-EUCJPMS-0.07/ucm/cp51932.ucm
606 * Link: http://legacy-encoding.sourceforge.jp/wiki/index.php?cp51932
607 * Link: http://msyk.at.webry.info/200511/article_2.html
609 ENC_REPLICATE("CP51932", "EUC-JP")
612 * Name: EUC-JIS-2004
613 * Link: https://ja.wikipedia.org/wiki/EUC-JIS-2004
615 ENC_REPLICATE("EUC-JIS-2004", "EUC-JP") /* defined at JIS X 0213:2004 */
616 ENC_ALIAS("EUC-JISX0213", "EUC-JIS-2004") /* defined at JIS X 0213:2000, and obsolete at JIS X 0213:2004 */