#include seq.cam ;N str.cam - a CAMILA library for the finite string STR data type ;A J.N. Oliveira (jno@di.uminho.pt) ;D ; This library provides a few functions useful in simple ; string manipulation. ; Note that strings in CAMILA (type STR) are of limited length. ; For longer strings resort to txt.cam. ; Last Update: 1999.11.11 ;E FUNC strMIN(s:STR-set):STR ; strMIN(s) computes least of a set of strings RETURN min-orio(chr(255),s); FUNC strCAT(l:STR-seq):STR ; ; strCAT(l) catenates all strings in sequence of strings l. ; RETURN if l==<> then "" else hd(l) ++ strCAT(tl(l)); FUNC strCenter(s:STR,l:INT):STR ; ; strCenter(s,l) centers s in a string of length l, ; the extra characters being " ". ; Pre-condition: l >= strlen(s) ; RETURN if l==strlen(s) then s else let (x=l.-strlen(s),m=x./2,r=rem(x,2),n=m.+r) in strcat(strFill(" ",m),s,strFill(" ",n)); FUNC strLeft(s:STR,l:INT):STR ; ; Ibidem strCenter(s,l) left-justifying instead of centering. ; Pre-condition: l >= strlen(s) ; RETURN if l==strlen(s) then s else strcat(strleft(s,l.-1)," "); FUNC strRight(s:STR,l:INT):STR ; ; Ibidem strCenter(s,l) right-justifying instead of centering. ; Pre-condition: l >= strlen(s) ; RETURN if l==strlen(s) then s else strcat(" ",strRight(s,l.-1)); FUNC strFill(s:STR,l:INT):STR ; ; strFill(s,l) replicates s l times. ; Pre-condition: l >= 0 ; RETURN if l==0 then "" else s ++ strFill(s,l.-1); FUNC strSeq2STR(l:STR-seq,s:STR):STR ; ; strSeq2STR(l) converts sequence of strings l into a single string, ; separated by s (typically, s=","). ; RETURN strCAT(seqAddSep(l,s)); FUNC strSet2STR(X:STR-set,s:STR):STR ; ; strSet2STR is the counterpart of strSeq2STR for finite sets. ; RETURN strSeq2STR(,s); FUNC strFF2index(ff:A->STR):A-seq ; ; strFF2index(ff) builds index of ff (range STR-increasing ordering). ; RETURN if ff==[] then <> else let (m=strMIN(ran(ff)), X={ a | a <- dom(ff): ff[a] == m }, l=< a | a <- X >) in l ^ strFF2index(ff\X);