-
Notifications
You must be signed in to change notification settings - Fork 0
/
char.zp
202 lines (170 loc) · 5.13 KB
/
char.zp
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
(define (char:cmp? cmp a b)
"compares two chars with a compare option cmp.
params:
- cmp: the comparison function
- a: the first character to compare
- b: the second character to compare
complexity: O(1)
returns: boolean"
(cmp (char->integer a) (char->integer b)))
(define (char:ci-cmp? cmp a b)
"compares two chars with a compare option cmp; case insensitive.
params:
- cmp: the comparison function
- a: the first character to compare
- b: the second character to compare
complexity: O(1)
returns: boolean"
(cmp (char->integer (char:lower-case a)) (char->integer (char:lower-case b))))
(define (char=? a b)
"checks whether two chars 'a' and 'b' are equal.
params:
- a: the first character to compare
- b: the second character to compare
complexity: O(1)
returns: boolean"
(char:cmp? = a b))
(define (char<? a b)
"checks whether a character 'a' is less than a character 'b'.
params:
- a: the first character to compare
- b: the second character to compare
complexity: O(1)
returns: boolean"
(char:cmp? < a b))
(define (char>? a b)
"checks if a character 'a' is greater than a character 'b'.
params:
- a: the first character to compare
- b: the second character to compare
complexity: O(1)
returns: boolean"
(char:cmp? > a b))
(define (char<=? a b)
"checks whether a character 'a' is less than or equal to a character 'b'.
params:
- a: the first character to compare
- b: the second character to compare
complexity: O(1)
returns: boolean"
(char:cmp? <= a b))
(define (char>=? a b)
"checks whether a character 'a' is greater than or equal to a character 'b'.
params:
- a: the first character to compare
- b: the second character to compare
complexity: O(1)
returns: boolean"
(char:cmp? >= a b))
(define (char/=? a b)
"checks whether a character 'a' is not equal to a character 'b'.
params:
- a: the first character to compare
- b: the second character to compare
complexity: O(1)
returns: boolean"
(char:cmp? /= a b))
(define (char-ci=? a b)
"checks whether two characters 'a' and 'b' are equal; case insensitive.
params:
- a: the first character to compare
- b: the second character to compare
complexity: O(1)
returns: boolean"
(char:ci-cmp? = a b))
(define (char-ci<? a b)
"checks whether a character 'a' is less than a character 'b'; case insensitive.
params:
- a: the character to compare
- b: the character to compare against
complexity: O(1)
returns: boolean"
(char:ci-cmp? < a b))
(define (char-ci>? a b)
"checks whether a character 'a' is greater than a character 'b'; case insensitive.
params:
- a: the character to compare
- b: the character to compare against
complexity: O(1)
returns: boolean"
(char:ci-cmp? > a b))
(define (char-ci<=? a b)
"checks whether a character 'a' is less than or equal to a character 'b'; case insensitive.
params:
- a: the character to compare
- b: the character to compare against
complexity: O(1)
returns: boolean"
(char:ci-cmp? <= a b))
(define (char-ci>=? a b)
"checks whether a character 'a' is greater than or equal to a character 'b'; case insensitive.
params:
- a: the character to compare
- b: the character to compare against
complexity: O(1)
returns: boolean"
(char:ci-cmp? >= a b))
(define (char-ci/=? a b)
"checks whether a character 'a' is not equal to the character 'b'; case insensitive.
params:
- a: the first character to check
- b: the second character to check
complexity: O(1)
returns: boolean"
(char:ci-cmp? /= a b))
(define (char:upper? c)
"checks whether the character is uppercase.
params:
- character: the character to check
complexity: O(1)
returns: boolean"
(let ((x (char->integer c)))
(and (> x 64) (< x 91))))
(define (char:lower? c)
"checks whether the character is lowercase.
params:
- character: the character to check
complexity: O(1)
returns: boolean"
(let ((x (char->integer c)))
(and (> x 96) (< x 123))))
(define (char:alpha? c)
"checks whether the character is alphabetical.
params:
- character: the character to check
complexity: O(1)
returns: boolean"
(or (char:upper? c) (char:lower? c)))
(define (char:num? c)
"checks whether the character is numerical.
params:
- character: the character to check
complexity: O(1)
returns: boolean"
(let ((x (char->integer c)))
(and (> x 47) (< x 58))))
(define (char:alphanum? c)
"checks whether the character is alphanumerical.
params:
- character: the character to check
complexity: O(1)
returns: boolean"
(or (char:alpha? c) (char:num? c)))
(define (char:whitespace? c)
"checks whether a character is a whitespace.
params:
- character: the character to check
complexity: O(1)
returns: boolean"
(let ((code (char->integer c)))
(in? '(32 9 10 11 12 13) code)))
(define (char:hex? char)
"checks whether a character is a valid hexadecimal sigit.
params:
- char: the character to check
complexity: O(1)
returns: boolean"
(let ((num (char->integer char)))
(or (char:num? char)
(and (> num 96) (< num 103))
(and (> num 64) (< num 71)))))