1
/* $Id: ctype.h 3553 2011-05-05 06:14:19Z nanang $ */
3
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
#ifndef __PJ_CTYPE_H__
21
#define __PJ_CTYPE_H__
25
* @brief C type helper macros.
29
#include <pj/compat/ctype.h>
34
* @defgroup pj_ctype ctype - Character Type
38
* This module contains several inline functions/macros for testing or
39
* manipulating character types. It is provided in PJLIB because PJLIB
40
* must not depend to LIBC.
44
* Returns a non-zero value if either isalpha or isdigit is true for c.
45
* @param c The integer character to test.
46
* @return Non-zero value if either isalpha or isdigit is true for c.
48
PJ_INLINE(int) pj_isalnum(unsigned char c) { return isalnum(c); }
51
* Returns a non-zero value if c is a particular representation of an
52
* alphabetic character.
53
* @param c The integer character to test.
54
* @return Non-zero value if c is a particular representation of an
55
* alphabetic character.
57
PJ_INLINE(int) pj_isalpha(unsigned char c) { return isalpha(c); }
60
* Returns a non-zero value if c is a particular representation of an
62
* @param c The integer character to test.
63
* @return Non-zero value if c is a particular representation of
66
PJ_INLINE(int) pj_isascii(unsigned char c) { return c<128; }
69
* Returns a non-zero value if c is a particular representation of
70
* a decimal-digit character.
71
* @param c The integer character to test.
72
* @return Non-zero value if c is a particular representation of
73
* a decimal-digit character.
75
PJ_INLINE(int) pj_isdigit(unsigned char c) { return isdigit(c); }
78
* Returns a non-zero value if c is a particular representation of
79
* a space character (0x09 - 0x0D or 0x20).
80
* @param c The integer character to test.
81
* @return Non-zero value if c is a particular representation of
82
* a space character (0x09 - 0x0D or 0x20).
84
PJ_INLINE(int) pj_isspace(unsigned char c) { return isspace(c); }
87
* Returns a non-zero value if c is a particular representation of
88
* a lowercase character.
89
* @param c The integer character to test.
90
* @return Non-zero value if c is a particular representation of
91
* a lowercase character.
93
PJ_INLINE(int) pj_islower(unsigned char c) { return islower(c); }
97
* Returns a non-zero value if c is a particular representation of
98
* a uppercase character.
99
* @param c The integer character to test.
100
* @return Non-zero value if c is a particular representation of
101
* a uppercase character.
103
PJ_INLINE(int) pj_isupper(unsigned char c) { return isupper(c); }
106
* Returns a non-zero value if c is a either a space (' ') or horizontal
107
* tab ('\\t') character.
108
* @param c The integer character to test.
109
* @return Non-zero value if c is a either a space (' ') or horizontal
110
* tab ('\\t') character.
112
PJ_INLINE(int) pj_isblank(unsigned char c) { return isblank(c); }
115
* Converts character to lowercase.
116
* @param c The integer character to convert.
117
* @return Lowercase character of c.
119
PJ_INLINE(int) pj_tolower(unsigned char c) { return tolower(c); }
122
* Converts character to uppercase.
123
* @param c The integer character to convert.
124
* @return Uppercase character of c.
126
PJ_INLINE(int) pj_toupper(unsigned char c) { return toupper(c); }
129
* Returns a non-zero value if c is a particular representation of
130
* an hexadecimal digit character.
131
* @param c The integer character to test.
132
* @return Non-zero value if c is a particular representation of
133
* an hexadecimal digit character.
135
PJ_INLINE(int) pj_isxdigit(unsigned char c){ return isxdigit(c); }
138
* Array of hex digits, in lowerspace.
140
/*extern char pj_hex_digits[];*/
141
#define pj_hex_digits "0123456789abcdef"
144
* Convert a value to hex representation.
145
* @param value Integral value to convert.
146
* @param p Buffer to hold the hex representation, which must be
147
* at least two bytes length.
149
PJ_INLINE(void) pj_val_to_hex_digit(unsigned value, char *p)
151
*p++ = pj_hex_digits[ (value & 0xF0) >> 4 ];
152
*p = pj_hex_digits[ (value & 0x0F) ];
156
* Convert hex digit c to integral value.
157
* @param c The hex digit character.
158
* @return The integral value between 0 and 15.
160
PJ_INLINE(unsigned) pj_hex_digit_to_val(unsigned char c)
163
return (c-'0') & 0x0F;
165
return (c-'A'+10) & 0x0F;
167
return (c-'a'+10) & 0x0F;
174
#endif /* __PJ_CTYPE_H__ */