#include "lib/fastbuf.h"
#include "lib/unicode.h"
#include "lib/ff-unicode.h"
+#include "lib/ff-binary.h"
int
bget_utf8_slow(struct fastbuf *b, uns repl)
bputc(b, 0x80 | (u & 0x3f));
}
}
+
+int
+bget_utf16_be_slow(struct fastbuf *b, uns repl)
+{
+ if (bpeekc(b) < 0)
+ return -1;
+ uns u = bgetw_be(b), x, y;
+ if ((int)u < 0)
+ return repl;
+ if ((x = u - 0xd800) >= 0x800)
+ return u;
+ if (x >= 0x400 || bpeekc(b) < 0 || (y = bgetw_be(b) - 0xdc00) >= 0x400)
+ return repl;
+ return 0x10000 + (x << 10) + y;
+}
+
+int
+bget_utf16_le_slow(struct fastbuf *b, uns repl)
+{
+ if (bpeekc(b) < 0)
+ return -1;
+ uns u = bgetw_le(b), x, y;
+ if ((int)u < 0)
+ return repl;
+ if ((x = u - 0xd800) >= 0x800)
+ return u;
+ if (x >= 0x400 || bpeekc(b) < 0 || (y = bgetw_le(b) - 0xdc00) >= 0x400)
+ return repl;
+ return 0x10000 + (x << 10) + y;
+}
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)
bput_utf8_32_slow(b, 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);
+}
+
#endif
return 1;
}
-/*** Generic UTF decoding ***/
-
-static uns
-bget_utf16_le_slow(struct fastbuf *fb, uns repl)
-{
- if ((int)bpeekc(fb) < 0)
- return ~0U;
- uns u = bgetw_le(fb), x, y;
- if ((int)u < 0)
- return repl;
- if ((x = u - 0xd800) >= 0x800)
- return u;
- if (x >= 0x400 || (int)bpeekc(fb) < 0 || (y = bgetw_le(fb) - 0xdc00) >= 0x400)
- return repl;
- return 0x10000 + (x << 10) + y;
-}
-
-static uns
-bget_utf16_be_slow(struct fastbuf *fb, uns repl)
-{
- if ((int)bpeekc(fb) < 0)
- return ~0U;
- uns u = bgetw_be(fb), x, y;
- if ((int)u < 0)
- return repl;
- if ((x = u - 0xd800) >= 0x800)
- return u;
- if (x >= 0x400 || (int)bpeekc(fb) < 0 || (y = bgetw_be(fb) - 0xdc00) >= 0x400)
- return repl;
- return 0x10000 + (x << 10) + y;
-}
-
-static inline uns
-bget_utf16_le_repl(struct fastbuf *fb, uns repl)
-{
- uns u;
- if (bavailr(fb) >= 4)
- {
- fb->bptr = utf16_le_get_repl(fb->bptr, &u, repl);
- return u;
- }
- else
- return bget_utf16_le_slow(fb, repl);
-}
-
-static inline uns
-bget_utf16_be_repl(struct fastbuf *fb, uns repl)
-{
- uns u;
- if (bavailr(fb) >= 4)
- {
- fb->bptr = utf16_be_get_repl(fb->bptr, &u, repl);
- return u;
- }
- else
- return bget_utf16_be_slow(fb, repl);
-}
-
/*** Memory management ***/
static void NONRET