30
30
#ifndef ___iprt_ctype_h
31
31
#define ___iprt_ctype_h
36
# if defined(_MSC_VER) && !defined(isblank)
38
# define isblank(ch) ( (ch) == ' ' || (ch) == '\t' )
42
/** @name C locale macros.
44
* @remarks The macros may reference the character more than once.
45
* @remarks Assumes a charset similar to ASCII.
46
* @remarks Can probably be optimized if someone has time.
33
#include <iprt/types.h>
35
/** @name C locale predicates and conversions.
37
* For most practical purposes, this can safely be used when parsing UTF-8
38
* strings. Just keep in mind that we only deal with the first 127 chars and
39
* that full correctness is only archived using the non-existing RTLocIs* API.
41
* @remarks Use the marcros, not the inlined functions.
43
* @remarks ASSUMES the source code includes the basic ASCII chars. This is a
44
* general IPRT assumption.
48
#define RT_C_IS_BLANK(ch) ( (ch) == ' ' || (ch) == '\t' )
49
#define RT_C_IS_ALNUM(ch) ( RT_C_IS_DIGIT(ch) || RT_C_IS_ALPHA(ch) )
50
#define RT_C_IS_ALPHA(ch) ( RT_C_IS_LOWER(ch) || RT_C_IS_UPPER(ch) )
51
#define RT_C_IS_CNTRL(ch) ( (ch) >= 0 && (ch) < 32 )
52
#define RT_C_IS_DIGIT(ch) ( (ch) >= '0' && (ch) <= '9' )
53
#define RT_C_IS_LOWER(ch) ( (ch) >= 'a' && (ch) <= 'z' )
54
#define RT_C_IS_GRAPH(ch) ( RT_C_IS_PRINT(ch) && !RT_C_IS_BLANK(ch) )
55
#define RT_C_IS_ODIGIT(ch) ( (ch) >= '0' && (ch) <= '7' )
56
#define RT_C_IS_PRINT(ch) ( (ch) >= 32 && (ch) < 127 ) /**< @todo possibly incorrect */
57
#define RT_C_IS_PUNCT(ch) ( (ch) == ',' || (ch) == '.' || (ch) == ':' || (ch) == ';' || (ch) == '!' || (ch) == '?' ) /**< @todo possibly incorrect */
58
#define RT_C_IS_SPACE(ch) ( (ch) == ' ' || (ch) == '\t' || (ch) == '\n' || (ch) == '\r' || (ch) == '\f' || (ch) == '\v' )
59
#define RT_C_IS_UPPER(ch) ( (ch) >= 'A' && (ch) <= 'Z' )
60
#define RT_C_IS_XDIGIT(ch) ( RT_C_IS_DIGIT(ch) || ((ch) >= 'a' && (ch) <= 'f') || ((ch) >= 'A' && (ch) <= 'F') )
62
#define RT_C_TO_LOWER(ch) ( RT_C_IS_UPPER(ch) ? (ch) + ('a' - 'A') : (ch) )
63
#define RT_C_TO_UPPER(ch) ( RT_C_IS_LOWER(ch) ? (ch) - ('a' - 'A') : (ch) )
46
#define RT_C_IS_BLANK(ch) RTLocCIsBlank((ch))
47
#define RT_C_IS_ALNUM(ch) RTLocCIsAlNum((ch))
48
#define RT_C_IS_ALPHA(ch) RTLocCIsAlpha((ch))
49
#define RT_C_IS_CNTRL(ch) RTLocCIsCntrl((ch))
50
#define RT_C_IS_DIGIT(ch) RTLocCIsDigit((ch))
51
#define RT_C_IS_LOWER(ch) RTLocCIsLower((ch))
52
#define RT_C_IS_GRAPH(ch) RTLocCIsGraph((ch))
53
#define RT_C_IS_ODIGIT(ch) RTLocCIsODigit((ch))
54
#define RT_C_IS_PRINT(ch) RTLocCIsPrint((ch))
55
#define RT_C_IS_PUNCT(ch) RTLocCIsPunct((ch))
56
#define RT_C_IS_SPACE(ch) RTLocCIsSpace((ch))
57
#define RT_C_IS_UPPER(ch) RTLocCIsUpper((ch))
58
#define RT_C_IS_XDIGIT(ch) RTLocCIsXDigit((ch))
60
#define RT_C_TO_LOWER(ch) RTLocCToLower((ch))
61
#define RT_C_TO_UPPER(ch) RTLocCToUpper((ch))
64
* Checks for a blank character.
66
* @returns true / false.
67
* @param ch The character to test.
69
DECL_FORCE_INLINE(bool) RTLocCIsBlank(int ch)
71
return ch == ' ' || ch == '\t';
75
* Checks for a control character.
77
* @returns true / false.
78
* @param ch The character to test.
80
DECL_FORCE_INLINE(bool) RTLocCIsCntrl(int ch)
82
return (ch) >= 0 && (ch) < 32;
86
* Checks for a decimal digit.
88
* @returns true / false.
89
* @param ch The character to test.
91
DECL_FORCE_INLINE(bool) RTLocCIsDigit(int ch)
93
return (ch) >= '0' && (ch) <= '9';
97
* Checks for a lower case character.
99
* @returns true / false.
100
* @param ch The character to test.
102
DECL_FORCE_INLINE(bool) RTLocCIsLower(int ch)
104
return (ch) >= 'a' && (ch) <= 'z';
108
* Checks for a octal digit.
110
* @returns true / false.
111
* @param ch The character to test.
113
DECL_FORCE_INLINE(bool) RTLocCIsODigit(int ch)
115
return (ch) >= '0' && (ch) <= '7';
119
* Checks for a printable character (whitespace included).
121
* @returns true / false.
122
* @param ch The character to test.
124
DECL_FORCE_INLINE(bool) RTLocCIsPrint(int ch)
126
/** @todo quite possibly incorrect */
127
return (ch) >= 32 && (ch) < 127;
131
* Checks for punctuation (?).
133
* @returns true / false.
134
* @param ch The character to test.
136
DECL_FORCE_INLINE(bool) RTLocCIsPunct(int ch)
138
/** @todo possibly incorrect */
139
return (ch) == ',' || (ch) == '.' || (ch) == ':' || (ch) == ';' || (ch) == '!' || (ch) == '?';
143
* Checks for a white-space character.
145
* @returns true / false.
146
* @param ch The character to test.
148
DECL_FORCE_INLINE(bool) RTLocCIsSpace(int ch)
150
return (ch) == ' ' || ((ch) >= '\t' && (ch) <= '\f');
154
* Checks for an upper case character.
156
* @returns true / false.
157
* @param ch The character to test.
159
DECL_FORCE_INLINE(bool) RTLocCIsUpper(int ch)
161
return (ch) >= 'A' && (ch) <= 'Z';
165
* Checks for a hexadecimal digit.
167
* @returns true / false.
168
* @param ch The character to test.
170
DECL_FORCE_INLINE(bool) RTLocCIsXDigit(int ch)
172
return RTLocCIsDigit(ch) || ((ch) >= 'a' && (ch) <= 'f') || ((ch) >= 'A' && (ch) <= 'F');
176
* Checks for an alphabetic character.
178
* @returns true / false.
179
* @param ch The character to test.
181
DECL_FORCE_INLINE(bool) RTLocCIsAlpha(int ch)
183
return RTLocCIsLower(ch) || RTLocCIsUpper(ch);
187
* Checks for an alphanumerical character.
189
* @returns true / false.
190
* @param ch The character to test.
192
DECL_FORCE_INLINE(bool) RTLocCIsAlNum(int ch)
194
return RTLocCIsDigit(ch) || RTLocCIsAlpha(ch);
198
* Checks for a printable character whitespace excluded.
200
* @returns true / false.
201
* @param ch The character to test.
203
DECL_FORCE_INLINE(bool) RTLocCIsGraph(int ch)
205
return RTLocCIsPrint(ch) && !RTLocCIsBlank(ch);
210
* Converts the character to lower case if applictable.
212
* @returns lower cased character or ch.
213
* @param ch The character to test.
215
DECL_FORCE_INLINE(int) RTLocCToLower(int ch)
217
return RTLocCIsUpper(ch) ? (ch) + ('a' - 'A') : (ch);
221
* Converts the character to upper case if applictable.
223
* @returns upper cased character or ch.
224
* @param ch The character to test.
226
DECL_FORCE_INLINE(int) RTLocCToUpper(int ch)
228
return RTLocCIsLower(ch) ? (ch) - ('a' - 'A') : (ch);