From b9bbb4cec487711e7161d15fe6062ddaf9e2ddf4 Mon Sep 17 00:00:00 2001 From: Nikolay Puzanov Date: Tue, 6 Dec 2022 15:05:21 +0300 Subject: [PATCH] Add some useful functions --- embddr/common.scm | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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)))))))