--- |Convert a 'MIMEType' to 'Ascii'.
-printMIMEType ∷ MIMEType → Ascii
-printMIMEType (MIMEType maj min params)
- = A.fromAsciiBuilder $
- ( A.toAsciiBuilder (A.fromCIAscii maj) ⊕
- A.toAsciiBuilder "/" ⊕
- A.toAsciiBuilder (A.fromCIAscii min) ⊕
- if null params then
- (∅)
- else
- A.toAsciiBuilder "; " ⊕
- joinWith "; " (map printPair params)
- )
- where
- printPair ∷ (CIAscii, Ascii) → A.AsciiBuilder
- printPair (name, value)
- = A.toAsciiBuilder (A.fromCIAscii name) ⊕
- A.toAsciiBuilder "=" ⊕
- if C8.any ((¬) ∘ isToken) (A.toByteString value) then
- quoteStr value
- else
- A.toAsciiBuilder value
+instance Lift MIMEType where
+ lift (MIMEType {..})
+ = [| MIMEType {
+ mtMedia = $(liftCIAscii mtMedia)
+ , mtSub = $(liftCIAscii mtSub)
+ , mtParams = $(lift mtParams)
+ }
+ |]
+
+-- |Convert a 'MIMEType' to an 'AsciiBuilder'.
+printMIMEType ∷ MIMEType → AsciiBuilder
+{-# INLINEABLE printMIMEType #-}
+printMIMEType (MIMEType {..})
+ = A.toAsciiBuilder (A.fromCIAscii mtMedia) ⊕
+ A.toAsciiBuilder "/" ⊕
+ A.toAsciiBuilder (A.fromCIAscii mtSub) ⊕
+ printMIMEParams mtParams