X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fff-utf8.h;h=dd86ba6504227aabc432c908ff8e9d30615597da;hb=c70b0bd774606177c893f6869ece09d0fd1d9034;hp=752c7187aea9096f02b6e1945c98f0d94108279e;hpb=1bb2d616aa5dc0613cd357a2352abe4470c36342;p=libucw.git diff --git a/lib/ff-utf8.h b/lib/ff-utf8.h index 752c7187..dd86ba65 100644 --- a/lib/ff-utf8.h +++ b/lib/ff-utf8.h @@ -2,6 +2,7 @@ * Sherlock Library: Reading and writing of UTF-8 on Fastbuf Streams * * (c) 2001--2004 Martin Mares + * (c) 2004 Robert Spalek * * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. @@ -14,14 +15,16 @@ #include "lib/unicode.h" int bget_utf8_slow(struct fastbuf *b); +int bget_utf8_32_slow(struct fastbuf *b); void bput_utf8_slow(struct fastbuf *b, uns u); +void bput_utf8_32_slow(struct fastbuf *b, uns u); static inline int bget_utf8(struct fastbuf *b) { uns u; - if (bavailr(b) >= 5) + if (bavailr(b) >= 3) { GET_UTF8(b->bptr, u); return u; @@ -40,4 +43,28 @@ bput_utf8(struct fastbuf *b, uns u) bput_utf8_slow(b, u); } +static inline int +bget_utf8_32(struct fastbuf *b) +{ + uns u; + + if (bavailr(b) >= 6) + { + GET_UTF8_32(b->bptr, u); + return u; + } + else + return bget_utf8_32_slow(b); +} + +static inline void +bput_utf8_32(struct fastbuf *b, uns u) +{ + ASSERT(u < (1U<<31)); + if (bavailw(b) >= 6) + PUT_UTF8_32(b->bptr, u); + else + bput_utf8_32_slow(b, u); +} + #endif