2 * UCW Library -- UTF-8 Functions
4 * (c) 1997--2004 Martin Mares <mj@ucw.cz>
5 * (c) 2003 Robert Spalek <robert@ucw.cz>
7 * This software may be freely distributed and used according to the terms
8 * of the GNU Lesser General Public License.
12 #include <ucw/unicode.h>
15 utf8_strlen(const byte *str)
27 utf8_strnlen(const byte *str, size_t n)
30 const byte *end = str + n;
44 int main(int argc, char **argv)
49 F(UTF8_GET) F(UTF8_32_GET) F(UTF16_BE_GET) F(UTF16_LE_GET) \
50 F(UTF8_PUT) F(UTF8_32_PUT) F(UTF16_BE_PUT) F(UTF16_LE_PUT)
53 #define F(x) FUNC_##x,
58 #define F(x) [FUNC_##x] = #x,
65 for (uint i = 0; i < ARRAY_SIZE(names); i++)
66 if (!strcasecmp(names[i], argv[1]))
70 fprintf(stderr, "Invalid usage!\n");
74 if (func < FUNC_UTF8_PUT)
76 byte *p = buf, *q = buf, *last;
78 bzero(buf, sizeof(buf));
79 while (scanf("%x", &u) == 1)
91 case FUNC_UTF8_32_GET:
92 p = utf8_32_get(p, &u);
94 case FUNC_UTF16_BE_GET:
95 p = utf16_be_get(p, &u);
97 case FUNC_UTF16_LE_GET:
98 p = utf16_le_get(p, &u);
104 ASSERT(last < p && p <= q);
111 while (scanf("%x", &u) == 1)
113 byte *p = buf, *q = buf;
119 case FUNC_UTF8_32_PUT:
120 p = utf8_32_put(p, u);
122 case FUNC_UTF16_BE_PUT:
123 p = utf16_be_put(p, u);
125 case FUNC_UTF16_LE_PUT:
126 p = utf16_le_put(p, u);
135 printf("%02x", *q++);