Add some useful functions
This commit is contained in:
parent
0aef21a949
commit
b9bbb4cec4
@ -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)))))))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user