xref: /haiku/headers/posix/ctype.h (revision 93a78ecaa45114d68952d08c4778f073515102f2)
1 #ifndef _CTYPE_H
2 #define _CTYPE_H
3 /*
4 ** Distributed under the terms of the OpenBeOS License.
5 */
6 
7 #ifdef __cplusplus
8 extern "C" {
9 #endif
10 
11 int isalnum(int);
12 int isalpha(int);
13 int isascii(int);
14 int isblank(int);
15 int iscntrl(int);
16 int isdigit(int);
17 int isgraph(int);
18 int islower(int);
19 int isprint(int);
20 int ispunct(int);
21 int isspace(int);
22 int isupper(int);
23 int isxdigit(int);
24 int toascii(int);
25 int tolower(int);
26 int toupper(int);
27 
28 enum {
29 	_ISblank = 0x0001,		/* blank */
30 	_IScntrl = 0x0002,		/* control */
31 	_ISpunct = 0x0004,		/* punctuation */
32 	_ISalnum = 0x0008,		/* alpha-numeric */
33 	_ISupper = 0x0100,		/* uppercase */
34 	_ISlower = 0x0200,		/* lowercase */
35 	_ISalpha = 0x0400,		/* alphabetic */
36 	_ISdigit = 0x0800,		/* digit */
37 	_ISxdigit = 0x1000,		/* hexadecimal digit */
38 	_ISspace = 0x2000,		/* white space */
39 	_ISprint = 0x4000,		/* printing */
40 	_ISgraph = 0x8000		/* graphical */
41 };
42 
43 /* Characteristics */
44 extern const unsigned short int *__ctype_b;
45 /* Case conversions */
46 extern const int *__ctype_tolower;
47 extern const int *__ctype_toupper;
48 
49 #define __isctype(c, type) \
50 	(__ctype_b[(int)(c)] & (unsigned short int)type)
51 
52 #define isascii(c) (((c) & ~0x7f) == 0)	/* ASCII characters have bit 8 cleared */
53 #define toascii(c) ((c) & 0x7f)			/* Clear higher bits */
54 
55 #define tolower(c) ((int)__ctype_tolower[(int)(c)])
56 #define toupper(c) ((int)__ctype_toupper[(int)(c)])
57 #define _tolower(c)	tolower(c)
58 #define _toupper(c)	toupper(c)
59 
60 #define isalnum(c)	__isctype((c), _ISalnum)
61 #define isalpha(c)	__isctype((c), _ISalpha)
62 #define isblank(c)	__isctype((c), _ISblank)
63 #define iscntrl(c)	__isctype((c), _IScntrl)
64 #define isdigit(c)	__isctype((c), _ISdigit)
65 #define islower(c)	__isctype((c), _ISlower)
66 #define isgraph(c)	__isctype((c), _ISgraph)
67 #define isprint(c)	__isctype((c), _ISprint)
68 #define ispunct(c)	__isctype((c), _ISpunct)
69 #define isspace(c)	__isctype((c), _ISspace)
70 #define isupper(c)	__isctype((c), _ISupper)
71 #define isxdigit(c)	__isctype((c), _ISxdigit)
72 
73 #ifdef __cplusplus
74 }
75 #endif
76 
77 #endif // _CTYPE_H
78