]> mj.ucw.cz Git - libucw.git/blob - charset/unistream.h
Audited usage of MAX_WORD_LEN, fixed several bugs and documented
[libucw.git] / charset / unistream.h
1 /*
2  *      The UniCode Library: Reading and writing of UTF-8 on Fastbuf Streams
3  *
4  *      (c) 2001--2002 Martin Mares <mj@ucw.cz>
5  *
6  *      This software may be freely distributed and used according to the terms
7  *      of the GNU Lesser General Public License.
8  */
9
10 #ifndef _UNISTREAM_H
11 #define _UNISTREAM_H
12
13 #include "charset/unicode.h"
14
15 int bget_utf8_slow(struct fastbuf *b);
16 void bput_utf8_slow(struct fastbuf *b, uns u);
17
18 static inline int
19 bget_utf8(struct fastbuf *b)
20 {
21   uns u;
22
23   if (b->bptr + 5 <= b->bufend)
24     {
25       GET_UTF8(b->bptr, u);
26       return u;
27     }
28   else
29     return bget_utf8_slow(b);
30 }
31
32 static inline void
33 bput_utf8(struct fastbuf *b, uns u)
34 {
35   ASSERT(u < 65536);
36   if (b->bptr + 5 <= b->bufend)
37     PUT_UTF8(b->bptr, u);
38   else
39     bput_utf8_slow(b, u);
40 }
41
42 #endif