-
Notifications
You must be signed in to change notification settings - Fork 6
/
ctype.h
203 lines (176 loc) · 2.63 KB
/
ctype.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/**
* @file ctype.h
* @brief Character tests and conversion functions.
* @author Miguel I. Garcia Lopez / FloppySoftware
*
* Character tests and conversion functions, for MESCC (Mike's Enhanced
* Small C Compiler for Z80 & CP/M).
*
* Revisions:
* - 19 Dec 2000 : Last revision.
* - 16 Apr 2007 : GPL'd.
* - 15 Aug 2016 : Documented. GPL v3.
*
* Copyright (c) 1999-2016 Miguel I. Garcia Lopez / FloppySoftware.
*
* Licensed under the GNU General Public License v3.
*
* http://www.floppysoftware.es
* floppysoftware@gmail.com
*/
#ifndef CTYPE_H
#define CTYPE_H
/**
* @fn int isalpha(char ch)
* @brief Test if ch is a letter.
* @param ch - character to test
* @return true or false
*/
#asm
isalpha
ld a,l
ld hl,0
cp 'A'
ret c
cp 'Z'+1
jr c,isalpha1
cp 'a'
ret c
cp 'z'+1
ret nc
isalpha1
inc l
ret
#endasm
/**
* @fn int isdigit(char ch)
* @brief Test if ch is a decimal digit.
* @param ch - character to test
* @return true or false
*/
#asm
isdigit
ld a,l
ld hl,0
cp '0'
ret c
cp '9'+1
ret nc
inc l
ret
#endasm
/**
* @fn int isxdigit(char ch)
* @brief Test if ch is an hexadecimal digit.
* @param ch - character to test
* @return true or false
*/
#asm
isxdigit
LD C,L
CALL isdigit
RET C
LD HL,0
LD A,C
CP 'A'
RET C
CP 'G'
JR C,isxdigit1
CP 'a'
RET C
CP 'g'
RET NC
isxdigit1
INC L
RET
#endasm
/**
* @fn int isalnum(char ch)
* @brief Test if ch is a letter or a decimal digit.
* @param ch - character to test
* @return true or false
*/
#asm
isalnum
LD C,L
CALL isdigit
RET C
LD L,C
JP isalpha
#endasm
/**
* @fn int isupper(char ch)
* @brief Test if ch is a letter in uppercase.
* @param ch - character to test
* @return true or false
*/
#asm
isupper
ld a,l
ld hl,0
cp 'A'
ret c
cp 'Z'+1
ret nc
inc l
ret
#endasm
/**
* @fn int islower(char ch)
* @brief Test if ch is a letter in lowercase.
* @param ch - character to test
* @return true or false
*/
#asm
islower
ld a,l
ld hl,0
cp 'a'
ret c
cp 'z'+1
ret nc
inc l
ret
#endasm
/**
* @fn int toupper(char ch)
* @brief Convert letter to uppercase.
*
* If ch is not a letter in lowercase, returns ch unchanged.
*
* @param ch - character to convert
* @return ch in uppercase
*/
#asm
toupper
ld a,l
cp 'a'
ret c
cp 'z'+1
ret nc
sub 20h
ld l,a
ret
#endasm
/**
* @fn int tolower(char ch)
* @brief Convert letter to lowercase.
*
* If ch is not a letter in uppercase, returns ch unchanged.
*
* @param ch - character to convert
* @return ch in lowercase
*/
#asm
tolower
ld a,l
cp 'A'
ret c
cp 'Z'+1
ret nc
add 20h
ld l,a
ret
#endasm
#endif