X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=Lucu.git;a=blobdiff_plain;f=Network%2FHTTP%2FLucu%2FChunk.hs;h=a419464eefbc322989141167b8d4cbf8bcc741db;hp=27deb740821f9c68bd5b3159c08469513c7c222d;hb=9bb89434103e9a22f100d6ecb7e65a5d461e0454;hpb=86d100e294fa482456980021cca10393b9830ec1 diff --git a/Network/HTTP/Lucu/Chunk.hs b/Network/HTTP/Lucu/Chunk.hs index 27deb74..a419464 100644 --- a/Network/HTTP/Lucu/Chunk.hs +++ b/Network/HTTP/Lucu/Chunk.hs @@ -1,38 +1,35 @@ +{-# LANGUAGE + UnicodeSyntax + #-} module Network.HTTP.Lucu.Chunk ( chunkHeaderP -- Num a => Parser a , chunkFooterP -- Parser () , chunkTrailerP -- Parser Headers ) 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 () - - -chunkTrailerP :: Parser Headers + extension ∷ Parser () + extension = skipMany $ + do _ ← char ';' + _ ← token + _ ← char '=' + _ ← token <|> quotedStr + return () + +chunkFooterP ∷ Parser () +chunkFooterP = crlf + +chunkTrailerP ∷ Parser Headers chunkTrailerP = headersP