]> mj.ucw.cz Git - libucw.git/commitdiff
Moved UTF-8 streams to lib/ff-utf8.[ch] (`ff' prefix will denote fastbuf
authorMartin Mares <mj@ucw.cz>
Sat, 10 Jul 2004 20:34:27 +0000 (20:34 +0000)
committerMartin Mares <mj@ucw.cz>
Sat, 10 Jul 2004 20:34:27 +0000 (20:34 +0000)
front-ends, `fb' will be the back-ends).

charset/unistream.c [deleted file]
charset/unistream.h [deleted file]
lib/ff-utf8.c [new file with mode: 0644]
lib/ff-utf8.h [new file with mode: 0644]

diff --git a/charset/unistream.c b/charset/unistream.c
deleted file mode 100644 (file)
index 6431b0a..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- *     The UniCode Library: Reading and writing of UTF-8 on Fastbuf Streams
- *
- *     (c) 2001 Martin Mares <mj@ucw.cz>
- *
- *     This software may be freely distributed and used according to the terms
- *     of the GNU Lesser General Public License.
- */
-
-#include "lib/lib.h"
-#include "lib/fastbuf.h"
-#include "charset/unicode.h"
-#include "charset/unistream.h"
-
-int
-bget_utf8_slow(struct fastbuf *b)
-{
-  int c = bgetc(b);
-  int code;
-
-  if (c < 0x80)                                /* Includes EOF */
-    return c;
-  if (c < 0xc0)                                /* Incorrect combination */
-    return UNI_REPLACEMENT;
-  if (c >= 0xf0)                       /* Too large, skip it */
-    {
-      while ((c = bgetc(b)) >= 0x80 && c < 0xc0)
-       ;
-      goto wrong;
-    }
-  if (c >= 0xe0)                       /* 3 bytes */
-    {
-      code = c & 0x0f;
-      if ((c = bgetc(b)) < 0x80 || c >= 0xc0)
-       goto wrong;
-      code = (code << 6) | (c & 0x3f);
-      if ((c = bgetc(b)) < 0x80 || c >= 0xc0)
-       goto wrong;
-      code = (code << 6) | (c & 0x3f);
-    }
-  else                                 /* 2 bytes */
-    {
-      code = c & 0x1f;
-      if ((c = bgetc(b)) < 0x80 || c >= 0xc0)
-       goto wrong;
-      code = (code << 6) | (c & 0x3f);
-    }
-  return code;
-
- wrong:
-  if (c >= 0)
-    bungetc(b);
-  return UNI_REPLACEMENT;
-}
-
-void
-bput_utf8_slow(struct fastbuf *b, uns u)
-{
-  ASSERT(u < 65536);
-  if (u < 0x80)
-    bputc(b, u);
-  else
-    {
-      if (u < 0x800)
-       bputc(b, 0xc0 | (u >> 6));
-      else
-       {
-         bputc(b, 0xe0 | (u >> 12));
-         bputc(b, 0x80 | ((u >> 6) & 0x3f));
-       }
-      bputc(b, 0x80 | (u & 0x3f));
-    }
-}
diff --git a/charset/unistream.h b/charset/unistream.h
deleted file mode 100644 (file)
index 66680ba..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- *     The UniCode Library: Reading and writing of UTF-8 on Fastbuf Streams
- *
- *     (c) 2001--2002 Martin Mares <mj@ucw.cz>
- *
- *     This software may be freely distributed and used according to the terms
- *     of the GNU Lesser General Public License.
- */
-
-#ifndef _UNISTREAM_H
-#define _UNISTREAM_H
-
-#include "charset/unicode.h"
-
-int bget_utf8_slow(struct fastbuf *b);
-void bput_utf8_slow(struct fastbuf *b, uns u);
-
-static inline int
-bget_utf8(struct fastbuf *b)
-{
-  uns u;
-
-  if (b->bptr + 5 <= b->bufend)
-    {
-      GET_UTF8(b->bptr, u);
-      return u;
-    }
-  else
-    return bget_utf8_slow(b);
-}
-
-static inline void
-bput_utf8(struct fastbuf *b, uns u)
-{
-  ASSERT(u < 65536);
-  if (b->bptr + 5 <= b->bufend)
-    PUT_UTF8(b->bptr, u);
-  else
-    bput_utf8_slow(b, u);
-}
-
-#endif
diff --git a/lib/ff-utf8.c b/lib/ff-utf8.c
new file mode 100644 (file)
index 0000000..f55719b
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ *     Sherlock Library: Reading and writing of UTF-8 on Fastbuf Streams
+ *
+ *     (c) 2001--2004 Martin Mares <mj@ucw.cz>
+ *
+ *     This software may be freely distributed and used according to the terms
+ *     of the GNU Lesser General Public License.
+ */
+
+#include "lib/lib.h"
+#include "lib/fastbuf.h"
+#include "lib/unicode.h"
+#include "lib/ff-utf8.h"
+
+int
+bget_utf8_slow(struct fastbuf *b)
+{
+  int c = bgetc(b);
+  int code;
+
+  if (c < 0x80)                                /* Includes EOF */
+    return c;
+  if (c < 0xc0)                                /* Incorrect combination */
+    return UNI_REPLACEMENT;
+  if (c >= 0xf0)                       /* Too large, skip it */
+    {
+      while ((c = bgetc(b)) >= 0x80 && c < 0xc0)
+       ;
+      goto wrong;
+    }
+  if (c >= 0xe0)                       /* 3 bytes */
+    {
+      code = c & 0x0f;
+      if ((c = bgetc(b)) < 0x80 || c >= 0xc0)
+       goto wrong;
+      code = (code << 6) | (c & 0x3f);
+      if ((c = bgetc(b)) < 0x80 || c >= 0xc0)
+       goto wrong;
+      code = (code << 6) | (c & 0x3f);
+    }
+  else                                 /* 2 bytes */
+    {
+      code = c & 0x1f;
+      if ((c = bgetc(b)) < 0x80 || c >= 0xc0)
+       goto wrong;
+      code = (code << 6) | (c & 0x3f);
+    }
+  return code;
+
+ wrong:
+  if (c >= 0)
+    bungetc(b);
+  return UNI_REPLACEMENT;
+}
+
+void
+bput_utf8_slow(struct fastbuf *b, uns u)
+{
+  ASSERT(u < 65536);
+  if (u < 0x80)
+    bputc(b, u);
+  else
+    {
+      if (u < 0x800)
+       bputc(b, 0xc0 | (u >> 6));
+      else
+       {
+         bputc(b, 0xe0 | (u >> 12));
+         bputc(b, 0x80 | ((u >> 6) & 0x3f));
+       }
+      bputc(b, 0x80 | (u & 0x3f));
+    }
+}
diff --git a/lib/ff-utf8.h b/lib/ff-utf8.h
new file mode 100644 (file)
index 0000000..f0a9e17
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ *     Sherlock Library: Reading and writing of UTF-8 on Fastbuf Streams
+ *
+ *     (c) 2001--2004 Martin Mares <mj@ucw.cz>
+ *
+ *     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
+
+#include "lib/fastbuf.h"
+#include "lib/unicode.h"
+
+int bget_utf8_slow(struct fastbuf *b);
+void bput_utf8_slow(struct fastbuf *b, uns u);
+
+static inline int
+bget_utf8(struct fastbuf *b)
+{
+  uns u;
+
+  if (b->bptr + 5 <= b->bufend)
+    {
+      GET_UTF8(b->bptr, u);
+      return u;
+    }
+  else
+    return bget_utf8_slow(b);
+}
+
+static inline void
+bput_utf8(struct fastbuf *b, uns u)
+{
+  ASSERT(u < 65536);
+  if (b->bptr + 5 <= b->bufend)
+    PUT_UTF8(b->bptr, u);
+  else
+    bput_utf8_slow(b, u);
+}
+
+#endif