00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "regenc.h"
00031
00032 static const int EncLen_EUCKR[] = {
00033 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00043 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00044 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00045 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00046 2, 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, 1
00049 };
00050
00051 typedef enum { FAILURE = -2, ACCEPT = -1, S0 = 0, S1 } state_t;
00052 #define A ACCEPT
00053 #define F FAILURE
00054 static const signed char trans[][0x100] = {
00055 {
00056 A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00057 A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00058 A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00059 A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00060 A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00061 A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00062 A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00063 A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00064 F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
00065 F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
00066 F, 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, 1, 1, 1,
00069 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00070 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00071 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, F
00072 },
00073 {
00074 F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
00075 F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
00076 F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
00077 F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
00078 F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
00079 F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
00080 F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
00081 F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
00082 F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
00083 F, F, F, F, F, F, F, F, F, F, F, F, F, F, F, F,
00084 F, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00085 A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00086 A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00087 A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00088 A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A,
00089 A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, F
00090 }
00091 };
00092 #undef A
00093 #undef F
00094
00095 static int
00096 euckr_mbc_enc_len(const UChar* p, const UChar* e, OnigEncoding enc ARG_UNUSED)
00097 {
00098 int firstbyte = *p++;
00099 state_t s = trans[0][firstbyte];
00100 #define RETURN(n) \
00101 return s == ACCEPT ? ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(n) : \
00102 ONIGENC_CONSTRUCT_MBCLEN_INVALID()
00103 if (s < 0) RETURN(1);
00104 if (p == e) return ONIGENC_CONSTRUCT_MBCLEN_NEEDMORE(EncLen_EUCKR[firstbyte]-1);
00105 s = trans[s][*p++];
00106 RETURN(2);
00107 #undef RETURN
00108 }
00109
00110 static OnigCodePoint
00111 euckr_mbc_to_code(const UChar* p, const UChar* end, OnigEncoding enc)
00112 {
00113 return onigenc_mbn_mbc_to_code(enc, p, end);
00114 }
00115
00116 static int
00117 euckr_code_to_mbc(OnigCodePoint code, UChar *buf, OnigEncoding enc)
00118 {
00119 return onigenc_mb2_code_to_mbc(enc, code, buf);
00120 }
00121
00122 static int
00123 euckr_mbc_case_fold(OnigCaseFoldType flag, const UChar** pp, const UChar* end,
00124 UChar* lower, OnigEncoding enc)
00125 {
00126 return onigenc_mbn_mbc_case_fold(enc, flag,
00127 pp, end, lower);
00128 }
00129
00130 #if 0
00131 static int
00132 euckr_is_mbc_ambiguous(OnigCaseFoldType flag,
00133 const UChar** pp, const UChar* end, OnigEncoding enc)
00134 {
00135 return onigenc_mbn_is_mbc_ambiguous(enc, flag, pp, end);
00136 }
00137 #endif
00138
00139 static int
00140 euckr_is_code_ctype(OnigCodePoint code, unsigned int ctype, OnigEncoding enc)
00141 {
00142 return onigenc_mb2_is_code_ctype(enc, code, ctype);
00143 }
00144
00145 #define euckr_islead(c) ((c) < 0xa1 || (c) == 0xff)
00146
00147 static UChar*
00148 euckr_left_adjust_char_head(const UChar* start, const UChar* s, const UChar* end, OnigEncoding enc)
00149 {
00150
00151
00152
00153 const UChar *p;
00154 int len;
00155
00156 if (s <= start) return (UChar* )s;
00157 p = s;
00158
00159 while (!euckr_islead(*p) && p > start) p--;
00160 len = enclen(enc, p, end);
00161 if (p + len > s) return (UChar* )p;
00162 p += len;
00163 return (UChar* )(p + ((s - p) & ~1));
00164 }
00165
00166 static int
00167 euckr_is_allowed_reverse_match(const UChar* s, const UChar* end ARG_UNUSED, OnigEncoding enc ARG_UNUSED)
00168 {
00169 const UChar c = *s;
00170 if (c <= 0x7e) return TRUE;
00171 else return FALSE;
00172 }
00173
00174 OnigEncodingDefine(euc_kr, EUC_KR) = {
00175 euckr_mbc_enc_len,
00176 "EUC-KR",
00177 2,
00178 1,
00179 onigenc_is_mbc_newline_0x0a,
00180 euckr_mbc_to_code,
00181 onigenc_mb2_code_to_mbclen,
00182 euckr_code_to_mbc,
00183 euckr_mbc_case_fold,
00184 onigenc_ascii_apply_all_case_fold,
00185 onigenc_ascii_get_case_fold_codes_by_str,
00186 onigenc_minimum_property_name_to_ctype,
00187 euckr_is_code_ctype,
00188 onigenc_not_support_get_ctype_code_range,
00189 euckr_left_adjust_char_head,
00190 euckr_is_allowed_reverse_match
00191 };
00192 ENC_ALIAS("eucKR", "EUC-KR")
00193