(in-package #:str) (declaim (optimize speed)) (declaim (ftype (function ((or pathname string)) (values simple-string &optional)) read-file)) (declaim (ftype (function (simple-string simple-string) (values (cons simple-string) &optional)) split)) (declaim (ftype (function ((or null (cons character))) (values simple-string &optional)) from-list)) (defun read-file (path) (with-open-file (file path) (let* ((size (file-length file)) (buf (make-string size))) (read-sequence buf file) buf))) (defun split (input delimiter) (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)))) (defun from-list (lst) (let ((str (make-string (length lst))) (i 0)) (dolist (item lst) (setf (char str i) item) (incf i)) str)) (defun underscore->hyphen (str) (let ((result (make-string-output-stream))) (dotimes (i (length str)) (if (char= #\_ (char str i)) (format result "-") (format result "~a" (char str i)))) (get-output-stream-string result))) (defun pascal->kebab (str) (let ((result (make-string-output-stream))) (dotimes (i (length str)) (if (and (> i 0) (upper-case-p (char str i))) (format result "-~a" (char str i)) (format result "~a" (char str i)))) (get-output-stream-string result))) (defun upcase->pascal (str) (let ((result (make-string-output-stream))) (dotimes (i (length str)) (if (and (< 0 i) (upper-case-p (char str i)) (not (lower-case-p (char str (1- i)))) (or (= i (1- (length str))) (not (lower-case-p (char str (1+ i)))))) (format result "~a" (char-downcase (char str i))) (format result "~a" (char str i)))) (get-output-stream-string result)))