]> gitweb.factorcode.org Git - factor.git/blobdiff - extra/irc/messages/parser/parser.factor
factor: trim using lists
[factor.git] / extra / irc / messages / parser / parser.factor
index ee126b2550ec247aed9361a5d101ca0a5b01ecc6..64abb07c3bf8ca91278112b79ed534b1a2dfd7cd 100644 (file)
@@ -1,28 +1,20 @@
 ! Copyright (C) 2009 Bruno Deferrari
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel fry splitting ascii calendar accessors combinators
-       arrays classes.tuple math.order words assocs
-       irc.messages.base sequences ;
+USING: accessors irc.messages.base kernel sequences splitting ;
 IN: irc.messages.parser
 
 <PRIVATE
 : split-at-first ( seq separators -- before after )
-    dupd '[ _ member? ] find [ cut 1 tail ] [ swap ] if ;
-
-: split-trailing ( string -- string string/f ) ":" split1 ;
-: remove-heading-: ( seq -- seq ) ":" ?head drop ;
-
-: split-prefix ( string -- string/f string )
-    dup ":" head? [
-        remove-heading-: " " split1
-    ] [ f swap ] if ;
+    dupd '[ _ member? ] find [ cut rest ] [ swap ] if ;
 
+! ":ircuser!n=user@isp.net JOIN :#factortest"
 : split-message ( string -- prefix command parameters trailing )
-    split-prefix split-trailing
-    [ [ blank? ] trim " " split unclip swap ] dip ;
+    ":" ?head [ " " split1 ] [ f swap ] if
+    ":" split1
+    [ split-words harvest unclip swap ] dip ;
 
 : sender ( irc-message -- sender )
-    prefix>> [ remove-heading-: "!" split-at-first drop ] [ f ] if* ;
+    prefix>> [ ":" ?head drop "!" split-at-first drop ] [ f ] if* ;
 PRIVATE>
 
 : string>irc-message ( string -- irc-message )
@@ -31,5 +23,5 @@ PRIVATE>
     [ >>parameters ]
     [ >>trailing ]
     tri*
-    [ (>>prefix) ] [ fill-irc-message-slots ] [ swap >>line ] tri
-    gmt >>timestamp dup sender >>sender ;
+    [ prefix<< ] [ fill-irc-message-slots ] [ swap >>line ] tri
+    dup sender >>sender ;