From 3249a20b60e9652ec772f057e540f60bbcf1f024 Mon Sep 17 00:00:00 2001 From: colin Date: Mon, 20 Feb 2023 10:04:33 -0800 Subject: Add: with-checked-plist macro, some validtators, and refactored --- utilities.lisp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'utilities.lisp') diff --git a/utilities.lisp b/utilities.lisp index 7acdbca..fee21fe 100644 --- a/utilities.lisp +++ b/utilities.lisp @@ -37,3 +37,32 @@ (loop :for char :across nick :always (find char +user-nick-chars+ :test #'char-equal)))) + +(defun/t asciip (thing) + "T if THING is an ASCII character, NIL otherwise." + :tests + (eql (#\x) t) + (eql (#\ö) nil) + (eql (#\nul) t) + (eql (#\return) t) + (eql (nil) nil) + (eql ("foo") nil) + :end + (and (characterp thing) + (<= 0 (char-code thing) 127))) + +(defun/t urlify (string) + "Canonical transformation for strings that makes them appropriate for urls." + :tests + (equal ("THIS IS COOL") "this-is-cool") + (equal ("This is cool") "this-is-cool") + (equal ("Mc'this is κoöl ") "mc-this-is-o-l") + :end + (str:join + #\- + (str:split-omit-nulls + #\space + (substitute-if-not + #\space + (a:conjoin #'asciip #'alphanumericp) + (string-downcase string))))) -- cgit v1.2.3