-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfuncs.a68
64 lines (49 loc) · 1.04 KB
/
funcs.a68
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
#
"warning: 1: value of BOOL denotation will be voided, in conditional-clause starting at "IF" in line 3."
I guessed it meant the TRUE would not be returned,
so I created the variable res for both functions.
#
PROC str includes = (CHAR includes, STRING str) BOOL: (
BOOL res := FALSE;
FOR i FROM 1 TO UPB str DO
IF str[i] = includes THEN
res := TRUE;
GO TO done
FI
OD;
done:
res
);
PROC str arr includes = (STRING item, [] STRING arr) BOOL: (
BOOL res := FALSE;
FOR i FROM 1 TO UPB arr DO
IF arr[i] = item THEN
res := TRUE;
GO TO done
FI
OD;
done:
res
);
PROC rtrim = (REF STRING str) STRING: (
STRING res := "";
CHAR last ch := str[UPB str];
WHILE last ch = " " DO
str := str[:UPB str - 1];
res +:= " ";
last ch := str[UPB str]
OD;
res
);
PROC only uppercase = (STRING str) BOOL: (
BOOL res := TRUE;
FOR i TO UPB str DO
CHAR ch = str[i];
IF str includes(ch, lower alphabet) THEN
res := FALSE;
GO TO done
FI
OD;
done:
res
)