]> mj.ucw.cz Git - libucw.git/blob - lib/chartype.h
Merge with git+ssh://git.ucw.cz/projects/sherlock/GIT/sherlock.git
[libucw.git] / lib / chartype.h
1 /*
2  *      UCW Library -- Character Types
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 _UCW_CHARTYPE_H
11 #define _UCW_CHARTYPE_H
12
13 #define _C_UPPER 1                      /* Upper-case letters */
14 #define _C_LOWER 2                      /* Lower-case letters */
15 #define _C_PRINT 4                      /* Printable */
16 #define _C_DIGIT 8                      /* Digits */
17 #define _C_CTRL 16                      /* Control characters */
18 #define _C_XDIGIT 32                    /* Hexadecimal digits */
19 #define _C_BLANK 64                     /* White spaces (spaces, tabs, newlines) */
20 #define _C_INNER 128                    /* `inner punctuation' -- underscore etc. */
21
22 #define _C_ALPHA (_C_UPPER | _C_LOWER)
23 #define _C_ALNUM (_C_ALPHA | _C_DIGIT)
24 #define _C_WORD (_C_ALNUM | _C_INNER)
25 #define _C_WSTART (_C_ALPHA | _C_INNER)
26
27 extern const unsigned char _c_cat[256], _c_upper[256], _c_lower[256];
28
29 #define Category(x) (_c_cat[(unsigned char)(x)])
30 #define Ccat(x,y) (Category(x) & y)
31
32 #define Cupper(x) Ccat(x, _C_UPPER)
33 #define Clower(x) Ccat(x, _C_LOWER)
34 #define Calpha(x) Ccat(x, _C_ALPHA)
35 #define Calnum(x) Ccat(x, _C_ALNUM)
36 #define Cprint(x) Ccat(x, _C_PRINT)
37 #define Cdigit(x) Ccat(x, _C_DIGIT)
38 #define Cxdigit(x) Ccat(x, _C_XDIGIT)
39 #define Cword(x) Ccat(x, _C_WORD)
40 #define Cblank(x) Ccat(x, _C_BLANK)
41 #define Cctrl(x) Ccat(x, _C_CTRL)
42 #define Cspace(x) Cblank(x)
43
44 #define Cupcase(x) _c_upper[(unsigned char)(x)]
45 #define Clocase(x) _c_lower[(unsigned char)(x)]
46
47 #define Cxvalue(x) (((x)<'A')?((x)-'0'):(((x)&0xdf)-'A'+10))
48
49 #endif