[yesod] Fix comment for contentTypeTypes & simpler implementation

In the implementation of contentTypeTypes make use of simpleContentType.
This commit is contained in:
Janek Spaderna 2018-01-18 12:00:46 +01:00
parent e2b0a5c454
commit 7f6f1821e8

View File

@ -78,6 +78,7 @@ import Yesod.Core.Types
import Text.Lucius (Css, renderCss)
import Text.Julius (Javascript, unJavascript)
import Data.Word8 (_semicolon, _slash)
import Control.Arrow (second)
-- | Zero-length enumerator.
emptyContent :: Content
@ -228,13 +229,13 @@ typeOctet = "application/octet-stream"
simpleContentType :: ContentType -> ContentType
simpleContentType = fst . B.break (== _semicolon)
-- Give just the media types as a pair.
-- | Give just the media types as a pair.
--
-- For example, \"text/html; charset=utf-8\" returns ("text", "html")
contentTypeTypes :: ContentType -> (B.ByteString, B.ByteString)
contentTypeTypes ct = (main, fst $ B.break (== _semicolon) (tailEmpty sub))
contentTypeTypes = second tailEmpty . B.break (== _slash) . simpleContentType
where
tailEmpty x = if B.null x then "" else B.tail x
(main, sub) = B.break (== _slash) ct
instance HasContentType a => HasContentType (DontFullyEvaluate a) where
getContentType = getContentType . liftM unDontFullyEvaluate