From 488e30c923d01d549fefd7e233459a086b35f543 Mon Sep 17 00:00:00 2001 From: tilpner Date: Sun, 12 Aug 2018 21:15:24 +0200 Subject: Add IO cleaning utilities --- irc/clean.rkt | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 irc/clean.rkt (limited to 'irc') 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 ""])) + +(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)))) -- cgit v1.2.3