]> git.sur5r.net Git - cc65/blob - src/common/chartype.c
Removed (pretty inconsistently used) tab chars from source code base.
[cc65] / src / common / chartype.c
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                chartype.c                                 */
4 /*                                                                           */
5 /*                    Character classification functions                     */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2000-2004 Ullrich von Bassewitz                                       */
10 /*               Römerstrasse 52                                             */
11 /*               D-70794 Filderstadt                                         */
12 /* EMail:        uz@cc65.org                                                 */
13 /*                                                                           */
14 /*                                                                           */
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.                                    */
18 /*                                                                           */
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:                            */
22 /*                                                                           */
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              */
30 /*    distribution.                                                          */
31 /*                                                                           */
32 /*****************************************************************************/
33
34
35
36 #include "chartype.h"
37
38
39
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.
47  */
48
49
50
51 /*****************************************************************************/
52 /*                                   Code                                    */
53 /*****************************************************************************/
54
55
56
57 int IsAlpha (char C)
58 /* Check for a letter */
59 {
60     return (C >= 'a' && C <= 'z') || (C >= 'A' && C <= 'Z');
61 }
62
63
64
65 int IsAlNum (char C)
66 /* Check for letter or digit */
67 {
68     return (C >= 'a' && C <= 'z') || (C >= 'A' && C <= 'Z') || (C >= '0' && C <= '9');
69 }
70
71
72
73 int IsAscii (char C)
74 /* Check for an ASCII character */
75 {
76     return (C & ~0x7F) == 0;
77 }
78
79
80
81 int IsBlank (char C)
82 /* Check for a space or tab */
83 {
84     return (C == ' ' || C == '\t');
85 }
86
87
88
89 int IsSpace (char C)
90 /* Check for any white space characters */
91 {
92     return (C == ' ' || C == '\n' || C == '\r' || C == '\t' || C == '\v' || C == '\f');
93 }
94
95
96
97 int IsDigit (char C)
98 /* Check for a digit */
99 {
100     return (C >= '0' && C <= '9');
101 }
102
103
104
105 int IsLower (char C)
106 /* Check for a lower case char */
107 {
108     return (C >= 'a' && C <= 'z');
109 }
110
111
112
113 int IsUpper (char C)
114 /* Check for upper case characters */
115 {
116     return (C >= 'A' && C <= 'Z');
117 }
118
119
120
121 int IsBDigit (char C)
122 /* Check for binary digits (0/1) */
123 {
124     return (C == '0' || C == '1');
125 }
126
127
128
129 int IsODigit (char C)
130 /* Check for octal digits (0..7) */
131 {
132     return (C >= '0' && C <= '7');
133 }
134
135
136
137 int IsXDigit (char C)
138 /* Check for hexadecimal digits */
139 {
140     return (C >= 'a' && C <= 'f') || (C >= 'A' && C <= 'F') || (C >= '0' && C <= '9');
141 }
142
143
144
145 int IsQuote (char C)
146 /* Check for a single or double quote */
147 {
148     return (C == '"' || C == '\'');
149 }
150
151
152