17 lines
662 B
Common Lisp
17 lines
662 B
Common Lisp
|
(in-package #:cl-forth)
|
||
|
|
||
|
(defun split-string (delimiter input-string)
|
||
|
"Splits INPUT-STRING into a list of tokens, using DELIMITER as the delimiter."
|
||
|
(let ((start 0)
|
||
|
(tokens '()))
|
||
|
(loop for i from 0 below (length input-string) ; Keep it below
|
||
|
for char = (char input-string i)
|
||
|
do (if (eql char delimiter)
|
||
|
(when (> i start)
|
||
|
(push (subseq input-string start i) tokens)
|
||
|
(setf start (1+ i)))))
|
||
|
;; Handle the last token if there is any
|
||
|
(when (> (length input-string) start)
|
||
|
(push (subseq input-string start (length input-string)) tokens))
|
||
|
(nreverse tokens)))
|