• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src/router/libid3tag/

Lines Matching refs:utf8

19  * $Id: utf8.c,v 1.9 2004/01/23 09:41:32 rob Exp $
31 # include "utf8.h"
35 * NAME: utf8->length()
36 * DESCRIPTION: return the number of ucs4 chars represented by a utf8 string
38 id3_length_t id3_utf8_length(id3_utf8_t const *utf8)
42 while (*utf8) {
43 if ((utf8[0] & 0x80) == 0x00)
45 else if ((utf8[0] & 0xe0) == 0xc0 &&
46 (utf8[1] & 0xc0) == 0x80) {
47 if (((utf8[0] & 0x1fL) << 6) >= 0x00000080L) {
49 utf8 += 1;
52 else if ((utf8[0] & 0xf0) == 0xe0 &&
53 (utf8[1] & 0xc0) == 0x80 &&
54 (utf8[2] & 0xc0) == 0x80) {
55 if ((((utf8[0] & 0x0fL) << 12) |
56 ((utf8[1] & 0x3fL) << 6)) >= 0x00000800L) {
58 utf8 += 2;
61 else if ((utf8[0] & 0xf8) == 0xf0 &&
62 (utf8[1] & 0xc0) == 0x80 &&
63 (utf8[2] & 0xc0) == 0x80 &&
64 (utf8[3] & 0xc0) == 0x80) {
65 if ((((utf8[0] & 0x07L) << 18) |
66 ((utf8[1] & 0x3fL) << 12)) >= 0x00010000L) {
68 utf8 += 3;
71 else if ((utf8[0] & 0xfc) == 0xf8 &&
72 (utf8[1] & 0xc0) == 0x80 &&
73 (utf8[2] & 0xc0) == 0x80 &&
74 (utf8[3] & 0xc0) == 0x80 &&
75 (utf8[4] & 0xc0) == 0x80) {
76 if ((((utf8[0] & 0x03L) << 24) |
77 ((utf8[0] & 0x3fL) << 18)) >= 0x00200000L) {
79 utf8 += 4;
82 else if ((utf8[0] & 0xfe) == 0xfc &&
83 (utf8[1] & 0xc0) == 0x80 &&
84 (utf8[2] & 0xc0) == 0x80 &&
85 (utf8[3] & 0xc0) == 0x80 &&
86 (utf8[4] & 0xc0) == 0x80 &&
87 (utf8[5] & 0xc0) == 0x80) {
88 if ((((utf8[0] & 0x01L) << 30) |
89 ((utf8[0] & 0x3fL) << 24)) >= 0x04000000L) {
91 utf8 += 5;
95 ++utf8;
102 * NAME: utf8->size()
103 * DESCRIPTION: return the encoding size of a utf8 string
105 id3_length_t id3_utf8_size(id3_utf8_t const *utf8)
107 id3_utf8_t const *ptr = utf8;
112 return ptr - utf8 + 1;
116 * NAME: utf8->ucs4duplicate()
117 * DESCRIPTION: duplicate and decode a utf8 string into ucs4
119 id3_ucs4_t *id3_utf8_ucs4duplicate(id3_utf8_t const *utf8)
123 ucs4 = malloc((id3_utf8_length(utf8) + 1) * sizeof(*ucs4));
125 id3_utf8_decode(utf8, ucs4);
131 * NAME: utf8->decodechar()
132 * DESCRIPTION: decode a series of utf8 chars into a single ucs4 char
134 id3_length_t id3_utf8_decodechar(id3_utf8_t const *utf8, id3_ucs4_t *ucs4)
136 id3_utf8_t const *start = utf8;
139 if ((utf8[0] & 0x80) == 0x00) {
140 *ucs4 = utf8[0];
141 return utf8 - start + 1;
143 else if ((utf8[0] & 0xe0) == 0xc0 &&
144 (utf8[1] & 0xc0) == 0x80) {
146 ((utf8[0] & 0x1fL) << 6) |
147 ((utf8[1] & 0x3fL) << 0);
149 return utf8 - start + 2;
151 else if ((utf8[0] & 0xf0) == 0xe0 &&
152 (utf8[1] & 0xc0) == 0x80 &&
153 (utf8[2] & 0xc0) == 0x80) {
155 ((utf8[0] & 0x0fL) << 12) |
156 ((utf8[1] & 0x3fL) << 6) |
157 ((utf8[2] & 0x3fL) << 0);
159 return utf8 - start + 3;
161 else if ((utf8[0] & 0xf8) == 0xf0 &&
162 (utf8[1] & 0xc0) == 0x80 &&
163 (utf8[2] & 0xc0) == 0x80 &&
164 (utf8[3] & 0xc0) == 0x80) {
166 ((utf8[0] & 0x07L) << 18) |
167 ((utf8[1] & 0x3fL) << 12) |
168 ((utf8[2] & 0x3fL) << 6) |
169 ((utf8[3] & 0x3fL) << 0);
171 return utf8 - start + 4;
173 else if ((utf8[0] & 0xfc) == 0xf8 &&
174 (utf8[1] & 0xc0) == 0x80 &&
175 (utf8[2] & 0xc0) == 0x80 &&
176 (utf8[3] & 0xc0) == 0x80 &&
177 (utf8[4] & 0xc0) == 0x80) {
179 ((utf8[0] & 0x03L) << 24) |
180 ((utf8[1] & 0x3fL) << 18) |
181 ((utf8[2] & 0x3fL) << 12) |
182 ((utf8[3] & 0x3fL) << 6) |
183 ((utf8[4] & 0x3fL) << 0);
185 return utf8 - start + 5;
187 else if ((utf8[0] & 0xfe) == 0xfc &&
188 (utf8[1] & 0xc0) == 0x80 &&
189 (utf8[2] & 0xc0) == 0x80 &&
190 (utf8[3] & 0xc0) == 0x80 &&
191 (utf8[4] & 0xc0) == 0x80 &&
192 (utf8[5] & 0xc0) == 0x80) {
194 ((utf8[0] & 0x01L) << 30) |
195 ((utf8[1] & 0x3fL) << 24) |
196 ((utf8[2] & 0x3fL) << 18) |
197 ((utf8[3] & 0x3fL) << 12) |
198 ((utf8[4] & 0x3fL) << 6) |
199 ((utf8[5] & 0x3fL) << 0);
201 return utf8 - start + 6;
204 ++utf8;
209 * NAME: utf8->encodechar()
210 * DESCRIPTION: encode a single ucs4 char into a series of up to 6 utf8 chars
212 id3_length_t id3_utf8_encodechar(id3_utf8_t *utf8, id3_ucs4_t ucs4)
215 utf8[0] = ucs4;
220 utf8[0] = 0xc0 | ((ucs4 >> 6) & 0x1f);
221 utf8[1] = 0x80 | ((ucs4 >> 0) & 0x3f);
226 utf8[0] = 0xe0 | ((ucs4 >> 12) & 0x0f);
227 utf8[1] = 0x80 | ((ucs4 >> 6) & 0x3f);
228 utf8[2] = 0x80 | ((ucs4 >> 0) & 0x3f);
233 utf8[0] = 0xf0 | ((ucs4 >> 18) & 0x07);
234 utf8[1] = 0x80 | ((ucs4 >> 12) & 0x3f);
235 utf8[2] = 0x80 | ((ucs4 >> 6) & 0x3f);
236 utf8[3] = 0x80 | ((ucs4 >> 0) & 0x3f);
241 utf8[0] = 0xf8 | ((ucs4 >> 24) & 0x03);
242 utf8[1] = 0x80 | ((ucs4 >> 18) & 0x3f);
243 utf8[2] = 0x80 | ((ucs4 >> 12) & 0x3f);
244 utf8[3] = 0x80 | ((ucs4 >> 6) & 0x3f);
245 utf8[4] = 0x80 | ((ucs4 >> 0) & 0x3f);
250 utf8[0] = 0xfc | ((ucs4 >> 30) & 0x01);
251 utf8[1] = 0x80 | ((ucs4 >> 24) & 0x3f);
252 utf8[2] = 0x80 | ((ucs4 >> 18) & 0x3f);
253 utf8[3] = 0x80 | ((ucs4 >> 12) & 0x3f);
254 utf8[4] = 0x80 | ((ucs4 >> 6) & 0x3f);
255 utf8[5] = 0x80 | ((ucs4 >> 0) & 0x3f);
262 return id3_utf8_encodechar(utf8, ID3_UCS4_REPLACEMENTCHAR);
266 * NAME: utf8->decode()
267 * DESCRIPTION: decode a complete utf8 string into a ucs4 string
269 void id3_utf8_decode(id3_utf8_t const *utf8, id3_ucs4_t *ucs4)
272 utf8 += id3_utf8_decodechar(utf8, ucs4);
277 * NAME: utf8->encode()
278 * DESCRIPTION: encode a complete ucs4 string into a utf8 string
280 void id3_utf8_encode(id3_utf8_t *utf8, id3_ucs4_t const *ucs4)
283 utf8 += id3_utf8_encodechar(utf8, *ucs4);
288 * NAME: utf8->put()
289 * DESCRIPTION: serialize a single utf8 character
291 id3_length_t id3_utf8_put(id3_byte_t **ptr, id3_utf8_t utf8)
294 *(*ptr)++ = utf8;
300 * NAME: utf8->get()
301 * DESCRIPTION: deserialize a single utf8 character
309 * NAME: utf8->serialize()
310 * DESCRIPTION: serialize a ucs4 string using utf8 encoding
316 id3_utf8_t utf8[6], *out;
319 switch (id3_utf8_encodechar(out = utf8, *ucs4++)) {
337 * NAME: utf8->deserialize()
338 * DESCRIPTION: deserialize a ucs4 string using utf8 encoding
343 id3_utf8_t *utf8ptr, *utf8;
348 utf8 = malloc((length + 1) * sizeof(*utf8));
349 if (utf8 == 0)
352 utf8ptr = utf8;
358 ucs4 = malloc((id3_utf8_length(utf8) + 1) * sizeof(*ucs4));
360 id3_utf8_decode(utf8, ucs4);
362 free(utf8);