-#-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))
+ (previous nil))
+ ((null end)
+ (cond
+ ((null previous)
+ (list string))
+ (t
+ (incf previous)
+ (if (< previous len)
+ (push (subseq string previous) output)
+ (unless skip-terminal
+ (push "" output)))
+ (nreverse output))))
+ (declare (type fixnum pos len)
+ (type (or null fixnum) end previous))
+ (push (subseq string pos end) output)
+ (setq previous end)
+ (setq pos (1+ end))))
+