~ubuntu-branches/ubuntu/trusty/virtualbox-ose/trusty

« back to all changes in this revision

Viewing changes to include/iprt/ctype.h

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2009-12-18 16:44:29 UTC
  • mfrom: (0.3.3 upstream) (0.4.6 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091218164429-jd34ccexpv5na11a
Tags: 3.1.2-dfsg-1ubuntu1
* Merge from Debian unstable (LP: #498219), remaining changes:
  - Disable update action
    - debian/patches/u01-disable-update-action.dpatch
  - VirtualBox should go in Accessories, not in System tools (LP: #288590)
    - debian/virtualbox-ose-qt.files/virtualbox-ose.desktop
  - Add Apport hook
    - debian/virtualbox-ose.files/source_virtualbox-ose.py
    - debian/virtualbox-ose.install
  - Add Launchpad integration
    - debian/control
    - debian/lpi-bug.xpm
    - debian/patches/u02-lp-integration.dpatch
* Fixes the following bugs:
  - Kernel module fails to build with Linux >= 2.6.32 (LP: #474625)
  - X.Org drivers need to be rebuilt against X-Server 1.7 (LP: #495935)
  - The *-source packages try to build the kernel modules even though the
    kernel headers aren't available (LP: #473334)
* Replace *-source packages with transitional packages for *-dkms.
* Adapt u01-disable-update-action.dpatch and u02-lp-integration.dpatch for
  new upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/** @file
2
 
 * IPRT - ctype.h wrapper and C locale variants.
 
2
 * IPRT - Simple character type classiciation and conversion.
3
3
 */
4
4
 
5
5
/*
30
30
#ifndef ___iprt_ctype_h
31
31
#define ___iprt_ctype_h
32
32
 
33
 
#ifdef IN_RING3
34
 
# include <ctype.h>
35
 
 
36
 
# if defined(_MSC_VER) && !defined(isblank)
37
 
/* isblank for MSC */
38
 
#  define isblank(ch)  ( (ch) == ' ' || (ch) == '\t' )
39
 
# endif
40
 
#endif /* IN_RING3 */
41
 
 
42
 
/** @name C locale macros.
43
 
 *
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>
 
34
 
 
35
/** @name C locale predicates and conversions.
 
36
 *
 
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.
 
40
 *
 
41
 * @remarks Use the marcros, not the inlined functions.
 
42
 *
 
43
 * @remarks ASSUMES the source code includes the basic ASCII chars. This is a
 
44
 *          general IPRT assumption.
47
45
 * @{ */
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') )
61
 
 
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))
 
59
 
 
60
#define RT_C_TO_LOWER(ch)   RTLocCToLower((ch))
 
61
#define RT_C_TO_UPPER(ch)   RTLocCToUpper((ch))
 
62
 
 
63
/**
 
64
 * Checks for a blank character.
 
65
 *
 
66
 * @returns true / false.
 
67
 * @param   ch      The character to test.
 
68
 */
 
69
DECL_FORCE_INLINE(bool) RTLocCIsBlank(int ch)
 
70
{
 
71
    return ch == ' ' || ch == '\t';
 
72
}
 
73
 
 
74
/**
 
75
 * Checks for a control character.
 
76
 *
 
77
 * @returns true / false.
 
78
 * @param   ch      The character to test.
 
79
 */
 
80
DECL_FORCE_INLINE(bool) RTLocCIsCntrl(int ch)
 
81
{
 
82
    return (ch) >= 0   && (ch) <  32;
 
83
}
 
84
 
 
85
/**
 
86
 * Checks for a decimal digit.
 
87
 *
 
88
 * @returns true / false.
 
89
 * @param   ch      The character to test.
 
90
 */
 
91
DECL_FORCE_INLINE(bool) RTLocCIsDigit(int ch)
 
92
{
 
93
    return (ch) >= '0' && (ch) <= '9';
 
94
}
 
95
 
 
96
/**
 
97
 * Checks for a lower case character.
 
98
 *
 
99
 * @returns true / false.
 
100
 * @param   ch      The character to test.
 
101
 */
 
102
DECL_FORCE_INLINE(bool) RTLocCIsLower(int ch)
 
103
{
 
104
    return (ch) >= 'a' && (ch) <= 'z';
 
105
}
 
106
 
 
107
/**
 
108
 * Checks for a octal digit.
 
109
 *
 
110
 * @returns true / false.
 
111
 * @param   ch      The character to test.
 
112
 */
 
113
DECL_FORCE_INLINE(bool) RTLocCIsODigit(int ch)
 
114
{
 
115
    return (ch) >= '0' && (ch) <= '7';
 
116
}
 
117
 
 
118
/**
 
119
 * Checks for a printable character (whitespace included).
 
120
 *
 
121
 * @returns true / false.
 
122
 * @param   ch      The character to test.
 
123
 */
 
124
DECL_FORCE_INLINE(bool) RTLocCIsPrint(int ch)
 
125
{
 
126
    /** @todo quite possibly incorrect */
 
127
    return (ch) >= 32  && (ch) < 127;
 
128
}
 
129
 
 
130
/**
 
131
 * Checks for punctuation (?).
 
132
 *
 
133
 * @returns true / false.
 
134
 * @param   ch      The character to test.
 
135
 */
 
136
DECL_FORCE_INLINE(bool) RTLocCIsPunct(int ch)
 
137
{
 
138
    /** @todo possibly incorrect */
 
139
    return (ch) == ',' || (ch) == '.'  || (ch) == ':'  || (ch) == ';'  || (ch) == '!'  || (ch) == '?';
 
140
}
 
141
 
 
142
/**
 
143
 * Checks for a white-space character.
 
144
 *
 
145
 * @returns true / false.
 
146
 * @param   ch      The character to test.
 
147
 */
 
148
DECL_FORCE_INLINE(bool) RTLocCIsSpace(int ch)
 
149
{
 
150
    return (ch) == ' ' || ((ch) >= '\t' && (ch) <= '\f');
 
151
}
 
152
 
 
153
/**
 
154
 * Checks for an upper case character.
 
155
 *
 
156
 * @returns true / false.
 
157
 * @param   ch      The character to test.
 
158
 */
 
159
DECL_FORCE_INLINE(bool) RTLocCIsUpper(int ch)
 
160
{
 
161
    return (ch) >= 'A' && (ch) <= 'Z';
 
162
}
 
163
 
 
164
/**
 
165
 * Checks for a hexadecimal digit.
 
166
 *
 
167
 * @returns true / false.
 
168
 * @param   ch      The character to test.
 
169
 */
 
170
DECL_FORCE_INLINE(bool) RTLocCIsXDigit(int ch)
 
171
{
 
172
    return RTLocCIsDigit(ch) || ((ch) >= 'a' && (ch) <= 'f') || ((ch) >= 'A' && (ch) <= 'F');
 
173
}
 
174
 
 
175
/**
 
176
 * Checks for an alphabetic character.
 
177
 *
 
178
 * @returns true / false.
 
179
 * @param   ch      The character to test.
 
180
 */
 
181
DECL_FORCE_INLINE(bool) RTLocCIsAlpha(int ch)
 
182
{
 
183
    return RTLocCIsLower(ch) || RTLocCIsUpper(ch);
 
184
}
 
185
 
 
186
/**
 
187
 * Checks for an alphanumerical character.
 
188
 *
 
189
 * @returns true / false.
 
190
 * @param   ch      The character to test.
 
191
 */
 
192
DECL_FORCE_INLINE(bool) RTLocCIsAlNum(int ch)
 
193
{
 
194
    return RTLocCIsDigit(ch) || RTLocCIsAlpha(ch);
 
195
}
 
196
 
 
197
/**
 
198
 * Checks for a printable character whitespace excluded.
 
199
 *
 
200
 * @returns true / false.
 
201
 * @param   ch      The character to test.
 
202
 */
 
203
DECL_FORCE_INLINE(bool) RTLocCIsGraph(int ch)
 
204
{
 
205
    return RTLocCIsPrint(ch) && !RTLocCIsBlank(ch);
 
206
}
 
207
 
 
208
 
 
209
/**
 
210
 * Converts the character to lower case if applictable.
 
211
 *
 
212
 * @returns lower cased character or ch.
 
213
 * @param   ch      The character to test.
 
214
 */
 
215
DECL_FORCE_INLINE(int) RTLocCToLower(int ch)
 
216
{
 
217
    return RTLocCIsUpper(ch) ? (ch) + ('a' - 'A') : (ch);
 
218
}
 
219
 
 
220
/**
 
221
 * Converts the character to upper case if applictable.
 
222
 *
 
223
 * @returns upper cased character or ch.
 
224
 * @param   ch      The character to test.
 
225
 */
 
226
DECL_FORCE_INLINE(int) RTLocCToUpper(int ch)
 
227
{
 
228
    return RTLocCIsLower(ch) ? (ch) - ('a' - 'A') : (ch);
 
229
}
 
230
 
 
231
 
64
232
/** @} */
65
233
 
66
234
#endif