]> gitweb @ CieloNegro.org - Lucu.git/blobdiff - Network/HTTP/Lucu/MIMEType/Guess.hs
changed everything like a maniac
[Lucu.git] / Network / HTTP / Lucu / MIMEType / Guess.hs
index 2319477f68dc3410fa69cbd6ae2cc5bce5173eea..3e3df1631b7af87c29012159681bc2474df5c10f 100644 (file)
@@ -1,6 +1,5 @@
 {-# LANGUAGE
     BangPatterns
-  , UnboxedTuples
   , UnicodeSyntax
   #-}
 -- |MIME Type guessing by a file extension. This is a poor man's way
@@ -18,7 +17,7 @@ module Network.HTTP.Lucu.MIMEType.Guess
 import Control.Applicative
 import qualified Data.Ascii as A
 import Data.Attoparsec.Char8 as P
-import qualified Data.Attoparsec.Lazy as AL
+import qualified Data.Attoparsec.Lazy as LP
 import qualified Data.ByteString.Lazy.Char8 as B
 import qualified Data.Map as M
 import Data.Map (Map)
@@ -46,9 +45,9 @@ guessTypeByFileName !extMap !fpath
 parseExtMapFile ∷ FilePath → IO ExtMap
 parseExtMapFile fpath
     = do file ← B.readFile fpath
-         case AL.parse extMapP file of
-           AL.Done _ xs  → return $ compile xs
-           AL.Fail _ _ e → fail ("Failed to parse: " ⧺ fpath ⧺ ": " ⧺ e)
+         case LP.parse extMapP file of
+           LP.Done _ xs  → return $ compile xs
+           LP.Fail _ _ e → fail ("Failed to parse: " ⧺ fpath ⧺ ": " ⧺ e)
 
 extMapP ∷ Parser [ (MIMEType, [Text]) ]
 extMapP = do xs ← P.many (comment <|> validLine <|> emptyLine)
@@ -116,11 +115,11 @@ serializeExtMap extMap moduleName variableName
                                   [] (HsUnGuardedRhs extMapExp) []]
                      ]
           extMapExp = HsApp (HsVar (Qual (Module "M") (HsIdent "fromList"))) (HsList records)
-          comment   =    "{- !!! WARNING !!!\n"
-                      ++ "   This file is automatically generated.\n"
-                      ++ "   DO NOT EDIT BY HAND OR YOU WILL REGRET -}\n\n"
+          comment   =   "{- !!! WARNING !!!\n"
+                       "   This file is automatically generated.\n"
+                       "   DO NOT EDIT BY HAND OR YOU WILL REGRET -}\n\n"
       in
-        comment ++ prettyPrint hsModule ++ "\n"
+        comment ⧺ prettyPrint hsModule ⧺ "\n"
     where
       records ∷ [HsExp]
       records = map record $ M.assocs extMap
@@ -138,4 +137,7 @@ serializeExtMap extMap moduleName variableName
           = HsApp (HsVar (UnQual (HsIdent "parseMIMEType")))
             (HsParen
              (HsApp (HsVar (Qual (Module "A") (HsIdent "unsafeFromString")))
-              (HsLit (HsString $ A.toString $ printMIMEType mt))))
+              (HsLit (HsString $ mimeToString mt))))
+
+      mimeToString ∷ MIMEType → String
+      mimeToString = A.toString ∘ A.fromAsciiBuilder ∘ printMIMEType