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
|
# SPAN -- Copy characters while they match a set
#
# B.Simon 25-Apr-88 Original
int procedure span (set, str, ic, outstr, maxch)
char set[ARB] # i: Set of characters used in matching
char str[ARB] # i: Input string
int ic # io: Index to input string character
char outstr[ARB] # o: Output string
int maxch # i: Maximum length of output string
#--
bool match
int jc, kc, setlen
int strlen()
begin
# Loop over characters in the input string
setlen = strlen (set)
for (jc = 1; str[ic] != EOS && jc <= maxch; ic = ic + 1) {
# See if the current character in the input string
# matches the characters in the set
match = false
do kc = 1, setlen {
if (str[ic] == set[kc]) {
match = true
break
}
}
# Copy character to the output string if it matches
if (! match)
break
outstr[jc] = str[ic]
jc = jc + 1
}
# Return number of characters in output string
outstr[jc] = EOS
return (jc - 1)
end
# NOSPAN -- Copy characters while they do not match a set
int procedure nospan (set, str, ic, outstr, maxch)
char set[ARB] # i: Set of characters used in matching
char str[ARB] # i: Input string
int ic # io: Index to input string character
char outstr[ARB] # o: Output string
int maxch # i: Maximum length of output string
#--
bool match
int jc, kc, setlen
int strlen()
begin
# Loop over characters in the input string
setlen = strlen (set)
for (jc = 1; str[ic] != EOS && jc <= maxch; ic = ic + 1) {
# See if the current character in the input string
# matches the characters in the set
match = false
do kc = 1, setlen {
if (str[ic] == set[kc]) {
match = true
break
}
}
# Copy character to the output string if it does not match
if (match)
break
outstr[jc] = str[ic]
jc = jc + 1
}
# Return number of characters in output string
outstr[jc] = EOS
return (jc - 1)
end
|