]> mj.ucw.cz Git - libucw.git/blob - charset/unicat.h
Sorter: Fixed a documentation comment
[libucw.git] / charset / unicat.h
1 /*
2  *      The UniCode Character Categorizer
3  *
4  *      (c) 1997--2004 Martin Mares <mj@ucw.cz>
5  *
6  *      This software may be freely distributed and used according to the terms
7  *      of the GNU Lesser General Public License.
8  */
9
10 #ifndef _CHARSET_UNICAT_H
11 #define _CHARSET_UNICAT_H
12
13 #ifdef CONFIG_UCW_CLEAN_ABI
14 #define Uexpand_lig ucw_Uexpand_lig
15 #define _U_cat ucw__U_cat
16 #define _U_lower ucw__U_lower
17 #define _U_unaccent ucw__U_unaccent
18 #define _U_upper ucw__U_upper
19 #endif
20
21 extern const byte *_U_cat[];
22 extern const u16 *_U_upper[], *_U_lower[], *_U_unaccent[];
23
24 static inline uns Ucategory(uns x)
25 {
26   if (_U_cat[x >> 8U])
27     return _U_cat[x >> 8U][x & 0xff];
28   else
29     return 0;
30 }
31
32 static inline uns Utoupper(uns x)
33 {
34   uns w = (_U_upper[x >> 8U]) ? _U_upper[x >> 8U][x & 0xff] : 0;
35   return w ? w : x;
36 }
37
38 static inline uns Utolower(uns x)
39 {
40   uns w = (_U_lower[x >> 8U]) ? _U_lower[x >> 8U][x & 0xff] : 0;
41   return w ? w : x;
42 }
43
44 static inline uns Uunaccent(uns x)
45 {
46   uns w = (_U_unaccent[x >> 8U]) ? _U_unaccent[x >> 8U][x & 0xff] : 0;
47   return w ? w : x;
48 }
49
50 extern const u16 *Uexpand_lig(uns x);
51
52 enum unicode_char_type {
53   _U_LETTER = 1,                /* Letters */
54   _U_UPPER = 2,                 /* Upper-case letters */
55   _U_LOWER = 4,                 /* Lower-case letters */
56   _U_CTRL = 8,                  /* Control characters */
57   _U_DIGIT = 16,                /* Digits */
58   _U_XDIGIT = 32,               /* Hexadecimal digits */
59   _U_SPACE = 64,                /* White spaces (spaces, tabs, newlines) */
60   _U_LIGATURE = 128,            /* Compatibility ligature (to be expanded) */
61 };
62
63 #define _U_LUPPER (_U_LETTER | _U_UPPER)
64 #define _U_LLOWER (_U_LETTER | _U_LOWER)
65
66 #define UCat(x,y) (Ucategory(x) & (y))
67
68 #define Ualpha(x) UCat(x, _U_LETTER)
69 #define Uupper(x) UCat(x, _U_UPPER)
70 #define Ulower(x) UCat(x, _U_LOWER)
71 #define Udigit(x) UCat(x, _U_DIGIT)
72 #define Uxdigit(x) UCat(x, (_U_DIGIT | _U_XDIGIT))
73 #define Ualnum(x) UCat(x, (_U_LETTER | _U_DIGIT))
74 #define Uctrl(x) UCat(x, _U_CTRL)
75 #define Uprint(x) !Uctrl(x)
76 #define Uspace(x) UCat(x, _U_SPACE)
77
78 #endif