From fec434a4e2d0ff65510581e461d87a945d25759a Mon Sep 17 00:00:00 2001 From: Uko Kokņevičs Date: Thu, 23 Oct 2025 10:17:00 +0300 Subject: Use serapeum's -> & defsubst --- src/strings.lisp | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) (limited to 'src/strings.lisp') diff --git a/src/strings.lisp b/src/strings.lisp index 04a20de..ab9f13c 100644 --- a/src/strings.lisp +++ b/src/strings.lisp @@ -4,6 +4,8 @@ (:documentation "String-oriented utilities.") (:use :c2cl :iterate) (:import-from :cl-unicode :general-category) + (:import-from :serapeum :->) + (:import-from :ukkoclot/src/streams :with-format-like-stream) (:export :escape-xml :is-tg-whitespace @@ -12,27 +14,20 @@ ;; These are very inefficient but I don't care until I profile -(defun escape-xml (str &optional out) - "Escape special XML characters in the STR. - -OUT is the output stream or `nil' for outputting to a string." - (if out - (escape-xml% str out) - (with-output-to-string (out) - (escape-xml% str out)))) - -(defun escape-xml% (str out) - "See `escape-xml'. - -OUT is always the stream." - (loop for ch across str do - (case ch - (#\< (write-string "<" out)) - (#\> (write-string ">" out)) - (#\& (write-string "&" out)) - (#\" (write-string """ out)) - (otherwise (write-char ch out))))) +(-> escape-xml (string &optional (or stream boolean)) (or string null)) +(defun escape-xml (str &optional out-spec) + "Escape special XML characters in the STR." + (with-format-like-stream (out out-spec) + (iter + (for ch in-string str) + (case ch + (#\< (write-string "<" out)) + (#\> (write-string ">" out)) + (#\& (write-string "&" out)) + (#\" (write-string """ out)) + (otherwise (write-char ch out)))))) +(-> is-tg-whitespace (character) boolean) (defun is-tg-whitespace (ch) "Checks if CH on its own would be considered whitespace by telegram." (let ((gc (general-category ch))) @@ -42,6 +37,7 @@ OUT is always the stream." (string= gc "Cc") ; Other, control (= (char-code ch) #x2800)))) ; BRAILLE PATTERN BLANK +(-> is-tg-whitespace-str (string) boolean) (defun is-tg-whitespace-str (str) "Checks if message containing just STR would be considered whitespace by telegram." (iter (for ch in-string str) -- cgit v1.2.3