summaryrefslogtreecommitdiff
path: root/utilities.lisp
diff options
context:
space:
mode:
Diffstat (limited to 'utilities.lisp')
-rw-r--r--utilities.lisp29
1 files changed, 29 insertions, 0 deletions
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)))))