]> gitweb @ CieloNegro.org - Lucu.git/blobdiff - Network/HTTP/Lucu/MIMEType.hs
Optimized as possible as I can.
[Lucu.git] / Network / HTTP / Lucu / MIMEType.hs
index bd799e0d58f840dc9cb700be51e33e19e6496057..9f653230d3597ae298cdeec99fca07276242b9f6 100644 (file)
@@ -1,10 +1,13 @@
+-- #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
 
@@ -12,11 +15,12 @@ import           Network.HTTP.Lucu.Parser
 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)
 
 
@@ -36,29 +40,35 @@ instance Show MIMEType where
                                    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
@@ -75,4 +85,4 @@ mimeTypeP = allowEOF $
                   return (name, value)
 
 mimeTypeListP :: Parser [MIMEType]
-mimeTypeListP = allowEOF $ listOf mimeTypeP
+mimeTypeListP = allowEOF $! listOf mimeTypeP