1 ! Copyright (C) 2009 Bruno Deferrari
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel fry splitting ascii calendar accessors combinators
4 arrays classes.tuple math.order words assocs
5 irc.messages.base sequences ;
6 IN: irc.messages.parser
9 : split-at-first ( seq separators -- before after )
10 dupd '[ _ member? ] find [ cut 1 tail ] [ swap ] if ;
12 : split-trailing ( string -- string string/f ) ":" split1 ;
13 : remove-heading-: ( seq -- seq ) ":" ?head drop ;
15 : split-prefix ( string -- string/f string )
17 remove-heading-: " " split1
20 : split-message ( string -- prefix command parameters trailing )
21 split-prefix split-trailing
22 [ [ blank? ] trim " " split unclip swap ] dip ;
24 : sender ( irc-message -- sender )
25 prefix>> [ remove-heading-: "!" split-at-first drop ] [ f ] if* ;
28 : string>irc-message ( string -- irc-message )
30 [ [ irc>type new ] [ >>command ] bi ]
34 [ (>>prefix) ] [ fill-irc-message-slots ] [ swap >>line ] tri
35 now >>timestamp dup sender >>sender ;