wine-matrix/util.lisp

22 lines
830 B
Common Lisp
Raw Normal View History

2024-11-05 21:18:06 -08:00
(in-package :wine-matrix/util)
(defun whitespace-p (char)
"Return non-nil if CHAR is whitespace."
(or (eq char #\Space) (not (graphic-char-p char))))
(defun remove-leading-whitespace (string)
"Return a substring of STRING without any leading whitespace."
(loop for i upfrom 0 below (length string)
while (whitespace-p (aref string i))
finally (return (subseq string i))))
(defun remove-trailing-whitespace (string)
"Return a substring of STRING without any leading whitespace."
(loop for i downfrom (1- (length string)) downto 0
while (whitespace-p (aref string i))
finally (return (subseq string 0 (1+ i)))))
(defun trim-string (string)
"Return a substring of STRING without any leading or trailing whitespace."
(remove-trailing-whitespace (remove-leading-whitespace string)))