summaryrefslogtreecommitdiff
path: root/irc
diff options
context:
space:
mode:
Diffstat (limited to 'irc')
-rw-r--r--irc/clean.rkt32
1 files changed, 32 insertions, 0 deletions
diff --git a/irc/clean.rkt b/irc/clean.rkt
new file mode 100644
index 0000000..09c2f93
--- /dev/null
+++ b/irc/clean.rkt
@@ -0,0 +1,32 @@
+#lang racket/base
+(require irc/command
+ racket/sequence racket/function racket/format)
+(provide (all-defined-out))
+
+(define (short-arg? v)
+ (or (string? v) (symbol? v) (number? v)))
+
+(define (ensure-all-short v)
+ (unless (andmap short-arg? v)
+ (error-user "You may only supply short (string, symbol, number) arguments")))
+
+(define (stringify v)
+ (cond [(string? v) (clean-control v)]
+ [(symbol? v) (clean-control (symbol->string v))]
+ [(number? v) (~a v)]
+ [else "<invalid>"]))
+
+(define (clean-control s)
+ (list->string
+ (sequence->list
+ (sequence-filter (negate char-iso-control?)
+ (in-string s)))))
+
+; insert zero-width space to prevent clients from notifying a user
+(define (break-highlight s)
+ (if (zero? (string-length s))
+ s
+ (string-append
+ (substring s 0 1)
+ "\u200B"
+ (substring s 1))))