X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Network%2FHTTP%2FLucu%2FChunk.hs;h=e8c9de41286c4fb3240425843acc67c52e565db5;hb=b1fac0a;hp=27deb740821f9c68bd5b3159c08469513c7c222d;hpb=9ac730212cb361eb10e5fe4ad0eec6758e2b200a;p=Lucu.git diff --git a/Network/HTTP/Lucu/Chunk.hs b/Network/HTTP/Lucu/Chunk.hs index 27deb74..e8c9de4 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 + ( 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 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 = many ( 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 () +chunkFooter = crlf + +chunkTrailer ∷ Parser Headers +chunkTrailer = headers