#include "lib/ff-unicode.h"
#include "lib/ff-binary.h"
+/*** UTF-8 ***/
+
int
bget_utf8_slow(struct fastbuf *b, uns repl)
{
}
}
+/*** UTF-16 ***/
+
int
bget_utf16_be_slow(struct fastbuf *b, uns repl)
{
return repl;
return 0x10000 + (x << 10) + y;
}
+
+void
+bput_utf16_be_slow(struct fastbuf *b, uns u)
+{
+ if (u < 0xd800 || (u < 0x10000 && u >= 0xe000))
+ {
+ bputc(b, u >> 8);
+ bputc(b, u & 0xff);
+ }
+ else if ((u -= 0x10000) < 0x100000)
+ {
+ bputc(b, 0xd8 | (u >> 18));
+ bputc(b, (u >> 10) & 0xff);
+ bputc(b, 0xdc | ((u >> 8) & 0x3));
+ bputc(b, u & 0xff);
+ }
+ else
+ ASSERT(0);
+}
+
+void
+bput_utf16_le_slow(struct fastbuf *b, uns u)
+{
+ if (u < 0xd800 || (u < 0x10000 && u >= 0xe000))
+ {
+ bputc(b, u & 0xff);
+ bputc(b, u >> 8);
+ }
+ else if ((u -= 0x10000) < 0x100000)
+ {
+ bputc(b, (u >> 10) & 0xff);
+ bputc(b, 0xd8 | (u >> 18));
+ bputc(b, u & 0xff);
+ bputc(b, 0xdc | ((u >> 8) & 0x3));
+ }
+ else
+ ASSERT(0);
+}
#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);
void bput_utf8_32_slow(struct fastbuf *b, uns u);
-int bget_utf16_be_slow(struct fastbuf *b, uns repl);
-int bget_utf16_le_slow(struct fastbuf *b, uns repl);
static inline int
bget_utf8_repl(struct fastbuf *b, uns repl)
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
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)
{
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
}
else if ((u -= 0x10000) < 0x100000)
{
- put_u16_le(p, u >> 10);
- put_u16_le(p + 2, u & 0x7ff);
+ put_u16_le(p, 0xd800 | (u >> 10));
+ put_u16_le(p + 2, 0xdc00 | (u & 0x3ff));
return p + 4;
}
else
}
else if ((u -= 0x10000) < 0x100000)
{
- put_u16_be(p, u >> 10);
- put_u16_be(p + 2, u & 0x7ff);
+ put_u16_be(p, 0xd800 | (u >> 10));
+ put_u16_be(p + 2, 0xdc00 | (u & 0x3ff));
return p + 4;
}
else