]> mj.ucw.cz Git - libucw.git/blob - lib/chartype.h
Word type 0 is reserved.
[libucw.git] / lib / chartype.h
1 /*
2  *      Sherlock Library -- Character Types
3  *
4  *      (c) 1997 Martin Mares <mj@ucw.cz>
5  */
6
7 #ifndef _SHERLOCK_CHARTYPE_H
8 #define _SHERLOCK_CHARTYPE_H
9
10 #define _C_UPPER 1                      /* Upper-case letters */
11 #define _C_LOWER 2                      /* Lower-case letters */
12 #define _C_PRINT 4                      /* Printable */
13 #define _C_DIGIT 8                      /* Digits */
14 #define _C_CTRL 16                      /* Control characters */
15 #define _C_XDIGIT 32                    /* Hexadecimal digits */
16 #define _C_BLANK 64                     /* Blanks */
17 #define _C_INNER 128                    /* `inner punctuation' -- underscore etc. */
18
19 #define _C_ALPHA (_C_UPPER | _C_LOWER)
20 #define _C_ALNUM (_C_ALPHA | _C_DIGIT)
21 #define _C_WORD (_C_ALNUM | _C_INNER)
22 #define _C_WSTART (_C_ALPHA | _C_INNER)
23
24 extern unsigned char _c_cat[256], _c_upper[256], _c_collate[256], _c_order[256];
25
26 #define Category(x) (_c_cat[(unsigned char)(x)])
27 #define Ccat(x,y) (Category(x) & y)
28
29 #define Cupper(x) Ccat(x, _C_UPPER)
30 #define Clower(x) Ccat(x, _C_LOWER)
31 #define Calpha(x) Ccat(x, _C_ALPHA)
32 #define Calnum(x) Ccat(x, _C_ALNUM)
33 #define Cprint(x) Ccat(x, _C_PRINT)
34 #define Cdigit(x) Ccat(x, _C_DIGIT)
35 #define Cxdigit(x) Ccat(x, _C_XDIGIT)
36 #define Cword(x) Ccat(x, _C_WORD)
37 #define Cblank(x) Ccat(x, _C_BLANK)
38 #define Cctrl(x) Ccat(x, _C_CTRL)
39 #define Cspace(x) Cblank(x)
40
41 #define Cupcase(x) _c_upper[(unsigned char)(x)]
42
43 #define Cxvalue(x) (((x)<'A')?((x)-'0'):(((x)&0xdf)-'A'+10))
44
45 #endif