41 lines
1 KiB
Text
41 lines
1 KiB
Text
get "libhdr"
|
|
|
|
// Squeeze a string
|
|
let squeeze(in, ch, out) = valof
|
|
$( out%0 := 0
|
|
for i=1 to in%0
|
|
if i=1 | in%i~=ch | in%(i-1)~=ch
|
|
$( out%0 := out%0 + 1
|
|
out%(out%0) := in%i
|
|
$)
|
|
resultis out
|
|
$)
|
|
|
|
// Print string with brackets and length
|
|
let brackets(s) be
|
|
writef("%N: <<<%S>>>*N", s%0, s)
|
|
|
|
// Print original and collapsed version
|
|
let show(s, ch) be
|
|
$( let v = vec 1+255/BYTESPERWORD
|
|
writef("Character: '%C'*N", ch)
|
|
brackets(s)
|
|
brackets(squeeze(s, ch, v))
|
|
wrch('*N')
|
|
$)
|
|
|
|
let start() be
|
|
$( let s1=""
|
|
let s2="*"If I were two-faced, would I be wearing this one?*" --- Abraham Lincoln "
|
|
let s3="..1111111111111111111111111111111111111111111111111111111111111117777888"
|
|
let s4="I never give 'em hell, I just tell the truth, and they think it's hell. "
|
|
let s5=" --- Harry S Truman "
|
|
|
|
show(s1, ' ')
|
|
show(s2, '-')
|
|
show(s3, '7')
|
|
show(s4, '.')
|
|
show(s5, ' ')
|
|
show(s5, '-')
|
|
show(s5, 'r')
|
|
$)
|