From fa3f23105ddcf07c5900de47f19af43d1db1b597 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Mon, 20 Feb 2017 00:05:27 -0800 Subject: Import Upstream version 2c3 --- strsrch.scm | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'strsrch.scm') 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)) + -- cgit v1.2.3