1 /*****************************************************************************/
5 /* Character classification functions */
9 /* (C) 2000-2004 Ullrich von Bassewitz */
10 /* Roemerstrasse 52 */
11 /* D-70794 Filderstadt */
12 /* EMail: uz@cc65.org */
15 /* This software is provided 'as-is', without any expressed or implied */
16 /* warranty. In no event will the authors be held liable for any damages */
17 /* arising from the use of this software. */
19 /* Permission is granted to anyone to use this software for any purpose, */
20 /* including commercial applications, and to alter it and redistribute it */
21 /* freely, subject to the following restrictions: */
23 /* 1. The origin of this software must not be misrepresented; you must not */
24 /* claim that you wrote the original software. If you use this software */
25 /* in a product, an acknowledgment in the product documentation would be */
26 /* appreciated but is not required. */
27 /* 2. Altered source versions must be plainly marked as such, and must not */
28 /* be misrepresented as being the original software. */
29 /* 3. This notice may not be removed or altered from any source */
32 /*****************************************************************************/
40 /* This module contains replacements for functions in ctype.h besides other
41 ** functions. There is a problem with using ctype.h directly:
42 ** The parameter must have a value of "unsigned char" or EOF.
43 ** So on platforms where a char is signed, this may give problems or at
44 ** least warnings. The wrapper functions below will have an "char" parameter
45 ** but handle it correctly. They will NOT work for EOF, but this is not a
46 ** problem, since EOF is always handled separately.
51 /*****************************************************************************/
53 /*****************************************************************************/
58 /* Check for a letter */
60 return (C >= 'a' && C <= 'z') || (C >= 'A' && C <= 'Z');
66 /* Check for letter or digit */
68 return (C >= 'a' && C <= 'z') || (C >= 'A' && C <= 'Z') || (C >= '0' && C <= '9');
74 /* Check for an ASCII character */
76 return (C & ~0x7F) == 0;
82 /* Check for a space or tab */
84 return (C == ' ' || C == '\t');
90 /* Check for any white space characters */
92 return (C == ' ' || C == '\n' || C == '\r' || C == '\t' || C == '\v' || C == '\f');
98 /* Check for a digit */
100 return (C >= '0' && C <= '9');
106 /* Check for a lower case char */
108 return (C >= 'a' && C <= 'z');
114 /* Check for upper case characters */
116 return (C >= 'A' && C <= 'Z');
121 int IsBDigit (char C)
122 /* Check for binary digits (0/1) */
124 return (C == '0' || C == '1');
129 int IsODigit (char C)
130 /* Check for octal digits (0..7) */
132 return (C >= '0' && C <= '7');
137 int IsXDigit (char C)
138 /* Check for hexadecimal digits */
140 return (C >= 'a' && C <= 'f') || (C >= 'A' && C <= 'F') || (C >= '0' && C <= '9');
146 /* Check for a single or double quote */
148 return (C == '"' || C == '\'');