2 * libdpkg - Debian packaging suite library routines
3 * c-ctype.h - ASCII C locale-only functions
5 * Copyright © 2009-2014 Guillem Jover <guillem@debian.org>
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.
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.
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/>.
21 #ifndef LIBDPKG_C_CTYPE_H
22 #define LIBDPKG_C_CTYPE_H
26 #include <dpkg/macros.h>
30 #define C_CTYPE_BIT(bit) (1 << (bit))
33 C_CTYPE_BLANK
= C_CTYPE_BIT(0),
34 C_CTYPE_WHITE
= C_CTYPE_BIT(1),
35 C_CTYPE_SPACE
= C_CTYPE_BIT(2),
36 C_CTYPE_UPPER
= C_CTYPE_BIT(3),
37 C_CTYPE_LOWER
= C_CTYPE_BIT(4),
38 C_CTYPE_DIGIT
= C_CTYPE_BIT(5),
40 C_CTYPE_ALPHA
= C_CTYPE_UPPER
| C_CTYPE_LOWER
,
41 C_CTYPE_ALNUM
= C_CTYPE_ALPHA
| C_CTYPE_DIGIT
,
45 c_isbits(int c
, enum c_ctype_bit bits
);
48 * Check if the character is [ \t].
53 return c_isbits(c
, C_CTYPE_BLANK
);
57 * Check if the character is [ \t\n].
62 return c_isbits(c
, C_CTYPE_WHITE
);
66 * Check if the character is [ \v\t\f\r\n].
71 return c_isbits(c
, C_CTYPE_SPACE
);
75 * Check if the character is [0-9].
80 return c_isbits(c
, C_CTYPE_DIGIT
);
84 * Check if the character is [A-Z].
89 return c_isbits(c
, C_CTYPE_UPPER
);
93 * Check if the character is [a-z].
98 return c_isbits(c
, C_CTYPE_LOWER
);
102 * Check if the character is [a-zA-Z].
107 return c_isbits(c
, C_CTYPE_ALPHA
);
111 * Check if the character is [a-zA-Z0-9].
116 return c_isbits(c
, C_CTYPE_ALNUM
);
120 * Maps the character to its lower-case form.
125 return (c_isupper(c
) ?
126 (DPKG_STATIC_CAST(unsigned char, c
) & ~0x20) | 0x20 : c
);