22 lines
830 B
Common Lisp
22 lines
830 B
Common Lisp
|
(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)))
|