(defun is-string-empty (str)
(zerop (length str)))
+(defvar *whitespace-chars* '(#\space #\tab #\return #\linefeed))
+
(defun is-char-whitespace (c)
(declare (character c) (optimize (speed 3) (safety 0)))
(or (char= c #\Space) (char= c #\Tab) (char= c #\Return)
"Return t if string is all whitespace"
(every #'is-char-whitespace str))
+(defun string-right-trim-whitespace (str)
+ (string-right-trim *whitespace-chars* str))
+
+(defun string-left-trim-whitespace (str)
+ (string-left-trim *whitespace-chars* str))
+
+(defun string-trim-whitespace (str)
+ (string-trim *whitespace-chars* str))
+
(defun replaced-string-length (str repl-alist)
(declare (simple-string str)
(optimize (speed 3) (safety 0) (space 0)))
(push (subseq string token-start token-end) tokens)))))
+(defun match-unique-abbreviation (abbr strings)
+ "Returns position of ABBR in STRINGS. ABBR may be a unique abbreviation.
+Returns NIL if no match found."
+ (let ((len (length abbr))
+ (matches nil))
+ (dotimes (i (length strings))
+ (let* ((s (nth i strings))
+ (l (length s)))
+ (cond
+ ((= len l)
+ (when (string= abbr s)
+ (push (cons s i) matches)))
+ ((< len l)
+ (when (string= abbr (subseq s 0 len))
+ (push (cons s i) matches))))))
+ (when (= 1 (length matches))
+ (cdr (first matches)))))