-#-excl
-(defun delimited-string-to-list (sequence &optional (separator #\space))
- "Split a string by a delimitor"
- (loop
- with start = 0
- for end = (position separator sequence :start start)
- collect (subseq sequence start end)
- until (null end)
- do
- (setf start (1+ end))))
-
-#+excl
-(defun list-to-delimited-string (list &optional (separator #\space))
- (excl:list-to-delimited-string list separator))
+(defun #-allegro delimited-string-to-list
+ #+allegro my-delimited-string-to-list
+ (string &optional (separator #\space) skip-terminal)
+ "split a string with delimiter"
+ (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))
+ (type string string)
+ (type character separator))
+ (do* ((len (length string))
+ (output '())
+ (pos 0)
+ (end (position separator string :start pos :end len)
+ (position separator string :start pos :end len)))
+ ((null end)
+ (if (< pos len)
+ (push (subseq string pos) output)
+ (when (or (not skip-terminal) (zerop len))
+ (push "" output)))
+ (nreverse output))
+ (declare (type fixnum pos len)
+ (type (or null fixnum) end))
+ (push (subseq string pos end) output)
+ (setq pos (1+ end))))
+