--- |A 'Map' from MIME parameter attributes to values. Attributes are
--- always case-insensitive according to RFC 2045
--- (<http://tools.ietf.org/html/rfc2045#section-5.1>).
-newtype MIMEParams
- = MIMEParams (M.Map CIAscii Text)
- deriving (Eq, Show, Read, Monoid, Typeable)
-
-instance Lift MIMEParams where
- lift (MIMEParams m) = [| MIMEParams $(lift m) |]
-
-instance Unfoldable MIMEParams (CIAscii, Text) where
- {-# INLINE insert #-}
- insert p (MIMEParams m)
- = MIMEParams $ insert p m
- {-# INLINE empty #-}
- empty
- = MIMEParams empty
- {-# INLINE singleton #-}
- singleton p
- = MIMEParams $ singleton p
- {-# INLINE insertMany #-}
- insertMany f (MIMEParams m)
- = MIMEParams $ insertMany f m
- {-# INLINE insertManySorted #-}
- insertManySorted f (MIMEParams m)
- = MIMEParams $ insertManySorted f m
-
-instance Foldable MIMEParams (CIAscii, Text) where
- {-# INLINE null #-}
- null (MIMEParams m) = null m
- {-# INLINE size #-}
- size (MIMEParams m) = size m
- {-# INLINE foldr #-}
- foldr f b (MIMEParams m) = foldr f b m
-
-instance Collection MIMEParams (CIAscii, Text) where
- {-# INLINE filter #-}
- filter f (MIMEParams m) = MIMEParams $ filter f m
-
-instance Indexed MIMEParams CIAscii Text where
- {-# INLINE index #-}
- index k (MIMEParams m) = index k m
- {-# INLINE adjust #-}
- adjust f k (MIMEParams m) = MIMEParams $ adjust f k m
- {-# INLINE inDomain #-}
- inDomain k (MIMEParams m) = inDomain k m
-
-instance Map MIMEParams CIAscii Text where
- {-# INLINE lookup #-}
- lookup k (MIMEParams m) = lookup k m
- {-# INLINE mapWithKey #-}
- mapWithKey f (MIMEParams m)
- = MIMEParams $ mapWithKey f m
- {-# INLINE unionWith #-}
- unionWith f (MIMEParams α) (MIMEParams β)
- = MIMEParams $ unionWith f α β
- {-# INLINE intersectionWith #-}
- intersectionWith f (MIMEParams α) (MIMEParams β)
- = MIMEParams $ intersectionWith f α β
- {-# INLINE differenceWith #-}
- differenceWith f (MIMEParams α) (MIMEParams β)
- = MIMEParams $ differenceWith f α β
- {-# INLINE isSubmapBy #-}
- isSubmapBy f (MIMEParams α) (MIMEParams β)
- = isSubmapBy f α β
- {-# INLINE isProperSubmapBy #-}
- isProperSubmapBy f (MIMEParams α) (MIMEParams β)
- = isProperSubmapBy f α β
-
-instance SortingCollection MIMEParams (CIAscii, Text) where
- {-# INLINE minView #-}
- minView (MIMEParams m) = second MIMEParams <$> minView m
-
--- |Convert MIME parameter values to an 'AsciiBuilder'.
-printMIMEParams ∷ MIMEParams → AsciiBuilder
-{-# INLINEABLE printMIMEParams #-}
-printMIMEParams = foldl' f (∅)
- where
- f ∷ AsciiBuilder → (CIAscii, Text) → AsciiBuilder
- {-# INLINE f #-}
- f ab (k, v) = ab ⊕ A.toAsciiBuilder "; " ⊕ printPair k v
+C.derive [d| instance Unfoldable MIMEParams (CIAscii, Text)
+ instance Foldable MIMEParams (CIAscii, Text)
+ instance Collection MIMEParams (CIAscii, Text)
+ instance Indexed MIMEParams CIAscii Text
+ instance Map MIMEParams CIAscii Text
+ instance SortingCollection MIMEParams (CIAscii, Text)
+ |]
+
+instance ConvertSuccess MIMEParams Ascii where
+ {-# INLINE convertSuccess #-}
+ convertSuccess = convertSuccessVia ((⊥) ∷ AsciiBuilder)
+
+instance ConvertSuccess MIMEParams AsciiBuilder where
+ {-# INLINEABLE convertSuccess #-}
+ convertSuccess = foldl' f (∅)
+ where
+ f ∷ AsciiBuilder → (CIAscii, Text) → AsciiBuilder
+ {-# INLINE f #-}
+ f ab (k, v) = ab ⊕ cs ("; " ∷ Ascii) ⊕ printPair k v