pax_global_header 0000666 0000000 0000000 00000000064 14054057004 0014511 g ustar 00root root 0000000 0000000 52 comment=e1b91281e13e7e1490fdcaf7e8aeda04759ec3b7 split-sequence-2.0.1/ 0000775 0000000 0000000 00000000000 14054057004 0014452 5 ustar 00root root 0000000 0000000 split-sequence-2.0.1/.travis.yml 0000664 0000000 0000000 00000001107 14054057004 0016562 0 ustar 00root root 0000000 0000000 os: linux dist: bionic language: generic env: jobs: - LISP=sbcl - LISP=ccl - LISP=ecl - LISP=abcl - LISP=clisp - LISP=allegro - LISP=sbcl32 - LISP=ccl32 # - LISP=cmucl jobs: allow_failures: - env: LISP=sbcl32 - env: LISP=ccl32 # - env: LISP=cmucl install: - curl -L https://raw.githubusercontent.com/lispci/cl-travis/master/install.sh | sh script: - cl -e "(print (lisp-implementation-version))(terpri) (ql:quickload :split-sequence/tests :verbose t) (uiop:quit (if (5am:run! :split-sequence) 0 -1))" split-sequence-2.0.1/LICENSE 0000664 0000000 0000000 00000002060 14054057004 0015455 0 ustar 00root root 0000000 0000000 Copyright (C) 2001-2018, Arthur Lemmens et al. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. split-sequence-2.0.1/README.md 0000664 0000000 0000000 00000007247 14054057004 0015743 0 ustar 00root root 0000000 0000000 SPLIT-SEQUENCE ============== [SPLIT-SEQUENCE](http://cliki.net/split-sequence) is a member of the [Common Lisp Utilities](http://cliki.net/Common%20Lisp%20Utilities) family of programs, designed by community consensus. _Function_ __SPLIT-SEQUENCE, SPLIT-SEQUENCE-IF, SPLIT-SEQUENCE-IF-NOT__ __Syntax:__ __split-sequence__ _delimiter sequence `&key` count remove-empty-subseqs from-end start end test test-not key ⇒ list, index_ __split-sequence-if__ _predicate sequence `&key` count remove-empty-subseqs from-end start end key ⇒ list, index_ __split-sequence-if-not__ _predicate sequence `&key` count remove-empty-subseqs from-end start end key ⇒ list, index_ __Arguments and Values:__ _delimiter_—an _object_. _predicate_—a designator for a _function_ of one _argument_ that returns a _generalized boolean_. _sequence_—a _proper sequence_. _count_—an _integer_ or __nil__. The default is __nil__. _remove-empty-subseqs_—a _generalized boolean_. The default is _false_. _from-end_—a _generalized boolean_. The default is _false_. _start, end_—_bounding index designators_ of _sequence_. The defaults for _start_ and _end_ are __0__ and __nil__, respectively. _test_—a _designator_ for a _function_ of two _arguments_ that returns a _generalized boolean_. _test-not_—a _designator_ for a _function_ of two _arguments_ that returns a _generalized boolean_. _key_—a _designator_ for a _function_ of one _argument_, or __nil__. _list_—a _proper sequence_. _index_—an _integer_ greater than or equal to zero, and less than or equal to the _length_ of the _sequence_. __Description:__ Splits _sequence_ into a list of subsequences delimited by objects _satisfying the test_. _List_ is a list of sequences of the same kind as _sequence_ that has elements consisting of subsequences of _sequence_ that were delimited in the argument by elements _satisfying the test_. Index is an index into _sequence_ indicating the unprocessed region, suitable as an argument to [subseq](http://www.lispworks.com/documentation/HyperSpec/Body/f_subseq.htm) to continue processing in the same manner if desired. The _count_ argument, if supplied, limits the number of subsequences in the first return value; if more than _count_ delimited subsequences exist in _sequence_, the _count_ leftmost delimited subsequences will be in order in the first return value, and the second return value will be the index into _sequence_ at which processing stopped. If _from-end_ is non-null, _sequence_ is conceptually processed from right to left, accumulating the subsequences in reverse order; _from-end_ only makes a difference in the case of a non-null _count_ argument. In the presence of _from-end_, the _count_ rightmost delimited subsequences will be in the order that they are in _sequence_ in the first return value, and the second is the index indicating the end of the unprocessed region. The _start_ and _end_ keyword arguments permit a certain subsequence of the _sequence_ to be processed without the need for a copying stage; their use is conceptually equivalent to partitioning the subsequence delimited by _start_ and _end_, only without the need for copying. If _remove-empty-subseqs_ is null (the default), then empty subsequences will be included in the result. In all cases, the subsequences in the first return value will be in the order that they appeared in _sequence_. __Examples:__
SPLIT-SEQUENCE> (split-sequence #\Space "A stitch in time saves nine.")
⇒ ("A" "stitch" "in" "time" "saves" "nine.")
⇒ 28
SPLIT-SEQUENCE> (split-sequence #\, "foo,bar ,baz, foobar , barbaz,")
⇒ ("foo" "bar " "baz" " foobar " " barbaz" "")
⇒ 30
split-sequence-2.0.1/api.lisp 0000664 0000000 0000000 00000007476 14054057004 0016132 0 ustar 00root root 0000000 0000000 ;;;; -*- Mode: Lisp; indent-tabs-mode: nil -*-
(in-package :split-sequence)
(defun list-long-enough-p (list length)
(or (zerop length)
(not (null (nthcdr (1- length) list)))))
(defun check-bounds (sequence start end)
(progn
(check-type start unsigned-byte "a non-negative integer")
(check-type end (or null unsigned-byte) "a non-negative integer or NIL")
(typecase sequence
(list
(when end
(unless (<= start end)
(error "Wrong sequence bounds. START: ~S END: ~S" start end))
(unless (list-long-enough-p sequence end)
(error "The list is too short: END was ~S but the list is ~S elements long."
end (length sequence)))))
(t
(let ((length (length sequence)))
(unless end (setf end length))
(unless (<= start end length)
(error "Wrong sequence bounds. START: ~S END: ~S" start end)))))))
(define-condition simple-program-error (program-error simple-condition) ())
(defmacro check-tests (test test-p test-not test-not-p)
`(if ,test-p
(if ,test-not-p
(error (make-condition 'simple-program-error
:format-control "Cannot specify both TEST and TEST-NOT."))
(check-type ,test (or function (and symbol (not null)))))
(when ,test-not-p
(check-type ,test-not (or function (and symbol (not null)))))))
(declaim (ftype (function (&rest t) (values list unsigned-byte))
split-sequence split-sequence-if split-sequence-if-not))
(defun split-sequence (delimiter sequence &key (start 0) (end nil) (from-end nil)
(count nil) (remove-empty-subseqs nil)
(test #'eql test-p) (test-not nil test-not-p)
(key #'identity))
(check-bounds sequence start end)
(check-tests test test-p test-not test-not-p)
(etypecase sequence
(list (split-list delimiter sequence start end from-end count
remove-empty-subseqs test test-not key))
(vector (split-vector delimiter sequence start end from-end count
remove-empty-subseqs test test-not key))
#+(or abcl sbcl)
(extended-sequence (split-extended-sequence delimiter sequence start end from-end count
remove-empty-subseqs test test-not key))))
(defun split-sequence-if (predicate sequence &key (start 0) (end nil) (from-end nil)
(count nil) (remove-empty-subseqs nil) (key #'identity))
(check-bounds sequence start end)
(etypecase sequence
(list (split-list-if predicate sequence start end from-end count
remove-empty-subseqs key))
(vector (split-vector-if predicate sequence start end from-end count
remove-empty-subseqs key))
#+(or abcl sbcl)
(extended-sequence (split-extended-sequence-if predicate sequence start end from-end count
remove-empty-subseqs key))))
(defun split-sequence-if-not (predicate sequence &key (start 0) (end nil) (from-end nil)
(count nil) (remove-empty-subseqs nil) (key #'identity))
(check-bounds sequence start end)
(etypecase sequence
(list (split-list-if-not predicate sequence start end from-end count
remove-empty-subseqs key))
(vector (split-vector-if-not predicate sequence start end from-end count
remove-empty-subseqs key))
#+(or abcl sbcl)
(extended-sequence (split-extended-sequence-if-not predicate sequence start end from-end count
remove-empty-subseqs key))))
(pushnew :split-sequence *features*)
split-sequence-2.0.1/documentation.lisp 0000664 0000000 0000000 00000004153 14054057004 0020217 0 ustar 00root root 0000000 0000000 ;;;; -*- Mode: Lisp; indent-tabs-mode: nil -*-
(in-package :split-sequence)
(setf (documentation 'split-sequence 'function)
"Return a list of subsequences in seq delimited by delimiter.
If :remove-empty-subseqs is NIL, empty subsequences will be included
in the result; otherwise they will be discarded. All other keywords
work analogously to those for CL:SUBSTITUTE. In particular, the
behaviour of :from-end is possibly different from other versions of
this function; :from-end values of NIL and T are equivalent unless
:count is supplied. :count limits the number of subseqs in the main
resulting list. The second return value is an index suitable as an
argument to CL:SUBSEQ into the sequence indicating where processing
stopped.")
(setf (documentation 'split-sequence-if 'function)
"Return a list of subsequences in seq delimited by items satisfying
predicate.
If :remove-empty-subseqs is NIL, empty subsequences will be included
in the result; otherwise they will be discarded. All other keywords
work analogously to those for CL:SUBSTITUTE-IF. In particular, the
behaviour of :from-end is possibly different from other versions of
this function; :from-end values of NIL and T are equivalent unless
:count is supplied. :count limits the number of subseqs in the main
resulting list. The second return value is an index suitable as an
argument to CL:SUBSEQ into the sequence indicating where processing
stopped.")
(setf (documentation 'split-sequence-if-not 'function)
"Return a list of subsequences in seq delimited by items satisfying
\(CL:COMPLEMENT predicate).
If :remove-empty-subseqs is NIL, empty subsequences will be included
in the result; otherwise they will be discarded. All other keywords
work analogously to those for CL:SUBSTITUTE-IF-NOT. In particular,
the behaviour of :from-end is possibly different from other versions
of this function; :from-end values of NIL and T are equivalent unless
:count is supplied. :count limits the number of subseqs in the main
resulting list. The second return value is an index suitable as an
argument to CL:SUBSEQ into the sequence indicating where processing
stopped.")
split-sequence-2.0.1/extended-sequence.lisp 0000664 0000000 0000000 00000012160 14054057004 0020751 0 ustar 00root root 0000000 0000000 ;;;; -*- Mode: Lisp; indent-tabs-mode: nil -*-
(in-package :split-sequence)
;;; For extended sequences, we make the assumption that all extended sequences
;;; can be at most ARRAY-DIMENSION-LIMIT long. This seems to match what SBCL
;;; assumes about them.
;;; TODO test this code. This will require creating such an extended sequence.
(deftype extended-sequence ()
'(and sequence (not list) (not vector)))
(declaim (inline
split-extended-sequence split-extended-sequence-if split-extended-sequence-if-not
split-extended-sequence-from-end split-extended-sequence-from-start))
(declaim (ftype (function (&rest t) (values list unsigned-byte))
split-extended-sequence split-extended-sequence-if split-extended-sequence-if-not))
(declaim (ftype (function (function extended-sequence array-index
(or null fixnum) (or null fixnum) boolean)
(values list fixnum))
split-extended-sequence-from-start split-extended-sequence-from-end))
(defun split-extended-sequence-from-end (position-fn sequence start end count remove-empty-subseqs)
(declare (optimize (speed 3) (debug 0))
(type (function (extended-sequence fixnum) (or null fixnum)) position-fn))
(loop
:with length = (length sequence)
:with end = (or end length)
:for right := end :then left
:for left := (max (or (funcall position-fn sequence right) -1)
(1- start))
:unless (and (= right (1+ left)) remove-empty-subseqs)
:if (and count (>= nr-elts count))
:return (values (nreverse subseqs) right)
:else
:collect (subseq sequence (1+ left) right) into subseqs
:and :sum 1 :into nr-elts :of-type fixnum
:until (< left start)
:finally (return (values (nreverse subseqs) (1+ left)))))
(defun split-extended-sequence-from-start (position-fn sequence start end count remove-empty-subseqs)
(declare (optimize (speed 3) (debug 0))
(type (function (extended-sequence fixnum) (or null fixnum)) position-fn))
(loop
:with length = (length sequence)
:with end = (or end length)
:for left := start :then (1+ right)
:for right := (min (or (funcall position-fn sequence left) length)
end)
:unless (and (= right left) remove-empty-subseqs)
:if (and count (>= nr-elts count))
:return (values subseqs left)
:else
:collect (subseq sequence left right) :into subseqs
:and :sum 1 :into nr-elts :of-type fixnum
:until (>= right end)
:finally (return (values subseqs right))))
(defun split-extended-sequence-if
(predicate sequence start end from-end count remove-empty-subseqs key)
(if from-end
(split-extended-sequence-from-end (lambda (sequence end)
(position-if predicate sequence :end end :from-end t :key key))
sequence start end count remove-empty-subseqs)
(split-extended-sequence-from-start (lambda (sequence start)
(position-if predicate sequence :start start :key key))
sequence start end count remove-empty-subseqs)))
(defun split-extended-sequence-if-not
(predicate sequence start end from-end count remove-empty-subseqs key)
(if from-end
(split-extended-sequence-from-end (lambda (sequence end)
(position-if-not predicate sequence :end end :from-end t :key key))
sequence start end count remove-empty-subseqs)
(split-extended-sequence-from-start (lambda (sequence start)
(position-if-not predicate sequence :start start :key key))
sequence start end count remove-empty-subseqs)))
(defun split-extended-sequence
(delimiter sequence start end from-end count remove-empty-subseqs test test-not key)
(cond
((and (not from-end) (null test-not))
(split-extended-sequence-from-start (lambda (sequence start)
(position delimiter sequence :start start :key key :test test))
sequence start end count remove-empty-subseqs))
((and (not from-end) test-not)
(split-extended-sequence-from-start (lambda (sequence start)
(position delimiter sequence :start start :key key :test-not test-not))
sequence start end count remove-empty-subseqs))
((and from-end (null test-not))
(split-extended-sequence-from-end (lambda (sequence end)
(position delimiter sequence :end end :from-end t :key key :test test))
sequence start end count remove-empty-subseqs))
(t
(split-extended-sequence-from-end (lambda (sequence end)
(position delimiter sequence :end end :from-end t :key key :test-not test-not))
sequence start end count remove-empty-subseqs))))
split-sequence-2.0.1/list.lisp 0000664 0000000 0000000 00000011564 14054057004 0016325 0 ustar 00root root 0000000 0000000 ;;;; -*- Mode: Lisp; indent-tabs-mode: nil -*-
(in-package :split-sequence)
(declaim (inline
collect-until count-while
split-list split-list-if split-list-if-not
split-list-from-end split-list-from-start split-list-internal))
(declaim (ftype (function (&rest t) (values list unsigned-byte))
split-list split-list-if split-list-if-not))
(declaim (ftype (function (function list unsigned-byte (or null unsigned-byte) (or null unsigned-byte)
boolean)
(values list unsigned-byte))
split-list-from-start split-list-from-end split-list-internal))
(defun collect-until (predicate list end)
"Collect elements from LIST until one that satisfies PREDICATE is found.
At most END elements will be examined. If END is null, all elements will be examined.
Returns four values:
* The collected items.
* The remaining items.
* The number of elements examined.
* Whether the search ended by running off the end, instead of by finding a delimiter."
(let ((examined 0)
(found nil))
(flet ((examine (value)
(incf examined)
(setf found (funcall predicate value))))
(loop :for (value . remaining) :on list
:until (eql examined end)
:until (examine value)
:collect value :into result
:finally (return (values result
remaining
examined
(and (not found)
(or (null end)
(= end examined)))))))))
(defun count-while (predicate list end)
"Count the number of elements satisfying PREDICATE at the beginning of LIST.
At most END elements will be counted. If END is null, all elements will be examined."
(if end
(loop :for value :in list
:for i :below end
:while (funcall predicate value)
:summing 1)
(loop :for value :in list
:while (funcall predicate value)
:summing 1)))
(defun split-list-internal (predicate list start end count remove-empty-subseqs)
(let ((count count)
(done nil)
(index start)
(end (when end (- end start)))
(list (nthcdr start list)))
(flet ((should-collect-p (chunk)
(unless (and remove-empty-subseqs (null chunk))
(when (numberp count) (decf count))
t))
(gather-chunk ()
(multiple-value-bind (chunk remaining examined ran-off-end)
(collect-until predicate list end)
(incf index examined)
(when end (decf end examined))
(setf list remaining
done ran-off-end)
chunk)))
(values (loop :with chunk
:until (or done (eql 0 count))
:do (setf chunk (gather-chunk))
:when (should-collect-p chunk)
:collect chunk)
(+ index
(if remove-empty-subseqs
(count-while predicate list end) ; chew off remaining empty seqs
0))))))
(defun split-list-from-end (predicate list start end count remove-empty-subseqs)
(let ((length (length list)))
(multiple-value-bind (result index)
(split-list-internal predicate (reverse list)
(if end (- length end) 0)
(- length start) count remove-empty-subseqs)
(loop :for cons on result
:for car := (car cons)
:do (setf (car cons) (nreverse car)))
(values (nreverse result) (- length index)))))
(defun split-list-from-start (predicate list start end count remove-empty-subseqs)
(split-list-internal predicate list start end count remove-empty-subseqs))
(defun split-list-if (predicate list start end from-end count remove-empty-subseqs key)
(let ((predicate (lambda (x) (funcall predicate (funcall key x)))))
(if from-end
(split-list-from-end predicate list start end count remove-empty-subseqs)
(split-list-from-start predicate list start end count remove-empty-subseqs))))
(defun split-list-if-not (predicate list start end from-end count remove-empty-subseqs key)
(split-list-if (complement predicate) list start end from-end count remove-empty-subseqs key))
(defun split-list
(delimiter list start end from-end count remove-empty-subseqs test test-not key)
(let ((predicate (if test-not
(lambda (x) (not (funcall test-not delimiter (funcall key x))))
(lambda (x) (funcall test delimiter (funcall key x))))))
(if from-end
(split-list-from-end predicate list start end count remove-empty-subseqs)
(split-list-from-start predicate list start end count remove-empty-subseqs))))
split-sequence-2.0.1/original-message.txt 0000664 0000000 0000000 00000010614 14054057004 0020443 0 ustar 00root root 0000000 0000000 From ...
Path: supernews.google.com!sn-xit-02!sn-xit-03!supernews.com!news.tele.dk!193.190.198.17!newsfeeds.belnet.be!
news.belnet.be!skynet.be!newsfeed2.news.nl.uu.net!sun4nl!not-for-mail
From: Arthur Lemmens