enc/shift_jis.c

Go to the documentation of this file.
00001 /**********************************************************************
00002   sjis.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 static const int EncLen_SJIS[] = {
00034   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00035   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00043   2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00044   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00045   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00046   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00047   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
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, 1, 1, 1
00050 };
00051 
00052 static const char SJIS_CAN_BE_TRAIL_TABLE[256] = {
00053   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00054   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00055   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00056   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00057   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00058   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00059   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00060   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
00061   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00062   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00063   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00064   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00065   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00066   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00067   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00068   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0
00069 };
00070 
00071 static const OnigPairCaseFoldCodes CaseFoldMap[] = {
00072   /* Fullwidth Alphabet */
00073   { 0x8260, 0x8281 },
00074   { 0x8261, 0x8282 },
00075   { 0x8262, 0x8283 },
00076   { 0x8263, 0x8284 },
00077   { 0x8264, 0x8285 },
00078   { 0x8265, 0x8286 },
00079   { 0x8266, 0x8287 },
00080   { 0x8267, 0x8288 },
00081   { 0x8268, 0x8289 },
00082   { 0x8269, 0x828a },
00083   { 0x826a, 0x828b },
00084   { 0x826b, 0x828c },
00085   { 0x826c, 0x828d },
00086   { 0x826d, 0x828e },
00087   { 0x826e, 0x828f },
00088   { 0x826f, 0x8290 },
00089   { 0x8270, 0x8291 },
00090   { 0x8271, 0x8292 },
00091   { 0x8272, 0x8293 },
00092   { 0x8273, 0x8294 },
00093   { 0x8274, 0x8295 },
00094   { 0x8275, 0x8296 },
00095   { 0x8276, 0x8297 },
00096   { 0x8277, 0x8298 },
00097   { 0x8278, 0x8299 },
00098   { 0x8279, 0x829a },
00099 
00100   /* Greek */
00101   { 0x839f, 0x83bf },
00102   { 0x83a0, 0x83c0 },
00103   { 0x83a1, 0x83c1 },
00104   { 0x83a2, 0x83c2 },
00105   { 0x83a3, 0x83c3 },
00106   { 0x83a4, 0x83c4 },
00107   { 0x83a5, 0x83c5 },
00108   { 0x83a6, 0x83c6 },
00109   { 0x83a7, 0x83c7 },
00110   { 0x83a8, 0x83c8 },
00111   { 0x83a9, 0x83c9 },
00112   { 0x83aa, 0x83ca },
00113   { 0x83ab, 0x83cb },
00114   { 0x83ac, 0x83cc },
00115   { 0x83ad, 0x83cd },
00116   { 0x83ae, 0x83ce },
00117   { 0x83af, 0x83cf },
00118   { 0x83b0, 0x83d0 },
00119   { 0x83b1, 0x83d1 },
00120   { 0x83b2, 0x83d2 },
00121   { 0x83b3, 0x83d3 },
00122   { 0x83b4, 0x83d4 },
00123   { 0x83b5, 0x83d5 },
00124   { 0x83b6, 0x83d6 },
00125 
00126   /* Cyrillic */
00127   { 0x8440, 0x8470 },
00128   { 0x8441, 0x8471 },
00129   { 0x8442, 0x8472 },
00130   { 0x8443, 0x8473 },
00131   { 0x8444, 0x8474 },
00132   { 0x8445, 0x8475 },
00133   { 0x8446, 0x8476 },
00134   { 0x8447, 0x8477 },
00135   { 0x8448, 0x8478 },
00136   { 0x8449, 0x8479 },
00137   { 0x844a, 0x847a },
00138   { 0x844b, 0x847b },
00139   { 0x844c, 0x847c },
00140   { 0x844d, 0x847d },
00141   { 0x844e, 0x847e },
00142   { 0x844f, 0x8480 },
00143   { 0x8450, 0x8481 },
00144   { 0x8451, 0x8482 },
00145   { 0x8452, 0x8483 },
00146   { 0x8453, 0x8484 },
00147   { 0x8454, 0x8485 },
00148   { 0x8455, 0x8486 },
00149   { 0x8456, 0x8487 },
00150   { 0x8457, 0x8488 },
00151   { 0x8458, 0x8489 },
00152   { 0x8459, 0x848a },
00153   { 0x845a, 0x848b },
00154   { 0x845b, 0x848c },
00155   { 0x845c, 0x848d },
00156   { 0x845d, 0x848e },
00157   { 0x845e, 0x848f },
00158   { 0x845f, 0x8490 },
00159   { 0x8460, 0x8491 },
00160 };
00161 
00162 #define SJIS_ISMB_FIRST(byte)  (EncLen_SJIS[byte] > 1)
00163 #define SJIS_ISMB_TRAIL(byte)  SJIS_CAN_BE_TRAIL_TABLE[(byte)]
00164 
00165 typedef enum { FAILURE = -2, ACCEPT = -1, S0 = 0, S1 } state_t;
00166 #define A ACCEPT
00167 #define F FAILURE
00168 static const signed char trans[][0x100] = {
00169   { /* S0   0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f */
00170     /* 0 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00171     /* 1 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00172     /* 2 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00173     /* 3 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00174     /* 4 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00175     /* 5 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00176     /* 6 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00177     /* 7 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00178     /* 8 */ F, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00179     /* 9 */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00180     /* a */ F, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00181     /* b */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00182     /* c */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00183     /* d */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00184     /* e */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00185     /* f */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, F, F, F
00186   },
00187   { /* S1   0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f */
00188     /* 0 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
00189     /* 1 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
00190     /* 2 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
00191     /* 3 */ F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
00192     /* 4 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00193     /* 5 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00194     /* 6 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00195     /* 7 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, F,
00196     /* 8 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00197     /* 9 */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00198     /* a */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00199     /* b */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00200     /* c */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00201     /* d */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00202     /* e */ A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00203     /* f */ A, A, A, A, A, A, A, A, A, A, A, A, A, F, F, F
00204   }
00205 };
00206 #undef A
00207 #undef F
00208 
00209 static int
00210 mbc_enc_len(const UChar* p, const UChar* e, OnigEncoding enc ARG_UNUSED)
00211 {
00212   int firstbyte = *p++;
00213   state_t s;
00214   s = trans[0][firstbyte];
00215   if (s < 0) return s == ACCEPT ? ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(1) :
00216                                   ONIGENC_CONSTRUCT_MBCLEN_INVALID();
00217   if (p == e) return ONIGENC_CONSTRUCT_MBCLEN_NEEDMORE(EncLen_SJIS[firstbyte]-1);
00218   s = trans[s][*p++];
00219   return s == ACCEPT ? ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(2) :
00220                        ONIGENC_CONSTRUCT_MBCLEN_INVALID();
00221 }
00222 
00223 static int
00224 code_to_mbclen(OnigCodePoint code, OnigEncoding enc ARG_UNUSED)
00225 {
00226   if (code < 256) {
00227     if (EncLen_SJIS[(int )code] == 1)
00228       return 1;
00229     else
00230       return ONIGERR_INVALID_CODE_POINT_VALUE;
00231   }
00232   else if (code <= 0xffff) {
00233     int low = code & 0xff;
00234     if (! SJIS_ISMB_TRAIL(low))
00235       return ONIGERR_INVALID_CODE_POINT_VALUE;
00236     return 2;
00237   }
00238   else
00239     return ONIGERR_TOO_BIG_WIDE_CHAR_VALUE;
00240 }
00241 
00242 static OnigCodePoint
00243 mbc_to_code(const UChar* p, const UChar* end, OnigEncoding enc)
00244 {
00245   int c, i, len;
00246   OnigCodePoint n;
00247 
00248   len = mbc_enc_len(p, end, enc);
00249   c = *p++;
00250   n = c;
00251   if (len == 1) return n;
00252 
00253   for (i = 1; i < len; i++) {
00254     if (p >= end) break;
00255     c = *p++;
00256     n <<= 8;  n += c;
00257   }
00258   return n;
00259 }
00260 
00261 static int
00262 code_to_mbc(OnigCodePoint code, UChar *buf, OnigEncoding enc)
00263 {
00264   UChar *p = buf;
00265 
00266   if ((code & 0xff00) != 0) *p++ = (UChar )(((code >>  8) & 0xff));
00267   *p++ = (UChar )(code & 0xff);
00268 
00269 #if 0
00270   if (mbc_enc_len(buf, p, enc) != (p - buf))
00271     return REGERR_INVALID_CODE_POINT_VALUE;
00272 #endif
00273   return (int )(p - buf);
00274 }
00275 
00276 static int
00277 apply_all_case_fold(OnigCaseFoldType flag,
00278                     OnigApplyAllCaseFoldFunc f, void* arg, OnigEncoding enc)
00279 {
00280   return onigenc_apply_all_case_fold_with_map(
00281             sizeof(CaseFoldMap)/sizeof(OnigPairCaseFoldCodes), CaseFoldMap, 0,
00282             flag, f, arg);
00283 }
00284 
00285 static OnigCodePoint
00286 get_lower_case(OnigCodePoint code)
00287 {
00288   if (ONIGENC_IS_IN_RANGE(code, 0x8260, 0x8279)) {
00289     /* Fullwidth Alphabet */
00290     return (OnigCodePoint )(code + 0x0021);
00291   }
00292   else if (ONIGENC_IS_IN_RANGE(code, 0x839f, 0x83b6)) {
00293     /* Greek */
00294     return (OnigCodePoint )(code + 0x0020);
00295   }
00296   else if (ONIGENC_IS_IN_RANGE(code, 0x8440, 0x8460)) {
00297     /* Cyrillic */
00298     int d = (code >= 0x844f) ? 1 : 0;
00299     return (OnigCodePoint )(code + (0x0030 + d));
00300   }
00301   return code;
00302 }
00303 
00304 static OnigCodePoint
00305 get_upper_case(OnigCodePoint code)
00306 {
00307   if (ONIGENC_IS_IN_RANGE(code, 0x8281, 0x829a)) {
00308     /* Fullwidth Alphabet */
00309     return (OnigCodePoint )(code - 0x0021);
00310   }
00311   else if (ONIGENC_IS_IN_RANGE(code, 0x83bf, 0x83d6)) {
00312     /* Greek */
00313     return (OnigCodePoint )(code - 0x0020);
00314   }
00315   else if (ONIGENC_IS_IN_RANGE(code, 0x8470, 0x847e) ||
00316            ONIGENC_IS_IN_RANGE(code, 0x8480, 0x8491)) {
00317     /* Cyrillic */
00318     int d = (code >= 0x8480) ? 1 : 0;
00319     return (OnigCodePoint )(code - (0x0030 - d));
00320   }
00321   return code;
00322 }
00323 
00324 static int
00325 get_case_fold_codes_by_str(OnigCaseFoldType flag,
00326                            const OnigUChar* p, const OnigUChar* end,
00327                            OnigCaseFoldCodeItem items[], OnigEncoding enc)
00328 {
00329   int len;
00330   OnigCodePoint code, code_lo, code_up;
00331 
00332   code = mbc_to_code(p, end, enc);
00333   if (ONIGENC_IS_ASCII_CODE(code))
00334     return onigenc_ascii_get_case_fold_codes_by_str(flag, p, end, items, enc);
00335 
00336   len = mbc_enc_len(p, end, enc);
00337   code_lo = get_lower_case(code);
00338   code_up = get_upper_case(code);
00339 
00340   if (code != code_lo) {
00341     items[0].byte_len = len;
00342     items[0].code_len = 1;
00343     items[0].code[0] = code_lo;
00344     return 1;
00345   }
00346   else if (code != code_up) {
00347     items[0].byte_len = len;
00348     items[0].code_len = 1;
00349     items[0].code[0] = code_up;
00350     return 1;
00351   }
00352 
00353   return 0;
00354 }
00355 
00356 static int
00357 mbc_case_fold(OnigCaseFoldType flag,
00358               const UChar** pp, const UChar* end, UChar* lower,
00359               OnigEncoding enc)
00360 {
00361   const UChar* p = *pp;
00362 
00363   if (ONIGENC_IS_MBC_ASCII(p)) {
00364     *lower = ONIGENC_ASCII_CODE_TO_LOWER_CASE(*p);
00365     (*pp)++;
00366     return 1;
00367   }
00368   else {
00369     OnigCodePoint code;
00370     int len;
00371 
00372     code = get_lower_case(mbc_to_code(p, end, enc));
00373     len = code_to_mbc(code, lower, enc);
00374     (*pp) += len;
00375     return len; /* return byte length of converted char to lower */
00376   }
00377 }
00378 
00379 #if 0
00380 static int
00381 is_mbc_ambiguous(OnigCaseFoldType flag,
00382                  const UChar** pp, const UChar* end)
00383 {
00384   return onigenc_mbn_is_mbc_ambiguous(enc, flag, pp, end);
00385 
00386 }
00387 #endif
00388 
00389 #if 0
00390 static int
00391 is_code_ctype(OnigCodePoint code, unsigned int ctype)
00392 {
00393   if (code < 128)
00394     return ONIGENC_IS_ASCII_CODE_CTYPE(code, ctype);
00395   else {
00396     if (CTYPE_IS_WORD_GRAPH_PRINT(ctype)) {
00397       return (code_to_mbclen(code) > 1 ? TRUE : FALSE);
00398     }
00399   }
00400 
00401   return FALSE;
00402 }
00403 #endif
00404 
00405 static UChar*
00406 left_adjust_char_head(const UChar* start, const UChar* s, const UChar* end, OnigEncoding enc)
00407 {
00408   const UChar *p;
00409   int len;
00410 
00411   if (s <= start) return (UChar* )s;
00412   p = s;
00413 
00414   if (SJIS_ISMB_TRAIL(*p)) {
00415     while (p > start) {
00416       if (! SJIS_ISMB_FIRST(*--p)) {
00417         p++;
00418         break;
00419       }
00420     }
00421   }
00422   len = mbc_enc_len(p, end, enc);
00423   if (p + len > s) return (UChar* )p;
00424   p += len;
00425   return (UChar* )(p + ((s - p) & ~1));
00426 }
00427 
00428 static int
00429 is_allowed_reverse_match(const UChar* s, const UChar* end, OnigEncoding enc ARG_UNUSED)
00430 {
00431   const UChar c = *s;
00432   return (SJIS_ISMB_TRAIL(c) ? FALSE : TRUE);
00433 }
00434 
00435 
00436 static int PropertyInited = 0;
00437 static const OnigCodePoint** PropertyList;
00438 static int PropertyListNum;
00439 static int PropertyListSize;
00440 static hash_table_type* PropertyNameTable;
00441 
00442 static const OnigCodePoint CR_Hiragana[] = {
00443   1,
00444   0x829f, 0x82f1
00445 }; /* CR_Hiragana */
00446 
00447 static const OnigCodePoint CR_Katakana[] = {
00448   4,
00449   0x00a6, 0x00af,
00450   0x00b1, 0x00dd,
00451   0x8340, 0x837e,
00452   0x8380, 0x8396,
00453 }; /* CR_Katakana */
00454 
00455 #ifdef ENC_CP932
00456 static const OnigCodePoint CR_Han[] = {
00457   6,
00458   0x8157, 0x8157,
00459   0x889f, 0x9872,       /* Kanji level 1 */
00460   0x989f, 0x9ffc,       /* Kanji level 2 */
00461   0xe040, 0xeaa4,       /* Kanji level 2 */
00462   0xed40, 0xeeec,       /* NEC-selected IBM extended characters (without symbols) */
00463   0xfa5c, 0xfc4b,       /* IBM extended characters (without symbols) */
00464 }; /* CR_Han */
00465 #else
00466 static const OnigCodePoint CR_Han[] = {
00467   4,
00468   0x8157, 0x8157,
00469   0x889f, 0x9872,       /* Kanji level 1 */
00470   0x989f, 0x9ffc,       /* Kanji level 2 */
00471   0xe040, 0xeaa4,       /* Kanji level 2 */
00472 }; /* CR_Han */
00473 #endif
00474 
00475 static const OnigCodePoint CR_Latin[] = {
00476   4,
00477   0x0041, 0x005a,
00478   0x0061, 0x007a,
00479   0x8260, 0x8279,
00480   0x8281, 0x829a,
00481 }; /* CR_Latin */
00482 
00483 static const OnigCodePoint CR_Greek[] = {
00484   2,
00485   0x839f, 0x83b6,
00486   0x83bf, 0x83d6,
00487 }; /* CR_Greek */
00488 
00489 static const OnigCodePoint CR_Cyrillic[] = {
00490   3,
00491   0x8440, 0x8460,
00492   0x8470, 0x847f,
00493   0x8480, 0x8491,
00494 }; /* CR_Cyrillic */
00495 
00496 static int
00497 init_property_list(void)
00498 {
00499   int r;
00500 
00501   PROPERTY_LIST_ADD_PROP("hiragana", CR_Hiragana);
00502   PROPERTY_LIST_ADD_PROP("katakana", CR_Katakana);
00503   PROPERTY_LIST_ADD_PROP("han", CR_Han);
00504   PROPERTY_LIST_ADD_PROP("latin", CR_Latin);
00505   PROPERTY_LIST_ADD_PROP("greek", CR_Greek);
00506   PROPERTY_LIST_ADD_PROP("cyrillic", CR_Cyrillic);
00507   PropertyInited = 1;
00508 
00509  end:
00510   return r;
00511 }
00512 
00513 static int
00514 property_name_to_ctype(OnigEncoding enc, UChar* p, UChar* end)
00515 {
00516   hash_data_type ctype;
00517   UChar *s, *e;
00518 
00519   PROPERTY_LIST_INIT_CHECK;
00520 
00521   s = e = ALLOCA_N(UChar, end-p+1);
00522   for (; p < end; p++) {
00523     *e++ = ONIGENC_ASCII_CODE_TO_LOWER_CASE(*p);
00524   }
00525 
00526   if (onig_st_lookup_strend(PropertyNameTable, s, e, &ctype) == 0) {
00527     return onigenc_minimum_property_name_to_ctype(enc, s, e);
00528   }
00529 
00530   return (int )ctype;
00531 }
00532 
00533 static int
00534 is_code_ctype(OnigCodePoint code, unsigned int ctype, OnigEncoding enc)
00535 {
00536   if (ctype <= ONIGENC_MAX_STD_CTYPE) {
00537     if (code < 128)
00538       return ONIGENC_IS_ASCII_CODE_CTYPE(code, ctype);
00539     else {
00540       if (CTYPE_IS_WORD_GRAPH_PRINT(ctype)) {
00541         return TRUE;
00542       }
00543     }
00544   }
00545   else {
00546     PROPERTY_LIST_INIT_CHECK;
00547 
00548     ctype -= (ONIGENC_MAX_STD_CTYPE + 1);
00549     if (ctype >= (unsigned int )PropertyListNum)
00550       return ONIGERR_TYPE_BUG;
00551 
00552     return onig_is_in_code_range((UChar* )PropertyList[ctype], code);
00553   }
00554 
00555   return FALSE;
00556 }
00557 
00558 static int
00559 get_ctype_code_range(OnigCtype ctype, OnigCodePoint* sb_out,
00560                      const OnigCodePoint* ranges[], OnigEncoding enc ARG_UNUSED)
00561 {
00562   if (ctype <= ONIGENC_MAX_STD_CTYPE) {
00563     return ONIG_NO_SUPPORT_CONFIG;
00564   }
00565   else {
00566     *sb_out = 0x80;
00567 
00568     PROPERTY_LIST_INIT_CHECK;
00569 
00570     ctype -= (ONIGENC_MAX_STD_CTYPE + 1);
00571     if (ctype >= (OnigCtype )PropertyListNum)
00572       return ONIGERR_TYPE_BUG;
00573 
00574     *ranges = PropertyList[ctype];
00575     return 0;
00576   }
00577 }
00578 
00579 #ifndef ENC_CP932
00580 OnigEncodingDefine(shift_jis, Shift_JIS) = {
00581   mbc_enc_len,
00582   "Shift_JIS",   /* name */
00583   2,             /* max byte length */
00584   1,             /* min byte length */
00585   onigenc_is_mbc_newline_0x0a,
00586   mbc_to_code,
00587   code_to_mbclen,
00588   code_to_mbc,
00589   mbc_case_fold,
00590   apply_all_case_fold,
00591   get_case_fold_codes_by_str,
00592   property_name_to_ctype,
00593   is_code_ctype,
00594   get_ctype_code_range,
00595   left_adjust_char_head,
00596   is_allowed_reverse_match,
00597   0,
00598   ONIGENC_FLAG_NONE,
00599 };
00600 /*
00601  * Name: Shift_JIS
00602  * MIBenum: 17
00603  * Link: http://www.iana.org/assignments/character-sets
00604  * Link: http://ja.wikipedia.org/wiki/Shift_JIS
00605  */
00606 
00607 /*
00608  * Name: MacJapanese
00609  * Link: http://unicode.org/Public/MAPPINGS/VENDORS/APPLE/JAPANESE.TXT
00610  * Link: http://ja.wikipedia.org/wiki/MacJapanese
00611  */
00612 ENC_REPLICATE("MacJapanese", "Shift_JIS")
00613 ENC_ALIAS("MacJapan", "MacJapanese")
00614 #endif
00615 

Generated on 19 Jul 2016 for Ruby by  doxygen 1.4.7