summaryrefslogtreecommitdiffstats
path: root/strsrch.scm
diff options
context:
space:
mode:
Diffstat (limited to 'strsrch.scm')
-rw-r--r--strsrch.scm22
1 files changed, 21 insertions, 1 deletions
diff --git a/strsrch.scm b/strsrch.scm
index b25c229..68bcf0e 100644
--- a/strsrch.scm
+++ b/strsrch.scm
@@ -1,6 +1,6 @@
;;; "MISCIO" Search for string from port.
; Written 1995, 1996 by Oleg Kiselyov (oleg@ponder.csci.unt.edu)
-; Modified 1996, 1997 by A. Jaffer (jaffer@ai.mit.edu)
+; Modified 1996, 1997, 1998 by A. Jaffer (jaffer@ai.mit.edu)
;
; This code is in the public domain.
@@ -121,3 +121,23 @@
(backtrack (+ 1 i) matched-substr-len))))))))
)
(match-1st-char)))
+
+(define (string-subst text old new . rest)
+ (define sub
+ (lambda (text)
+ (set! text
+ (cond ((equal? "" text) text)
+ ((substring? old text)
+ => (lambda (idx)
+ (string-append
+ (substring text 0 idx)
+ new
+ (sub (substring
+ text (+ idx (string-length old))
+ (string-length text))))))
+ (else text)))
+ (if (null? rest)
+ text
+ (apply string-subst text rest))))
+ (sub text))
+