VirtualBox

source: vbox/trunk/include/iprt/ctype.h@ 28590

Last change on this file since 28590 was 24025, checked in by vboxsync, 15 years ago

iprt/ctype.h: removed disabled code.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.9 KB
Line 
1/** @file
2 * IPRT - Simple character type classiciation and conversion.
3 */
4
5/*
6 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
7 *
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.
15 *
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.
21 *
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.
24 *
25 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
26 * Clara, CA 95054 USA or visit http://www.sun.com if you need
27 * additional information or have any questions.
28 */
29
30#ifndef ___iprt_ctype_h
31#define ___iprt_ctype_h
32
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.
45 * @{ */
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 */
69DECL_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 */
80DECL_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 */
91DECL_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 */
102DECL_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 */
113DECL_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 */
124DECL_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 */
136DECL_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 */
148DECL_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 */
159DECL_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 */
170DECL_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 */
181DECL_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 */
192DECL_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 */
203DECL_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 */
215DECL_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 */
226DECL_FORCE_INLINE(int) RTLocCToUpper(int ch)
227{
228 return RTLocCIsLower(ch) ? (ch) - ('a' - 'A') : (ch);
229}
230
231
232/** @} */
233
234#endif
235
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette