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 int
00033 utf32le_mbc_enc_len(const UChar* p ARG_UNUSED, const OnigUChar* e ARG_UNUSED,
00034 OnigEncoding enc ARG_UNUSED)
00035 {
00036 return 4;
00037 }
00038
00039 static int
00040 utf32le_is_mbc_newline(const UChar* p, const UChar* end,
00041 OnigEncoding enc ARG_UNUSED)
00042 {
00043 if (p + 3 < end) {
00044 if (*p == 0x0a && *(p+1) == 0 && *(p+2) == 0 && *(p+3) == 0)
00045 return 1;
00046 #ifdef USE_UNICODE_ALL_LINE_TERMINATORS
00047 if ((*p == 0x0b ||*p == 0x0c ||*p == 0x0d || *p == 0x85)
00048 && *(p+1) == 0x00 && (p+2) == 0x00 && *(p+3) == 0x00)
00049 return 1;
00050 if (*(p+1) == 0x20 && (*p == 0x29 || *p == 0x28)
00051 && *(p+2) == 0x00 && *(p+3) == 0x00)
00052 return 1;
00053 #endif
00054 }
00055 return 0;
00056 }
00057
00058 static OnigCodePoint
00059 utf32le_mbc_to_code(const UChar* p, const UChar* end ARG_UNUSED,
00060 OnigEncoding enc ARG_UNUSED)
00061 {
00062 return (OnigCodePoint )(((p[3] * 256 + p[2]) * 256 + p[1]) * 256 + p[0]);
00063 }
00064
00065 static int
00066 utf32le_code_to_mbclen(OnigCodePoint code ARG_UNUSED,
00067 OnigEncoding enc ARG_UNUSED)
00068 {
00069 return 4;
00070 }
00071
00072 static int
00073 utf32le_code_to_mbc(OnigCodePoint code, UChar *buf,
00074 OnigEncoding enc ARG_UNUSED)
00075 {
00076 UChar* p = buf;
00077
00078 *p++ = (UChar ) (code & 0xff);
00079 *p++ = (UChar )((code & 0xff00) >> 8);
00080 *p++ = (UChar )((code & 0xff0000) >>16);
00081 *p++ = (UChar )((code & 0xff000000) >>24);
00082 return 4;
00083 }
00084
00085 static int
00086 utf32le_mbc_case_fold(OnigCaseFoldType flag,
00087 const UChar** pp, const UChar* end, UChar* fold,
00088 OnigEncoding enc)
00089 {
00090 const UChar* p = *pp;
00091
00092 if (ONIGENC_IS_ASCII_CODE(*p) && *(p+1) == 0 && *(p+2) == 0 && *(p+3) == 0) {
00093 #ifdef USE_UNICODE_CASE_FOLD_TURKISH_AZERI
00094 if ((flag & ONIGENC_CASE_FOLD_TURKISH_AZERI) != 0) {
00095 if (*p == 0x49) {
00096 *fold++ = 0x31;
00097 *fold++ = 0x01;
00098 }
00099 }
00100 else {
00101 #endif
00102 *fold++ = ONIGENC_ASCII_CODE_TO_LOWER_CASE(*p);
00103 *fold++ = 0;
00104 #ifdef USE_UNICODE_CASE_FOLD_TURKISH_AZERI
00105 }
00106 #endif
00107
00108 *fold++ = 0;
00109 *fold = 0;
00110 *pp += 4;
00111 return 4;
00112 }
00113 else
00114 return onigenc_unicode_mbc_case_fold(enc, flag, pp,
00115 end, fold);
00116 }
00117
00118 #if 0
00119 static int
00120 utf32le_is_mbc_ambiguous(OnigCaseFoldType flag, const UChar** pp, const UChar* end)
00121 {
00122 const UChar* p = *pp;
00123
00124 (*pp) += 4;
00125
00126 if (*(p+1) == 0 && *(p+2) == 0 && *(p+3) == 0) {
00127 int c, v;
00128
00129 if (*p == 0xdf && (flag & INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR) != 0) {
00130 return TRUE;
00131 }
00132
00133 c = *p;
00134 v = ONIGENC_IS_UNICODE_ISO_8859_1_BIT_CTYPE(c,
00135 (BIT_CTYPE_UPPER | BIT_CTYPE_LOWER));
00136 if ((v | BIT_CTYPE_LOWER) != 0) {
00137
00138 if (c >= 0xaa && c <= 0xba)
00139 return FALSE;
00140 else
00141 return TRUE;
00142 }
00143 return (v != 0 ? TRUE : FALSE);
00144 }
00145
00146 return FALSE;
00147 }
00148 #endif
00149
00150 static UChar*
00151 utf32le_left_adjust_char_head(const UChar* start, const UChar* s, const UChar* end,
00152 OnigEncoding enc ARG_UNUSED)
00153 {
00154 ptrdiff_t rem;
00155
00156 if (s <= start) return (UChar* )s;
00157
00158 rem = (int )((s - start) % 4);
00159 return (UChar* )(s - rem);
00160 }
00161
00162 static int
00163 utf32le_get_case_fold_codes_by_str(OnigCaseFoldType flag,
00164 const OnigUChar* p, const OnigUChar* end,
00165 OnigCaseFoldCodeItem items[],
00166 OnigEncoding enc)
00167 {
00168 return onigenc_unicode_get_case_fold_codes_by_str(enc,
00169 flag, p, end, items);
00170 }
00171
00172 OnigEncodingDefine(utf_32le, UTF_32LE) = {
00173 utf32le_mbc_enc_len,
00174 "UTF-32LE",
00175 4,
00176 4,
00177 utf32le_is_mbc_newline,
00178 utf32le_mbc_to_code,
00179 utf32le_code_to_mbclen,
00180 utf32le_code_to_mbc,
00181 utf32le_mbc_case_fold,
00182 onigenc_unicode_apply_all_case_fold,
00183 utf32le_get_case_fold_codes_by_str,
00184 onigenc_unicode_property_name_to_ctype,
00185 onigenc_unicode_is_code_ctype,
00186 onigenc_utf16_32_get_ctype_code_range,
00187 utf32le_left_adjust_char_head,
00188 onigenc_always_false_is_allowed_reverse_match,
00189 0,
00190 ONIGENC_FLAG_UNICODE,
00191 };
00192 ENC_ALIAS("UCS-4LE", "UTF-32LE")
00193