Add some useful functions

This commit is contained in:
Nikolay Puzanov 2022-12-06 15:05:21 +03:00
parent 0aef21a949
commit b9bbb4cec4

View File

@ -19,6 +19,8 @@
has-duplicates? find-duplicates
insert-between
string-replace-text
string-split-trim
get-word
substitute
read-template
@ -217,3 +219,22 @@
(map (lambda (str)
(substitute str template-format subst-list))
ls)))
;;; Split string and remove empty itemes
(define (string-split-trim str pred?)
(remove string-null?
(string-split str pred?)))
;;; Get word delimited by pred? from port
(define* (get-word port #:optional (pred? char-whitespace?))
(let get-word-rec ((chlist '()))
(let ((c (get-char port)))
(if (eof-object? c)
(if (null? chlist)
#f
(list->string (reverse chlist)))
(if (pred? c)
(if (null? chlist)
(get-word-rec chlist)
(list->string (reverse chlist)))
(get-word-rec (cons c chlist)))))))