;;;; string-utils.scm -*- Scheme -*- ;;;; Kon Lovett, Jul '18 ;;;; Kon Lovett, Aug '10 (module string-utils (;export string-fixed-length) (import scheme (chicken fixnum) (chicken type) (only memoized-string make-string+) (only type-checks check-char check-string check-fixnum )) (: string-fixed-length (string fixnum #!rest --> string)) ; (define (string-fixed-length s n #!key (pad-char #\space) (trailing "...")) (let ( (rem (fx- (check-fixnum 'string-fixed-length n) (string-length (check-string 'string-fixed-length s)))) ) (if (positive? rem) (string-append s (make-string+ rem (check-char 'string-fixed-length pad-char))) (let ( (lim (fx- n (string-length (check-string 'string-fixed-length trailing)))) ) (if (positive? lim) (string-append (substring s 0 lim) trailing) trailing ) ) ) ) ) ) ;module string-utils