]> mj.ucw.cz Git - libucw.git/blobdiff - lib/unicode-utf8.c
small fixes in perl modules
[libucw.git] / lib / unicode-utf8.c
index 5a9d1bfc9ff3531fba8d30760c647fd0a9facae2..5f7b8186e55c62d19f88bb2179599ae497fa9e98 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *     Sherlock Library -- UTF-8 Functions
+ *     UCW Library -- UTF-8 Functions
  *
  *     (c) 1997--2004 Martin Mares <mj@ucw.cz>
  *     (c) 2003 Robert Spalek <robert@ucw.cz>
@@ -35,3 +35,57 @@ utf8_strnlen(byte *str, uns n)
     }
   return len;
 }
+
+#ifdef TEST
+#include <string.h>
+#include <stdio.h>
+int main(int argc, char **argv)
+{
+  byte buf[256];
+  if (argc > 1 && !strncmp(argv[1], "get", 3))
+    {
+      int f32 = !strcmp(argv[1], "get32");
+      byte *p = buf;
+      uns u;
+      while (scanf("%x", &u) == 1)
+       *p++ = u;
+      *p = 0;
+      p = buf;
+      while (*p)
+       {
+         if (p != buf)
+           putchar(' ');
+         if (f32)
+           GET_UTF8_32(p, u);
+         else
+           GET_UTF8(p, u);
+         printf("%04x", u);
+       }
+      putchar('\n');
+    }
+  else if (argc > 1 && !strncmp(argv[1], "put", 3))
+    {
+      uns u, i=0;
+      int f32 = !strcmp(argv[1], "put32");
+      while (scanf("%x", &u) == 1)
+       {
+         byte *p = buf;
+         if (f32)
+           PUT_UTF8_32(p, u);
+         else
+           PUT_UTF8(p, u);
+         *p = 0;
+         for (p=buf; *p; p++)
+           {
+             if (i++)
+               putchar(' ');
+             printf("%02x", *p);
+           }
+       }
+      putchar('\n');
+    }
+  else
+    puts("?");
+  return 0;
+}
+#endif