Add substitute function
This commit is contained in:
parent
877efd7f95
commit
01fc086e62
@ -19,6 +19,7 @@
|
|||||||
has-duplicates? find-duplicates
|
has-duplicates? find-duplicates
|
||||||
insert-between
|
insert-between
|
||||||
string-replace-text
|
string-replace-text
|
||||||
|
substitute
|
||||||
read-template
|
read-template
|
||||||
|
|
||||||
make-mux-selectors))
|
make-mux-selectors))
|
||||||
@ -194,6 +195,15 @@
|
|||||||
str))
|
str))
|
||||||
str))))))
|
str))))))
|
||||||
|
|
||||||
|
;;; Substitute template
|
||||||
|
(define (substitute text template-format subst-list)
|
||||||
|
(fold (lambda (s out)
|
||||||
|
(string-replace-text
|
||||||
|
out
|
||||||
|
(format template-format (first s))
|
||||||
|
(format "~a" (second s))))
|
||||||
|
text subst-list))
|
||||||
|
|
||||||
;;; Read template and substitute replacements
|
;;; Read template and substitute replacements
|
||||||
;;; Returns list of strings (lines)
|
;;; Returns list of strings (lines)
|
||||||
(define (read-template template-file template-format subst-list)
|
(define (read-template template-file template-format subst-list)
|
||||||
@ -204,10 +214,6 @@
|
|||||||
(if (eof-object? s)
|
(if (eof-object? s)
|
||||||
(reverse l)
|
(reverse l)
|
||||||
(loop (cons s l)))))))))
|
(loop (cons s l)))))))))
|
||||||
(map (lambda (str) (fold (lambda (s out)
|
(map (lambda (str)
|
||||||
(string-replace-text
|
(substitute str template-format subst-list))
|
||||||
out
|
|
||||||
(format template-format (first s))
|
|
||||||
(format "~a" (second s))))
|
|
||||||
str subst-list))
|
|
||||||
ls)))
|
ls)))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user