diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2021-11-20 17:18:09 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2021-11-20 17:18:09 -0700 |
commit | 4342650ea28bffbcd41905b18350c4b0d478d774 (patch) | |
tree | ab57bdd4e125277b4ba52ee3a9ab84bad64abc3c /src/util.lisp | |
parent | ffef4da856cd374a3557341b3bb51f070aa8de6f (diff) | |
download | consfigurator-4342650ea28bffbcd41905b18350c4b0d478d774.tar.gz |
LINES: support trimming the lines
TRIMFUN will typically be STRING-TRIM, STRING-LEFT-TRIM or STRING-RIGHT-TRIM.
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Diffstat (limited to 'src/util.lisp')
-rw-r--r-- | src/util.lisp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/util.lisp b/src/util.lisp index 0bbf585..704a288 100644 --- a/src/util.lisp +++ b/src/util.lisp @@ -40,10 +40,12 @@ (declare (ignore args)) (values)) -(defun lines (text) +(defun lines (text &optional trimfun (trimchars '(#\Space #\Tab))) (with-input-from-string (stream text) (let (bolp buffer) - (flet ((reset () + (flet ((trim (line) + (if trimfun (funcall trimfun trimchars line) line)) + (reset () (setq bolp t buffer (make-array 0 :fill-pointer 0 :element-type 'character)))) @@ -53,7 +55,7 @@ for char = (read-char stream nil nil) if char if (member char '(#\Return #\Newline) :test #'char=) - collect buffer + collect (trim buffer) and do (reset) (when (char= char #\Return) (when-let ((next (peek-char nil stream nil nil))) @@ -63,7 +65,7 @@ (vector-push-extend char buffer) end else - unless bolp collect buffer end + unless bolp collect (trim buffer) end and do (loop-finish)))))) (defun unlines (lines) |