Re: split-sequence
- From: Brian Downing <see-signature@xxxxxxxxx>
- Date: Fri, 30 Dec 2005 13:05:24 GMT
In article <1135874537.504798.124120@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
justinhj <justinhj@xxxxxxxxx> wrote:
> The original was by Frank Bus I think. I've changed it so it strips
> leading spaces each item (the original did that too, but not the last
> item in the list)
>
> (defun split(string delimiter)
> (let ((start (search delimiter string)))
> (if (not start)
> (if (= 0 (length string))
> nil
> (list (string-trim '(#\Space) string)))
> (let ((value (string-trim '(#\Space) (subseq string 0 start)))
> (rest (subseq string (+ start (length delimiter)))))
> (if (= 0 (length value))
> (split rest delimiter)
> (cons value (split rest delimiter)))))))
More loopy, less consy, and will work on any kind of sequence if you
don't provide the :string-trim keyword:
(defun split-sequence-subsequence (subsequence sequence &key string-trim)
(loop for last = 0 then (+ pos (length subsequence))
for pos = (search subsequence sequence :start2 last)
for subseq = (subseq sequence last (or pos (length sequence)))
when string-trim do (setf subseq (string-trim string-trim subseq))
unless (zerop (length subseq)) collect subseq
while pos))
-bcd
--
*** Brian Downing <bdowning at lavos dot net>
.
- References:
- split-sequence
- From: Tin Gherdanarra
- Re: split-sequence
- From: Paolo Amoroso
- Re: split-sequence
- From: justinhj
- split-sequence
- Prev by Date: Re: LELISP (-->LISP) --> C/C++ or other common language
- Next by Date: Re: LELISP (-->LISP) --> C/C++ or other common language
- Previous by thread: Re: split-sequence
- Next by thread: Re: split-sequence
- Index(es):
Relevant Pages
|