Skip to content

Instantly share code, notes, and snippets.

@funrep
Created September 21, 2013 20:36
Show Gist options
  • Save funrep/6653937 to your computer and use it in GitHub Desktop.
Save funrep/6653937 to your computer and use it in GitHub Desktop.
#lang racket
(provide split-message
get-nick
get-host
get-chan
get-action)
(define (split-message s)
(let ([ss (regexp-split #rx":" s)])
(match ss
[(list " " _ ...) (cdr ss)]
[_ ss])))
(define (split-bang s)
(regexp-split #rx"!" s))
(define (split-at s)
(regexp-split #rx"@" s))
(define (get-nick ss)
(regexp-replace #rx"[@~!&]" (car (split-bang (car ss))) ""))
(define (get-host ss)
(car (string-split
(cadr (split-at
(cadr (split-bang (car ss))))))))
(define (get-chan ss)
(if (null? ss)
"" ; FIXME
(if (chan? (car ss))
(car ss)
(get-chan (cdr ss)))))
(define (chan? s)
(match s
[(regexp #rx"^#.") #t]
[_ #f]))
(define (get-action ss)
(cadr (string-split (car ss))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment