1/** @file
2  Character classification function implementations for <ctype.h>.
3
4  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
5  This program and the accompanying materials are licensed and made available under
6  the terms and conditions of the BSD License that accompanies this distribution.
7  The full text of the license may be found at
8  http://opensource.org/licenses/bsd-license.
9
10  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12**/
13#include  <LibConfig.h>
14
15#define NO_CTYPE_MACROS            // So that we don't define the classification macros
16#include  <ctype.h>
17
18/** Internal worker function for character classification.
19
20    Determines if a character is a member of a set of character classes.
21
22    @param[in]    _c      The character to be tested.
23    @param[in]    mask    A bitmapped specification of the character classes to
24                          test the character against.  These bits are defined
25                          in _ctype.h.
26
27    @retval   0         The character, _c, is NOT a member of the character classes specified by mask.
28    @retval   nonZero   The character, _c, IS a member of a specified character class.
29**/
30int
31__isCClass(
32  IN  int _c,
33  unsigned int mask
34  )
35{
36  return ((_c < 0 || _c > 127) ? 0 : (_cClass[_c] & mask));
37}
38
39/** The isalnum function tests for any character for which isalpha or isdigit
40    is true.
41
42    @param[in]    c   The character to be tested.
43
44    @return   Returns nonzero (true) if and only if the value of the parameter c
45              can be classified as specified in the description of the function.
46**/
47int
48isalnum(
49  IN  int c
50  )
51{
52  return (__isCClass( c, (_CD | _CU | _CL | _XA)));
53}
54
55/** The isalpha function tests for any character for which isupper or islower
56    is true, or any character that is one of a locale-specific set of
57    alphabetic characters for which none of iscntrl, isdigit, ispunct, or
58    isspace is true. In the "C" locale, isalpha returns true only for the
59    characters for which isupper or islower is true.
60
61    @param[in]    c   The character to be tested.
62
63    @return   Returns nonzero (true) if and only if the value of the parameter c
64              can be classified as specified in the description of the function.
65**/
66int
67isalpha(
68  IN  int c
69  )
70{
71  return (__isCClass( c, (_CU | _CL | _XA)));
72}
73
74/** The iscntrl function tests for any control character.
75
76    @param[in]    c   The character to be tested.
77
78    @return   Returns nonzero (true) if and only if the value of the parameter c
79              can be classified as specified in the description of the function.
80**/
81int
82iscntrl(
83  IN  int c
84  )
85{
86  return (__isCClass( c, (_CC)));
87}
88
89/** The isdigit function tests for any decimal-digit character.
90
91    @param[in]    c   The character to be tested.
92
93    @return   Returns nonzero (true) if and only if the value of the parameter c
94              can be classified as specified in the description of the function.
95**/
96int
97isdigit(
98  IN  int c
99  )
100{
101  return (__isCClass( c, (_CD)));
102}
103
104/** The isgraph function tests for any printing character except space (' ').
105
106    @param[in]    c   The character to be tested.
107
108    @return   Returns nonzero (true) if and only if the value of the parameter c
109              can be classified as specified in the description of the function.
110**/
111int
112isgraph(
113  IN  int c
114  )
115{
116  return (__isCClass( c, (_CG)));
117}
118
119/** The islower function tests for any character that is a lowercase letter or
120    is one of a locale-specific set of characters for which none of iscntrl,
121    isdigit, ispunct, or isspace is true.  In the "C" locale, islower returns
122    true only for the lowercase letters.
123
124    @param[in]    c   The character to be tested.
125
126    @return   Returns nonzero (true) if and only if the value of the parameter c
127              can be classified as specified in the description of the function.
128**/
129int
130islower(
131  IN  int c
132  )
133{
134  return (__isCClass( c, (_CL)));
135}
136
137/** The isprint function tests for any printing character including space (' ').
138
139    @param[in]    c   The character to be tested.
140
141    @return   Returns nonzero (true) if and only if the value of the parameter c
142              can be classified as specified in the description of the function.
143**/
144int
145isprint(
146  IN  int c
147  )
148{
149  return (__isCClass( c, (_CS | _CG)));
150}
151
152/** The ispunct function tests for any printing character that is one of a
153    locale-specific set of punctuation characters for which neither isspace nor
154    isalnum is true. In the "C" locale, ispunct returns true for every printing
155    character for which neither isspace nor isalnum is true.
156
157    @param[in]    c   The character to be tested.
158
159    @return   Returns nonzero (true) if and only if the value of the parameter c
160              can be classified as specified in the description of the function.
161**/
162int
163ispunct(
164  IN  int c
165  )
166{
167  return (__isCClass( c, (_CP)));
168}
169
170/** The isspace function tests for any character that is a standard white-space
171    character or is one of a locale-specific set of characters for which
172    isalnum is false. The standard white-space characters are the following:
173    space (' '), form feed ('\f'), new-line ('\n'), carriage return ('\r'),
174    horizontal tab ('\t'), and vertical tab ('\v'). In the "C" locale, isspace
175    returns true only for the standard white-space characters.
176
177    @param[in]    c   The character to be tested.
178
179    @return   Returns nonzero (true) if and only if the value of the parameter c
180              can be classified as specified in the description of the function.
181**/
182int
183isspace(
184  IN  int c
185  )
186{
187  return (__isCClass( c, (_CW)));
188}
189
190/** The isupper function tests for any character that is an uppercase letter or
191    is one of a locale-specific set of characters for which none of iscntrl,
192    isdigit, ispunct, or isspace is true. In the "C" locale, isupper returns
193    true only for the uppercase letters.
194
195    @param[in]    c   The character to be tested.
196
197    @return   Returns nonzero (true) if and only if the value of the parameter c
198              can be classified as specified in the description of the function.
199**/
200int
201isupper(
202  IN  int c
203  )
204{
205  return (__isCClass( c, (_CU)));
206}
207
208/** The isxdigit function tests for any hexadecimal-digit character.
209
210    @param[in]    c   The character to be tested.
211
212    @return   Returns nonzero (true) if and only if the value of the parameter c
213              can be classified as specified in the description of the function.
214**/
215int
216isxdigit(
217  IN  int c
218  )
219{
220  return (__isCClass( c, (_CD | _CX)));
221}
222
223/** The isblank function tests that a character is a white-space character that results
224    in a number of space (' ') characters being sent to the output device.  In the C locale
225    this is either ' ' or '\t'.
226
227    @param[in]    c   The character to be tested.
228
229    @return   Returns nonzero (true) if and only if the value of the parameter c
230              can be classified as specified in the description of the function.
231**/
232int
233isblank(
234  IN  int c
235  )
236{
237  return (__isCClass( c, (_CB)));
238}
239
240/** The isascii function tests that a character is one of the 128 7-bit ASCII characters.
241
242  @param[in]  c   The character to test.
243
244  @return     Returns nonzero (true) if c is a valid ASCII character.  Otherwize,
245              zero (false) is returned.
246**/
247int
248isascii(
249  IN  int c
250  )
251{
252  return ((c >= 0) && (c < 128));
253}
254
255/** Test whether a character is one of the characters used as a separator
256    between directory elements in a path.
257
258    Characters are '/', '\\'
259
260    This non-standard function is unique to this implementation.
261
262    @param[in]    c   The character to be tested.
263
264    @return   Returns nonzero (true) if and only if the value of the parameter c
265              can be classified as specified in the description of the function.
266**/
267int
268isDirSep(int c)
269{
270  return (__isCClass( c, (_C0)));
271}
272