4 * (c) 1997 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
10 #include "lib/chartype.h"
12 extern byte *_U_cat[];
13 extern word *_U_upper[], *_U_lower[], *_U_unaccent[];
15 static inline uns Ucategory(word x)
18 return _U_cat[x >> 8U][x & 0xff];
23 static inline word Utoupper(word x)
25 word w = (_U_upper[x >> 8U]) ? _U_upper[x >> 8U][x & 0xff] : 0;
29 static inline word Utolower(word x)
31 word w = (_U_lower[x >> 8U]) ? _U_lower[x >> 8U][x & 0xff] : 0;
35 static inline word Uunaccent(word x)
37 word w = (_U_unaccent[x >> 8U]) ? _U_unaccent[x >> 8U][x & 0xff] : 0;
41 #define UCat(x,y) (Ucategory(x) & (y))
43 #define Uupper(x) UCat(x, _C_UPPER)
44 #define Ulower(x) UCat(x, _C_LOWER)
45 #define Ualpha(x) UCat(x, _C_ALPHA)
46 #define Ualnum(x) UCat(x, _C_ALNUM)
47 #define Uprint(x) !Uctrl(x)
48 #define Udigit(x) UCat(x, _C_DIGIT)
49 #define Uxdigit(x) UCat(x, _C_XDIGIT)
50 #define Uword(x) UCat(x, _C_WORD)
51 #define Ublank(x) UCat(x, _C_BLANK)
52 #define Uctrl(x) UCat(x, _C_CTRL)
53 #define Uspace(x) Ublank(x)
55 #define UNI_REPLACEMENT 0xfffc
57 #define PUT_UTF8(p,u) do { \
62 *p++ = 0xc0 | (u >> 6); \
63 *p++ = 0x80 | (u & 0x3f); \
67 *p++ = 0xe0 | (u >> 12); \
68 *p++ = 0x80 | ((u >> 6) & 0x3f); \
69 *p++ = 0x80 | (u & 0x3f); \
73 #define IS_UTF8(c) ((c) >= 0xc0)
75 #define GET_UTF8_CHAR(p,u) do { \
77 { /* Too large, use replacement char */ \
79 while ((*p & 0xc0) == 0x80) \
81 u = UNI_REPLACEMENT; \
83 else if (*p >= 0xe0) \
86 if ((*p & 0xc0) == 0x80) \
87 u = (u << 6) | (*p++ & 0x3f); \
88 if ((*p & 0xc0) == 0x80) \
89 u = (u << 6) | (*p++ & 0x3f); \
94 if ((*p & 0xc0) == 0x80) \
95 u = (u << 6) | (*p++ & 0x3f); \
99 #define GET_UTF8(p,u) \
101 GET_UTF8_CHAR(p,u); \
105 #define UTF8_SKIP(p) do { \
107 while (*p >= 0x80 && *p < 0xc0) \
111 #define UTF8_SPACE(u) ((u) < 0x80 ? 1 : (u) < 0x800 ? 2 : 3)
113 uns ucs2_to_utf8(byte *, word *);
114 uns utf8_to_ucs2(word *, byte *);
115 byte *static_ucs2_to_utf8(word *);