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