2 * Character Set Conversion Library 1.2
4 * (c) 1998--2004 Martin Mares <mj@ucw.cz>
5 * (c) 2007 Pavel Charvat <pchar@ucw.cz>
7 * This software may be freely distributed and used according to the terms
8 * of the GNU Lesser General Public License.
11 /* Generator of inlined conversion routines */
23 unsigned short *in_to_x = c->in_to_x;
27 unsigned short *x_to_out = c->x_to_out;
34 if (unlikely(c->state))
48 if (unlikely(s >= se))
50 #ifndef CONV_WRITE_STD
51 code = x_to_uni[in_to_x[*s++]];
56 if (unlikely(s >= se))
67 if ((s[0] & 0xc0) != 0x80)
70 code = (code << 6) | (*s++ & 0x3f);
74 if ((s[0] & 0xc0) != 0x80 || (s[1] & 0xc0) != 0x80)
77 code = (code << 6) | (*s++ & 0x3f);
78 code = (code << 6) | (*s++ & 0x3f);
84 if ((*s++ & 0xc0) != 0x80)
96 code = UNI_REPLACEMENT;
100 #ifdef CONV_READ_UTF16_BE
101 if (unlikely(s + 4 >= se))
103 c->state = UTF16_BE_READ;
106 s = utf16_be_get(s, &code);
109 #ifdef CONV_READ_UTF16_LE
110 if (unlikely(s + 4 >= se))
112 c->state = UTF16_LE_READ;
115 s = utf16_le_get(s, &code);
122 #ifdef CONV_WRITE_STD
123 #ifndef CONV_READ_STD
124 code = x_to_out[uni_to_x[code >> 8U][code & 0xff]];
126 code = x_to_out[in_to_x[*s++]];
130 if (unlikely(d >= de))
132 c->state = SINGLE_WRITE;
140 byte *k = string_table + code - 0x100;
142 if (unlikely((uns)(de - d) < len))
144 c->state = SEQ_WRITE;
154 #ifdef CONV_WRITE_UTF8
161 else if (code < 0x800)
165 *d++ = 0xc0 | (code >> 6);
166 *d++ = 0x80 | (code & 0x3f);
172 *d++ = 0xe0 | (code >> 12);
173 *d++ = 0x80 | ((code >> 6) & 0x3f);
174 *d++ = 0x80 | (code & 0x3f);
178 #ifdef CONV_WRITE_UTF16_BE
179 if (unlikely(de - d < 2))
181 else if (code < 0xd800 || code - 0xe000 < 0x2000 ||
182 ((code -= 0x10000) >= 0x10000 && (code = UNI_REPLACEMENT)))
187 else if (likely(de - d < 4))
189 *d++ = 0xd8 | (code >> 18);
190 *d++ = (code >> 10) & 0xff;
191 *d++ = 0xdc | ((code >> 8) & 3);
198 c->state = UTF16_BE_WRITE;
203 #ifdef CONV_WRITE_UTF16_LE
204 if (unlikely(de - d < 2))
206 else if (code < 0xd800 || code - 0xe000 < 0x2000 ||
207 ((code -= 0x10000) >= 0x10000 && (code = UNI_REPLACEMENT)))
212 else if (likely(de - d < 4))
214 *d++ = (code >> 10) & 0xff;
215 *d++ = 0xd8 | (code >> 18);
217 *d++ = 0xdc | ((code >> 8) & 3);
223 c->state = UTF16_LE_WRITE;
234 return CONV_SOURCE_END;
236 #ifdef CONV_READ_UTF8
238 if (cc < 0xe0) { c->code = cc & 0x1f; c->remains = 1; }
239 else if (cc < 0xf0) { c->code = cc & 0x0f; c->remains = 2; }
243 if (cc < 0xf8) c->remains = 3;
244 else if (cc < 0xfc) c->remains = 4;
245 else if (cc < 0xfe) c->remains = 5;
248 c->state = UTF8_READ;
252 #ifdef CONV_WRITE_UTF8
254 c->state = UTF8_WRITE_START;
279 /*** Undefine all parameters ***/
282 #undef CONV_READ_UTF8
283 #undef CONV_READ_UTF16_BE
284 #undef CONV_READ_UTF16_LE
285 #undef CONV_WRITE_STD
286 #undef CONV_WRITE_UTF8
287 #undef CONV_WRITE_UTF16_BE
288 #undef CONV_WRITE_UTF16_LE