about summary refs log tree commit diff
path: root/prescheme-nim-local/lib/ps-string.scm
diff options
context:
space:
mode:
Diffstat (limited to 'prescheme-nim-local/lib/ps-string.scm')
-rw-r--r--prescheme-nim-local/lib/ps-string.scm25
1 files changed, 25 insertions, 0 deletions
diff --git a/prescheme-nim-local/lib/ps-string.scm b/prescheme-nim-local/lib/ps-string.scm
new file mode 100644
index 0000000..6e72793
--- /dev/null
+++ b/prescheme-nim-local/lib/ps-string.scm
@@ -0,0 +1,25 @@
+;;; ps-string: string utilities for Pre-Scheme
+
+(define (string-copy! target offset source start end)
+  (do ((tgt offset (+ tgt 1))
+       (src start (+ src 1)))
+      ((= src end))
+    (string-set! target tgt (string-ref source src)))
+  (unspecific))
+
+(define (string-append a b)
+  (let* ((len-a (string-length a))
+         (len-b (string-length b))
+         (target (make-string (+ len-a len-b))))
+    (string-copy! target 0 a 0 len-a)
+    (string-copy! target len-a b 0 len-b)
+    target))
+
+(define (string-repeat source n)
+  (let* ((len (string-length source))
+         (total (* len n))
+         (target (make-string total)))
+    (do ((ix 0 (+ ix len)))
+        ((= ix total))
+      (string-copy! target ix source 0 len))
+    target))