]> mj.ucw.cz Git - libucw.git/blob - lib/ff-utf8.h
taken much faster implementation of Adler32 and put into a separate source-code
[libucw.git] / lib / ff-utf8.h
1 /*
2  *      Sherlock Library: Reading and writing of UTF-8 on Fastbuf Streams
3  *
4  *      (c) 2001--2004 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 _FF_UTF8_H
11 #define _FF_UTF8_H
12
13 #include "lib/fastbuf.h"
14 #include "lib/unicode.h"
15
16 int bget_utf8_slow(struct fastbuf *b);
17 void bput_utf8_slow(struct fastbuf *b, uns u);
18
19 static inline int
20 bget_utf8(struct fastbuf *b)
21 {
22   uns u;
23
24   if (b->bptr + 5 <= b->bufend)
25     {
26       GET_UTF8(b->bptr, u);
27       return u;
28     }
29   else
30     return bget_utf8_slow(b);
31 }
32
33 static inline void
34 bput_utf8(struct fastbuf *b, uns u)
35 {
36   ASSERT(u < 65536);
37   if (b->bptr + 5 <= b->bufend)
38     PUT_UTF8(b->bptr, u);
39   else
40     bput_utf8_slow(b, u);
41 }
42
43 #endif