Name | Executed | Routines | % | Executed | Lines | % | Unexecuted |
/home/matt/eu/rds/include/std/types.e | 30 | 30 | 100.00% | 187 | 190 | 98.42% | 3 |
Routine | Executed | Lines | Unexecuted | |
ascii_string() | 11 | 12 | 91.67% | 1 |
char_test() | 22 | 23 | 95.65% | 1 |
string() | 11 | 12 | 91.67% | 1 |
boolean() | 2 | 2 | 100.00% | 0 |
get_charsets() | 6 | 6 | 100.00% | 0 |
integer_array() | 8 | 8 | 100.00% | 0 |
number_array() | 8 | 8 | 100.00% | 0 |
sequence_array() | 8 | 8 | 100.00% | 0 |
set_charsets() | 7 | 7 | 100.00% | 0 |
set_default_charsets() | 22 | 22 | 100.00% | 0 |
t_alnum() | 2 | 2 | 100.00% | 0 |
t_alpha() | 2 | 2 | 100.00% | 0 |
t_ascii() | 2 | 2 | 100.00% | 0 |
t_boolean() | 2 | 2 | 100.00% | 0 |
t_bytearray() | 2 | 2 | 100.00% | 0 |
t_cntrl() | 2 | 2 | 100.00% | 0 |
t_consonant() | 2 | 2 | 100.00% | 0 |
t_digit() | 2 | 2 | 100.00% | 0 |
t_display() | 2 | 2 | 100.00% | 0 |
t_graph() | 2 | 2 | 100.00% | 0 |
t_identifier() | 6 | 6 | 100.00% | 0 |
t_lower() | 2 | 2 | 100.00% | 0 |
t_print() | 2 | 2 | 100.00% | 0 |
t_punct() | 2 | 2 | 100.00% | 0 |
t_space() | 2 | 2 | 100.00% | 0 |
t_specword() | 2 | 2 | 100.00% | 0 |
t_text() | 10 | 10 | 100.00% | 0 |
t_upper() | 2 | 2 | 100.00% | 0 |
t_vowel() | 2 | 2 | 100.00% | 0 |
t_xdigit() | 2 | 2 | 100.00% | 0 |
# | Executed | |
1 | -- (c) Copyright - See License.txt | |
2 | -- | |
3 | namespace types | |
4 | ||
5 | --**** | |
6 | -- == Types - Extended | |
7 | -- | |
8 | -- < | |
9 | ||
10 | --** | |
11 | -- Object not assigned | |
12 | 101 | public constant OBJ_UNASSIGNED = 0 |
13 | ||
14 | --** | |
15 | -- Object is integer | |
16 | 101 | public constant OBJ_INTEGER = 1 |
17 | ||
18 | --** | |
19 | -- Object is atom | |
20 | 101 | public constant OBJ_ATOM = 2 |
21 | ||
22 | --** | |
23 | -- Object is sequence | |
24 | 101 | public constant OBJ_SEQUENCE = 3 |
25 | ||
26 | ||
27 | --**** | |
28 | -- Signature: | |
29 | -- | |
30 | -- | |
31 | -- Description: | |
32 | -- Returns information about the object type of the supplied argument ##x##. | |
33 | -- | |
34 | -- Returns: | |
35 | -- # An integer. | |
36 | -- ** OBJ_UNASSIGNED if ##x## has not been assigned anything yet. | |
37 | -- ** OBJ_INTEGER if ##x## holds an integer value. | |
38 | -- ** OBJ_ATOM if ##x## holds a number that is not an integer. | |
39 | -- ** OBJ_SEQUENCE if ##x## holds a sequence value. | |
40 | -- | |
41 | -- Example 1: | |
42 | -- | |
43 | -- ? object(1) --> OBJ_INTEGER | |
44 | -- ? object(1.1) --> OBJ_ATOM | |
45 | -- ? object("1") --> OBJ_SEQUENCE | |
46 | -- object x | |
47 | -- ? object(x) --> OBJ_UNASSIGNED | |
48 | -- | |
49 | -- | |
50 | -- See Also: | |
51 | -- [[:sequence]](), [[:integer]](), [[:atom]]() | |
52 | ||
53 | ||
54 | --**** | |
55 | -- Signature: | |
56 | -- | |
57 | -- | |
58 | -- Description: | |
59 | -- Tests the supplied argument ##x## to see if it is an integer or not. | |
60 | -- | |
61 | -- Returns: | |
62 | -- # An integer. | |
63 | -- ** 1 if ##x## is an integer. | |
64 | -- ** 0 if ##x## is not an integer. | |
65 | -- | |
66 | -- Example 1: | |
67 | -- | |
68 | -- ? integer(1) --> 1 | |
69 | -- ? integer(1.1) --> 0 | |
70 | -- ? integer("1") --> 0 | |
71 | -- | |
72 | -- | |
73 | -- See Also: | |
74 | -- [[:sequence]](), [[:object]](), [[:atom]]() | |
75 | ||
76 | ||
77 | --**** | |
78 | -- Signature: | |
79 | -- | |
80 | -- | |
81 | -- Description: | |
82 | -- Tests the supplied argument ##x## to see if it is an atom or not. | |
83 | -- | |
84 | -- Returns: | |
85 | -- # An integer. | |
86 | -- ** 1 if ##x## is an atom. | |
87 | -- ** 0 if ##x## is not an atom. | |
88 | -- | |
89 | -- Example 1: | |
90 | -- | |
91 | -- ? atom(1) --> 1 | |
92 | -- ? atom(1.1) --> 1 | |
93 | -- ? atom("1") --> 0 | |
94 | -- | |
95 | -- | |
96 | -- See Also: | |
97 | -- [[:sequence]](), [[:object]](), [[:integer]]() | |
98 | ||
99 | ||
100 | --**** | |
101 | -- Signature: | |
102 | -- | |
103 | -- | |
104 | -- Description: | |
105 | -- Tests the supplied argument ##x## to see if it is a sequence or not. | |
106 | -- | |
107 | -- Returns: | |
108 | -- # An integer. | |
109 | -- ** 1 if ##x## is a sequence. | |
110 | -- ** 0 if ##x## is not an sequence. | |
111 | -- | |
112 | -- Example 1: | |
113 | -- | |
114 | -- ? sequence(1) --> 0 | |
115 | -- ? sequence({1}) --> 1 | |
116 | -- ? sequence("1") --> 1 | |
117 | -- | |
118 | -- | |
119 | -- See Also: | |
120 | -- [[:integer]](), [[:object]](), [[:atom]]() | |
121 | ||
122 | --** | |
123 | -- Boolean FALSE value | |
124 | 101 | public constant FALSE = (1=0) |
125 | ||
126 | --** | |
127 | -- Boolean TRUE value | |
128 | 101 | public constant TRUE = (1=1) |
129 | ||
130 | --** | |
131 | -- Predefined character sets: | |
132 | public enum | |
133 | 101 | CS_FIRST = 0, |
134 | 101 | CS_Consonant, |
135 | 101 | CS_Vowel, |
136 | 101 | CS_Hexadecimal, |
137 | 101 | CS_Whitespace, |
138 | 101 | CS_Punctuation, |
139 | 101 | CS_Printable, |
140 | 101 | CS_Displayable, |
141 | 101 | CS_Lowercase, |
142 | 101 | CS_Uppercase, |
143 | 101 | CS_Alphanumeric, |
144 | 101 | CS_Identifier, |
145 | 101 | CS_Alphabetic, |
146 | 101 | CS_ASCII, |
147 | 101 | CS_Control, |
148 | 101 | CS_Digit, |
149 | 101 | CS_Graphic, |
150 | 101 | CS_Bytes, |
151 | 101 | CS_SpecWord, |
152 | 101 | CS_Boolean, |
153 | 101 | CS_LAST |
154 | ||
155 | --**** | |
156 | -- === Support Functions | |
157 | -- | |
158 | ||
159 | --** | |
160 | -- Determine whether one or more characters are in a given character set. | |
161 | -- | |
162 | -- Parameters: | |
163 | -- # ##test_data## : an object to test, either a character or a string | |
164 | -- # ##char_set## : a sequence, either a list of allowable characters, or a list of pairs representing allowable ranges. | |
165 | -- | |
166 | -- Returns: | |
167 | -- An **integer**, 1 if all characters are allowed, else 0. | |
168 | -- | |
169 | -- Comments: | |
170 | -- | |
171 | -- ##pCharset## is either a simple sequence of characters eg. "qwertyuiop[]\\" | |
172 | -- or a sequence of character pairs, which represent allowable ranges | |
173 | -- of characters. eg. Alphabetic is defined as ~{{'a','z'}, {'A', 'Z'}} | |
174 | -- | |
175 | -- To add an isolated character to a character set which is defined using ranges, present it as a range of length 1, like in ##{%,%}##. | |
176 | -- | |
177 | -- Example 1: | |
178 | -- | |
179 | -- char_test("ABCD", {{'A', 'D'}}) | |
180 | -- -- TRUE, every char is in the range 'A' to 'D' | |
181 | -- | |
182 | -- char_test("ABCD", {{'A', 'C'}}) | |
183 | -- -- FALSE, not every char is in the range 'A' to 'C' | |
184 | -- | |
185 | -- char_test("Harry", {{'a', 'z'}, {'D', 'J'}}) | |
186 | -- -- TRUE, every char is either in the range 'a' to 'z', or in the range 'D' to 'J' | |
187 | -- | |
188 | -- char_test("Potter", "novel") | |
189 | -- -- FALSE, not every character is in the set 'n', 'o', 'v', 'e', 'l' | |
190 | -- | |
191 | ||
192 | 879 | |
193 | integer lChr | |
194 | ||
195 | 879 | if integer(test_data) then |
196 | 722 | if sequence(char_set[1]) then |
197 | 666 | for j = 1 to length(char_set) do |
198 | 775 | if test_data >= char_set[j][1] and test_data <= char_set[j][2] then return TRUE end if |
199 | 416 | end for |
200 | 307 | return FALSE |
201 | else | |
202 | 56 | return find(test_data, char_set) > 0 |
203 | end if | |
204 | 157 | elsif sequence(test_data) then |
205 | 142 | if length(test_data) = 0 then return FALSE end if |
206 | 126 | for i = 1 to length(test_data) label "NXTCHR" do |
207 | 283 | if sequence(test_data[i]) then return FALSE end if |
208 | 280 | if not integer(test_data[i]) then return FALSE end if |
209 | 276 | lChr = test_data[i] |
210 | 276 | if sequence(char_set[1]) then |
211 | 229 | for j = 1 to length(char_set) do |
212 | 332 | if lChr >= char_set[j][1] and lChr <= char_set[j][2] then continue "NXTCHR" end if |
213 | 163 | end for |
214 | else | |
215 | 47 | if find(lChr, char_set) > 0 then continue "NXTCHR" end if |
216 | end if | |
217 | 79 | return FALSE |
218 | 0 | end for |
219 | 40 | return TRUE |
220 | else | |
221 | 15 | return FALSE |
222 | end if | |
223 | end function | |
224 | ||
225 | sequence Defined_Sets | |
226 | ||
227 | --** | |
228 | -- Sets all the defined character sets to their default definitions. | |
229 | -- | |
230 | -- Example 1: | |
231 | -- | |
232 | -- set_default_charsets() | |
233 | -- | |
234 | ||
235 | 101 | |
236 | 101 | Defined_Sets = repeat(0, CS_LAST - CS_FIRST - 1) |
237 | 101 | Defined_Sets[CS_Alphabetic ] = {{'a', 'z'}, {'A', 'Z'}} |
238 | 101 | Defined_Sets[CS_Alphanumeric] = {{'0', '9'}, {'a', 'z'}, {'A', 'Z'}} |
239 | 101 | Defined_Sets[CS_Identifier] = {{'0', '9'}, {'a', 'z'}, {'A', 'Z'}, {'_', '_'}} |
240 | 101 | Defined_Sets[CS_Uppercase ] = {{'A', 'Z'}} |
241 | 101 | Defined_Sets[CS_Lowercase ] = {{'a', 'z'}} |
242 | 101 | Defined_Sets[CS_Printable ] = {{' ', '~'}} |
243 | 101 | Defined_Sets[CS_Displayable ] = {{' ', '~'}, " ", "\t\t", "\n\n", "\r\r", {8,8}, {7,7} } |
244 | 101 | Defined_Sets[CS_Whitespace ] = " \t\n\r" & 11 & 160 |
245 | 101 | Defined_Sets[CS_Consonant ] = "bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ" |
246 | 101 | Defined_Sets[CS_Vowel ] = "aeiouAEIOU" |
247 | 101 | Defined_Sets[CS_Hexadecimal ] = {{'0', '9'}, {'A', 'F'},{'a', 'f'}} |
248 | 101 | Defined_Sets[CS_Punctuation ] = {{' ', '/'}, {':', '?'}, {'[', '`'}, {'{', '~'}} |
249 | 101 | Defined_Sets[CS_Control ] = {{0, 31}, {127, 127}} |
250 | 101 | Defined_Sets[CS_ASCII ] = {{0, 127}} |
251 | 101 | Defined_Sets[CS_Digit ] = {{'0', '9'}} |
252 | 101 | Defined_Sets[CS_Graphic ] = {{'!', '~'}} |
253 | 101 | Defined_Sets[CS_Bytes ] = {{0, 255}} |
254 | 101 | Defined_Sets[CS_SpecWord ] = "_" |
255 | 101 | Defined_Sets[CS_Boolean ] = {TRUE,FALSE} |
256 | 101 | end procedure |
257 | ||
258 | --** | |
259 | -- Gets the definition for each of the defined character sets. | |
260 | -- | |
261 | -- Returns: | |
262 | -- A **sequence**, of pairs. The first element of each pair | |
263 | -- is the character set id , eg. CS_Whitespace, and the second is the definition | |
264 | -- of that character set. | |
265 | -- | |
266 | -- Comments: | |
267 | -- This is the same format required for the [[:set_charsets]]() routine. | |
268 | -- | |
269 | -- Example 1: | |
270 | -- | |
271 | -- sequence sets | |
272 | -- sets = get_charsets() | |
273 | -- | |
274 | -- | |
275 | -- See Also: | |
276 | -- [[:set_charsets]], [[:set_default_charsets]] | |
277 | ||
278 | 1 | |
279 | sequence result_ | |
280 | ||
281 | 1 | result_ = {} |
282 | 1 | for i = CS_FIRST + 1 to CS_LAST - 1 do |
283 | 19 | result_ = append(result_, {i, Defined_Sets[i]} ) |
284 | 19 | end for |
285 | ||
286 | 1 | return result_ |
287 | end function | |
288 | ||
289 | --** | |
290 | -- Sets the definition for one or more defined character sets. | |
291 | -- | |
292 | -- Parameters: | |
293 | -- # ##charset_list## : a sequence of zero or more character set definitions. | |
294 | -- | |
295 | -- Comments: | |
296 | -- ##charset_list## must be a sequence of pairs. The first element of each pair | |
297 | -- is the character set id , eg. CS_Whitespace, and the second is the definition | |
298 | -- of that character set. | |
299 | -- | |
300 | -- This is the same format returned by the [[:get_charsets]]() routine. | |
301 | -- | |
302 | -- You cannot create new character sets using this routine. | |
303 | -- | |
304 | -- Example 1: | |
305 | -- | |
306 | -- set_charsets({{CS_Whitespace, " \t"}}) | |
307 | -- t_space('\n') --> FALSE | |
308 | -- | |
309 | -- t_specword('$') --> FALSE | |
310 | -- set_charsets({{CS_SpecWord, "_-#$%"}}) | |
311 | -- t_specword('$') --> TRUE | |
312 | -- | |
313 | -- | |
314 | -- See Also: | |
315 | -- [[:get_charsets]] | |
316 | ||
317 | 3 | |
318 | 3 | for i = 1 to length(charset_list) do |
319 | 21 | if sequence(charset_list[i]) and length(charset_list[i]) = 2 then |
320 | 21 | if integer(charset_list[i][1]) and charset_list[i][1] > CS_FIRST and charset_list[i][1] < CS_LAST then |
321 | 21 | Defined_Sets[charset_list[i][1]] = charset_list[i][2] |
322 | end if | |
323 | end if | |
324 | 21 | end for |
325 | 3 | end procedure |
326 | ||
327 | --**** | |
328 | -- === Types | |
329 | -- | |
330 | ||
331 | --** | |
332 | -- Returns TRUE if argument is 1 or 0 | |
333 | -- | |
334 | -- Returns FALSE if the argument is anything else other than 1 or 0. | |
335 | -- | |
336 | -- Example 1: | |
337 | -- | |
338 | -- boolean(-1) -- FALSE | |
339 | -- boolean(0) -- TRUE | |
340 | -- boolean(1) -- TRUE | |
341 | -- boolean(1.234) -- FALSE | |
342 | -- boolean('A') -- FALSE | |
343 | -- boolean('9') -- FALSE | |
344 | -- boolean('?') -- FALSE | |
345 | -- boolean("abc") -- FALSE | |
346 | -- boolean("ab3") -- FALSE | |
347 | -- boolean({1,2,"abc"}) -- FALSE | |
348 | -- boolean({1, 2, 9.7) -- FALSE | |
349 | -- boolean({}) -- FALSE (empty sequence) | |
350 | -- | |
351 | ||
352 | 700 | |
353 | -- A boolean is a value that is either zero or one. | |
354 | ||
355 | 700 | return find(test_data,{1,0}) != 0 |
356 | ||
357 | end type | |
358 | ||
359 | --** | |
360 | -- Returns TRUE if argument is boolean (1 or 0) or if every element of | |
361 | -- the argument is boolean. | |
362 | -- | |
363 | -- Returns FALSE if the argument is an empty sequence, or contains sequences, | |
364 | -- or contains non-boolean elements | |
365 | -- | |
366 | -- Example 1: | |
367 | -- | |
368 | -- t_boolean(-1) -- FALSE | |
369 | -- t_boolean(0) -- TRUE | |
370 | -- t_boolean(1) -- TRUE | |
371 | -- t_boolean({1, 1, 0}) -- TRUE | |
372 | -- t_boolean({1, 1, 9.7}) -- FALSE | |
373 | -- t_boolean({}) -- FALSE (empty sequence) | |
374 | -- | |
375 | 6 | |
376 | 6 | return char_test(test_data, Defined_Sets[CS_Boolean]) |
377 | end type | |
378 | ||
379 | --** | |
380 | -- Returns TRUE if argument is an alphanumeric character or if every element of | |
381 | -- the argument is an alphanumeric character. | |
382 | -- | |
383 | -- Returns FALSE if the argument is an empty sequence, or contains sequences, | |
384 | -- or contains non-alphanumeric elements | |
385 | -- | |
386 | -- Example 1: | |
387 | -- | |
388 | -- t_alnum(-1) -- FALSE | |
389 | -- t_alnum(0) -- FALSE | |
390 | -- t_alnum(1) -- FALSE | |
391 | -- t_alnum(1.234) -- FALSE | |
392 | -- t_alnum('A') -- TRUE | |
393 | -- t_alnum('9') -- TRUE | |
394 | -- t_alnum('?') -- FALSE | |
395 | -- t_alnum("abc") -- TRUE (every element is alphabetic or a digit) | |
396 | -- t_alnum("ab3") -- TRUE | |
397 | -- t_alnum({1, 2, "abc"}) -- FALSE (contains a sequence) | |
398 | -- t_alnum({1, 2, 9.7}) -- FALSE (contains a non-integer) | |
399 | -- t_alnum({}) -- FALSE (empty sequence) | |
400 | -- | |
401 | ||
402 | 20 | |
403 | 20 | return char_test(test_data, Defined_Sets[CS_Alphanumeric]) |
404 | end type | |
405 | ||
406 | --** | |
407 | -- Returns TRUE if argument is an alphanumeric character or if every element of | |
408 | -- the argument is an alphanumeric character and that the first character is not | |
409 | -- numeric and the whole group of characters are not all numeric. | |
410 | -- | |
411 | -- Returns FALSE if the argument is an empty sequence, or contains sequences, | |
412 | -- or contains non-alphanumeric elements | |
413 | -- | |
414 | -- Example 1: | |
415 | -- | |
416 | -- t_identifier(-1) -- FALSE | |
417 | -- t_identifier(0) -- FALSE | |
418 | -- t_identifier(1) -- FALSE | |
419 | -- t_identifier(1.234) -- FALSE | |
420 | -- t_identifier('A') -- TRUE | |
421 | -- t_identifier('9') -- FALSE | |
422 | -- t_identifier('?') -- FALSE | |
423 | -- t_identifier("abc") -- TRUE (every element is alphabetic or a digit) | |
424 | -- t_identifier("ab3") -- TRUE | |
425 | -- t_identifier("ab_3") -- TRUE (underscore is allowed) | |
426 | -- t_identifier("1abc") -- FALSE (identifier cannot start with a number) | |
427 | -- t_identifier("102") -- FALSE (identifier cannot be all numeric) | |
428 | -- t_identifier({1, 2, "abc"}) -- FALSE (contains a sequence) | |
429 | -- t_identifier({1, 2, 9.7}) -- FALSE (contains a non-integer) | |
430 | -- t_identifier({}) -- FALSE (empty sequence) | |
431 | -- | |
432 | ||
433 | 10 | |
434 | -- Test to make sure the first character is not a number | |
435 | 10 | if t_digit(test_data) then |
436 | 2 | return 0 |
437 | 8 | elsif sequence(test_data) and length(test_data) > 0 and t_digit(test_data[1]) then |
438 | 2 | return 0 |
439 | end if | |
440 | ||
441 | 6 | return char_test(test_data, Defined_Sets[CS_Identifier]) |
442 | end type | |
443 | ||
444 | --** | |
445 | -- Returns TRUE if argument is an alphabetic character or if every element of | |
446 | -- the argument is an alphabetic character. | |
447 | -- | |
448 | -- Returns FALSE if the argument is an empty sequence, or contains sequences, | |
449 | -- or contains non-alphabetic elements | |
450 | -- | |
451 | -- Example 1: | |
452 | -- | |
453 | -- t_alpha(-1) -- FALSE | |
454 | -- t_alpha(0) -- FALSE | |
455 | -- t_alpha(1) -- FALSE | |
456 | -- t_alpha(1.234) -- FALSE | |
457 | -- t_alpha('A') -- TRUE | |
458 | -- t_alpha('9') -- FALSE | |
459 | -- t_alpha('?') -- FALSE | |
460 | -- t_alpha("abc") -- TRUE (every element is alphabetic) | |
461 | -- t_alpha("ab3") -- FALSE | |
462 | -- t_alpha({1, 2, "abc"}) -- FALSE (contains a sequence) | |
463 | -- t_alpha({1, 2, 9.7}) -- FALSE (contains a non-integer) | |
464 | -- t_alpha({}) -- FALSE (empty sequence) | |
465 | -- | |
466 | ||
467 | 51 | |
468 | 51 | return char_test(test_data, Defined_Sets[CS_Alphabetic]) |
469 | end type | |
470 | ||
471 | --** | |
472 | -- Returns TRUE if argument is an ASCII character or if every element of | |
473 | -- the argument is an ASCII character. | |
474 | -- | |
475 | -- Returns FALSE if the argument is an empty sequence, or contains sequences, | |
476 | -- or contains non-ASCII elements | |
477 | -- | |
478 | -- Example 1: | |
479 | -- | |
480 | -- t_ascii(-1) -- FALSE | |
481 | -- t_ascii(0) -- TRUE | |
482 | -- t_ascii(1) -- TRUE | |
483 | -- t_ascii(1.234) -- FALSE | |
484 | -- t_ascii('A') -- TRUE | |
485 | -- t_ascii('9') -- TRUE | |
486 | -- t_ascii('?') -- TRUE | |
487 | -- t_ascii("abc") -- TRUE (every element is ascii) | |
488 | -- t_ascii("ab3") -- TRUE | |
489 | -- t_ascii({1, 2, "abc"}) -- FALSE (contains a sequence) | |
490 | -- t_ascii({1, 2, 9.7}) -- FALSE (contains a non-integer) | |
491 | -- t_ascii({}) -- FALSE (empty sequence) | |
492 | -- | |
493 | ||
494 | 16 | |
495 | 16 | return char_test(test_data, Defined_Sets[CS_ASCII]) |
496 | end type | |
497 | ||
498 | --** | |
499 | -- Returns TRUE if argument is an Control character or if every element of | |
500 | -- the argument is an Control character. | |
501 | -- | |
502 | -- Returns FALSE if the argument is an empty sequence, or contains sequences, | |
503 | -- or contains non-Control elements | |
504 | -- | |
505 | -- Example 1: | |
506 | -- | |
507 | -- t_cntrl(-1) -- FALSE | |
508 | -- t_cntrl(0) -- TRUE | |
509 | -- t_cntrl(1) -- TRUE | |
510 | -- t_cntrl(1.234) -- FALSE | |
511 | -- t_cntrl('A') -- FALSE | |
512 | -- t_cntrl('9') -- FALSE | |
513 | -- t_cntrl('?') -- FALSE | |
514 | -- t_cntrl("abc") -- FALSE (every element is ascii) | |
515 | -- t_cntrl("ab3") -- FALSE | |
516 | -- t_cntrl({1, 2, "abc"}) -- FALSE (contains a sequence) | |
517 | -- t_cntrl({1, 2, 9.7}) -- FALSE (contains a non-integer) | |
518 | -- t_cntrl({1, 2, 'a'}) -- FALSE (contains a non-control) | |
519 | -- t_cntrl({}) -- FALSE (empty sequence) | |
520 | -- | |
521 | ||
522 | 17 | |
523 | 17 | return char_test(test_data, Defined_Sets[CS_Control]) |
524 | end type | |
525 | ||
526 | --** | |
527 | -- Returns TRUE if argument is an digit character or if every element of | |
528 | -- the argument is an digit character. | |
529 | -- | |
530 | -- Returns FALSE if the argument is an empty sequence, or contains sequences, | |
531 | -- or contains non-digits | |
532 | -- | |
533 | -- Example 1: | |
534 | -- | |
535 | -- t_digit(-1) -- FALSE | |
536 | -- t_digit(0) -- FALSE | |
537 | -- t_digit(1) -- FALSE | |
538 | -- t_digit(1.234) -- FALSE | |
539 | -- t_digit('A') -- FALSE | |
540 | -- t_digit('9') -- TRUE | |
541 | -- t_digit('?') -- FALSE | |
542 | -- t_digit("abc") -- FALSE | |
543 | -- t_digit("ab3") -- FALSE | |
544 | -- t_digit("123") -- TRUE | |
545 | -- t_digit({1, 2, "abc"}) -- FALSE (contains a sequence) | |
546 | -- t_digit({1, 2, 9.7}) -- FALSE (contains a non-integer) | |
547 | -- t_digit({1, 2, 'a'}) -- FALSE (contains a non-digit) | |
548 | -- t_digit({}) -- FALSE (empty sequence) | |
549 | -- | |
550 | ||
551 | 174 | |
552 | 174 | return char_test(test_data, Defined_Sets[CS_Digit]) |
553 | end type | |
554 | ||
555 | --** | |
556 | -- Returns TRUE if argument is a glyph character or if every element of | |
557 | -- the argument is a glyph character. (One that is visible when displayed) | |
558 | -- | |
559 | -- Returns FALSE if the argument is an empty sequence, or contains sequences, | |
560 | -- or contains non-glyph | |
561 | -- | |
562 | -- Example 1: | |
563 | -- | |
564 | -- t_graph(-1) -- FALSE | |
565 | -- t_graph(0) -- FALSE | |
566 | -- t_graph(1) -- FALSE | |
567 | -- t_graph(1.234) -- FALSE | |
568 | -- t_graph('A') -- TRUE | |
569 | -- t_graph('9') -- TRUE | |
570 | -- t_graph('?') -- TRUE | |
571 | -- t_graph(' ') -- FALSE | |
572 | -- t_graph("abc") -- TRUE | |
573 | -- t_graph("ab3") -- TRUE | |
574 | -- t_graph("123") -- TRUE | |
575 | -- t_graph({1, 2, "abc"}) -- FALSE (contains a sequence) | |
576 | -- t_graph({1, 2, 9.7}) -- FALSE (contains a non-integer) | |
577 | -- t_graph({1, 2, 'a'}) -- FALSE (control chars (1,2) don't have glyphs) | |
578 | -- t_graph({}) -- FALSE (empty sequence) | |
579 | -- | |
580 | ||
581 | 19 | |
582 | 19 | return char_test(test_data, Defined_Sets[CS_Graphic]) |
583 | end type | |
584 | ||
585 | --** | |
586 | -- Returns TRUE if argument is a special word character or if every element of | |
587 | -- the argument is a special word character. | |
588 | -- | |
589 | -- Returns FALSE if the argument is an empty sequence, or contains sequences, | |
590 | -- or contains non-special-word characters. | |
591 | -- | |
592 | -- Comments: | |
593 | -- A //special word character// is any character that is not normally part of | |
594 | -- a word but in certain cases may be considered. This is most commonly used | |
595 | -- when looking for words in programming source code which allows an underscore | |
596 | -- as a word character. | |
597 | -- | |
598 | -- Example 1: | |
599 | -- | |
600 | -- t_specword(-1) -- FALSE | |
601 | -- t_specword(0) -- FALSE | |
602 | -- t_specword(1) -- FALSE | |
603 | -- t_specword(1.234) -- FALSE | |
604 | -- t_specword('A') -- FALSE | |
605 | -- t_specword('9') -- FALSE | |
606 | -- t_specword('?') -- FALSE | |
607 | -- t_specword('_') -- TRUE | |
608 | -- t_specword("abc") -- FALSE | |
609 | -- t_specword("ab3") -- FALSE | |
610 | -- t_specword("123") -- FALSE | |
611 | -- t_specword({1, 2, "abc"}) -- FALSE (contains a sequence) | |
612 | -- t_specword({1, 2, 9.7}) -- FALSE (contains a non-integer) | |
613 | -- t_specword({1, 2, 'a'}) -- FALSE (control chars (1,2) don't have glyphs) | |
614 | -- t_specword({}) -- FALSE (empty sequence) | |
615 | -- | |
616 | ||
617 | 23 | |
618 | 23 | return char_test(test_data, Defined_Sets[CS_SpecWord]) |
619 | end type | |
620 | ||
621 | --** | |
622 | -- Returns TRUE if argument is a byte or if every element of | |
623 | -- the argument is a byte. (Integers from 0 to 255) | |
624 | -- | |
625 | -- Returns FALSE if the argument is an empty sequence, or contains sequences, | |
626 | -- or contains non-byte | |
627 | -- | |
628 | -- Example 1: | |
629 | -- | |
630 | -- t_bytearray(-1) -- FALSE (contains value less than zero) | |
631 | -- t_bytearray(0) -- TRUE | |
632 | -- t_bytearray(1) -- TRUE | |
633 | -- t_bytearray(10) -- TRUE | |
634 | -- t_bytearray(100) -- TRUE | |
635 | -- t_bytearray(1000) -- FALSE (greater than 255) | |
636 | -- t_bytearray(1.234) -- FALSE (contains a floating number) | |
637 | -- t_bytearray('A') -- TRUE | |
638 | -- t_bytearray('9') -- TRUE | |
639 | -- t_bytearray('?') -- TRUE | |
640 | -- t_bytearray(' ') -- TRUE | |
641 | -- t_bytearray("abc") -- TRUE | |
642 | -- t_bytearray("ab3") -- TRUE | |
643 | -- t_bytearray("123") -- TRUE | |
644 | -- t_bytearray({1, 2, "abc"}) -- FALSE (contains a sequence) | |
645 | -- t_bytearray({1, 2, 9.7}) -- FALSE (contains a non-integer) | |
646 | -- t_bytearray({1, 2, 'a'}) -- TRUE | |
647 | -- t_bytearray({}) -- FALSE (empty sequence) | |
648 | -- | |
649 | ||
650 | 18 | |
651 | 18 | return char_test(test_data, Defined_Sets[CS_Bytes]) |
652 | end type | |
653 | ||
654 | --** | |
655 | -- Returns TRUE if argument is a lowercase character or if every element of | |
656 | -- the argument is an lowercase character. | |
657 | -- | |
658 | -- Returns FALSE if the argument is an empty sequence, or contains sequences, | |
659 | -- or contains non-lowercase | |
660 | -- | |
661 | -- Example 1: | |
662 | -- | |
663 | -- t_lower(-1) -- FALSE | |
664 | -- t_lower(0) -- FALSE | |
665 | -- t_lower(1) -- FALSE | |
666 | -- t_lower(1.234) -- FALSE | |
667 | -- t_lower('A') -- FALSE | |
668 | -- t_lower('9') -- FALSE | |
669 | -- t_lower('?') -- FALSE | |
670 | -- t_lower("abc") -- TRUE | |
671 | -- t_lower("ab3") -- FALSE | |
672 | -- t_lower("123") -- TRUE | |
673 | -- t_lower({1, 2, "abc"}) -- FALSE (contains a sequence) | |
674 | -- t_lower({1, 2, 9.7}) -- FALSE (contains a non-integer) | |
675 | -- t_lower({1, 2, 'a'}) -- FALSE (contains a non-digit) | |
676 | -- t_lower({}) -- FALSE (empty sequence) | |
677 | -- | |
678 | ||
679 | 144 | |
680 | 144 | return char_test(test_data, Defined_Sets[CS_Lowercase]) |
681 | end type | |
682 | ||
683 | --** | |
684 | -- Returns TRUE if argument is a character that has an ASCII glyph or if every element of | |
685 | -- the argument is a character that has an ASCII glyph. | |
686 | -- | |
687 | -- Returns FALSE if the argument is an empty sequence, or contains sequences, | |
688 | -- or contains characters that do not have an ASCII glyph. | |
689 | -- | |
690 | -- Example 1: | |
691 | -- | |
692 | -- t_print(-1) -- FALSE | |
693 | -- t_print(0) -- FALSE | |
694 | -- t_print(1) -- FALSE | |
695 | -- t_print(1.234) -- FALSE | |
696 | -- t_print('A') -- TRUE | |
697 | -- t_print('9') -- TRUE | |
698 | -- t_print('?') -- TRUE | |
699 | -- t_print("abc") -- TRUE | |
700 | -- t_print("ab3") -- TRUE | |
701 | -- t_print("123") -- TRUE | |
702 | -- t_print("123 ") -- FALSE (contains a space) | |
703 | -- t_print("123\n") -- FALSE (contains a new-line) | |
704 | -- t_print({1, 2, "abc"}) -- FALSE (contains a sequence) | |
705 | -- t_print({1, 2, 9.7}) -- FALSE (contains a non-integer) | |
706 | -- t_print({1, 2, 'a'}) -- FALSE | |
707 | -- t_print({}) -- FALSE (empty sequence) | |
708 | -- | |
709 | ||
710 | 52 | |
711 | 52 | return char_test(test_data, Defined_Sets[CS_Printable]) |
712 | end type | |
713 | ||
714 | --** | |
715 | -- Returns TRUE if argument is a character that can be displayed or if every element of | |
716 | -- the argument is a character that can be displayed. | |
717 | -- | |
718 | -- Returns FALSE if the argument is an empty sequence, or contains sequences, | |
719 | -- or contains characters that cannot be displayed. | |
720 | -- | |
721 | -- Example 1: | |
722 | -- | |
723 | -- t_display(-1) -- FALSE | |
724 | -- t_display(0) -- FALSE | |
725 | -- t_display(1) -- FALSE | |
726 | -- t_display(1.234) -- FALSE | |
727 | -- t_display('A') -- TRUE | |
728 | -- t_display('9') -- TRUE | |
729 | -- t_display('?') -- TRUE | |
730 | -- t_display("abc") -- TRUE | |
731 | -- t_display("ab3") -- TRUE | |
732 | -- t_display("123") -- TRUE | |
733 | -- t_display("123 ") -- TRUE | |
734 | -- t_display("123\n") -- TRUE | |
735 | -- t_display({1, 2, "abc"}) -- FALSE (contains a sequence) | |
736 | -- t_display({1, 2, 9.7}) -- FALSE (contains a non-integer) | |
737 | -- t_display({1, 2, 'a'}) -- FALSE | |
738 | -- t_display({}) -- FALSE (empty sequence) | |
739 | -- | |
740 | ||
741 | 7 | |
742 | 7 | return char_test(test_data, Defined_Sets[CS_Displayable]) |
743 | end type | |
744 | ||
745 | --** | |
746 | -- Returns TRUE if argument is an punctuation character or if every element of | |
747 | -- the argument is an punctuation character. | |
748 | -- | |
749 | -- Returns FALSE if the argument is an empty sequence, or contains sequences, | |
750 | -- or contains non-punctuation symbols. | |
751 | -- | |
752 | -- Example 1: | |
753 | -- | |
754 | -- t_punct(-1) -- FALSE | |
755 | -- t_punct(0) -- FALSE | |
756 | -- t_punct(1) -- FALSE | |
757 | -- t_punct(1.234) -- FALSE | |
758 | -- t_punct('A') -- FALSE | |
759 | -- t_punct('9') -- FALSE | |
760 | -- t_punct('?') -- TRUE | |
761 | -- t_punct("abc") -- FALSE | |
762 | -- t_punct("(-)") -- TRUE | |
763 | -- t_punct("123") -- TRUE | |
764 | -- t_punct({1, 2, "abc"}) -- FALSE (contains a sequence) | |
765 | -- t_punct({1, 2, 9.7}) -- FALSE (contains a non-integer) | |
766 | -- t_punct({1, 2, 'a'}) -- FALSE (contains a non-digit) | |
767 | -- t_punct({}) -- FALSE (empty sequence) | |
768 | -- | |
769 | ||
770 | 21 | |
771 | 21 | return char_test(test_data, Defined_Sets[CS_Punctuation]) |
772 | end type | |
773 | ||
774 | --** | |
775 | -- Returns TRUE if argument is a whitespace character or if every element of | |
776 | -- the argument is an whitespace character. | |
777 | -- | |
778 | -- Returns FALSE if the argument is an empty sequence, or contains sequences, | |
779 | -- or contains non-whitespace character. | |
780 | -- | |
781 | -- Example 1: | |
782 | -- | |
783 | -- t_space(-1) -- FALSE | |
784 | -- t_space(0) -- FALSE | |
785 | -- t_space(1) -- FALSE | |
786 | -- t_space(1.234) -- FALSE | |
787 | -- t_space('A') -- FALSE | |
788 | -- t_space('9') -- FALSE | |
789 | -- t_space('\t') -- TRUE | |
790 | -- t_space("abc") -- FALSE | |
791 | -- t_space("123") -- FALSE | |
792 | -- t_space({1, 2, "abc"}) -- FALSE (contains a sequence) | |
793 | -- t_space({1, 2, 9.7}) -- FALSE (contains a non-integer) | |
794 | -- t_space({1, 2, 'a'}) -- FALSE (contains a non-digit) | |
795 | -- t_space({}) -- FALSE (empty sequence) | |
796 | -- | |
797 | ||
798 | 31 | |
799 | 31 | return char_test(test_data, Defined_Sets[CS_Whitespace]) |
800 | end type | |
801 | ||
802 | --** | |
803 | -- Returns TRUE if argument is an uppercase character or if every element of | |
804 | -- the argument is an uppercase character. | |
805 | -- | |
806 | -- Returns FALSE if the argument is an empty sequence, or contains sequences, | |
807 | -- or contains non-uppercase characters. | |
808 | -- | |
809 | -- Example 1: | |
810 | -- | |
811 | -- t_upper(-1) -- FALSE | |
812 | -- t_upper(0) -- FALSE | |
813 | -- t_upper(1) -- FALSE | |
814 | -- t_upper(1.234) -- FALSE | |
815 | -- t_upper('A') -- TRUE | |
816 | -- t_upper('9') -- FALSE | |
817 | -- t_upper('?') -- FALSE | |
818 | -- t_upper("abc") -- FALSE | |
819 | -- t_upper("ABC") -- TRUE | |
820 | -- t_upper("123") -- FALSE | |
821 | -- t_upper({1, 2, "abc"}) -- FALSE (contains a sequence) | |
822 | -- t_upper({1, 2, 9.7}) -- FALSE (contains a non-integer) | |
823 | -- t_upper({1, 2, 'a'}) -- FALSE (contains a non-digit) | |
824 | -- t_upper({}) -- FALSE (empty sequence) | |
825 | -- | |
826 | ||
827 | 219 | |
828 | 219 | return char_test(test_data, Defined_Sets[CS_Uppercase]) |
829 | end type | |
830 | ||
831 | --** | |
832 | -- Returns TRUE if argument is an hexadecimal digit character or if every element of | |
833 | -- the argument is an hexadecimal digit character. | |
834 | -- | |
835 | -- Returns FALSE if the argument is an empty sequence, or contains sequences, | |
836 | -- or contains non-hexadecimal character. | |
837 | -- | |
838 | -- Example 1: | |
839 | -- | |
840 | -- t_xdigit(-1) -- FALSE | |
841 | -- t_xdigit(0) -- FALSE | |
842 | -- t_xdigit(1) -- FALSE | |
843 | -- t_xdigit(1.234) -- FALSE | |
844 | -- t_xdigit('A') -- TRUE | |
845 | -- t_xdigit('9') -- TRUE | |
846 | -- t_xdigit('?') -- FALSE | |
847 | -- t_xdigit("abc") -- TRUE | |
848 | -- t_xdigit("fgh") -- FALSE | |
849 | -- t_xdigit("123") -- TRUE | |
850 | -- t_xdigit({1, 2, "abc"}) -- FALSE (contains a sequence) | |
851 | -- t_xdigit({1, 2, 9.7}) -- FALSE (contains a non-integer) | |
852 | -- t_xdigit({1, 2, 'a'}) -- FALSE (contains a non-digit) | |
853 | -- t_xdigit({}) -- FALSE (empty sequence) | |
854 | -- | |
855 | ||
856 | 23 | |
857 | 23 | return char_test(test_data, Defined_Sets[CS_Hexadecimal]) |
858 | end type | |
859 | ||
860 | --** | |
861 | -- Returns TRUE if argument is a vowel or if every element of | |
862 | -- the argument is a vowel character. | |
863 | -- | |
864 | -- Returns FALSE if the argument is an empty sequence, or contains sequences, | |
865 | -- or contains non-vowels | |
866 | -- | |
867 | -- Example 1: | |
868 | -- | |
869 | -- t_vowel(-1) -- FALSE | |
870 | -- t_vowel(0) -- FALSE | |
871 | -- t_vowel(1) -- FALSE | |
872 | -- t_vowel(1.234) -- FALSE | |
873 | -- t_vowel('A') -- TRUE | |
874 | -- t_vowel('9') -- FALSE | |
875 | -- t_vowel('?') -- FALSE | |
876 | -- t_vowel("abc") -- FALSE | |
877 | -- t_vowel("aiu") -- TRUE | |
878 | -- t_vowel("123") -- FALSE | |
879 | -- t_vowel({1, 2, "abc"}) -- FALSE (contains a sequence) | |
880 | -- t_vowel({1, 2, 9.7}) -- FALSE (contains a non-integer) | |
881 | -- t_vowel({1, 2, 'a'}) -- FALSE (contains a non-digit) | |
882 | -- t_vowel({}) -- FALSE (empty sequence) | |
883 | -- | |
884 | ||
885 | 14 | |
886 | 14 | return char_test(test_data, Defined_Sets[CS_Vowel]) |
887 | end type | |
888 | ||
889 | --** | |
890 | -- Returns TRUE if argument is a consonant character or if every element of | |
891 | -- the argument is an consonant character. | |
892 | -- | |
893 | -- Returns FALSE if the argument is an empty sequence, or contains sequences, | |
894 | -- or contains non-consonant character. | |
895 | -- | |
896 | -- Example 1: | |
897 | -- | |
898 | -- t_consonant(-1) -- FALSE | |
899 | -- t_consonant(0) -- FALSE | |
900 | -- t_consonant(1) -- FALSE | |
901 | -- t_consonant(1.234) -- FALSE | |
902 | -- t_consonant('A') -- FALSE | |
903 | -- t_consonant('9') -- FALSE | |
904 | -- t_consonant('?') -- FALSE | |
905 | -- t_consonant("abc") -- FALSE | |
906 | -- t_consonant("rTfM") -- TRUE | |
907 | -- t_consonant("123") -- FALSE | |
908 | -- t_consonant({1, 2, "abc"}) -- FALSE (contains a sequence) | |
909 | -- t_consonant({1, 2, 9.7}) -- FALSE (contains a non-integer) | |
910 | -- t_consonant({1, 2, 'a'}) -- FALSE (contains a non-digit) | |
911 | -- t_consonant({}) -- FALSE (empty sequence) | |
912 | -- | |
913 | ||
914 | 14 | |
915 | 14 | return char_test(test_data, Defined_Sets[CS_Consonant]) |
916 | end type | |
917 | ||
918 | 101 | set_default_charsets() |
919 | ||
920 | --** | |
921 | -- Returns: | |
922 | -- TRUE if argument is a sequence that only contains zero or more integers. | |
923 | -- | |
924 | -- Example 1: | |
925 | -- | |
926 | -- integer_array(-1) -- FALSE (not a sequence) | |
927 | -- integer_array("abc") -- TRUE (all single characters) | |
928 | -- integer_array({1, 2, "abc"}) -- FALSE (contains a sequence) | |
929 | -- integer_array({1, 2, 9.7}) -- FALSE (contains a non-integer) | |
930 | -- integer_array({1, 2, 'a'}) -- TRUE | |
931 | -- integer_array({}) -- TRUE | |
932 | -- | |
933 | 12 | |
934 | 12 | if not sequence(x) then |
935 | 1 | return 0 |
936 | end if | |
937 | ||
938 | 11 | for i = 1 to length(x) do |
939 | 23 | if not integer(x[i]) then |
940 | 2 | return 0 |
941 | end if | |
942 | 21 | end for |
943 | 9 | return 1 |
944 | end type | |
945 | ||
946 | --** | |
947 | -- Returns: | |
948 | -- TRUE if argument is a sequence that only contains zero or more characters. | |
949 | -- | |
950 | -- Comment: | |
951 | -- A 'character' is defined as a positive integer or zero. This is a broad | |
952 | -- definition that may be refined once proper UNICODE support is implemented. | |
953 | -- | |
954 | -- Example 1: | |
955 | -- | |
956 | -- t_text(-1) -- FALSE (not a sequence) | |
957 | -- t_text("abc") -- TRUE (all single characters) | |
958 | -- t_text({1, 2, "abc"}) -- FALSE (contains a sequence) | |
959 | -- t_text({1, 2, 9.7}) -- FALSE (contains a non-integer) | |
960 | -- t_text({1, 2, 'a'}) -- TRUE | |
961 | -- t_text({1, -2, 'a'}) -- FALSE (contains a negative integer) | |
962 | -- t_text({}) -- TRUE | |
963 | -- | |
964 | 229 | |
965 | 229 | if not sequence(x) then |
966 | 1 | return 0 |
967 | end if | |
968 | ||
969 | 228 | for i = 1 to length(x) do |
970 | 222 | if not integer(x[i]) then |
971 | 2 | return 0 |
972 | end if | |
973 | 220 | if x[i] < 0 then |
974 | 1 | return 0 |
975 | end if | |
976 | 219 | end for |
977 | 225 | return 1 |
978 | end type | |
979 | ||
980 | --** | |
981 | -- Returns: | |
982 | -- TRUE if argument is a sequence that only contains zero or more numbers. | |
983 | -- | |
984 | -- Example 1: | |
985 | -- | |
986 | -- number_array(-1) -- FALSE (not a sequence) | |
987 | -- number_array("abc") -- TRUE (all single characters) | |
988 | -- number_array({1, 2, "abc"}) -- FALSE (contains a sequence) | |
989 | -- number_array(1, 2, 9.7}) -- TRUE | |
990 | -- number_array(1, 2, 'a'}) -- TRUE | |
991 | -- number_array({}) -- TRUE | |
992 | -- | |
993 | 193 | |
994 | 193 | if not sequence(x) then |
995 | 176 | return 0 |
996 | end if | |
997 | ||
998 | 17 | for i = 1 to length(x) do |
999 | 36 | if not atom(x[i]) then |
1000 | 1 | return 0 |
1001 | end if | |
1002 | 35 | end for |
1003 | 16 | return 1 |
1004 | end type | |
1005 | ||
1006 | --** | |
1007 | -- Returns: | |
1008 | -- TRUE if argument is a sequence that only contains zero or more sequences. | |
1009 | -- | |
1010 | -- Example 1: | |
1011 | -- | |
1012 | -- sequence_array(-1) -- FALSE (not a sequence) | |
1013 | -- sequence_array("abc") -- FALSE (all single characters) | |
1014 | -- sequence_array({1, 2, "abc"}) -- FALSE (contains some atoms) | |
1015 | -- sequence_array({1, 2, 9.7}) -- FALSE | |
1016 | -- sequence_array({1, 2, 'a'}) -- FALSE | |
1017 | -- sequence_array({"abc", {3.4, 99182.78737}}) -- TRUE | |
1018 | -- sequence_array({}) -- TRUE | |
1019 | -- | |
1020 | 7 | |
1021 | 7 | if not sequence(x) then |
1022 | 1 | return 0 |
1023 | end if | |
1024 | ||
1025 | 6 | for i = 1 to length(x) do |
1026 | 6 | if not sequence(x[i]) then |
1027 | 4 | return 0 |
1028 | end if | |
1029 | 2 | end for |
1030 | 2 | return 1 |
1031 | end type | |
1032 | ||
1033 | --** | |
1034 | -- Returns: | |
1035 | -- TRUE if argument is a sequence that only contains zero or more ASCII characters. | |
1036 | -- | |
1037 | -- Comment: | |
1038 | -- An ASCII 'character' is defined as a integer in the range [0 to 127]. | |
1039 | -- | |
1040 | -- Example 1: | |
1041 | -- | |
1042 | -- ascii_string(-1) -- FALSE (not a sequence) | |
1043 | -- ascii_string("abc") -- TRUE (all single ASCII characters) | |
1044 | -- ascii_string({1, 2, "abc"}) -- FALSE (contains a sequence) | |
1045 | -- ascii_string({1, 2, 9.7}) -- FALSE (contains a non-integer) | |
1046 | -- ascii_string({1, 2, 'a'}) -- TRUE | |
1047 | -- ascii_string({1, -2, 'a'}) -- FALSE (contains a negative integer) | |
1048 | -- ascii_string({}) -- TRUE | |
1049 | -- | |
1050 | 19 | |
1051 | 19 | if not sequence(x) then |
1052 | 1 | return 0 |
1053 | end if | |
1054 | ||
1055 | 18 | for i = 1 to length(x) do |
1056 | 28 | if not integer(x[i]) then |
1057 | 2 | return 0 |
1058 | end if | |
1059 | 26 | if x[i] < 0 then |
1060 | 0 | return 0 |
1061 | end if | |
1062 | 26 | if x[i] > 127 then |
1063 | 13 | return 0 |
1064 | end if | |
1065 | 13 | end for |
1066 | 3 | return 1 |
1067 | end type | |
1068 | ||
1069 | --** | |
1070 | -- Returns: | |
1071 | -- TRUE if argument is a sequence that only contains zero or more byte characters. | |
1072 | -- | |
1073 | -- Comment: | |
1074 | -- A byte 'character' is defined as a integer in the range [0 to 255]. | |
1075 | -- | |
1076 | -- Example 1: | |
1077 | -- | |
1078 | -- string(-1) -- FALSE (not a sequence) | |
1079 | -- string("abc'6") -- TRUE (all single byte characters) | |
1080 | -- string({1, 2, "abc'6"}) -- FALSE (contains a sequence) | |
1081 | -- string({1, 2, 9.7}) -- FALSE (contains a non-integer) | |
1082 | -- string({1, 2, 'a'}) -- TRUE | |
1083 | -- string({1, -2, 'a'}) -- FALSE (contains a negative integer) | |
1084 | -- string({}) -- TRUE | |
1085 | -- | |
1086 | 304 | |
1087 | 304 | if not sequence(x) then |
1088 | 52 | return 0 |
1089 | end if | |
1090 | ||
1091 | 252 | for i = 1 to length(x) do |
1092 | 10217 | if not integer(x[i]) then |
1093 | 10 | return 0 |
1094 | end if | |
1095 | 10207 | if x[i] < 0 then |
1096 | 1 | return 0 |
1097 | end if | |
1098 | 10206 | if x[i] > 255 then |
1099 | 0 | return 0 |
1100 | end if | |
1101 | 10206 | end for |
1102 | 241 | return 1 |
1103 | end type | |
1104 | ||
1105 | --** | |
1106 | -- value returned from [[:routine_id]]() | |
1107 | -- when the routine doesm't exist or is out of scope. | |
1108 | -- this is typically seen as -1 in legacy code. | |
1109 | 101 | public constant INVALID_ROUTINE_ID = routine_id("INVALID_ROUTINE_ID") |
1110 | ||
1111 | --** | |
1112 | -- to be used as a flag for no [[:routine_id]]() supplied. | |
1113 | 101 | public constant NO_ROUTINE_ID = -99999 |
1114 |