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