From 0e6ad43b6ccdf3c67d1e2f6fe2dcfab3e4cc3552 Mon Sep 17 00:00:00 2001 From: Uko Kokņevičs Date: Mon, 13 Oct 2025 06:06:51 +0300 Subject: Improve define-tg-method --- src/strings.lisp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'src/strings.lisp') diff --git a/src/strings.lisp b/src/strings.lisp index 68289aa..b11c31c 100644 --- a/src/strings.lisp +++ b/src/strings.lisp @@ -3,11 +3,23 @@ (defpackage :ukkoclot/strings (:use :c2cl :iterate) (:import-from :cl-unicode :general-category) - (:export :escape-xml :is-tg-whitespace-str :lisp->snake-case :snake->lisp-case :starts-with :starts-with-ignore-case)) + (:export + :ends-with + :escape-xml + :is-tg-whitespace-str + :lisp->camel-case + :lisp->snake-case + :snake->lisp-case + :starts-with + :starts-with-ignore-case)) (in-package :ukkoclot/strings) ;; These are very inefficient but I don't care until I profile +(defun ends-with (str suffix) + (and (> (length str) (length suffix)) + (string= str suffix :start1 (- (length str) (length suffix))))) + (defun escape-xml (str &optional out) (if out (escape-xml% str out) @@ -36,6 +48,18 @@ (iter (for ch in-string str) (always (is-tg-whitespace ch)))) +(defun lisp->camel-case (str) + (with-output-to-string (out) + (let ((should-caps nil)) + (iter (for ch in-string str) + (cond ((char= ch #\-) + (setf should-caps t)) + (should-caps + (write-char (char-upcase ch) out) + (setf should-caps nil)) + (t + (write-char (char-downcase ch) out))))))) + (defun lisp->snake-case (str) (with-output-to-string (out) (loop for ch across str do -- cgit v1.2.3