Debian Codegraph @

vendor/onigmo-source/enc/utf_16le.c

raw symbols SCIP
1 /**********************************************************************
2 utf_16le.c - Oniguruma (regular expression library)
3 **********************************************************************/
4 /*-
5 * Copyright (c) 2002-2008 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30 #include "regenc.h"cxx . . $ `<file>/vendor/onigmo-source/regenc.h`/
31 #include "iso_8859.h"cxx . . $ `<file>/vendor/onigmo-source/enc/iso_8859.h`/
32
33 #if 0
34 static const int EncLen_UTF16[] = {
35 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
36 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
37 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
38 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
39 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
40 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
41 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
42 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
43 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
44 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
45 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
46 2, 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, 4, 4, 4, 4, 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 };
52 #endif
53
54 static int
55 utf16le_mbc_enc_lencxx . . $ utf16le_mbc_enc_len(d6816dd497b890ca).(const UCharcxx . . $ `vendor/onigmo-source/onigmo.h:76:10`!* p, const OnigUCharcxx . . $ OnigUChar#* e,
56 OnigEncodingcxx . . $ OnigEncoding# enc ARG_UNUSEDcxx . . $ `vendor/onigmo-source/regenc.h:82:11`!)
57 {
58 int len = (int)(e - p);
59 UCharcxx . . $ `vendor/onigmo-source/onigmo.h:76:10`! byte;
60 if (len < 2)
61 return ONIGENC_CONSTRUCT_MBCLEN_NEEDMOREcxx . . $ `vendor/onigmo-source/onigmo.h:352:9`!(1);
62 byte = p[1];
63 if (!UTF16_IS_SURROGATEcxx . . $ `vendor/onigmo-source/regenc.h:188:9`!(byte)) {
64 return ONIGENC_CONSTRUCT_MBCLEN_CHARFOUNDcxx . . $ `vendor/onigmo-source/onigmo.h:345:9`!(2);
65 }
66 if (UTF16_IS_SURROGATE_FIRSTcxx . . $ `vendor/onigmo-source/regenc.h:186:9`!(byte)) {
67 if (len < 4)
68 return ONIGENC_CONSTRUCT_MBCLEN_NEEDMOREcxx . . $ `vendor/onigmo-source/onigmo.h:352:9`!(4-len);
69 if (UTF16_IS_SURROGATE_SECONDcxx . . $ `vendor/onigmo-source/regenc.h:187:9`!(p[3]))
70 return ONIGENC_CONSTRUCT_MBCLEN_CHARFOUNDcxx . . $ `vendor/onigmo-source/onigmo.h:345:9`!(4);
71 }
72 return ONIGENC_CONSTRUCT_MBCLEN_INVALIDcxx . . $ `vendor/onigmo-source/onigmo.h:349:9`!();
73 }
74
75 static int
76 utf16le_is_mbc_newlinecxx . . $ utf16le_is_mbc_newline(d6816dd497b890ca).(const UCharcxx . . $ `vendor/onigmo-source/onigmo.h:76:10`!* p, const UCharcxx . . $ `vendor/onigmo-source/onigmo.h:76:10`!* end,
77 OnigEncodingcxx . . $ OnigEncoding# enc ARG_UNUSEDcxx . . $ `vendor/onigmo-source/regenc.h:82:11`!)
78 {
79 if (p + 1 < end) {
80 if (*p == 0x0a && *(p+1) == 0x00)
81 return 1;
82 #ifdef USE_UNICODE_ALL_LINE_TERMINATORS
83 if ((*p == 0x0b || *p == 0x0c || *p == 0x0d || *p == 0x85)
84 && *(p+1) == 0x00)
85 return 1;
86 if (*(p+1) == 0x20 && (*p == 0x29 || *p == 0x28))
87 return 1;
88 #endif
89 }
90 return 0;
91 }
92
93 static OnigCodePointcxx . . $ OnigCodePoint#
94 utf16le_mbc_to_codecxx . . $ utf16le_mbc_to_code(542d90b8bf35e660).(const UCharcxx . . $ `vendor/onigmo-source/onigmo.h:76:10`!* p, const UCharcxx . . $ `vendor/onigmo-source/onigmo.h:76:10`!* end ARG_UNUSEDcxx . . $ `vendor/onigmo-source/regenc.h:82:11`!,
95 OnigEncodingcxx . . $ OnigEncoding# enc ARG_UNUSEDcxx . . $ `vendor/onigmo-source/regenc.h:82:11`!)
96 {
97 OnigCodePointcxx . . $ OnigCodePoint# code;
98 UCharcxx . . $ `vendor/onigmo-source/onigmo.h:76:10`! c0 = *p;
99 UCharcxx . . $ `vendor/onigmo-source/onigmo.h:76:10`! c1 = *(p+1);
100
101 if (UTF16_IS_SURROGATE_FIRSTcxx . . $ `vendor/onigmo-source/regenc.h:186:9`!(c1)) {
102 code = ((((c1 << 8) + c0) & 0x03ff) << 10)
103 + (((p[3] << 8) + p[2]) & 0x03ff) + 0x10000;
104 }
105 else {
106 code = c1 * 256 + p[0];
107 }
108 return code;
109 }
110
111 static int
112 utf16le_code_to_mbclencxx . . $ utf16le_code_to_mbclen(ed1ebf883eff915d).(OnigCodePointcxx . . $ OnigCodePoint# code,
113 OnigEncodingcxx . . $ OnigEncoding# enc ARG_UNUSEDcxx . . $ `vendor/onigmo-source/regenc.h:82:11`!)
114 {
115 return (code > 0xffff ? 4 : 2);
116 }
117
118 static int
119 utf16le_code_to_mbccxx . . $ utf16le_code_to_mbc(cc36a00e84837546).(OnigCodePointcxx . . $ OnigCodePoint# code, UCharcxx . . $ `vendor/onigmo-source/onigmo.h:76:10`! *buf,
120 OnigEncodingcxx . . $ OnigEncoding# enc ARG_UNUSEDcxx . . $ `vendor/onigmo-source/regenc.h:82:11`!)
121 {
122 UCharcxx . . $ `vendor/onigmo-source/onigmo.h:76:10`!* p = buf;
123
124 if (code > 0xffff) {
125 unsigned int high = (code >> 10) + 0xD7C0;
126 unsigned int low = (code & 0x3FF) + 0xDC00;
127 *p++ = high & 0xFF;
128 *p++ = (high >> 8) & 0xFF;
129 *p++ = low & 0xFF;
130 *p++ = (low >> 8) & 0xFF;
131 return 4;
132 }
133 else {
134 *p++ = (UCharcxx . . $ `vendor/onigmo-source/onigmo.h:76:10`! )(code & 0xff);
135 *p++ = (UCharcxx . . $ `vendor/onigmo-source/onigmo.h:76:10`! )((code & 0xff00) >> 8);
136 return 2;
137 }
138 }
139
140 static int
141 utf16le_mbc_case_foldcxx . . $ utf16le_mbc_case_fold(c1ec0ee5809b8ef8).(OnigCaseFoldTypecxx . . $ OnigCaseFoldType# flag,
142 const UCharcxx . . $ `vendor/onigmo-source/onigmo.h:76:10`!** pp, const UCharcxx . . $ `vendor/onigmo-source/onigmo.h:76:10`!* end, UCharcxx . . $ `vendor/onigmo-source/onigmo.h:76:10`!* fold,
143 OnigEncodingcxx . . $ OnigEncoding# enc)
144 {
145 const UCharcxx . . $ `vendor/onigmo-source/onigmo.h:76:10`!* p = *pp;
146
147 if (ONIGENC_IS_ASCII_CODEcxx . . $ `vendor/onigmo-source/regenc.h:213:9`!(*p) && *(p+1) == 0) {
148 #ifdef USE_UNICODE_CASE_FOLD_TURKISH_AZERI
149 if ((flag & ONIGENC_CASE_FOLD_TURKISH_AZERI) != 0) {
150 if (*p == 0x49) {
151 *fold++ = 0x31;
152 *fold = 0x01;
153 (*pp) += 2;
154 return 2;
155 }
156 }
157 #endif
158
159 *fold++ = ONIGENC_ASCII_CODE_TO_LOWER_CASEcxx . . $ `vendor/onigmo-source/regenc.h:214:9`!(*p);
160 *fold = 0;
161 *pp += 2;
162 return 2;
163 }
164 else
165 return onigenc_unicode_mbc_case_foldcxx . . $ onigenc_unicode_mbc_case_fold(971301441d819429).(enc, flag, pp,
166 end, fold);
167 }
168
169 #if 0
170 static int
171 utf16le_is_mbc_ambiguous(OnigCaseFoldType flag, const UChar** pp,
172 const UChar* end)
173 {
174 const UChar* p = *pp;
175
176 (*pp) += EncLen_UTF16[*(p+1)];
177
178 if (*(p+1) == 0) {
179 int c, v;
180
181 if (*p == SHARP_s && (flag & INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR) != 0) {
182 return TRUE;
183 }
184
185 c = *p;
186 v = ONIGENC_IS_UNICODE_ISO_8859_1_BIT_CTYPE(c,
187 (BIT_CTYPE_UPPER | BIT_CTYPE_LOWER));
188 if ((v | BIT_CTYPE_LOWER) != 0) {
189 /* 0xaa, 0xb5, 0xba are lower case letter, but can't convert. */
190 if (c >= 0xaa && c <= 0xba)
191 return FALSE;
192 else
193 return TRUE;
194 }
195 return (v != 0 ? TRUE : FALSE);
196 }
197
198 return FALSE;
199 }
200 #endif
201
202 static UCharcxx . . $ `vendor/onigmo-source/onigmo.h:76:10`!*
203 utf16le_left_adjust_char_headcxx . . $ utf16le_left_adjust_char_head(e837d4bf7cdd11f9).(const UCharcxx . . $ `vendor/onigmo-source/onigmo.h:76:10`!* start, const UCharcxx . . $ `vendor/onigmo-source/onigmo.h:76:10`!* s, const UCharcxx . . $ `vendor/onigmo-source/onigmo.h:76:10`!* end,
204 OnigEncodingcxx . . $ OnigEncoding# enc ARG_UNUSEDcxx . . $ `vendor/onigmo-source/regenc.h:82:11`!)
205 {
206 if (s <= start) return (UCharcxx . . $ `vendor/onigmo-source/onigmo.h:76:10`!* )s;
207
208 if ((s - start) % 2 == 1) {
209 s--;
210 }
211
212 if (UTF16_IS_SURROGATE_SECONDcxx . . $ `vendor/onigmo-source/regenc.h:187:9`!(*(s+1)) && s > start + 1)
213 s -= 2;
214
215 return (UCharcxx . . $ `vendor/onigmo-source/onigmo.h:76:10`!* )s;
216 }
217
218 static int
219 utf16le_get_case_fold_codes_by_strcxx . . $ utf16le_get_case_fold_codes_by_str(915325dbff6e96ee).(OnigCaseFoldTypecxx . . $ OnigCaseFoldType# flag,
220 const OnigUCharcxx . . $ OnigUChar#* p, const OnigUCharcxx . . $ OnigUChar#* end,
221 OnigCaseFoldCodeItemcxx . . $ OnigCaseFoldCodeItem# items[],
222 OnigEncodingcxx . . $ OnigEncoding# enc)
223 {
224 return onigenc_unicode_get_case_fold_codes_by_strcxx . . $ onigenc_unicode_get_case_fold_codes_by_str(1749d66e1d069997).(enc,
225 flag, p, end, items);
226 }
227
228 OnigEncodingDefinecxx . . $ `vendor/onigmo-source/regenc.h:241:10`!(utf_16le, UTF_16LE) = {
229 utf16le_mbc_enc_lencxx . . $ utf16le_mbc_enc_len(d6816dd497b890ca).,
230 "UTF-16LE", /* name */
231 4, /* max byte length */
232 2, /* min byte length */
233 utf16le_is_mbc_newlinecxx . . $ utf16le_is_mbc_newline(d6816dd497b890ca).,
234 utf16le_mbc_to_codecxx . . $ utf16le_mbc_to_code(542d90b8bf35e660).,
235 utf16le_code_to_mbclencxx . . $ utf16le_code_to_mbclen(ed1ebf883eff915d).,
236 utf16le_code_to_mbccxx . . $ utf16le_code_to_mbc(cc36a00e84837546).,
237 utf16le_mbc_case_foldcxx . . $ utf16le_mbc_case_fold(c1ec0ee5809b8ef8).,
238 onigenc_unicode_apply_all_case_foldcxx . . $ onigenc_unicode_apply_all_case_fold(52943f35c546f971).,
239 utf16le_get_case_fold_codes_by_strcxx . . $ utf16le_get_case_fold_codes_by_str(915325dbff6e96ee).,
240 onigenc_unicode_property_name_to_ctypecxx . . $ onigenc_unicode_property_name_to_ctype(fb2245aa60ebfd32).,
241 onigenc_unicode_is_code_ctypecxx . . $ onigenc_unicode_is_code_ctype(7f36058cb237933f).,
242 onigenc_utf16_32_get_ctype_code_rangecxx . . $ onigenc_utf16_32_get_ctype_code_range(f3da0df4ba860021).,
243 utf16le_left_adjust_char_headcxx . . $ utf16le_left_adjust_char_head(e837d4bf7cdd11f9).,
244 onigenc_always_false_is_allowed_reverse_matchcxx . . $ onigenc_always_false_is_allowed_reverse_match(d6816dd497b890ca).,
245 onigenc_unicode_case_mapcxx . . $ onigenc_unicode_case_map(963ee2b6f1418456).,
246 0,
247 ONIGENC_FLAG_UNICODEcxx . . $ `vendor/onigmo-source/onigmo.h:313:9`!,
248 };