diff options
Diffstat (limited to 'src/Common')
| -rw-r--r-- | src/Common/Mime.hs | 23 | 
1 files changed, 23 insertions, 0 deletions
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  | 
