X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Network%2FHTTP%2FLucu%2FChunk.hs;h=25d69078b79387a8afc6aad93fcb02dfb65f4b70;hb=ca338174155913a969808d7b20193973394e474e;hp=44f2ae4c16890bc3df3b4064938c378335d2af9c;hpb=b340a77fa7bd051dd13a41d0a5b1ad30220bc6b6;p=Lucu.git diff --git a/Network/HTTP/Lucu/Chunk.hs b/Network/HTTP/Lucu/Chunk.hs index 44f2ae4..25d6907 100644 --- a/Network/HTTP/Lucu/Chunk.hs +++ b/Network/HTTP/Lucu/Chunk.hs @@ -1,36 +1,35 @@ --- #hide +{-# 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 + extension ∷ Parser () + extension = skipMany $ + do _ ← char ';' + _ ← token + _ ← char '=' + _ ← token <|> quotedStr return () +chunkFooterP ∷ Parser () +chunkFooterP = crlf -chunkFooterP :: Parser () -chunkFooterP = crlf >> return () - - -chunkTrailerP :: Parser Headers +chunkTrailerP ∷ Parser Headers chunkTrailerP = headersP