X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Funicode-utf8.c;h=5f7b8186e55c62d19f88bb2179599ae497fa9e98;hb=d047dae8f369ac5cbc3dedf8907b2c05694bb892;hp=5a9d1bfc9ff3531fba8d30760c647fd0a9facae2;hpb=f528738ecc582e648fb5ab97fc579b8d14327175;p=libucw.git diff --git a/lib/unicode-utf8.c b/lib/unicode-utf8.c index 5a9d1bfc..5f7b8186 100644 --- a/lib/unicode-utf8.c +++ b/lib/unicode-utf8.c @@ -1,5 +1,5 @@ /* - * Sherlock Library -- UTF-8 Functions + * UCW Library -- UTF-8 Functions * * (c) 1997--2004 Martin Mares * (c) 2003 Robert Spalek @@ -35,3 +35,57 @@ utf8_strnlen(byte *str, uns n) } return len; } + +#ifdef TEST +#include +#include +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