diff options
Diffstat (limited to 'str.lisp')
-rw-r--r-- | str.lisp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/str.lisp b/str.lisp new file mode 100644 index 0000000..e099e26 --- /dev/null +++ b/str.lisp @@ -0,0 +1,21 @@ +(in-package #:str) + +(declaim (optimize (speed 3) (safety 0))) + +(declaim (ftype (function ((or pathname string)) (values string &optional)) read-file)) +(defun read-file (path) + (with-open-file (file path) + (let* ((size (file-length file)) + (buf (make-string size))) + (read-sequence buf file) + buf))) + +(declaim (ftype (function (simple-string simple-string) (values (cons string) &optional)) split)) +(defun split (input delimiter) + (defun split-rec (result start) + (let ((next (search delimiter input :start2 start))) + (if next + (split-rec (queue:add result (subseq input start next)) (min (+ (length delimiter) next) + (length input))) + (queue:add result (subseq input start next))))) + (queue:to-list (split-rec (queue:new) 0))) |