Debian Codegraph @

Xpjproject/pjlib/include/pj/ctype.h

raw symbols SCIP
1 /*
2 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
3 * Copyright (C) 2003-2008 Benny Prijono <[email protected]>
4 *
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 2 of the License, or
8 * (at your option) any later version.
9 *
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.
14 *
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
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 #ifndef __PJ_CTYPE_H__
20 #define __PJ_CTYPE_H__
21
22 /**
23 * @file ctype.h
24 * @brief C type helper macros.
25 */
26
27 #include <pj/types.h>
28 #include <pj/compat/ctype.h>
29
30 PJ_BEGIN_DECL
31
32 /**
33 * @defgroup pj_ctype ctype - Character Type
34 * @ingroup PJ_MISC
35 * @{
36 *
37 * This module contains several inline functions/macros for testing or
38 * manipulating character types. It is provided in PJLIB because PJLIB
39 * must not depend to LIBC.
40 */
41
42 /**
43 * Returns a non-zero value if either isalpha or isdigit is true for c.
44 * @param c The integer character to test.
45 * @return Non-zero value if either isalpha or isdigit is true for c.
46 */
47 PJ_INLINE(int) pj_isalnum(unsigned char c) { return isalnum(c); }
48
49 /**
50 * Returns a non-zero value if c is a particular representation of an
51 * alphabetic character.
52 * @param c The integer character to test.
53 * @return Non-zero value if c is a particular representation of an
54 * alphabetic character.
55 */
56 PJ_INLINE(int) pj_isalpha(unsigned char c) { return isalpha(c); }
57
58 /**
59 * Returns a non-zero value if c is a particular representation of an
60 * ASCII character.
61 * @param c The integer character to test.
62 * @return Non-zero value if c is a particular representation of
63 * an ASCII character.
64 */
65 PJ_INLINE(int) pj_isascii(unsigned char c) { return c<128; }
66
67 /**
68 * Returns a non-zero value if c is a particular representation of
69 * a decimal-digit character.
70 * @param c The integer character to test.
71 * @return Non-zero value if c is a particular representation of
72 * a decimal-digit character.
73 */
74 PJ_INLINE(int) pj_isdigit(unsigned char c) { return isdigit(c); }
75
76 /**
77 * Returns a non-zero value if c is a particular representation of
78 * a space character (0x09 - 0x0D or 0x20).
79 * @param c The integer character to test.
80 * @return Non-zero value if c is a particular representation of
81 * a space character (0x09 - 0x0D or 0x20).
82 */
83 PJ_INLINE(int) pj_isspace(unsigned char c) { return isspace(c); }
84
85 /**
86 * Returns a non-zero value if c is a particular representation of
87 * a lowercase character.
88 * @param c The integer character to test.
89 * @return Non-zero value if c is a particular representation of
90 * a lowercase character.
91 */
92 PJ_INLINE(int) pj_islower(unsigned char c) { return islower(c); }
93
94
95 /**
96 * Returns a non-zero value if c is a particular representation of
97 * a uppercase character.
98 * @param c The integer character to test.
99 * @return Non-zero value if c is a particular representation of
100 * a uppercase character.
101 */
102 PJ_INLINE(int) pj_isupper(unsigned char c) { return isupper(c); }
103
104 /**
105 * Returns a non-zero value if c is a either a space (' ') or horizontal
106 * tab ('\\t') character.
107 * @param c The integer character to test.
108 * @return Non-zero value if c is a either a space (' ') or horizontal
109 * tab ('\\t') character.
110 */
111 PJ_INLINE(int) pj_isblank(unsigned char c) { return (c==' ' || c=='\t'); }
112
113 /**
114 * Converts character to lowercase.
115 * @param c The integer character to convert.
116 * @return Lowercase character of c.
117 */
118 PJ_INLINE(int) pj_tolower(unsigned char c) { return tolower(c); }
119
120 /**
121 * Converts character to uppercase.
122 * @param c The integer character to convert.
123 * @return Uppercase character of c.
124 */
125 PJ_INLINE(int) pj_toupper(unsigned char c) { return toupper(c); }
126
127 /**
128 * Returns a non-zero value if c is a particular representation of
129 * an hexadecimal digit character.
130 * @param c The integer character to test.
131 * @return Non-zero value if c is a particular representation of
132 * an hexadecimal digit character.
133 */
134 PJ_INLINE(int) pj_isxdigit(unsigned char c){ return isxdigit(c); }
135
136 /**
137 * Array of hex digits, in lowerspace.
138 */
139 /*extern char pj_hex_digits[];*/
140 #define pj_hex_digits "0123456789abcdef"
141
142 /**
143 * Convert a value to hex representation.
144 * @param value Integral value to convert.
145 * @param p Buffer to hold the hex representation, which must be
146 * at least two bytes length.
147 */
148 PJ_INLINE(void) pj_val_to_hex_digit(unsigned value, char *p)
149 {
150 *p++ = pj_hex_digits[ (value & 0xF0) >> 4 ];
151 *p = pj_hex_digits[ (value & 0x0F) ];
152 }
153
154 /**
155 * Convert hex digit c to integral value.
156 * @param c The hex digit character.
157 * @return The integral value between 0 and 15.
158 */
159 PJ_INLINE(unsigned) pj_hex_digit_to_val(unsigned char c)
160 {
161 if (c <= '9')
162 return (c-'0') & 0x0F;
163 else if (c <= 'F')
164 return (c-'A'+10) & 0x0F;
165 else
166 return (c-'a'+10) & 0x0F;
167 }
168
169 /** @} */
170
171 PJ_END_DECL
172
173 #endif /* __PJ_CTYPE_H__ */
174