On Wed, 5 Jan 2011 02:46:07 -0500
Matthew Mondor <mm_li...@pulsar-zone.net> wrote:
> Oh, of course it could be renamed to split-sequence or the like too,
> with instances of string replaced with sequence...
Cleaned up implementation attached, if it may serve (license as MIT/BSD
or LGPL as wanted)
--
Matt
(defun white-space-p (c)
"Returns T if character C consists of a space, tabulator or newline,
NIL otherwise."
(declare (type character c))
(member c '(#\Space #\Tab #\Newline)))
(defun split-sequence (sequence &key (start 0) (end nil) (max nil)
(separator #'white-space-p))
"Returns an array containing the components from SEQUENCE as well as
the number of components returned.
Begins looking for components at offset START (default 0),
stops before END (default NIL for end of sequence)
and will return a maximum of MAX components (default NIL for no limit).
The SEPARATOR function should return T for elements matching the wanted
separators, or NIL (defaults to #'WHITE-SPACE-P, for use with strings)."
(declare (type fixnum start)
(type (or null fixnum) end max))
(let ((array (make-array (or max 16)
:fill-pointer 0
:adjustable t))
(array-len 0)
(s start))
(declare (type fixnum array-len)
(type (or null fixnum s)))
(flet ((add-component (c)
(unless (vector-push c array)
(adjust-array array (* 2 (array-dimension array 0)))
(vector-push c array))))
(unless end
(setf end (length sequence)))
(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 sequence :start i))
do
(setf i (or (position-if separator sequence :start s)
end))
(add-component (subseq sequence s i))
(incf array-len)))
(values array array-len)))
------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and,
should the need arise, upgrade to a full multi-node Oracle RAC database
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Ecls-list mailing list
Ecls-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ecls-list