X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Network%2FHTTP%2FLucu%2FChunk.hs;h=b48727cc0f364fdbe3037cd759cbbf01476216a4;hb=ece223c;hp=dd7465e2bf5ae5c15956c68f95138696bf3de996;hpb=d05d8c883eaca12ee621975a2b95c5ebdc2357d2;p=Lucu.git diff --git a/Network/HTTP/Lucu/Chunk.hs b/Network/HTTP/Lucu/Chunk.hs index dd7465e..b48727c 100644 --- a/Network/HTTP/Lucu/Chunk.hs +++ b/Network/HTTP/Lucu/Chunk.hs @@ -1,36 +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 () -{-# SPECIALIZE chunkHeaderP :: Parser Int #-} - - -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