diff options
author | tilpner | 2018-08-12 21:15:24 +0200 |
---|---|---|
committer | tilpner | 2018-08-12 21:15:24 +0200 |
commit | 488e30c923d01d549fefd7e233459a086b35f543 (patch) | |
tree | 0292fbe8dbdd8a3628fcc40778404efa819a098b /irc | |
parent | 068e52e766bf176adfe648dc9aa266f12c950471 (diff) | |
download | meep-488e30c923d01d549fefd7e233459a086b35f543.tar.gz meep-488e30c923d01d549fefd7e233459a086b35f543.tar.xz meep-488e30c923d01d549fefd7e233459a086b35f543.zip |
Add IO cleaning utilities
Diffstat (limited to 'irc')
-rw-r--r-- | irc/clean.rkt | 32 |
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)))) |