diff --git a/embddr/common.scm b/embddr/common.scm index 7efb175..9e6bbf9 100644 --- a/embddr/common.scm +++ b/embddr/common.scm @@ -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)))))))