2 * The UniCode Library: Reading and writing of UTF-8 on Fastbuf Streams
4 * (c) 2001 Martin Mares <mj@ucw.cz>
8 #include "lib/fastbuf.h"
9 #include "charset/unicode.h"
10 #include "charset/unistream.h"
13 bget_utf8_slow(struct fastbuf *b)
18 if (c < 0x80) /* Includes EOF */
20 if (c < 0xc0) /* Incorrect combination */
21 return UNI_REPLACEMENT;
22 if (c >= 0xf0) /* Too large, skip it */
24 while ((c = bgetc(b)) >= 0x80 && c < 0xc0)
28 if (c >= 0xe0) /* 3 bytes */
31 if ((c = bgetc(b)) < 0x80 || c >= 0xc0)
33 code = (code << 6) | (c & 0x3f);
34 if ((c = bgetc(b)) < 0x80 || c >= 0xc0)
36 code = (code << 6) | (c & 0x3f);
41 if ((c = bgetc(b)) < 0x80 || c >= 0xc0)
43 code = (code << 6) | (c & 0x3f);
50 return UNI_REPLACEMENT;
54 bput_utf8_slow(struct fastbuf *b, uns u)
62 bputc(b, 0xc0 | (u >> 6));
65 bputc(b, 0xe0 | (u >> 12));
66 bputc(b, 0x80 | ((u >> 6) & 0x3f));
68 bputc(b, 0x80 | (u & 0x3f));