Fix MAC password.
[gnutls.git] / gl / c-ctype.c
blobb87e6ef31a47a556442849a89ff26c0e7723ed9a
1 /* Character handling in C locale.
3 Copyright 2000-2003, 2006 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software Foundation,
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19 #include <config.h>
21 /* Specification. */
22 #define NO_C_CTYPE_MACROS
23 #include "c-ctype.h"
25 /* The function isascii is not locale dependent. Its use in EBCDIC is
26 questionable. */
27 bool
28 c_isascii (int c)
30 return (c >= 0x00 && c <= 0x7f);
33 bool
34 c_isalnum (int c)
36 #if C_CTYPE_CONSECUTIVE_DIGITS \
37 && C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE
38 #if C_CTYPE_ASCII
39 return ((c >= '0' && c <= '9')
40 || ((c & ~0x20) >= 'A' && (c & ~0x20) <= 'Z'));
41 #else
42 return ((c >= '0' && c <= '9')
43 || (c >= 'A' && c <= 'Z')
44 || (c >= 'a' && c <= 'z'));
45 #endif
46 #else
47 switch (c)
49 case '0': case '1': case '2': case '3': case '4': case '5':
50 case '6': case '7': case '8': case '9':
51 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
52 case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
53 case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
54 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
55 case 'Y': case 'Z':
56 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
57 case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
58 case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
59 case 's': case 't': case 'u': case 'v': case 'w': case 'x':
60 case 'y': case 'z':
61 return 1;
62 default:
63 return 0;
65 #endif
68 bool
69 c_isalpha (int c)
71 #if C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE
72 #if C_CTYPE_ASCII
73 return ((c & ~0x20) >= 'A' && (c & ~0x20) <= 'Z');
74 #else
75 return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'));
76 #endif
77 #else
78 switch (c)
80 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
81 case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
82 case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
83 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
84 case 'Y': case 'Z':
85 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
86 case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
87 case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
88 case 's': case 't': case 'u': case 'v': case 'w': case 'x':
89 case 'y': case 'z':
90 return 1;
91 default:
92 return 0;
94 #endif
97 bool
98 c_isblank (int c)
100 return (c == ' ' || c == '\t');
103 bool
104 c_iscntrl (int c)
106 #if C_CTYPE_ASCII
107 return ((c & ~0x1f) == 0 || c == 0x7f);
108 #else
109 switch (c)
111 case ' ': case '!': case '"': case '#': case '$': case '%':
112 case '&': case '\'': case '(': case ')': case '*': case '+':
113 case ',': case '-': case '.': case '/':
114 case '0': case '1': case '2': case '3': case '4': case '5':
115 case '6': case '7': case '8': case '9':
116 case ':': case ';': case '<': case '=': case '>': case '?':
117 case '@':
118 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
119 case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
120 case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
121 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
122 case 'Y': case 'Z':
123 case '[': case '\\': case ']': case '^': case '_': case '`':
124 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
125 case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
126 case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
127 case 's': case 't': case 'u': case 'v': case 'w': case 'x':
128 case 'y': case 'z':
129 case '{': case '|': case '}': case '~':
130 return 0;
131 default:
132 return 1;
134 #endif
137 bool
138 c_isdigit (int c)
140 #if C_CTYPE_CONSECUTIVE_DIGITS
141 return (c >= '0' && c <= '9');
142 #else
143 switch (c)
145 case '0': case '1': case '2': case '3': case '4': case '5':
146 case '6': case '7': case '8': case '9':
147 return 1;
148 default:
149 return 0;
151 #endif
154 bool
155 c_islower (int c)
157 #if C_CTYPE_CONSECUTIVE_LOWERCASE
158 return (c >= 'a' && c <= 'z');
159 #else
160 switch (c)
162 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
163 case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
164 case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
165 case 's': case 't': case 'u': case 'v': case 'w': case 'x':
166 case 'y': case 'z':
167 return 1;
168 default:
169 return 0;
171 #endif
174 bool
175 c_isgraph (int c)
177 #if C_CTYPE_ASCII
178 return (c >= '!' && c <= '~');
179 #else
180 switch (c)
182 case '!': case '"': case '#': case '$': case '%': case '&':
183 case '\'': case '(': case ')': case '*': case '+': case ',':
184 case '-': case '.': case '/':
185 case '0': case '1': case '2': case '3': case '4': case '5':
186 case '6': case '7': case '8': case '9':
187 case ':': case ';': case '<': case '=': case '>': case '?':
188 case '@':
189 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
190 case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
191 case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
192 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
193 case 'Y': case 'Z':
194 case '[': case '\\': case ']': case '^': case '_': case '`':
195 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
196 case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
197 case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
198 case 's': case 't': case 'u': case 'v': case 'w': case 'x':
199 case 'y': case 'z':
200 case '{': case '|': case '}': case '~':
201 return 1;
202 default:
203 return 0;
205 #endif
208 bool
209 c_isprint (int c)
211 #if C_CTYPE_ASCII
212 return (c >= ' ' && c <= '~');
213 #else
214 switch (c)
216 case ' ': case '!': case '"': case '#': case '$': case '%':
217 case '&': case '\'': case '(': case ')': case '*': case '+':
218 case ',': case '-': case '.': case '/':
219 case '0': case '1': case '2': case '3': case '4': case '5':
220 case '6': case '7': case '8': case '9':
221 case ':': case ';': case '<': case '=': case '>': case '?':
222 case '@':
223 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
224 case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
225 case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
226 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
227 case 'Y': case 'Z':
228 case '[': case '\\': case ']': case '^': case '_': case '`':
229 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
230 case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
231 case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
232 case 's': case 't': case 'u': case 'v': case 'w': case 'x':
233 case 'y': case 'z':
234 case '{': case '|': case '}': case '~':
235 return 1;
236 default:
237 return 0;
239 #endif
242 bool
243 c_ispunct (int c)
245 #if C_CTYPE_ASCII
246 return ((c >= '!' && c <= '~')
247 && !((c >= '0' && c <= '9')
248 || ((c & ~0x20) >= 'A' && (c & ~0x20) <= 'Z')));
249 #else
250 switch (c)
252 case '!': case '"': case '#': case '$': case '%': case '&':
253 case '\'': case '(': case ')': case '*': case '+': case ',':
254 case '-': case '.': case '/':
255 case ':': case ';': case '<': case '=': case '>': case '?':
256 case '@':
257 case '[': case '\\': case ']': case '^': case '_': case '`':
258 case '{': case '|': case '}': case '~':
259 return 1;
260 default:
261 return 0;
263 #endif
266 bool
267 c_isspace (int c)
269 return (c == ' ' || c == '\t'
270 || c == '\n' || c == '\v' || c == '\f' || c == '\r');
273 bool
274 c_isupper (int c)
276 #if C_CTYPE_CONSECUTIVE_UPPERCASE
277 return (c >= 'A' && c <= 'Z');
278 #else
279 switch (c)
281 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
282 case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
283 case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
284 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
285 case 'Y': case 'Z':
286 return 1;
287 default:
288 return 0;
290 #endif
293 bool
294 c_isxdigit (int c)
296 #if C_CTYPE_CONSECUTIVE_DIGITS \
297 && C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE
298 #if C_CTYPE_ASCII
299 return ((c >= '0' && c <= '9')
300 || ((c & ~0x20) >= 'A' && (c & ~0x20) <= 'F'));
301 #else
302 return ((c >= '0' && c <= '9')
303 || (c >= 'A' && c <= 'F')
304 || (c >= 'a' && c <= 'f'));
305 #endif
306 #else
307 switch (c)
309 case '0': case '1': case '2': case '3': case '4': case '5':
310 case '6': case '7': case '8': case '9':
311 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
312 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
313 return 1;
314 default:
315 return 0;
317 #endif
321 c_tolower (int c)
323 #if C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE
324 return (c >= 'A' && c <= 'Z' ? c - 'A' + 'a' : c);
325 #else
326 switch (c)
328 case 'A': return 'a';
329 case 'B': return 'b';
330 case 'C': return 'c';
331 case 'D': return 'd';
332 case 'E': return 'e';
333 case 'F': return 'f';
334 case 'G': return 'g';
335 case 'H': return 'h';
336 case 'I': return 'i';
337 case 'J': return 'j';
338 case 'K': return 'k';
339 case 'L': return 'l';
340 case 'M': return 'm';
341 case 'N': return 'n';
342 case 'O': return 'o';
343 case 'P': return 'p';
344 case 'Q': return 'q';
345 case 'R': return 'r';
346 case 'S': return 's';
347 case 'T': return 't';
348 case 'U': return 'u';
349 case 'V': return 'v';
350 case 'W': return 'w';
351 case 'X': return 'x';
352 case 'Y': return 'y';
353 case 'Z': return 'z';
354 default: return c;
356 #endif
360 c_toupper (int c)
362 #if C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE
363 return (c >= 'a' && c <= 'z' ? c - 'a' + 'A' : c);
364 #else
365 switch (c)
367 case 'a': return 'A';
368 case 'b': return 'B';
369 case 'c': return 'C';
370 case 'd': return 'D';
371 case 'e': return 'E';
372 case 'f': return 'F';
373 case 'g': return 'G';
374 case 'h': return 'H';
375 case 'i': return 'I';
376 case 'j': return 'J';
377 case 'k': return 'K';
378 case 'l': return 'L';
379 case 'm': return 'M';
380 case 'n': return 'N';
381 case 'o': return 'O';
382 case 'p': return 'P';
383 case 'q': return 'Q';
384 case 'r': return 'R';
385 case 's': return 'S';
386 case 't': return 'T';
387 case 'u': return 'U';
388 case 'v': return 'V';
389 case 'w': return 'W';
390 case 'x': return 'X';
391 case 'y': return 'Y';
392 case 'z': return 'Z';
393 default: return c;
395 #endif