diff options
author | Juan Manuel Tomás <jtomas1815@gmail.com> | 2023-03-12 14:32:50 -0300 |
---|---|---|
committer | Juan Manuel Tomás <jtomas1815@gmail.com> | 2023-03-12 14:32:50 -0300 |
commit | 3d6e80b447ef96cdac3aada1f2ca08073648294f (patch) | |
tree | b41f6a6a9d9d5747128750c56ce4db4597be7ee0 /str.lisp | |
parent | cf7dc2892c1f3a474b7c49f35cbab08bfa08ef71 (diff) | |
download | utils-3d6e80b447ef96cdac3aada1f2ca08073648294f.tar.gz utils-3d6e80b447ef96cdac3aada1f2ca08073648294f.zip |
Tidy up different stuff
Diffstat (limited to 'str.lisp')
-rw-r--r-- | str.lisp | 23 |
1 files changed, 11 insertions, 12 deletions
@@ -1,8 +1,8 @@ (in-package #:str) -(declaim (optimize (speed 3) (safety 1))) +(declaim (optimize speed)) -(declaim (ftype (function ((or pathname string)) (values string &optional)) read-file)) +(declaim (ftype (function ((or pathname string)) (values simple-string &optional)) read-file)) (defun read-file (path) (with-open-file (file path) (let* ((size (file-length file)) @@ -10,17 +10,17 @@ (read-sequence buf file) buf))) -(declaim (ftype (function (simple-string simple-string) (values (cons string) &optional)) split)) +(declaim (ftype (function (simple-string simple-string) (values (cons simple-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))) + (labels ((split-rec (result start) + (let ((next (search delimiter input :start2 start))) + (if next + (split-rec (queue:add result (subseq input start next)) (min (the fixnum (+ (length delimiter) next)) + (the fixnum (length input)))) + (queue:add result (subseq input start next)))))) + (queue:to-list (split-rec (queue:new) 0)))) -(declaim (ftype (function ((cons character)) (values simple-string &optional)) from-list)) +(declaim (ftype (function ((or null (cons character))) (values simple-string &optional)) from-list)) (defun from-list (lst) (let ((str (make-string (length lst))) (i 0)) @@ -28,4 +28,3 @@ (setf (char str i) item) (incf i)) str)) - |