module Text.XML.HXT.Parser.ProtocolHandlerUtil
( parseContentType
)
where
import Text.XML.HXT.DOM.XmlKeywords
import Text.XML.HXT.DOM.Util ( stringToUpper
, stringTrim
)
import qualified Text.ParserCombinators.Parsec as P
parseContentType :: P.Parser [(String, String)]
parseContentType
= P.try ( do
mimeType <- ( do
mt <- P.many (P.noneOf ";")
rtMT mt
)
charset <- ( do
_ <- P.char ';'
_ <- P.many (P.oneOf " \t'")
_ <- P.string "charset="
_ <- P.option '"' (P.oneOf "\"'")
cs <- P.many1 (P.noneOf "\"'")
return [ (transferEncoding, stringToUpper cs) ]
)
return (mimeType ++ charset)
)
P.<|>
( do
mt <- P.many (P.noneOf ";")
rtMT mt
)
where
rtMT mt = return [ (transferMimeType, stringTrim mt) ]