| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- (in-package :cl-user)
- (defpackage #:assboard.utils
- (:use :cl)
- (:export
- #:+project-path+
- #:starts-with
- #:replace-all))
- (in-package :assboard.utils)
- (defmacro aget (key alist)
- `(cdr (assoc ,key ,alist :test #'equal)))
- (defmethod yason:encode ((symbol symbol) &optional (stream *standard-output*))
- (yason:encode (s-sql:to-sql-name symbol) stream))
- (defparameter +project-path+
- (asdf:component-pathname (asdf:find-system '#:assboard)))
- (defun starts-with (with-what str)
- (let ((len (min (length str) (length with-what))))
- (equal (subseq str 0 len)
- with-what)))
- (defun replace-all (string part replacement &key (test #'char=))
- "Returns a new string in which all the occurences of the part
- is replaced with replacement."
- (with-output-to-string (out)
- (loop with part-length = (length part)
- for old-pos = 0 then (+ pos part-length)
- for pos = (search part string
- :start2 old-pos
- :test test)
- do (write-string string out
- :start old-pos
- :end (or pos (length string)))
- when pos do (write-string replacement out)
- while pos)))
- (defun vec-to-hash (vec key-fn)
- (loop for val across vec
- with result = (make-hash-table :test #'equal :size (length vec))
- do (setf (gethash (funcall key-fn val) result) val)
- finally (return result)))
|