1 /* Conversion UTF-8 to UCS-4.
2 Copyright (C) 2001-2002, 2006-2007 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2001.
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU Library General Public License as published
7 by the Free Software Foundation; either version 2, or (at your option)
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
28 u8_mbtouc_unsafe_aux (ucs4_t *puc, const uint8_t *s, size_t n)
38 #if CONFIG_UNICODE_SAFETY
39 if ((s[1] ^ 0x80) < 0x40)
42 *puc = ((unsigned int) (c & 0x1f) << 6)
43 | (unsigned int) (s[1] ^ 0x80);
46 /* invalid multibyte character */
50 /* incomplete multibyte character */
59 #if CONFIG_UNICODE_SAFETY
60 if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40
61 && (c >= 0xe1 || s[1] >= 0xa0)
62 && (c != 0xed || s[1] < 0xa0))
65 *puc = ((unsigned int) (c & 0x0f) << 12)
66 | ((unsigned int) (s[1] ^ 0x80) << 6)
67 | (unsigned int) (s[2] ^ 0x80);
70 /* invalid multibyte character */
74 /* incomplete multibyte character */
83 #if CONFIG_UNICODE_SAFETY
84 if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40
85 && (s[3] ^ 0x80) < 0x40
86 && (c >= 0xf1 || s[1] >= 0x90)
88 && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90))
93 *puc = ((unsigned int) (c & 0x07) << 18)
94 | ((unsigned int) (s[1] ^ 0x80) << 12)
95 | ((unsigned int) (s[2] ^ 0x80) << 6)
96 | (unsigned int) (s[3] ^ 0x80);
99 /* invalid multibyte character */
103 /* incomplete multibyte character */
113 #if CONFIG_UNICODE_SAFETY
114 if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40
115 && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40
116 && (c >= 0xf9 || s[1] >= 0x88))
119 *puc = ((unsigned int) (c & 0x03) << 24)
120 | ((unsigned int) (s[1] ^ 0x80) << 18)
121 | ((unsigned int) (s[2] ^ 0x80) << 12)
122 | ((unsigned int) (s[3] ^ 0x80) << 6)
123 | (unsigned int) (s[4] ^ 0x80);
126 /* invalid multibyte character */
130 /* incomplete multibyte character */
139 #if CONFIG_UNICODE_SAFETY
140 if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40
141 && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40
142 && (s[5] ^ 0x80) < 0x40
143 && (c >= 0xfd || s[1] >= 0x84))
146 *puc = ((unsigned int) (c & 0x01) << 30)
147 | ((unsigned int) (s[1] ^ 0x80) << 24)
148 | ((unsigned int) (s[2] ^ 0x80) << 18)
149 | ((unsigned int) (s[3] ^ 0x80) << 12)
150 | ((unsigned int) (s[4] ^ 0x80) << 6)
151 | (unsigned int) (s[5] ^ 0x80);
154 /* invalid multibyte character */
158 /* incomplete multibyte character */
165 /* invalid multibyte character */