Add substitute function

This commit is contained in:
Nikolay Puzanov 2022-11-30 18:02:43 +03:00
parent 877efd7f95
commit 01fc086e62

View File

@ -19,6 +19,7 @@
has-duplicates? find-duplicates
insert-between
string-replace-text
substitute
read-template
make-mux-selectors))
@ -194,6 +195,15 @@
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
;;; Returns list of strings (lines)
(define (read-template template-file template-format subst-list)
@ -204,10 +214,6 @@
(if (eof-object? s)
(reverse l)
(loop (cons s l)))))))))
(map (lambda (str) (fold (lambda (s out)
(string-replace-text
out
(format template-format (first s))
(format "~a" (second s))))
str subst-list))
(map (lambda (str)
(substitute str template-format subst-list))
ls)))