/usr/share/axiom-20170501/src/algebra/ISTRING.spad is in axiom-source 20170501-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 202 203 | )abbrev domain ISTRING IndexedString
++ Authors: Stephen Watt, Michael Monagan, Manuel Bronstein 1986 .. 1991
++ Description:
++ This domain implements low-level strings
IndexedString(mn) : SIG == CODE where
mn : Integer
B ==> Boolean
C ==> Character
I ==> Integer
N ==> NonNegativeInteger
U ==> UniversalSegment Integer
SIG ==> StringAggregate() with
hash : % -> I
++ hash(x) provides a hashing function for strings
CODE ==> add
-- These assume Character's Rep is Small I
Qelt ==> QENUM$Lisp
Qequal ==> EQUAL$Lisp
Qsetelt ==> QESET$Lisp
Qsize ==> QCSIZE$Lisp
Cheq ==> EQL$Lisp
Chlt ==> QSLESSP$Lisp
Chgt ==> QSGREATERP$Lisp
c: Character
cc: CharacterClass
new(n, c) == MAKE_-FULL_-CVEC(n, c)$Lisp
empty() == MAKE_-FULL_-CVEC(0$Lisp)$Lisp
empty?(s) == Qsize(s) = 0
#s == Qsize(s)
s = t == Qequal(s, t)
s < t == CGREATERP(t,s)$Lisp
concat(s:%,t:%) == STRCONC(s,t)$Lisp
copy s == COPY_-SEQ(s)$Lisp
insert(s:%, t:%, i:I) == concat(concat(s(mn..i-1), t), s(i..))
coerce(s:%):OutputForm == outputForm(s pretend String)
minIndex s == mn
upperCase_! s == map_!(upperCase, s)
lowerCase_! s == map_!(lowerCase, s)
latex s == concat("\mbox{``", concat(s pretend String, "''}"))
replace(s, sg, t) ==
l := lo(sg) - mn
m := #s
n := #t
h:I := if hasHi sg then hi(sg) - mn else maxIndex s - mn
l < 0 or h >= m or h < l-1 => error "index out of range"
r := new((m-(h-l+1)+n)::N, space$C)
for k in 0.. for i in 0..l-1 repeat Qsetelt(r, k, Qelt(s, i))
for k in k.. for i in 0..n-1 repeat Qsetelt(r, k, Qelt(t, i))
for k in k.. for i in h+1..m-1 repeat Qsetelt(r, k, Qelt(s, i))
r
setelt(s:%, i:I, c:C) ==
i < mn or i > maxIndex(s) => error "index out of range"
Qsetelt(s, i - mn, c)
c
substring?(part, whole, startpos) ==
np:I := Qsize part
nw:I := Qsize whole
(startpos := startpos - mn) < 0 => error "index out of bounds"
np > nw - startpos => false
for ip in 0..np-1 for iw in startpos.. repeat
not Cheq(Qelt(part, ip), Qelt(whole, iw)) => return false
true
position(s:%, t:%, startpos:I) ==
(startpos := startpos - mn) < 0 => error "index out of bounds"
startpos >= Qsize t => mn - 1
r:I := STRPOS(s, t, startpos, NIL$Lisp)$Lisp
EQ(r, NIL$Lisp)$Lisp => mn - 1
r + mn
position(c: Character, t: %, startpos: I) ==
(startpos := startpos - mn) < 0 => error "index out of bounds"
startpos >= Qsize t => mn - 1
for r in startpos..Qsize t - 1 repeat
if Cheq(Qelt(t, r), c) then return r + mn
mn - 1
position(cc: CharacterClass, t: %, startpos: I) ==
(startpos := startpos - mn) < 0 => error "index out of bounds"
startpos >= Qsize t => mn - 1
for r in startpos..Qsize t - 1 repeat
if member?(Qelt(t,r), cc) then return r + mn
mn - 1
suffix?(s, t) ==
(m := maxIndex s) > (n := maxIndex t) => false
substring?(s, t, mn + n - m)
split(s, c) ==
n := maxIndex s
for i in mn..n while s.i = c repeat 0
l := empty()$List(%)
j:Integer -- j is conditionally intialized
while i <= n and (j := position(c, s, i)) >= mn repeat
l := concat(s(i..j-1), l)
for i in j..n while s.i = c repeat 0
if i <= n then l := concat(s(i..n), l)
reverse_! l
split(s, cc) ==
n := maxIndex s
for i in mn..n while member?(s.i,cc) repeat 0
l := empty()$List(%)
j:Integer -- j is conditionally intialized
while i <= n and (j := position(cc, s, i)) >= mn repeat
l := concat(s(i..j-1), l)
for i in j..n while member?(s.i,cc) repeat 0
if i <= n then l := concat(s(i..n), l)
reverse_! l
leftTrim(s, c) ==
n := maxIndex s
for i in mn .. n while s.i = c repeat 0
s(i..n)
leftTrim(s, cc) ==
n := maxIndex s
for i in mn .. n while member?(s.i,cc) repeat 0
s(i..n)
rightTrim(s, c) ==
for j in maxIndex s .. mn by -1 while s.j = c repeat 0
s(minIndex(s)..j)
rightTrim(s, cc) ==
for j in maxIndex s .. mn by -1 while member?(s.j, cc) repeat 0
s(minIndex(s)..j)
concat l ==
t := new(+/[#s for s in l], space$C)
i := mn
for s in l repeat
copyInto_!(t, s, i)
i := i + #s
t
copyInto_!(y, x, s) ==
m := #x
n := #y
s := s - mn
s < 0 or s+m > n => error "index out of range"
RPLACSTR(y, s, m, x, 0, m)$Lisp
y
elt(s:%, i:I) ==
i < mn or i > maxIndex(s) => error "index out of range"
Qelt(s, i - mn)
elt(s:%, sg:U) ==
l := lo(sg) - mn
h := if hasHi sg then hi(sg) - mn else maxIndex s - mn
l < 0 or h >= #s => error "index out of bound"
SUBSTRING(s, l, max(0, h-l+1))$Lisp
hash(s:$):Integer ==
n:I := Qsize s
zero? n => 0
(n = 1) => ord(s.mn)
ord(s.mn) * ord s(mn+n-1) * ord s(mn + n quo 2)
match(pattern,target,wildcard) ==
stringMatch(pattern,target,CHARACTER(wildcard)$Lisp)$Lisp
match?(pattern, target, dontcare) ==
n := maxIndex pattern
p := position(dontcare, pattern, m := minIndex pattern)::N
p = m-1 => pattern = target
(p ^= m) and not prefix?(pattern(m..p-1), target) => false
i := p -- index into target
q := position(dontcare, pattern, p + 1)::N
while q ^= m-1 repeat
s := pattern(p+1..q-1)
i := position(s, target, i)::N
i = m-1 => return false
i := i + #s
p := q
q := position(dontcare, pattern, q + 1)::N
(p ^= n) and not suffix?(pattern(p+1..n), target) => false
true
|