X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Network%2FHTTP%2FLucu%2FChunk.hs;h=b48727cc0f364fdbe3037cd759cbbf01476216a4;hb=ece223c516e66223ef1d5d8e6bbe4054a235d983;hp=27deb740821f9c68bd5b3159c08469513c7c222d;hpb=9ac730212cb361eb10e5fe4ad0eec6758e2b200a;p=Lucu.git diff --git a/Network/HTTP/Lucu/Chunk.hs b/Network/HTTP/Lucu/Chunk.hs index 27deb74..b48727c 100644 --- a/Network/HTTP/Lucu/Chunk.hs +++ b/Network/HTTP/Lucu/Chunk.hs @@ -1,38 +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 - _ <- extension - _ <- crlf - - let [(len, _)] = readHex hexLen +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 return len where - extension :: Parser () - extension = many ( 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