ps-string.scm 740 B

1234567891011121314151617181920212223242526
  1. ;;; ps-string: string utilities for Pre-Scheme
  2. (define (string-copy! target offset source start end)
  3. (do ((tgt offset (+ tgt 1))
  4. (src start (+ src 1)))
  5. ((= src end))
  6. (string-set! target tgt (string-ref source src)))
  7. (unspecific))
  8. (define (string-append a b)
  9. (let* ((len-a (string-length a))
  10. (len-b (string-length b))
  11. (target (make-string (+ len-a len-b))))
  12. (string-copy! target 0 a 0 len-a)
  13. (string-copy! target len-a b 0 len-b)
  14. target))
  15. (define (string-repeat source n)
  16. (let* ((len (string-length source))
  17. (total (* len n))
  18. (target (make-string total)))
  19. (do ((ix 0 (+ ix len)))
  20. ((= ix total))
  21. (string-copy! target ix source 0 len))
  22. target))