COVERAGE SUMMARY
FILE SUMMARY
NameExecutedRoutines%ExecutedLines%Unexecuted
/home/matt/eu/rds/include/std/types.e3030100.00%18719098.42%3
ROUTINE SUMMARY
RoutineExecutedLinesUnexecuted
ascii_string()111291.67%1
char_test()222395.65%1
string()111291.67%1
boolean()22100.00%0
get_charsets()66100.00%0
integer_array()88100.00%0
number_array()88100.00%0
sequence_array()88100.00%0
set_charsets()77100.00%0
set_default_charsets()2222100.00%0
t_alnum()22100.00%0
t_alpha()22100.00%0
t_ascii()22100.00%0
t_boolean()22100.00%0
t_bytearray()22100.00%0
t_cntrl()22100.00%0
t_consonant()22100.00%0
t_digit()22100.00%0
t_display()22100.00%0
t_graph()22100.00%0
t_identifier()66100.00%0
t_lower()22100.00%0
t_print()22100.00%0
t_punct()22100.00%0
t_space()22100.00%0
t_specword()22100.00%0
t_text()1010100.00%0
t_upper()22100.00%0
t_vowel()22100.00%0
t_xdigit()22100.00%0
LINE COVERAGE DETAIL
#Executed
1
-- (c) Copyright - See License.txt
2
--
3
namespace types
4
5
--****
6
-- == Types - Extended
7
--
8
-- <>
9
10
--**
11
-- Object not assigned
12101
public constant OBJ_UNASSIGNED = 0
13
14
--**
15
-- Object is integer
16101
public constant OBJ_INTEGER = 1
17
18
--**
19
-- Object is atom
20101
public constant OBJ_ATOM = 2
21
22
--**
23
-- Object is sequence
24101
public constant OBJ_SEQUENCE = 3
25
26
27
--****
28
-- Signature:
29
-- function object(object x)
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
-- function integer(object x)
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
-- function atom(object x)
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
-- function sequence( object x)
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
124101
public constant FALSE = (1=0)
125
126
--**
127
-- Boolean TRUE value
128101
public constant TRUE = (1=1)
129
130
--**
131
-- Predefined character sets:
132
public enum
133101
CS_FIRST = 0,
134101
CS_Consonant,
135101
CS_Vowel,
136101
CS_Hexadecimal,
137101
CS_Whitespace,
138101
CS_Punctuation,
139101
CS_Printable,
140101
CS_Displayable,
141101
CS_Lowercase,
142101
CS_Uppercase,
143101
CS_Alphanumeric,
144101
CS_Identifier,
145101
CS_Alphabetic,
146101
CS_ASCII,
147101
CS_Control,
148101
CS_Digit,
149101
CS_Graphic,
150101
CS_Bytes,
151101
CS_SpecWord,
152101
CS_Boolean,
153101
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
192879
193
integer lChr
194
195879
if integer(test_data) then
196722
if sequence(char_set[1]) then
197666
for j = 1 to length(char_set) do
198775
if test_data >= char_set[j][1] and test_data <= char_set[j][2] then return TRUE end if
199416
end for
200307
return FALSE
201
else
20256
return find(test_data, char_set) > 0
203
end if
204157
elsif sequence(test_data) then
205142
if length(test_data) = 0 then return FALSE end if
206126
for i = 1 to length(test_data) label "NXTCHR" do
207283
if sequence(test_data[i]) then return FALSE end if
208280
if not integer(test_data[i]) then return FALSE end if
209276
lChr = test_data[i]
210276
if sequence(char_set[1]) then
211229
for j = 1 to length(char_set) do
212332
if lChr >= char_set[j][1] and lChr <= char_set[j][2] then continue "NXTCHR" end if
213163
end for
214
else
21547
if find(lChr, char_set) > 0 then continue "NXTCHR" end if
216
end if
21779
return FALSE
2180
end for
21940
return TRUE
220
else
22115
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
235101
236101
Defined_Sets = repeat(0, CS_LAST - CS_FIRST - 1)
237101
Defined_Sets[CS_Alphabetic ] = {{'a', 'z'}, {'A', 'Z'}}
238101
Defined_Sets[CS_Alphanumeric] = {{'0', '9'}, {'a', 'z'}, {'A', 'Z'}}
239101
Defined_Sets[CS_Identifier] = {{'0', '9'}, {'a', 'z'}, {'A', 'Z'}, {'_', '_'}}
240101
Defined_Sets[CS_Uppercase ] = {{'A', 'Z'}}
241101
Defined_Sets[CS_Lowercase ] = {{'a', 'z'}}
242101
Defined_Sets[CS_Printable ] = {{' ', '~'}}
243101
Defined_Sets[CS_Displayable ] = {{' ', '~'}, " ", "\t\t", "\n\n", "\r\r", {8,8}, {7,7} }
244101
Defined_Sets[CS_Whitespace ] = " \t\n\r" & 11 & 160
245101
Defined_Sets[CS_Consonant ] = "bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ"
246101
Defined_Sets[CS_Vowel ] = "aeiouAEIOU"
247101
Defined_Sets[CS_Hexadecimal ] = {{'0', '9'}, {'A', 'F'},{'a', 'f'}}
248101
Defined_Sets[CS_Punctuation ] = {{' ', '/'}, {':', '?'}, {'[', '`'}, {'{', '~'}}
249101
Defined_Sets[CS_Control ] = {{0, 31}, {127, 127}}
250101
Defined_Sets[CS_ASCII ] = {{0, 127}}
251101
Defined_Sets[CS_Digit ] = {{'0', '9'}}
252101
Defined_Sets[CS_Graphic ] = {{'!', '~'}}
253101
Defined_Sets[CS_Bytes ] = {{0, 255}}
254101
Defined_Sets[CS_SpecWord ] = "_"
255101
Defined_Sets[CS_Boolean ] = {TRUE,FALSE}
256101
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
2781
279
sequence result_
280
2811
result_ = {}
2821
for i = CS_FIRST + 1 to CS_LAST - 1 do
28319
result_ = append(result_, {i, Defined_Sets[i]} )
28419
end for
285
2861
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
3173
3183
for i = 1 to length(charset_list) do
31921
if sequence(charset_list[i]) and length(charset_list[i]) = 2 then
32021
if integer(charset_list[i][1]) and charset_list[i][1] > CS_FIRST and charset_list[i][1] < CS_LAST then
32121
Defined_Sets[charset_list[i][1]] = charset_list[i][2]
322
end if
323
end if
32421
end for
3253
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
352700
353
-- A boolean is a value that is either zero or one.
354
355700
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
--
3756
3766
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
40220
40320
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
43310
434
-- Test to make sure the first character is not a number
43510
if t_digit(test_data) then
4362
return 0
4378
elsif sequence(test_data) and length(test_data) > 0 and t_digit(test_data[1]) then
4382
return 0
439
end if
440
4416
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
46751
46851
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
49416
49516
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
52217
52317
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
551174
552174
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
58119
58219
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
61723
61823
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
65018
65118
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
679144
680144
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
71052
71152
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
7417
7427
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
77021
77121
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
79831
79931
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
827219
828219
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
85623
85723
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
88514
88614
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
91414
91514
return char_test(test_data, Defined_Sets[CS_Consonant])
916
end type
917
918101
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
--
93312
93412
if not sequence(x) then
9351
return 0
936
end if
937
93811
for i = 1 to length(x) do
93923
if not integer(x[i]) then
9402
return 0
941
end if
94221
end for
9439
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
--
964229
965229
if not sequence(x) then
9661
return 0
967
end if
968
969228
for i = 1 to length(x) do
970222
if not integer(x[i]) then
9712
return 0
972
end if
973220
if x[i] < 0 then
9741
return 0
975
end if
976219
end for
977225
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
--
993193
994193
if not sequence(x) then
995176
return 0
996
end if
997
99817
for i = 1 to length(x) do
99936
if not atom(x[i]) then
10001
return 0
1001
end if
100235
end for
100316
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
--
10207
10217
if not sequence(x) then
10221
return 0
1023
end if
1024
10256
for i = 1 to length(x) do
10266
if not sequence(x[i]) then
10274
return 0
1028
end if
10292
end for
10302
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
--
105019
105119
if not sequence(x) then
10521
return 0
1053
end if
1054
105518
for i = 1 to length(x) do
105628
if not integer(x[i]) then
10572
return 0
1058
end if
105926
if x[i] < 0 then
10600
return 0
1061
end if
106226
if x[i] > 127 then
106313
return 0
1064
end if
106513
end for
10663
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
--
1086304
1087304
if not sequence(x) then
108852
return 0
1089
end if
1090
1091252
for i = 1 to length(x) do
109210217
if not integer(x[i]) then
109310
return 0
1094
end if
109510207
if x[i] < 0 then
10961
return 0
1097
end if
109810206
if x[i] > 255 then
10990
return 0
1100
end if
110110206
end for
1102241
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.
1109101
public constant INVALID_ROUTINE_ID = routine_id("INVALID_ROUTINE_ID")
1110
1111
--**
1112
-- to be used as a flag for no [[:routine_id]]() supplied.
1113101
public constant NO_ROUTINE_ID = -99999
1114