X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Fff-utf8.h;h=31510ff4411b5aceb85c9c921f20ff9d8f086474;hb=8977e6ac284666f602be2a8d954842c343854e41;hp=f0a9e17f93c003f2527fbc049c45009181e2786a;hpb=414288b47086de5aafa715dd9c794f62f94f8ab2;p=libucw.git diff --git a/lib/ff-utf8.h b/lib/ff-utf8.h index f0a9e17f..31510ff4 100644 --- a/lib/ff-utf8.h +++ b/lib/ff-utf8.h @@ -1,27 +1,30 @@ /* - * Sherlock Library: Reading and writing of UTF-8 on Fastbuf Streams + * UCW 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. */ -#ifndef _FF_UTF8_H -#define _FF_UTF8_H +#ifndef _UCW_FF_UTF8_H +#define _UCW_FF_UTF8_H #include "lib/fastbuf.h" #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 (b->bptr + 5 <= b->bufend) + if (bavailr(b) >= 3) { GET_UTF8(b->bptr, u); return u; @@ -34,10 +37,34 @@ static inline void bput_utf8(struct fastbuf *b, uns u) { ASSERT(u < 65536); - if (b->bptr + 5 <= b->bufend) + if (bavailw(b) >= 3) PUT_UTF8(b->bptr, u); else 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