
(defun white-space-p (c)
  "Returns T if character C consists of a space, tabulator or newline,
NIL otherwise."
  (member c '(#\Space #\Tab #\Newline)))

(defun split-string-words (string &key (start 0) (end nil) (max nil)
			   (separator #'white-space-p))
  "Returns an array containing the words from STRING as well as the number
of words returned.  Begins looking for words at offset START (default 0),
stops before END (default NIL for end of string) and will return a maximum
of MAX words (default NIL for no limit).  The SEPARATOR function should
return T for chars matching the wanted separators, or NIL (defaults to
WHITE-SPACE-P)."
  (declare (type fixnum start)
	   (type (or null fixnum) end max))
  (let ((array (make-array 0
                           :fill-pointer t
                           :adjustable t))
	(array-len 0)
	(s start))
    (declare (type fixnum array-len)
	     (type (or null fixnum s)))
    (unless end
      (setf end (length string)))
    (when max
      (decf max))
    (loop
       for i of-type fixnum from s below end
       until (and max (< max array-len))
       while (setf s (position-if-not separator string :start i))
       do
	 (setf i (or (position-if separator string :start s)
		     end))
	 (vector-push-extend (subseq string s i) array 1)
	 (incf array-len))
    (values array array-len)))
