2 * UCW Library: Reading and writing of UTF-8 and UTF-16 on Fastbuf Streams
4 * (c) 2001--2004 Martin Mares <mj@ucw.cz>
5 * (c) 2004 Robert Spalek <robert@ucw.cz>
6 * (c) 2007--2008 Pavel Charvat <pchar@ucw.cz>
8 * This software may be freely distributed and used according to the terms
9 * of the GNU Lesser General Public License.
12 #ifndef _UCW_FF_UNICODE_H
13 #define _UCW_FF_UNICODE_H
15 #include <ucw/fastbuf.h>
16 #include <ucw/unicode.h>
18 #ifdef CONFIG_UCW_CLEAN_ABI
19 #define bget_utf16_be_slow ucw_bget_utf16_be_slow
20 #define bget_utf16_le_slow ucw_bget_utf16_le_slow
21 #define bget_utf8_32_slow ucw_bget_utf8_32_slow
22 #define bget_utf8_slow ucw_bget_utf8_slow
23 #define bput_utf16_be_slow ucw_bput_utf16_be_slow
24 #define bput_utf16_le_slow ucw_bput_utf16_le_slow
25 #define bput_utf8_32_slow ucw_bput_utf8_32_slow
26 #define bput_utf8_slow ucw_bput_utf8_slow
31 int bget_utf8_slow(struct fastbuf *b, uns repl);
32 int bget_utf8_32_slow(struct fastbuf *b, uns repl);
33 void bput_utf8_slow(struct fastbuf *b, uns u);
34 void bput_utf8_32_slow(struct fastbuf *b, uns u);
36 static inline int bget_utf8_repl(struct fastbuf *b, uns repl)
41 b->bptr = utf8_get_repl(b->bptr, &u, repl);
45 return bget_utf8_slow(b, repl);
48 static inline int bget_utf8_32_repl(struct fastbuf *b, uns repl)
53 b->bptr = utf8_32_get_repl(b->bptr, &u, repl);
57 return bget_utf8_32_slow(b, repl);
60 static inline int bget_utf8(struct fastbuf *b) /** Read a single utf8 character from range [0, 0xffff]. **/
62 return bget_utf8_repl(b, UNI_REPLACEMENT);
65 static inline int bget_utf8_32(struct fastbuf *b) /** Read a single utf8 character (from the whole unicode range). **/
67 return bget_utf8_32_repl(b, UNI_REPLACEMENT);
70 static inline void bput_utf8(struct fastbuf *b, uns u) /** Write a single utf8 character from range [0, 0xffff]. **/
73 b->bptr = utf8_put(b->bptr, u);
78 static inline void bput_utf8_32(struct fastbuf *b, uns u) /** Write a single utf8 character (from the whole unicode range). **/
81 b->bptr = utf8_32_put(b->bptr, u);
83 bput_utf8_32_slow(b, u);
88 int bget_utf16_be_slow(struct fastbuf *b, uns repl);
89 int bget_utf16_le_slow(struct fastbuf *b, uns repl);
90 void bput_utf16_be_slow(struct fastbuf *b, uns u);
91 void bput_utf16_le_slow(struct fastbuf *b, uns u);
93 static inline int bget_utf16_be_repl(struct fastbuf *b, uns repl)
98 b->bptr = utf16_be_get_repl(b->bptr, &u, repl);
102 return bget_utf16_be_slow(b, repl);
105 static inline int bget_utf16_le_repl(struct fastbuf *b, uns repl)
110 b->bptr = utf16_le_get_repl(b->bptr, &u, repl);
114 return bget_utf16_le_slow(b, repl);
118 * Read an utf16 character from fastbuf.
119 * Big endian version.
121 static inline int bget_utf16_be(struct fastbuf *b)
123 return bget_utf16_be_repl(b, UNI_REPLACEMENT);
127 * Read an utf16 character from fastbuf.
128 * Little endian version.
130 static inline int bget_utf16_le(struct fastbuf *b)
132 return bget_utf16_le_repl(b, UNI_REPLACEMENT);
136 * Write an utf16 character to fastbuf.
137 * Big endian version.
139 static inline void bput_utf16_be(struct fastbuf *b, uns u)
142 b->bptr = utf16_be_put(b->bptr, u);
144 bput_utf16_be_slow(b, u);
148 * Write an utf16 character to fastbuf.
149 * Little endian version.
151 static inline void bput_utf16_le(struct fastbuf *b, uns u)
154 b->bptr = utf16_le_put(b->bptr, u);
156 bput_utf16_le_slow(b, u);