1 /*-
2 * Copyright (c) 2008
3 * Thorsten Glaser <tg@mirbsd.org>
4 *
5 * Provided that these terms and disclaimer and all copyright notices
6 * are retained or reproduced in an accompanying document, permission
7 * is granted to deal in this work without restriction, including un-
8 * limited rights to use, publicly perform, distribute, sell, modify,
9 * merge, give away, or sublicence.
10 *
11 * This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
12 * the utmost extent permitted by applicable law, neither express nor
13 * implied; without malicious intent or gross negligence. In no event
14 * may a licensor, author or contributor be held liable for indirect,
15 * direct, other damage, loss, or other issues arising in any way out
16 * of dealing in the work, even if advised of the possibility of such
17 * damage or existence of a defect, except proven that it results out
18 * of said person's immediate fault when using the work as intended.
19 */
20
21 #define _ANSI_LIBRARY
22 #include <ctype.h>
23 #include <stdio.h>
24
25 __RCSID("$MirOS: src/lib/libc/gen/isctype.c,v 1.11 2009/11/09 21:30:48 tg Exp $");
26
27 #undef isalnum
28 #undef isalpha
29 #undef isascii
30 #undef isbinry
31 #undef isblank
32 #undef iscntrl
33 #undef isdigit
34 #undef isgraph
35 #undef islower
36 #undef isprint
37 #undef ispunct
38 #undef isspace
39 #undef istitle
40 #undef isupper
41 #undef isxdigit
42 #undef toascii
43 #undef tolower
44 #undef totitle
45 #undef toupper
46
47 #define __CTYPE_IMPL2(t) \
48 int is ## t (int c) \
49 { \
50 return __CTYPE_IMPL(c,t); \
51 }
52
53 __CTYPE_IMPL2(alnum)
__CTYPE_IMPL2(alpha)54 __CTYPE_IMPL2(alpha)
55 __CTYPE_IMPL2(blank)
56 __CTYPE_IMPL2(cntrl)
57 __CTYPE_IMPL2(digit)
58 __CTYPE_IMPL2(graph)
59 __CTYPE_IMPL2(lower)
60 __CTYPE_IMPL2(print)
61 __CTYPE_IMPL2(punct)
62 __CTYPE_IMPL2(space)
63 __CTYPE_IMPL2(upper)
64 __CTYPE_IMPL2(xdigit)
65
66 int
67 istitle(int c __unused)
68 {
69 return (0);
70 }
71
72 int
isascii(int c)73 isascii(int c)
74 {
75 return ((unsigned int)c < 0x80);
76 }
77
78 int
toascii(int c)79 toascii(int c)
80 {
81 return (c & 0x7F);
82 }
83
84 int
tolower(int c)85 tolower(int c)
86 {
87 return (((c) >= 'A') && ((c) <= 'Z') ? (c) - 'A' + 'a' : (c));
88 }
89
90 int
totitle(int c)91 totitle(int c)
92 {
93 return (((c) >= 'a') && ((c) <= 'z') ? (c) - 'a' + 'A' : (c));
94 }
95
96 int
toupper(int c)97 toupper(int c)
98 {
99 return (((c) >= 'a') && ((c) <= 'z') ? (c) - 'a' + 'A' : (c));
100 }
101
102 int
isbinry(int ch)103 isbinry(int ch)
104 {
105 uint8_t c = ch;
106 return ((c == 0x00) || (c == 0xC0) ||
107 (c == 0xC1) || (c > 0xEF));
108 }
109