dpkg 1.21.11
c-ctype.h
Go to the documentation of this file.
1/*
2 * libdpkg - Debian packaging suite library routines
3 * c-ctype.h - 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#ifndef LIBDPKG_C_CTYPE_H
22#define LIBDPKG_C_CTYPE_H
23
24#include <stdbool.h>
25
26#include <dpkg/macros.h>
27
29
30#define C_CTYPE_BIT(bit) (1 << (bit))
31
39
42};
43
44bool
45c_isbits(int c, enum c_ctype_bit bits);
46
50static inline bool
51c_isblank(int c)
52{
53 return c_isbits(c, C_CTYPE_BLANK);
54}
55
59static inline bool
60c_iswhite(int c)
61{
62 return c_isbits(c, C_CTYPE_WHITE);
63}
64
68static inline bool
69c_isspace(int c)
70{
71 return c_isbits(c, C_CTYPE_SPACE);
72}
73
77static inline bool
78c_isdigit(int c)
79{
80 return c_isbits(c, C_CTYPE_DIGIT);
81}
82
86static inline bool
87c_isupper(int c)
88{
89 return c_isbits(c, C_CTYPE_UPPER);
90}
91
95static inline bool
96c_islower(int c)
97{
98 return c_isbits(c, C_CTYPE_LOWER);
99}
100
104static inline bool
105c_isalpha(int c)
106{
107 return c_isbits(c, C_CTYPE_ALPHA);
108}
109
113static inline bool
114c_isalnum(int c)
115{
116 return c_isbits(c, C_CTYPE_ALNUM);
117}
118
122static inline int
123c_tolower(int c)
124{
125 return (c_isupper(c) ?
126 (DPKG_STATIC_CAST(unsigned char, c) & ~0x20) | 0x20 : c);
127}
128
130
131#endif
c_ctype_bit
Definition: c-ctype.h:32
@ C_CTYPE_ALPHA
Definition: c-ctype.h:40
@ C_CTYPE_WHITE
Definition: c-ctype.h:34
@ C_CTYPE_ALNUM
Definition: c-ctype.h:41
@ C_CTYPE_BLANK
Definition: c-ctype.h:33
@ C_CTYPE_LOWER
Definition: c-ctype.h:37
@ C_CTYPE_SPACE
Definition: c-ctype.h:35
@ C_CTYPE_UPPER
Definition: c-ctype.h:36
@ C_CTYPE_DIGIT
Definition: c-ctype.h:38
bool c_isbits(int c, enum c_ctype_bit bits)
Check if the character is bits ctype.
Definition: c-ctype.c:183
#define C_CTYPE_BIT(bit)
Definition: c-ctype.h:30
#define DPKG_BEGIN_DECLS
Definition: macros.h:86
#define DPKG_END_DECLS
Definition: macros.h:87
#define DPKG_STATIC_CAST(type, expr)
Cast an expression to a given type that works on C or C++.
Definition: macros.h:117