Mstdlib-1.24.0
m_chr.h
1/* The MIT License (MIT)
2 *
3 * Copyright (c) 2015 Monetra Technologies, LLC.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 * THE SOFTWARE.
22 */
23
24#ifndef __M_CHR_H__
25#define __M_CHR_H__
26
27/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
28
29#include <mstdlib/base/m_defs.h>
30#include <mstdlib/base/m_types.h>
31
32/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
33
34__BEGIN_DECLS
35
36
37M_BEGIN_IGNORE_REDECLARATIONS
38# if M_BLACKLIST_FUNC == 1
39# ifdef isalnum
40# undef isalnum
41# else
42 M_DEPRECATED_FOR(M_chr_isalnum, int isalnum(int c))
43# endif
44
45# ifdef isalpha
46# undef isalpha
47# else
48 M_DEPRECATED_FOR(M_chr_isalpha, int isalpha(int c))
49# endif
50
51# ifdef iscntrl
52# undef iscntrl
53# else
54 M_DEPRECATED_FOR(M_chr_iscntrl, int iscntrl(int c))
55# endif
56
57# ifdef isdigit
58# undef isdigit
59# else
60 M_DEPRECATED_FOR(M_chr_isdigit, int isdigit(int c))
61# endif
62
63# ifdef isgraph
64# undef isgraph
65# else
66 M_DEPRECATED_FOR(M_chr_isgraph, int isgraph(int c))
67# endif
68
69# ifdef islower
70# undef islower
71# else
72 M_DEPRECATED_FOR(M_chr_islower, int islower(int c))
73# endif
74
75# ifdef isprint
76# undef isprint
77# else
78 M_DEPRECATED_FOR(M_chr_isprint, int isprint(int c))
79# endif
80
81# ifdef ispunct
82# undef ispunct
83# else
84 M_DEPRECATED_FOR(M_chr_ispunct, int ispunct(int c))
85# endif
86
87# ifdef isspace
88# undef isspace
89# else
90 M_DEPRECATED_FOR(M_chr_isspace, int isspace(int c))
91# endif
92
93# ifdef isupper
94# undef isupper
95# else
96 M_DEPRECATED_FOR(M_chr_isupper, int isupper(int c))
97# endif
98
99# ifdef isxdigit
100# undef isxdigit
101# else
102 M_DEPRECATED_FOR(M_chr_isxdigit, int isxdigit(int c))
103# endif
104
105# ifdef isascii
106# undef isascii
107# else
108 M_DEPRECATED_FOR(M_chr_isascii, int isascii(int c))
109# endif
110
111# ifdef isblank
112# undef isblank
113# else
114 M_DEPRECATED_FOR(M_chr_isblank, int isblank(int c))
115# endif
116# endif
117M_END_IGNORE_REDECLARATIONS
118
119/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
120
121
122/*! \addtogroup m_chr Character
123 * \ingroup mstdlib_base
124 *
125 * ASCII character checks and conversion.
126 *
127 * Handles checking if a caracter is a certain type. Also handles
128 * converting characters to other representations. Such as to lowercase,
129 * and to uppercase.
130 *
131 * @{
132 */
133
134typedef M_bool (*M_chr_predicate_func)(char c);
135typedef char (*M_chr_map_func)(char);
136
137
138/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
139
140/*! Checks for an alphanumeric character.
141 *
142 * Equivalent regular expression: <tt>[A-Za-z0-9]</tt>.
143 *
144 * \param[in] c The character to check.
145 *
146 * \return True if in character class or false if not.
147 */
148M_API M_bool M_chr_isalnum(char c);
149
150
151/*! Checks for an alphanumeric character, spaces allowed.
152 *
153 * Equivalent regular expression: <tt>[A-Za-z0-9 ]</tt>.
154 *
155 * \param[in] c The character to check.
156 *
157 * \return True if in character class or false if not.
158 */
159M_API M_bool M_chr_isalnumsp(char c);
160
161
162/*! Checks for an alphabetic character.
163 *
164 * Equivalent regular expression: <tt>[A-Za-z]</tt>.
165 *
166 * \param[in] c The character to check.
167 *
168 * \return True if in character class or false if not.
169 */
170M_API M_bool M_chr_isalpha(char c);
171
172
173/*! Checks for an alphabetic character, spaces allowed.
174 *
175 * Equivalent regular expression: <tt>[A-Za-z ]</tt>.
176 *
177 * \param[in] c The character to check.
178 *
179 * \return True if in character class or false if not.
180 */
181M_API M_bool M_chr_isalphasp(char c);
182
183
184/*! Checks for 7-bit ASCII character.
185 *
186 * Equivalent regular expression: <tt>[\\x00-\\x7f]</tt>.
187 *
188 * \param[in] c The character to check.
189 *
190 * \return True if in character class or false if not.
191 */
192M_API M_bool M_chr_isascii(char c);
193
194
195/*! Checks for a blank character.
196 *
197 * Equivalent regular expression: <tt>[ \\t]</tt>
198 *
199 * \param[in] c The character to check.
200 *
201 * \return True if in character class or false if not.
202 */
203M_API M_bool M_chr_isblank(char c);
204
205
206/*! Checks for a control character.
207 *
208 * Equivalent regular expression: <tt>[ \\t]</tt>.
209 *
210 * \param[in] c The character to check.
211 *
212 * \return True if in character class or false if not.
213 */
214M_API M_bool M_chr_iscntrl(char c);
215
216
217/*! Checks for a digit zero through nine.
218 *
219 * Equivalent regular expression: <tt>[0-9]</tt>.
220 *
221 * \param[in] c The character to check.
222 *
223 * \return True if in character class or false if not.
224 */
225M_API M_bool M_chr_isdigit(char c);
226
227
228/*! Checks for a digit zero through nine or a period.
229 *
230 * Equivalent regular expression: <tt>[0-9\.]</tt>.
231 *
232 * \param[in] c The character to check.
233 *
234 * \return True if in character class or false if not.
235 */
236M_API M_bool M_chr_isdec(char c);
237
238
239/*! Checks for any printable character except space.
240 *
241 * Equivalent regular expression: <tt>[!-~]</tt>.
242 *
243 * \param[in] c The character to check.
244 *
245 * \return True if in character class or false if not.
246 */
247M_API M_bool M_chr_isgraph(char c);
248
249
250/*! Checks for a lower-case character [a-z].
251 *
252 * Equivalent regular expression: <tt>[a-z]</tt>.
253 *
254 * \param[in] c The character to check.
255 *
256 * \return True if in character class or false if not.
257 */
258M_API M_bool M_chr_islower(char c);
259
260
261/*! Checks for an uppercase letter.
262 *
263 * Equivalent regular expression: <tt>[A-Z]</tt>.
264 * \param[in] c The character to check.
265 *
266 * \return True if in character class or false if not.
267 */
268M_API M_bool M_chr_isupper(char c);
269
270
271/*! Checks for any printable character including space.
272 *
273 * Equivalent regular expression: <tt>[ -~]</tt>.
274 *
275 * \param[in] c The character to check.
276 *
277 * \return True if in character class or false if not.
278 */
279M_API M_bool M_chr_isprint(char c);
280
281
282/*! Checks for any printable character which is not a space or an alphanumeric character.
283 *
284 * Equivalent regular expression: <tt>[!-/:-@[-`{-~]</tt>.
285 *
286 * \param[in] c The character to check.
287 *
288 * \return True if in character class or false if not.
289 */
290M_API M_bool M_chr_ispunct(char c);
291
292
293/*! Checks for white-space characters.
294 *
295 * Equivalent regular expression: <tt>[\\f\\n\\r\\t\\v]</tt>.
296 *
297 * \param[in] c The character to check.
298 *
299 * \return True if in character class or false if not.
300 */
301M_API M_bool M_chr_isspace(char c);
302
303
304/*! Checks for a hexadecimal digits.
305 *
306 * Equivalent regular expression: <tt>[0-9a-fA-F]</tt>.
307 *
308 * \param[in] c The character to check.
309 *
310 * \return True if in character class or false if not.
311 */
312M_API M_bool M_chr_ishex(char c);
313
314
315/* - - - - - - - - - - - - - - - - - - - - - - - - - */
316
317/*! Convert character to lower case, if possible.
318 *
319 * \param[in] c The character to convert.
320 *
321 * \return c if not uppercase, otherwise the lowercase equivalent of c.
322 */
323M_API char M_chr_tolower(char c);
324
325
326/*! Convert character to upper case, if possible
327 *
328 * \param[in] c The character to convert.
329 *
330 * \return c if not lowercase, otherwise the uppercase equivalent of c
331 */
332M_API char M_chr_toupper(char c);
333
334
335/* - - - - - - - - - - - - - - - - - - - - - - - - - */
336
337/*! Convert a base-10 digit represented as a character to its corresponding integer representation.
338 *
339 * \param[in] c The decimal character to convert.
340 *
341 * \return 0-9 on valid input, -1 if c is not a digit.
342 */
343M_API int M_chr_digit(char c);
344
345
346/*! Convert a base-16 (hexadecimal) digit represented as a character to its corresponding integer representation.
347 *
348 * \param[in] c The hexadecimal character to convert.
349 *
350 * \return 0-9 on valid input, -1 if c is not a digit.
351 */
352M_API int M_chr_xdigit(char c);
353
354
355/*! @} */
356
357__END_DECLS
358
359#endif /* __M_CHR_H__* */
M_bool(* M_chr_predicate_func)(char c)
Definition: m_chr.h:134
M_bool M_chr_islower(char c)
int M_chr_xdigit(char c)
int M_chr_digit(char c)
M_bool M_chr_isupper(char c)
M_bool M_chr_isalphasp(char c)
M_bool M_chr_isalnumsp(char c)
M_bool M_chr_isspace(char c)
M_bool M_chr_ispunct(char c)
M_bool M_chr_isascii(char c)
M_bool M_chr_iscntrl(char c)
M_bool M_chr_isdigit(char c)
char M_chr_toupper(char c)
M_bool M_chr_isprint(char c)
char(* M_chr_map_func)(char)
Definition: m_chr.h:135
M_bool M_chr_isalnum(char c)
M_bool M_chr_isgraph(char c)
char M_chr_tolower(char c)
M_bool M_chr_isblank(char c)
M_bool M_chr_isdec(char c)
M_bool M_chr_ishex(char c)
M_bool M_chr_isalpha(char c)