summaryrefslogtreecommitdiff
path: root/str.lisp
diff options
context:
space:
mode:
authorJuan Manuel Tomás <jtomas1815@gmail.com>2023-07-24 00:09:53 -0300
committerJuan Manuel Tomás <jtomas1815@gmail.com>2023-07-24 00:09:53 -0300
commitbb4b2bc484ed1d827d707a5a50b234d6994af90c (patch)
tree832ec90bf0f34252447c3fd49311d3af3e319d56 /str.lisp
parent3d6e80b447ef96cdac3aada1f2ca08073648294f (diff)
downloadutils-main.tar.gz
utils-main.zip
Add char, color and name transformersHEADmain
Diffstat (limited to 'str.lisp')
-rw-r--r--str.lisp39
1 files changed, 34 insertions, 5 deletions
diff --git a/str.lisp b/str.lisp
index aee3604..e00fb0f 100644
--- a/str.lisp
+++ b/str.lisp
@@ -1,8 +1,10 @@
(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))
@@ -10,17 +12,16 @@
(read-sequence buf file)
buf)))
-(declaim (ftype (function (simple-string simple-string) (values (cons simple-string) &optional)) split))
(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))))
+ (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 ((or null (cons character))) (values simple-string &optional)) from-list))
(defun from-list (lst)
(let ((str (make-string (length lst)))
(i 0))
@@ -28,3 +29,31 @@
(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)))