]> gitweb @ CieloNegro.org - Lucu.git/blobdiff - Network/HTTP/Lucu/Chunk.hs
Many bugfixes
[Lucu.git] / Network / HTTP / Lucu / Chunk.hs
index 342362c07959b21353d7334867277d4f285f9b45..b48727cc0f364fdbe3037cd759cbbf01476216a4 100644 (file)
@@ -1,35 +1,34 @@
+{-# LANGUAGE
+    UnicodeSyntax
+  #-}
 module Network.HTTP.Lucu.Chunk
-    ( chunkHeaderP  -- Num a => Parser a
-    , chunkFooterP  -- Parser ()
-    , chunkTrailerP -- Parser Headers
+    ( chunkHeaderP
+    , chunkFooterP
+    , chunkTrailerP
     )
     where
-
-import           Network.HTTP.Lucu.Headers
-import           Network.HTTP.Lucu.Parser
-import           Network.HTTP.Lucu.Parser.Http
-import           Numeric
-
-
-chunkHeaderP :: Num a => Parser a
-chunkHeaderP = do hexLen <- many1 hexDigit
+import Control.Applicative
+import Data.Attoparsec.Char8
+import Data.Bits
+import Network.HTTP.Lucu.Headers
+import Network.HTTP.Lucu.Parser.Http
+
+chunkHeaderP ∷ (Integral a, Bits a) ⇒ Parser a
+{-# INLINEABLE chunkHeaderP #-}
+chunkHeaderP = do len ← hexadecimal
                   extension
                   crlf
-
-                  let [(len, _)] = readHex hexLen
                   return len
     where
-      extension :: Parser ()
-      extension = do many $ do char ';'
-                               token
-                               char '='
-                               token <|> quotedStr
-                     return ()
-
-
-chunkFooterP :: Parser ()
-chunkFooterP = crlf >> return ()
+      extension ∷ Parser ()
+      extension
+          = skipMany ( char ';' *>
+                       token    *>
+                       char '=' *>
+                       (token <|> quotedStr) )
 
+chunkFooterP ∷ Parser ()
+chunkFooterP = crlf
 
-chunkTrailerP :: Parser Headers
+chunkTrailerP  Parser Headers
 chunkTrailerP = headersP