4 * (c) 1997 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
10 #include "lib/chartype.h"
12 extern byte *_U_cat[], *_U_sig[];
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 static inline byte Usig(word x)
44 return _U_sig[x >> 8U][x & 0xff] ? : 0xff;
49 #define UCat(x,y) (Ucategory(x) & (y))
51 #define Uupper(x) UCat(x, _C_UPPER)
52 #define Ulower(x) UCat(x, _C_LOWER)
53 #define Ualpha(x) UCat(x, _C_ALPHA)
54 #define Ualnum(x) UCat(x, _C_ALNUM)
55 #define Uprint(x) !Uctrl(x)
56 #define Udigit(x) UCat(x, _C_DIGIT)
57 #define Uxdigit(x) UCat(x, _C_XDIGIT)
58 #define Uword(x) UCat(x, _C_WORD)
59 #define Ublank(x) UCat(x, _C_BLANK)
60 #define Uctrl(x) UCat(x, _C_CTRL)
61 #define Uspace(x) Ublank(x)
63 #define UNI_REPLACEMENT 0xfffc
65 #define PUT_UTF8(p,u) do { \
70 *p++ = 0xc0 | (u >> 6); \
71 *p++ = 0x80 | (u & 0x3f); \
75 *p++ = 0xe0 | (u >> 12); \
76 *p++ = 0x80 | ((u >> 6) & 0x3f); \
77 *p++ = 0x80 | (u & 0x3f); \
81 #define IS_UTF8(c) ((c) >= 0xc0)
83 #define GET_UTF8_CHAR(p,u) do { \
85 { /* Too large, use replacement char */ \
87 while ((*p & 0xc0) == 0x80) \
89 u = UNI_REPLACEMENT; \
91 else if (*p >= 0xe0) \
94 if ((*p & 0xc0) == 0x80) \
95 u = (u << 6) | (*p++ & 0x3f); \
96 if ((*p & 0xc0) == 0x80) \
97 u = (u << 6) | (*p++ & 0x3f); \
102 if ((*p & 0xc0) == 0x80) \
103 u = (u << 6) | (*p++ & 0x3f); \
107 #define GET_UTF8(p,u) \
109 GET_UTF8_CHAR(p,u); \
113 #define UTF8_SPACE(u) ((u) < 0x80 ? 1 : (u) < 0x800 ? 2 : 3)
115 uns ucs2_to_utf8(byte *, word *);
116 uns utf8_to_ucs2(word *, byte *);
117 byte *static_ucs2_to_utf8(word *);