X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=strings.lisp;h=a97c37ba551f5d2e436da7954d69a138e248232d;hb=035b66e6fe51559e2db70691ddcae4ab641a4873;hp=1832ff2a5dfa58f94564ee87f7b59587527c7b6e;hpb=d60bf2d464b393bdff8482bcaacd8d49957467ce;p=kmrcl.git diff --git a/strings.lisp b/strings.lisp index 1832ff2..a97c37b 100644 --- a/strings.lisp +++ b/strings.lisp @@ -602,20 +602,24 @@ for characters in a string" (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))) + +(defun collapse-whitespace (s) + "Convert multiple whitespace characters to a single space character." + (declare (simple-string s) + (optimize (speed 3) (safety 0))) + (with-output-to-string (stream) + (do ((pos 0 (1+ pos)) + (in-white nil) + (len (length s))) + ((= pos len)) + (declare (fixnum pos len)) + (let ((c (schar s pos))) + (declare (character c)) (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))))) + ((kl:is-char-whitespace c) + (unless in-white + (write-char #\space stream)) + (setq in-white t)) + (t + (setq in-white nil) + (write-char c stream)))))))