po: Update German man pages translation
[dpkg.git] / lib / dpkg / c-ctype.h
blobb04fda86b92236c2a5e8b006504823d778efcafb
1 /*
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
24 #include <stdbool.h>
26 #include <dpkg/macros.h>
28 DPKG_BEGIN_DECLS
30 #define C_CTYPE_BIT(bit) (1 << (bit))
32 enum c_ctype_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,
44 bool
45 c_isbits(int c, enum c_ctype_bit bits);
47 /**
48 * Check if the character is [ \t].
50 static inline bool
51 c_isblank(int c)
53 return c_isbits(c, C_CTYPE_BLANK);
56 /**
57 * Check if the character is [ \t\n].
59 static inline bool
60 c_iswhite(int c)
62 return c_isbits(c, C_CTYPE_WHITE);
65 /**
66 * Check if the character is [ \v\t\f\r\n].
68 static inline bool
69 c_isspace(int c)
71 return c_isbits(c, C_CTYPE_SPACE);
74 /**
75 * Check if the character is [0-9].
77 static inline bool
78 c_isdigit(int c)
80 return c_isbits(c, C_CTYPE_DIGIT);
83 /**
84 * Check if the character is [A-Z].
86 static inline bool
87 c_isupper(int c)
89 return c_isbits(c, C_CTYPE_UPPER);
92 /**
93 * Check if the character is [a-z].
95 static inline bool
96 c_islower(int c)
98 return c_isbits(c, C_CTYPE_LOWER);
102 * Check if the character is [a-zA-Z].
104 static inline bool
105 c_isalpha(int c)
107 return c_isbits(c, C_CTYPE_ALPHA);
111 * Check if the character is [a-zA-Z0-9].
113 static inline bool
114 c_isalnum(int c)
116 return c_isbits(c, C_CTYPE_ALNUM);
120 * Maps the character to its lower-case form.
122 static inline int
123 c_tolower(int c)
125 return (c_isupper(c) ?
126 (DPKG_STATIC_CAST(unsigned char, c) & ~0x20) | 0x20 : c);
129 DPKG_END_DECLS
131 #endif