X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=strings.lisp;h=a97c37ba551f5d2e436da7954d69a138e248232d;hb=8224e25bdd090129666f046627052323ec8f2dbd;hp=fd2f37ca071e8dc6a7f8f7b1a849cbf849d19738;hpb=7367c68a5daa2ef45c7adf1f4097596f84f5e4dd;p=kmrcl.git diff --git a/strings.lisp b/strings.lisp index fd2f37c..a97c37b 100644 --- a/strings.lisp +++ b/strings.lisp @@ -603,3 +603,23 @@ for characters in a string" +(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 + ((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)))))))