enc/euc_jp.c

Go to the documentation of this file.
00001 /**********************************************************************
00002   euc_jp.c -  Onigmo (Oniguruma-mod) (regular expression library)
00003 **********************************************************************/
00004 /*-
00005  * Copyright (c) 2002-2008  K.Kosako  <sndgk393 AT ybb DOT ne DOT jp>
00006  * Copyright (c) 2011       K.Takata  <kentkt AT csc DOT jp>
00007  * All rights reserved.
00008  *
00009  * Redistribution and use in source and binary forms, with or without
00010  * modification, are permitted provided that the following conditions
00011  * are met:
00012  * 1. Redistributions of source code must retain the above copyright
00013  *    notice, this list of conditions and the following disclaimer.
00014  * 2. Redistributions in binary form must reproduce the above copyright
00015  *    notice, this list of conditions and the following disclaimer in the
00016  *    documentation and/or other materials provided with the distribution.
00017  *
00018  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
00019  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
00022  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00023  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00024  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00025  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00026  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00027  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00028  * SUCH DAMAGE.
00029  */
00030 
00031 #include "regint.h"
00032 
00033 #define eucjp_islead(c)    ((UChar )((c) - 0xa1) > 0xfe - 0xa1)
00034 
00035 static const int EncLen_EUCJP[] = {
00036   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00037   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00038   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00039   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00040   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00041   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00042   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00043   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00044   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
00045   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00046   1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00047   2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00048   2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00049   2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00050   2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00051   2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1
00052 };
00053 
00054 typedef enum { FAILURE = -2, ACCEPT = -1, S0 = 0, S1, S2 } state_t;
00055 #define A ACCEPT
00056 #define F FAILURE
00057 static const signed char trans[][0x100] = {
00058   { /* S0   0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f */
00059     /* 0 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00060     /* 1 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00061     /* 2 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00062     /* 3 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00063     /* 4 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00064     /* 5 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00065     /* 6 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00066     /* 7 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00067     /* 8 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, 1, 2,
00068     /* 9 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
00069     /* a */ F, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00070     /* b */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00071     /* c */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00072     /* d */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00073     /* e */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00074     /* f */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, F
00075   },
00076   { /* S1   0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f */
00077     /* 0 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
00078     /* 1 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
00079     /* 2 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
00080     /* 3 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
00081     /* 4 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
00082     /* 5 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
00083     /* 6 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
00084     /* 7 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
00085     /* 8 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
00086     /* 9 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
00087     /* a */ F, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00088     /* b */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00089     /* c */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00090     /* d */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00091     /* e */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00092     /* f */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, F
00093   },
00094   { /* S2   0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f */
00095     /* 0 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
00096     /* 1 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
00097     /* 2 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
00098     /* 3 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
00099     /* 4 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
00100     /* 5 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
00101     /* 6 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
00102     /* 7 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
00103     /* 8 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
00104     /* 9 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
00105     /* a */ F, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00106     /* b */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00107     /* c */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00108     /* d */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00109     /* e */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00110     /* f */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, F
00111   },
00112 
00113 };
00114 #undef A
00115 #undef F
00116 
00117 static const OnigPairCaseFoldCodes CaseFoldMap[] = {
00118   /* Fullwidth Alphabet */
00119   { 0xa3c1, 0xa3e1 },
00120   { 0xa3c2, 0xa3e2 },
00121   { 0xa3c3, 0xa3e3 },
00122   { 0xa3c4, 0xa3e4 },
00123   { 0xa3c5, 0xa3e5 },
00124   { 0xa3c6, 0xa3e6 },
00125   { 0xa3c7, 0xa3e7 },
00126   { 0xa3c8, 0xa3e8 },
00127   { 0xa3c9, 0xa3e9 },
00128   { 0xa3ca, 0xa3ea },
00129   { 0xa3cb, 0xa3eb },
00130   { 0xa3cc, 0xa3ec },
00131   { 0xa3cd, 0xa3ed },
00132   { 0xa3ce, 0xa3ee },
00133   { 0xa3cf, 0xa3ef },
00134   { 0xa3d0, 0xa3f0 },
00135   { 0xa3d1, 0xa3f1 },
00136   { 0xa3d2, 0xa3f2 },
00137   { 0xa3d3, 0xa3f3 },
00138   { 0xa3d4, 0xa3f4 },
00139   { 0xa3d5, 0xa3f5 },
00140   { 0xa3d6, 0xa3f6 },
00141   { 0xa3d7, 0xa3f7 },
00142   { 0xa3d8, 0xa3f8 },
00143   { 0xa3d9, 0xa3f9 },
00144   { 0xa3da, 0xa3fa },
00145 
00146   /* Greek */
00147   { 0xa6a1, 0xa6c1 },
00148   { 0xa6a2, 0xa6c2 },
00149   { 0xa6a3, 0xa6c3 },
00150   { 0xa6a4, 0xa6c4 },
00151   { 0xa6a5, 0xa6c5 },
00152   { 0xa6a6, 0xa6c6 },
00153   { 0xa6a7, 0xa6c7 },
00154   { 0xa6a8, 0xa6c8 },
00155   { 0xa6a9, 0xa6c9 },
00156   { 0xa6aa, 0xa6ca },
00157   { 0xa6ab, 0xa6cb },
00158   { 0xa6ac, 0xa6cc },
00159   { 0xa6ad, 0xa6cd },
00160   { 0xa6ae, 0xa6ce },
00161   { 0xa6af, 0xa6cf },
00162   { 0xa6b0, 0xa6d0 },
00163   { 0xa6b1, 0xa6d1 },
00164   { 0xa6b2, 0xa6d2 },
00165   { 0xa6b3, 0xa6d3 },
00166   { 0xa6b4, 0xa6d4 },
00167   { 0xa6b5, 0xa6d5 },
00168   { 0xa6b6, 0xa6d6 },
00169   { 0xa6b7, 0xa6d7 },
00170   { 0xa6b8, 0xa6d8 },
00171 
00172   /* Cyrillic */
00173   { 0xa7a1, 0xa7d1 },
00174   { 0xa7a2, 0xa7d2 },
00175   { 0xa7a3, 0xa7d3 },
00176   { 0xa7a4, 0xa7d4 },
00177   { 0xa7a5, 0xa7d5 },
00178   { 0xa7a6, 0xa7d6 },
00179   { 0xa7a7, 0xa7d7 },
00180   { 0xa7a8, 0xa7d8 },
00181   { 0xa7a9, 0xa7d9 },
00182   { 0xa7aa, 0xa7da },
00183   { 0xa7ab, 0xa7db },
00184   { 0xa7ac, 0xa7dc },
00185   { 0xa7ad, 0xa7dd },
00186   { 0xa7ae, 0xa7de },
00187   { 0xa7af, 0xa7df },
00188   { 0xa7b0, 0xa7e0 },
00189   { 0xa7b1, 0xa7e1 },
00190   { 0xa7b2, 0xa7e2 },
00191   { 0xa7b3, 0xa7e3 },
00192   { 0xa7b4, 0xa7e4 },
00193   { 0xa7b5, 0xa7e5 },
00194   { 0xa7b6, 0xa7e6 },
00195   { 0xa7b7, 0xa7e7 },
00196   { 0xa7b8, 0xa7e8 },
00197   { 0xa7b9, 0xa7e9 },
00198   { 0xa7ba, 0xa7ea },
00199   { 0xa7bb, 0xa7eb },
00200   { 0xa7bc, 0xa7ec },
00201   { 0xa7bd, 0xa7ed },
00202   { 0xa7be, 0xa7ee },
00203   { 0xa7bf, 0xa7ef },
00204   { 0xa7c0, 0xa7f0 },
00205   { 0xa7c1, 0xa7f1 },
00206 };
00207 
00208 static int
00209 mbc_enc_len(const UChar* p, const UChar* e, OnigEncoding enc ARG_UNUSED)
00210 {
00211   int firstbyte = *p++;
00212   state_t s;
00213   s = trans[0][firstbyte];
00214   if (s < 0) return s == ACCEPT ? ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(1) :
00215                                   ONIGENC_CONSTRUCT_MBCLEN_INVALID();
00216   if (p == e) return ONIGENC_CONSTRUCT_MBCLEN_NEEDMORE(EncLen_EUCJP[firstbyte]-1);
00217   s = trans[s][*p++];
00218   if (s < 0) return s == ACCEPT ? ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(2) :
00219                                   ONIGENC_CONSTRUCT_MBCLEN_INVALID();
00220   if (p == e) return ONIGENC_CONSTRUCT_MBCLEN_NEEDMORE(EncLen_EUCJP[firstbyte]-2);
00221   s = trans[s][*p++];
00222   return s == ACCEPT ? ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(3) :
00223                        ONIGENC_CONSTRUCT_MBCLEN_INVALID();
00224 }
00225 
00226 static OnigCodePoint
00227 mbc_to_code(const UChar* p, const UChar* end, OnigEncoding enc)
00228 {
00229   int c, i, len;
00230   OnigCodePoint n;
00231 
00232   len = mbc_enc_len(p, end, enc);
00233   n = (OnigCodePoint )*p++;
00234   if (len == 1) return n;
00235 
00236   for (i = 1; i < len; i++) {
00237     if (p >= end) break;
00238     c = *p++;
00239     n <<= 8;  n += c;
00240   }
00241   return n;
00242 }
00243 
00244 static int
00245 code_to_mbclen(OnigCodePoint code, OnigEncoding enc ARG_UNUSED)
00246 {
00247   if (ONIGENC_IS_CODE_ASCII(code)) return 1;
00248   else if (code > 0x00ffffff)
00249     return ONIGERR_TOO_BIG_WIDE_CHAR_VALUE;
00250   else if ((code & 0xff808080) == 0x00808080) return 3;
00251   else if ((code & 0xffff8080) == 0x00008080) return 2;
00252   else
00253     return ONIGERR_INVALID_CODE_POINT_VALUE;
00254 }
00255 
00256 #if 0
00257 static int
00258 code_to_mbc_first(OnigCodePoint code)
00259 {
00260   int first;
00261 
00262   if ((code & 0xff0000) != 0) {
00263     first = (code >> 16) & 0xff;
00264   }
00265   else if ((code & 0xff00) != 0) {
00266     first = (code >> 8) & 0xff;
00267   }
00268   else {
00269     return (int )code;
00270   }
00271   return first;
00272 }
00273 #endif
00274 
00275 static int
00276 code_to_mbc(OnigCodePoint code, UChar *buf, OnigEncoding enc)
00277 {
00278   UChar *p = buf;
00279 
00280   if ((code & 0xff0000) != 0) *p++ = (UChar )(((code >> 16) & 0xff));
00281   if ((code &   0xff00) != 0) *p++ = (UChar )(((code >>  8) & 0xff));
00282   *p++ = (UChar )(code & 0xff);
00283 
00284 #if 1
00285   if (mbc_enc_len(buf, p, enc) != (p - buf))
00286     return ONIGERR_INVALID_CODE_POINT_VALUE;
00287 #endif
00288   return (int )(p - buf);
00289 }
00290 
00291 static int
00292 apply_all_case_fold(OnigCaseFoldType flag,
00293                     OnigApplyAllCaseFoldFunc f, void* arg, OnigEncoding enc)
00294 {
00295   return onigenc_apply_all_case_fold_with_map(
00296             sizeof(CaseFoldMap)/sizeof(OnigPairCaseFoldCodes), CaseFoldMap, 0,
00297             flag, f, arg);
00298 }
00299 
00300 static OnigCodePoint
00301 get_lower_case(OnigCodePoint code)
00302 {
00303   if (ONIGENC_IS_IN_RANGE(code, 0xa3c1, 0xa3da)) {
00304     /* Fullwidth Alphabet */
00305     return (OnigCodePoint )(code + 0x0020);
00306   }
00307   else if (ONIGENC_IS_IN_RANGE(code, 0xa6a1, 0xa6b8)) {
00308     /* Greek */
00309     return (OnigCodePoint )(code + 0x0020);
00310   }
00311   else if (ONIGENC_IS_IN_RANGE(code, 0xa7a1, 0xa7c1)) {
00312     /* Cyrillic */
00313     return (OnigCodePoint )(code + 0x0030);
00314   }
00315   return code;
00316 }
00317 
00318 static OnigCodePoint
00319 get_upper_case(OnigCodePoint code)
00320 {
00321   if (ONIGENC_IS_IN_RANGE(code, 0xa3e1, 0xa3fa)) {
00322     /* Fullwidth Alphabet */
00323     return (OnigCodePoint )(code - 0x0020);
00324   }
00325   else if (ONIGENC_IS_IN_RANGE(code, 0xa6c1, 0xa6d8)) {
00326     /* Greek */
00327     return (OnigCodePoint )(code - 0x0020);
00328   }
00329   else if (ONIGENC_IS_IN_RANGE(code, 0xa7d1, 0xa7f1)) {
00330     /* Cyrillic */
00331     return (OnigCodePoint )(code - 0x0030);
00332   }
00333   return code;
00334 }
00335 
00336 static int
00337 get_case_fold_codes_by_str(OnigCaseFoldType flag,
00338                            const OnigUChar* p, const OnigUChar* end,
00339                            OnigCaseFoldCodeItem items[], OnigEncoding enc)
00340 {
00341   int len;
00342   OnigCodePoint code, code_lo, code_up;
00343 
00344   code = mbc_to_code(p, end, enc);
00345   if (ONIGENC_IS_ASCII_CODE(code))
00346     return onigenc_ascii_get_case_fold_codes_by_str(flag, p, end, items, enc);
00347 
00348   len = mbc_enc_len(p, end, enc);
00349   code_lo = get_lower_case(code);
00350   code_up = get_upper_case(code);
00351 
00352   if (code != code_lo) {
00353     items[0].byte_len = len;
00354     items[0].code_len = 1;
00355     items[0].code[0] = code_lo;
00356     return 1;
00357   }
00358   else if (code != code_up) {
00359     items[0].byte_len = len;
00360     items[0].code_len = 1;
00361     items[0].code[0] = code_up;
00362     return 1;
00363   }
00364 
00365   return 0;
00366 }
00367 
00368 static int
00369 mbc_case_fold(OnigCaseFoldType flag,
00370               const UChar** pp, const UChar* end, UChar* lower,
00371               OnigEncoding enc)
00372 {
00373   const UChar* p = *pp;
00374 
00375   if (ONIGENC_IS_MBC_ASCII(p)) {
00376     *lower = ONIGENC_ASCII_CODE_TO_LOWER_CASE(*p);
00377     (*pp)++;
00378     return 1;
00379   }
00380   else {
00381     OnigCodePoint code;
00382     int len;
00383 
00384     code = get_lower_case(mbc_to_code(p, end, enc));
00385     len = code_to_mbc(code, lower, enc);
00386     (*pp) += len;
00387     return len; /* return byte length of converted char to lower */
00388   }
00389 }
00390 
00391 static UChar*
00392 left_adjust_char_head(const UChar* start, const UChar* s, const UChar* end, OnigEncoding enc)
00393 {
00394   /* In this encoding
00395      mb-trail bytes doesn't mix with single bytes.
00396   */
00397   const UChar *p;
00398   int len;
00399 
00400   if (s <= start) return (UChar* )s;
00401   p = s;
00402 
00403   while (!eucjp_islead(*p) && p > start) p--;
00404   len = mbc_enc_len(p, end, enc);
00405   if (p + len > s) return (UChar* )p;
00406   p += len;
00407   return (UChar* )(p + ((s - p) & ~1));
00408 }
00409 
00410 static int
00411 is_allowed_reverse_match(const UChar* s, const UChar* end, OnigEncoding enc ARG_UNUSED)
00412 {
00413   const UChar c = *s;
00414   if (c <= 0x7e || c == 0x8e || c == 0x8f)
00415     return TRUE;
00416   else
00417     return FALSE;
00418 }
00419 
00420 
00421 static int PropertyInited = 0;
00422 static const OnigCodePoint** PropertyList;
00423 static int PropertyListNum;
00424 static int PropertyListSize;
00425 static hash_table_type* PropertyNameTable;
00426 
00427 static const OnigCodePoint CR_Hiragana[] = {
00428   1,
00429 #ifdef ENC_EUC_JIS_2004
00430   0xa4a1, 0xa4fb
00431 #else
00432   0xa4a1, 0xa4f3
00433 #endif
00434 }; /* CR_Hiragana */
00435 
00436 #ifdef ENC_EUC_JIS_2004
00437 static const OnigCodePoint CR_Katakana[] = {
00438   5,
00439   0x8ea6, 0x8eaf,       /* JIS X 0201 Katakana */
00440   0x8eb1, 0x8edd,       /* JIS X 0201 Katakana */
00441   0xa5a1, 0xa5fe,
00442   0xa6ee, 0xa6fe,
00443   0xa7f2, 0xa7f5,
00444 }; /* CR_Katakana */
00445 #else
00446 static const OnigCodePoint CR_Katakana[] = {
00447   3,
00448   0x8ea6, 0x8eaf,       /* JIS X 0201 Katakana */
00449   0x8eb1, 0x8edd,       /* JIS X 0201 Katakana */
00450   0xa5a1, 0xa5f6,
00451 }; /* CR_Katakana */
00452 #endif
00453 
00454 #ifdef ENC_EUC_JIS_2004
00455 static const OnigCodePoint CR_Han[] = {
00456   /* EUC-JIS-2004 (JIS X 0213:2004) */
00457   7,
00458   /* plane 1 */
00459   0xa1b8, 0xa1b8,
00460   0xaea1, 0xfefe,       /* Kanji level 1, 2 and 3 */
00461   /* plane 2 */
00462   0x8fa1a1, 0x8fa1fe,   /* row 1 */
00463   0x8fa3a1, 0x8fa5fe,   /* row 3 .. 5 */
00464   0x8fa8a1, 0x8fa8fe,   /* row 8 */
00465   0x8faca1, 0x8faffe,   /* row 12 .. 15 */
00466   0x8feea1, 0x8ffef6,   /* row 78 .. 94 */
00467 }; /* CR_Han */
00468 #else
00469 static const OnigCodePoint CR_Han[] = {
00470   /* EUC-JP (JIS X 0208 based) */
00471   4,
00472   0xa1b8, 0xa1b8,
00473   0xb0a1, 0xcfd3,       /* Kanji level 1 */
00474   0xd0a1, 0xf4a6,       /* Kanji level 2 */
00475   0x8fb0a1, 0x8fedf3    /* JIS X 0212 Supplemental Kanji (row 16 .. 77) */
00476 }; /* CR_Han */
00477 #endif
00478 
00479 static const OnigCodePoint CR_Latin[] = {
00480   4,
00481   0x0041, 0x005a,
00482   0x0061, 0x007a,
00483   0xa3c1, 0xa3da,
00484   0xa3e1, 0xa3fa,
00485   /* TODO: add raw 8 .. 11 to support EUC-JIS-2004 */
00486   /* TODO: add JIS X 0212 row 9 .. 11 */
00487 }; /* CR_Latin */
00488 
00489 static const OnigCodePoint CR_Greek[] = {
00490   2,
00491   0xa6a1, 0xa6b8,
00492 #ifdef ENC_EUC_JIS_2004
00493   0xa6c1, 0xa6d9,
00494 #else
00495   0xa6c1, 0xa6d8,
00496   /* TODO: add JIS X 0212 row 6 */
00497 #endif
00498 }; /* CR_Greek */
00499 
00500 static const OnigCodePoint CR_Cyrillic[] = {
00501   2,
00502   0xa7a1, 0xa7c1,
00503   0xa7d1, 0xa7f1,
00504   /* TODO: add JIS X 0212 row 7 */
00505 }; /* CR_Cyrillic */
00506 
00507 static int
00508 init_property_list(void)
00509 {
00510   int r;
00511 
00512   PROPERTY_LIST_ADD_PROP("hiragana", CR_Hiragana);
00513   PROPERTY_LIST_ADD_PROP("katakana", CR_Katakana);
00514   PROPERTY_LIST_ADD_PROP("han", CR_Han);
00515   PROPERTY_LIST_ADD_PROP("latin", CR_Latin);
00516   PROPERTY_LIST_ADD_PROP("greek", CR_Greek);
00517   PROPERTY_LIST_ADD_PROP("cyrillic", CR_Cyrillic);
00518   PropertyInited = 1;
00519 
00520  end:
00521   return r;
00522 }
00523 
00524 static int
00525 property_name_to_ctype(OnigEncoding enc, UChar* p, UChar* end)
00526 {
00527   st_data_t ctype;
00528   UChar *s, *e;
00529 
00530   PROPERTY_LIST_INIT_CHECK;
00531 
00532   s = e = ALLOCA_N(UChar, end-p+1);
00533   for (; p < end; p++) {
00534     *e++ = ONIGENC_ASCII_CODE_TO_LOWER_CASE(*p);
00535   }
00536 
00537   if (onig_st_lookup_strend(PropertyNameTable, s, e, &ctype) == 0) {
00538     return onigenc_minimum_property_name_to_ctype(enc, s, e);
00539   }
00540 
00541   return (int )ctype;
00542 }
00543 
00544 static int
00545 is_code_ctype(OnigCodePoint code, unsigned int ctype, OnigEncoding enc ARG_UNUSED)
00546 {
00547   if (ctype <= ONIGENC_MAX_STD_CTYPE) {
00548     if (code < 128)
00549       return ONIGENC_IS_ASCII_CODE_CTYPE(code, ctype);
00550     else {
00551       if (CTYPE_IS_WORD_GRAPH_PRINT(ctype)) {
00552         return (code_to_mbclen(code, enc) > 1 ? TRUE : FALSE);
00553       }
00554     }
00555   }
00556   else {
00557     PROPERTY_LIST_INIT_CHECK;
00558 
00559     ctype -= (ONIGENC_MAX_STD_CTYPE + 1);
00560     if (ctype >= (unsigned int )PropertyListNum)
00561       return ONIGERR_TYPE_BUG;
00562 
00563     return onig_is_in_code_range((UChar* )PropertyList[ctype], code);
00564   }
00565 
00566   return FALSE;
00567 }
00568 
00569 static int
00570 get_ctype_code_range(OnigCtype ctype, OnigCodePoint* sb_out,
00571                      const OnigCodePoint* ranges[], OnigEncoding enc ARG_UNUSED)
00572 {
00573   if (ctype <= ONIGENC_MAX_STD_CTYPE) {
00574     return ONIG_NO_SUPPORT_CONFIG;
00575   }
00576   else {
00577     *sb_out = 0x80;
00578 
00579     PROPERTY_LIST_INIT_CHECK;
00580 
00581     ctype -= (ONIGENC_MAX_STD_CTYPE + 1);
00582     if (ctype >= (OnigCtype )PropertyListNum)
00583       return ONIGERR_TYPE_BUG;
00584 
00585     *ranges = PropertyList[ctype];
00586     return 0;
00587   }
00588 }
00589 
00590 
00591 OnigEncodingDefine(euc_jp, EUC_JP) = {
00592   mbc_enc_len,
00593   "EUC-JP",   /* name */
00594   3,          /* max enc length */
00595   1,          /* min enc length */
00596   onigenc_is_mbc_newline_0x0a,
00597   mbc_to_code,
00598   code_to_mbclen,
00599   code_to_mbc,
00600   mbc_case_fold,
00601   apply_all_case_fold,
00602   get_case_fold_codes_by_str,
00603   property_name_to_ctype,
00604   is_code_ctype,
00605   get_ctype_code_range,
00606   left_adjust_char_head,
00607   is_allowed_reverse_match,
00608   0,
00609   ONIGENC_FLAG_NONE,
00610 };
00611 /*
00612  * Name: EUC-JP
00613  * MIBenum: 18
00614  * Link: http://www.iana.org/assignments/character-sets
00615  * Link: http://home.m05.itscom.net/numa/cde/sjis-euc/sjis-euc.html
00616  * Link: http://home.m05.itscom.net/numa/uocjleE.pdf
00617  */
00618 ENC_ALIAS("eucJP", "EUC-JP") /* UI-OSF Application Platform Profile for Japanese Environment Version 1.1 */
00619 
00620 /*
00621  * Name: eucJP-ms
00622  * Link: http://home.m05.itscom.net/numa/cde/ucs-conv/ucs-conv.html
00623  * Link: http://www2d.biglobe.ne.jp/~msyk/charcode/cp932/eucJP-ms.html
00624  * Link: http://ja.wikipedia.org/wiki/EUC-JP
00625  */
00626 ENC_REPLICATE("eucJP-ms", "EUC-JP") /* TOG/JVC CDE/Motif Technical WG */
00627 ENC_ALIAS("euc-jp-ms", "eucJP-ms")
00628 
00629 /*
00630  * Name: CP51932
00631  * MIBenum: 2108
00632  * Link: http://www.iana.org/assignments/charset-reg/CP51932
00633  * Link: http://search.cpan.org/src/NARUSE/Encode-EUCJPMS-0.07/ucm/cp51932.ucm
00634  * Link: http://legacy-encoding.sourceforge.jp/wiki/index.php?cp51932
00635  * Link: http://msyk.at.webry.info/200511/article_2.html
00636  */
00637 ENC_REPLICATE("CP51932", "EUC-JP")
00638 
00639 /*
00640  * Name: EUC-JIS-2004
00641  * Link: http://ja.wikipedia.org/wiki/EUC-JIS-2004
00642  */
00643 ENC_REPLICATE("EUC-JIS-2004", "EUC-JP") /* defined at JIS X 0213:2004 */
00644 ENC_ALIAS("EUC-JISX0213", "EUC-JIS-2004") /* defined at JIS X 0213:2000, and obsolete at JIS X 0213:2004 */
00645 

Generated on 19 Jul 2016 for Ruby by  doxygen 1.4.7