summaryrefslogtreecommitdiffstats
path: root/strsrch.scm
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2017-02-20 00:05:27 -0800
committerBryan Newbold <bnewbold@robocracy.org>2017-02-20 00:05:27 -0800
commitfa3f23105ddcf07c5900de47f19af43d1db1b597 (patch)
treeb2c6cce6b97698098f50cbc78c23fdc0f8d401ab /strsrch.scm
parentf24b9140d6f74804d5599ec225717d38ca443813 (diff)
downloadslib-fa3f23105ddcf07c5900de47f19af43d1db1b597.tar.gz
slib-fa3f23105ddcf07c5900de47f19af43d1db1b597.zip
Import Upstream version 2c3upstream/2c3
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))
+