From 985974c264804ff788b3b5242fef707d4b7fa9a6 Mon Sep 17 00:00:00 2001 From: evuez Date: Mon, 1 Apr 2024 15:17:30 +0200 Subject: Initial commit --- src/Common/Mime.hs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/Common/Mime.hs (limited to 'src/Common') diff --git a/src/Common/Mime.hs b/src/Common/Mime.hs new file mode 100644 index 0000000..5356312 --- /dev/null +++ b/src/Common/Mime.hs @@ -0,0 +1,23 @@ +module Common.Mime (getType, getSubtype, MimeType (..)) where + +import Common (split2, trim) +import Intro + +data MimeType = Text String | Image String | Application String + +getType :: String -> Maybe MimeType +getType mime = case type_ of + "text" -> Just (Text subtype) + "image" -> Just (Image subtype) + "application" -> Just (Application subtype) + _ -> Nothing + where + (type_, subtype) = split2 (== '/') $ trim mime + +getSubtype :: String -> String +getSubtype = trim . snd . split2 (== '/') + +instance Show MimeType where + show (Text sub) = "text/" ++ sub + show (Image sub) = "image/" ++ sub + show (Application sub) = "application/" ++ sub -- cgit v1.2.3