+-- #prune
+
+-- |Manipulation of MIME Types.
module Network.HTTP.Lucu.MIMEType
( MIMEType(..)
- , (+/+) -- String -> String -> MIMEType
- , (+:+) -- MIMEType -> (String, String) -> MIMEType
- , (+=+) -- String -> String -> (String, String)
- , mimeTypeP -- Parser MIMEType
- , mimeTypeListP -- Parser [MIMEType]
+ , (</>)
+ , (<:>)
+ , (<=>)
+ , mimeTypeP
+ , mimeTypeListP
)
where
import Network.HTTP.Lucu.Parser.Http
import Network.HTTP.Lucu.Utils
-
+-- |@'MIMEType' \"major\" \"minor\" [(\"name\", \"value\")]@
+-- represents \"major\/minor; name=value\".
data MIMEType = MIMEType {
- mtMajor :: String
- , mtMinor :: String
- , mtParams :: [ (String, String) ]
+ mtMajor :: !String
+ , mtMinor :: !String
+ , mtParams :: ![ (String, String) ]
} deriving (Eq)
value
-infix 9 +/+, +=+
-infixl 8 +:+
-
+infix 9 </>, <=>
+infixl 8 <:>
-(+/+) :: String -> String -> MIMEType
-maj +/+ min
+-- |@\"major\" \<\/\> \"minor\"@ constructs a MIME Type
+-- \"major\/minor\".
+(</>) :: String -> String -> MIMEType
+maj </> min
= MIMEType maj min []
-
-(+:+) :: MIMEType -> (String, String) -> MIMEType
-mt@(MIMEType _ _ params) +:+ pair
- = mt {
+-- |This operator appends a @(name, value)@ pair to a MIME Type.
+(<:>) :: MIMEType -> (String, String) -> MIMEType
+mt@(MIMEType _ _ params) <:> pair
+ = pair `seq`
+ mt {
mtParams = mtParams mt ++ [pair]
}
-
-(+=+) :: String -> String -> (String, String)
-name +=+ value = (name, value)
-
+-- |This operator takes two strings and makes a tuple of them. So you
+-- can say
+--
+-- > "text" </> "xml" <:> "charset" <=> "UTF-8" <:> "q" <=> "0.9"
+--
+-- to represent \"text\/xml; charset=UTF-8; q=0.9\".
+(<=>) :: String -> String -> (String, String)
+name <=> value = (name, value)
mimeTypeP :: Parser MIMEType
-mimeTypeP = allowEOF $
+mimeTypeP = allowEOF $!
do maj <- token
char '/'
min <- token
return (name, value)
mimeTypeListP :: Parser [MIMEType]
-mimeTypeListP = allowEOF $ listOf mimeTypeP
+mimeTypeListP = allowEOF $! listOf mimeTypeP