1 /*
2  * libdpkg - Debian packaging suite library routines
3  * c-ctype.c - ASCII C locale-only functions
4  *
5  * Copyright © 2009-2014 Guillem Jover <guillem@debian.org>
6  *
7  * This is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  */
20 
21 #include <config.h>
22 #include <compat.h>
23 
24 #include <dpkg/c-ctype.h>
25 
26 #undef S
27 #define S C_CTYPE_SPACE
28 #undef W
29 #define W C_CTYPE_WHITE
30 #undef B
31 #define B C_CTYPE_BLANK
32 #undef U
33 #define U C_CTYPE_UPPER
34 #undef L
35 #define L C_CTYPE_LOWER
36 #undef D
37 #define D C_CTYPE_DIGIT
38 
39 static unsigned short int c_ctype[256] = {
40 /** 0 **/
41 	/* \0 */ 0,
42 	0,
43 	0,
44 	0,
45 	0,
46 	0,
47 	0,
48 	/* \a */ 0,
49 	/* \b */ 0,
50 	/* \t */ S | W | B,
51 	/* \n */ S | W,
52 	/* \v */ S,
53 	/* \f */ S,
54 	/* \r */ S,
55 	0,
56 	0,
57 /** 16 **/
58 	0,
59 	0,
60 	0,
61 	0,
62 	0,
63 	0,
64 	0,
65 	0,
66 	0,
67 	0,
68 	0,
69 	0,
70 	0,
71 	0,
72 	0,
73 	0,
74 /** 32 **/
75 	/*   */ S | W | B,
76 	/* ! */ 0,
77 	/* " */ 0,
78 	/* # */ 0,
79 	/* $ */ 0,
80 	/* % */ 0,
81 	/* & */ 0,
82 	/* ' */ 0,
83 	/* ( */ 0,
84 	/* ) */ 0,
85 	/* * */ 0,
86 	/* + */ 0,
87 	/* , */ 0,
88 	/* - */ 0,
89 	/* . */ 0,
90 	/* / */ 0,
91 /** 48 **/
92 	/* 0 */ D,
93 	/* 1 */ D,
94 	/* 2 */ D,
95 	/* 3 */ D,
96 	/* 4 */ D,
97 	/* 5 */ D,
98 	/* 6 */ D,
99 	/* 7 */ D,
100 	/* 8 */ D,
101 	/* 9 */ D,
102 	/* : */ 0,
103 	/* ; */ 0,
104 	/* < */ 0,
105 	/* = */ 0,
106 	/* > */ 0,
107 	/* ? */ 0,
108 /* 64 */
109 	/* @ */ 0,
110 	/* A */ U,
111 	/* B */ U,
112 	/* C */ U,
113 	/* D */ U,
114 	/* E */ U,
115 	/* F */ U,
116 	/* G */ U,
117 	/* H */ U,
118 	/* I */ U,
119 	/* J */ U,
120 	/* K */ U,
121 	/* L */ U,
122 	/* M */ U,
123 	/* N */ U,
124 	/* O */ U,
125 /* 80 */
126 	/* P */ U,
127 	/* Q */ U,
128 	/* R */ U,
129 	/* S */ U,
130 	/* T */ U,
131 	/* U */ U,
132 	/* V */ U,
133 	/* W */ U,
134 	/* X */ U,
135 	/* Y */ U,
136 	/* Z */ U,
137 	/* [ */ 0,
138 	/* \ */ 0,
139 	/* ] */ 0,
140 	/* ^ */ 0,
141 	/* _ */ 0,
142 /* 96 */
143 	/* ` */ 0,
144 	/* a */ L,
145 	/* b */ L,
146 	/* c */ L,
147 	/* d */ L,
148 	/* e */ L,
149 	/* f */ L,
150 	/* g */ L,
151 	/* h */ L,
152 	/* i */ L,
153 	/* j */ L,
154 	/* k */ L,
155 	/* l */ L,
156 	/* m */ L,
157 	/* n */ L,
158 	/* o */ L,
159 /* 112 */
160 	/* p */ L,
161 	/* q */ L,
162 	/* r */ L,
163 	/* s */ L,
164 	/* t */ L,
165 	/* u */ L,
166 	/* v */ L,
167 	/* w */ L,
168 	/* x */ L,
169 	/* y */ L,
170 	/* z */ L,
171 	/* { */ 0,
172 	/* | */ 0,
173 	/* } */ 0,
174 	/* ~ */ 0,
175 	0,
176 /* 128 */
177 };
178 
179 /**
180  * Check if the character is bits ctype.
181  */
182 bool
c_isbits(int c,enum c_ctype_bit bits)183 c_isbits(int c, enum c_ctype_bit bits)
184 {
185 	return ((c_ctype[(unsigned char)c] & bits) != 0);
186 }
187