]>
git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - ubuntu/vbox/include/iprt/ctype.h
2 * IPRT - Simple character type classiciation and conversion.
6 * Copyright (C) 2006-2016 Oracle Corporation
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
26 #ifndef ___iprt_ctype_h
27 #define ___iprt_ctype_h
29 #include <iprt/types.h>
31 /** @name C locale predicates and conversions.
33 * For most practical purposes, this can safely be used when parsing UTF-8
34 * strings. Just keep in mind that we only deal with the first 127 chars and
35 * that full correctness is only archived using the non-existing RTLocIs* API.
37 * @remarks Use the marcros, not the inlined functions.
39 * @remarks ASSUMES the source code includes the basic ASCII chars. This is a
40 * general IPRT assumption.
42 #define RT_C_IS_BLANK(ch) RTLocCIsBlank((ch))
43 #define RT_C_IS_ALNUM(ch) RTLocCIsAlNum((ch))
44 #define RT_C_IS_ALPHA(ch) RTLocCIsAlpha((ch))
45 #define RT_C_IS_CNTRL(ch) RTLocCIsCntrl((ch))
46 #define RT_C_IS_DIGIT(ch) RTLocCIsDigit((ch))
47 #define RT_C_IS_LOWER(ch) RTLocCIsLower((ch))
48 #define RT_C_IS_GRAPH(ch) RTLocCIsGraph((ch))
49 #define RT_C_IS_ODIGIT(ch) RTLocCIsODigit((ch))
50 #define RT_C_IS_PRINT(ch) RTLocCIsPrint((ch))
51 #define RT_C_IS_PUNCT(ch) RTLocCIsPunct((ch))
52 #define RT_C_IS_SPACE(ch) RTLocCIsSpace((ch))
53 #define RT_C_IS_UPPER(ch) RTLocCIsUpper((ch))
54 #define RT_C_IS_XDIGIT(ch) RTLocCIsXDigit((ch))
56 #define RT_C_TO_LOWER(ch) RTLocCToLower((ch))
57 #define RT_C_TO_UPPER(ch) RTLocCToUpper((ch))
60 * Checks for a blank character.
62 * @returns true / false.
63 * @param ch The character to test.
65 DECL_FORCE_INLINE(bool) RTLocCIsBlank(int ch
)
67 return ch
== 0x20 /* space */
68 || ch
== 0x09; /* horizontal tab */
72 * Checks for a control character.
74 * @returns true / false.
75 * @param ch The character to test.
77 * @note Will return true of ch is '\0'!
79 DECL_FORCE_INLINE(bool) RTLocCIsCntrl(int ch
)
81 return (unsigned)ch
< 32U /* 0..2f */
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 (unsigned)ch
- 0x30 < 10U; /* 30..39 */
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 (unsigned)ch
- 0x61U
< 26U; /* 61..7a */
108 * Checks for an octal digit.
110 * @returns true / false.
111 * @param ch The character to test.
113 DECL_FORCE_INLINE(bool) RTLocCIsODigit(int ch
)
115 return (unsigned)ch
- 0x30 < 8U; /* 30..37 */
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 return (unsigned)ch
- 0x20U
< 95U; /* 20..7e */
130 * Checks for punctuation (?).
132 * @returns true / false.
133 * @param ch The character to test.
135 DECL_FORCE_INLINE(bool) RTLocCIsPunct(int ch
)
137 return (unsigned)ch
- 0x21U
< 15U /* 21..2f */
138 || (unsigned)ch
- 0x2aU
< 6U /* 2a..2f */
139 || (unsigned)ch
- 0x3aU
< 7U /* 3a..40 */
140 || (unsigned)ch
- 0x5bU
< 6U /* 5a..60 */
141 || (unsigned)ch
- 0x7bU
< 4U /* 7b..7e */;
145 * Checks for a white-space character.
147 * @returns true / false.
148 * @param ch The character to test.
150 DECL_FORCE_INLINE(bool) RTLocCIsSpace(int ch
)
152 return ch
== 0x20 /* 20 (space) */
153 || (unsigned)ch
- 0x09U
< 5U; /* 09..0d */
157 * Checks for an upper case character.
159 * @returns true / false.
160 * @param ch The character to test.
162 DECL_FORCE_INLINE(bool) RTLocCIsUpper(int ch
)
164 return (unsigned)ch
- 0x41 < 26U; /* 41..5a */
168 * Checks for a hexadecimal digit.
170 * @returns true / false.
171 * @param ch The character to test.
173 DECL_FORCE_INLINE(bool) RTLocCIsXDigit(int ch
)
175 return (unsigned)ch
- 0x30 < 10U /* 30..39 (0-9) */
176 || (unsigned)ch
- 0x41 < 6 /* 41..46 (A-F) */
177 || (unsigned)ch
- 0x61 < 6; /* 61..66 (a-f) */
181 * Checks for an alphabetic character.
183 * @returns true / false.
184 * @param ch The character to test.
186 DECL_FORCE_INLINE(bool) RTLocCIsAlpha(int ch
)
188 return RTLocCIsLower(ch
) || RTLocCIsUpper(ch
);
192 * Checks for an alphanumerical character.
194 * @returns true / false.
195 * @param ch The character to test.
197 DECL_FORCE_INLINE(bool) RTLocCIsAlNum(int ch
)
199 return RTLocCIsDigit(ch
) || RTLocCIsAlpha(ch
);
203 * Checks for a printable character whitespace excluded.
205 * @returns true / false.
206 * @param ch The character to test.
208 DECL_FORCE_INLINE(bool) RTLocCIsGraph(int ch
)
210 return RTLocCIsPrint(ch
) && !RTLocCIsBlank(ch
);
215 * Converts the character to lower case if applictable.
217 * @returns lower cased character or ch.
218 * @param ch The character to test.
220 DECL_FORCE_INLINE(int) RTLocCToLower(int ch
)
222 return RTLocCIsUpper(ch
) ? (ch
) + 0x20 : (ch
);
226 * Converts the character to upper case if applictable.
228 * @returns upper cased character or ch.
229 * @param ch The character to test.
231 DECL_FORCE_INLINE(int) RTLocCToUpper(int ch
)
233 return RTLocCIsLower(ch
) ? (ch
) - 0x20 : (ch
);