]> mj.ucw.cz Git - libucw.git/blob - lib/ff-utf8.h
Minor cleanup of KMP:
[libucw.git] / lib / ff-utf8.h
1 /*
2  *      UCW Library: Reading and writing of UTF-8 on Fastbuf Streams
3  *
4  *      (c) 2001--2004 Martin Mares <mj@ucw.cz>
5  *      (c) 2004 Robert Spalek <robert@ucw.cz>
6  *
7  *      This software may be freely distributed and used according to the terms
8  *      of the GNU Lesser General Public License.
9  */
10
11 #ifndef _FF_UTF8_H
12 #define _FF_UTF8_H
13
14 #include "lib/fastbuf.h"
15 #include "lib/unicode.h"
16
17 int bget_utf8_slow(struct fastbuf *b);
18 int bget_utf8_32_slow(struct fastbuf *b);
19 void bput_utf8_slow(struct fastbuf *b, uns u);
20 void bput_utf8_32_slow(struct fastbuf *b, uns u);
21
22 static inline int
23 bget_utf8(struct fastbuf *b)
24 {
25   uns u;
26
27   if (bavailr(b) >= 3)
28     {
29       GET_UTF8(b->bptr, u);
30       return u;
31     }
32   else
33     return bget_utf8_slow(b);
34 }
35
36 static inline void
37 bput_utf8(struct fastbuf *b, uns u)
38 {
39   ASSERT(u < 65536);
40   if (bavailw(b) >= 3)
41     PUT_UTF8(b->bptr, u);
42   else
43     bput_utf8_slow(b, u);
44 }
45
46 static inline int
47 bget_utf8_32(struct fastbuf *b)
48 {
49   uns u;
50
51   if (bavailr(b) >= 6)
52     {
53       GET_UTF8_32(b->bptr, u);
54       return u;
55     }
56   else
57     return bget_utf8_32_slow(b);
58 }
59
60 static inline void
61 bput_utf8_32(struct fastbuf *b, uns u)
62 {
63   ASSERT(u < (1U<<31));
64   if (bavailw(b) >= 6)
65     PUT_UTF8_32(b->bptr, u);
66   else
67     bput_utf8_32_slow(b, u);
68 }
69
70 #endif