2 * Sherlock Library -- Unicode Characters
4 * (c) 1997--2004 Martin Mares <mj@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
13 /* Macros for handling UTF-8 */
15 #define UNI_REPLACEMENT 0xfffc
17 #define PUT_UTF8(p,u) do { \
22 *p++ = 0xc0 | (u >> 6); \
23 *p++ = 0x80 | (u & 0x3f); \
27 *p++ = 0xe0 | (u >> 12); \
28 *p++ = 0x80 | ((u >> 6) & 0x3f); \
29 *p++ = 0x80 | (u & 0x3f); \
33 #define IS_UTF8(c) ((c) >= 0xc0)
35 #define GET_UTF8_CHAR(p,u) do { \
37 { /* Too large, use replacement char */ \
39 while ((*p & 0xc0) == 0x80) \
41 u = UNI_REPLACEMENT; \
43 else if (*p >= 0xe0) \
46 if ((*p & 0xc0) == 0x80) \
47 u = (u << 6) | (*p++ & 0x3f); \
48 if ((*p & 0xc0) == 0x80) \
49 u = (u << 6) | (*p++ & 0x3f); \
54 if ((*p & 0xc0) == 0x80) \
55 u = (u << 6) | (*p++ & 0x3f); \
59 #define GET_UTF8(p,u) \
65 #define UTF8_SKIP(p) do { \
68 while (c & 0x40 && *p >= 0x80 && *p < 0xc0) \
72 #define UTF8_SKIP_BWD(p) while ((--*(p) & 0xc0) == 0x80)
74 #define UTF8_SPACE(u) ((u) < 0x80 ? 1 : (u) < 0x800 ? 2 : 3)
78 uns utf8_strlen(byte *str);
79 uns utf8_strnlen(byte *str, uns n);