X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fff-unicode.h;h=93f8a06ec013bf83dee248eb6f6699f40df081c2;hb=6b475e1471242a1db6ee254f98501cc11c8bf1c4;hp=e3838b1c1a691d365b9b6c485d7ee13326e6ee81;hpb=10f1d0ab666c28cf8aeca9c04a254af5c6ed6b22;p=libucw.git diff --git a/lib/ff-unicode.h b/lib/ff-unicode.h index e3838b1c..93f8a06e 100644 --- a/lib/ff-unicode.h +++ b/lib/ff-unicode.h @@ -14,6 +14,8 @@ #include "lib/fastbuf.h" #include "lib/unicode.h" +/*** UTF-8 ***/ + int bget_utf8_slow(struct fastbuf *b, uns repl); int bget_utf8_32_slow(struct fastbuf *b, uns repl); void bput_utf8_slow(struct fastbuf *b, uns u); @@ -60,7 +62,6 @@ bget_utf8_32(struct fastbuf *b) static inline void bput_utf8(struct fastbuf *b, uns u) { - ASSERT(u < 65536); if (bavailw(b) >= 3) b->bptr = utf8_put(b->bptr, u); else @@ -70,11 +71,73 @@ bput_utf8(struct fastbuf *b, uns u) static inline void bput_utf8_32(struct fastbuf *b, uns u) { - ASSERT(u < (1U<<31)); if (bavailw(b) >= 6) b->bptr = utf8_32_put(b->bptr, u); else bput_utf8_32_slow(b, u); } +/*** UTF-16 ***/ + +int bget_utf16_be_slow(struct fastbuf *b, uns repl); +int bget_utf16_le_slow(struct fastbuf *b, uns repl); +void bput_utf16_be_slow(struct fastbuf *b, uns u); +void bput_utf16_le_slow(struct fastbuf *b, uns u); + +static inline int +bget_utf16_be_repl(struct fastbuf *b, uns repl) +{ + uns u; + if (bavailr(b) >= 4) + { + b->bptr = utf16_be_get_repl(b->bptr, &u, repl); + return u; + } + else + return bget_utf16_be_slow(b, repl); +} + +static inline int +bget_utf16_le_repl(struct fastbuf *b, uns repl) +{ + uns u; + if (bavailr(b) >= 4) + { + b->bptr = utf16_le_get_repl(b->bptr, &u, repl); + return u; + } + else + return bget_utf16_le_slow(b, repl); +} + +static inline int +bget_utf16_be(struct fastbuf *b) +{ + return bget_utf16_be_repl(b, UNI_REPLACEMENT); +} + +static inline int +bget_utf16_le(struct fastbuf *b) +{ + return bget_utf16_le_repl(b, UNI_REPLACEMENT); +} + +static inline void +bput_utf16_be(struct fastbuf *b, uns u) +{ + if (bavailw(b) >= 4) + b->bptr = utf16_be_put(b->bptr, u); + else + bput_utf16_be_slow(b, u); +} + +static inline void +bput_utf16_lbe(struct fastbuf *b, uns u) +{ + if (bavailw(b) >= 4) + b->bptr = utf16_le_put(b->bptr, u); + else + bput_utf16_le_slow(b, u); +} + #endif