]> gitweb @ CieloNegro.org - Lucu.git/blobdiff - Network/HTTP/Lucu/Chunk.hs
Destroy Data.Attoparsec.Parsable; use Data.Default instead
[Lucu.git] / Network / HTTP / Lucu / Chunk.hs
index 9ad41f86786c0cdf15aed8c03717426356a88d1a..c2135ef1105ae96e85f0f39db1a32240b7ee5929 100644 (file)
@@ -1,37 +1,37 @@
--- #hide
+{-# LANGUAGE
+    UnicodeSyntax
+  #-}
 module Network.HTTP.Lucu.Chunk
-    ( chunkHeaderP  -- Num a => Parser a
-    , chunkFooterP  -- Parser ()
-    , chunkTrailerP -- Parser Headers
+    ( chunkHeader
+    , chunkFooter
+    , chunkTrailer
     )
     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
-                  extension
-                  crlf
-
-                  let [(len, _)] = readHex hexLen
-                  return len
+import Control.Applicative
+import Data.Attoparsec.Char8
+import Data.Bits
+import Data.Default
+import Network.HTTP.Lucu.Headers
+import Network.HTTP.Lucu.Parser.Http
+
+chunkHeader ∷ (Integral a, Bits a) ⇒ Parser a
+{-# INLINEABLE chunkHeader #-}
+chunkHeader = do len ← hexadecimal
+                 extension
+                 crlf
+                 return len
     where
-      extension :: Parser ()
-      extension = do many $ do char ';'
-                               token
-                               char '='
-                               token <|> quotedStr
-                     return ()
-{-# SPECIALIZE chunkHeaderP :: Parser Int #-}
-
-
-chunkFooterP :: Parser ()
-chunkFooterP = crlf >> return ()
-
-
-chunkTrailerP :: Parser Headers
-chunkTrailerP = headersP
+      extension ∷ Parser ()
+      extension
+          = skipMany ( char ';' *>
+                       token    *>
+                       char '=' *>
+                       (token <|> quotedStr) )
+
+chunkFooter ∷ Parser ()
+{-# INLINE chunkFooter #-}
+chunkFooter = crlf
+
+chunkTrailer ∷ Parser Headers
+{-# INLINE chunkTrailer #-}
+chunkTrailer = def