X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Network%2FHTTP%2FLucu%2FMIMEType%2FGuess.hs;h=cd178dec2afb18402169b2f316dd8c067f65b88e;hb=c9a2696;hp=edf177276eecc6feaf98be043ce13f96b3083e0d;hpb=19043d7882f936be9b073cae34b52905016c3ad7;p=Lucu.git diff --git a/Network/HTTP/Lucu/MIMEType/Guess.hs b/Network/HTTP/Lucu/MIMEType/Guess.hs index edf1772..cd178de 100644 --- a/Network/HTTP/Lucu/MIMEType/Guess.hs +++ b/Network/HTTP/Lucu/MIMEType/Guess.hs @@ -17,9 +17,11 @@ module Network.HTTP.Lucu.MIMEType.Guess ) where import Control.Applicative -import Data.Attoparsec.Char8 as P -import Data.Attoparsec.Lazy as LP +import Data.Attoparsec.Char8 +import qualified Data.Attoparsec.Lazy as LP import qualified Data.ByteString.Lazy.Char8 as Lazy +import Data.Convertible.Base +import Data.Convertible.Instances.Text () import qualified Data.Map as M import Data.Map (Map) import Data.Typeable @@ -27,13 +29,12 @@ import Data.List import Data.Monoid import Data.Monoid.Unicode import Data.Text (Text) -import qualified Data.Text as T import Data.Text.Encoding import Language.Haskell.TH.Syntax import Language.Haskell.TH.Quote import Network.HTTP.Lucu.MIMEType +import Network.HTTP.Lucu.OrphanInstances () import Network.HTTP.Lucu.Parser -import Network.HTTP.Lucu.Utils import Prelude.Unicode import System.FilePath @@ -43,8 +44,7 @@ newtype ExtMap deriving (Eq, Show, Read, Monoid, Typeable) instance Lift ExtMap where - lift (ExtMap m) - = [| ExtMap $(liftMap liftText lift m) |] + lift (ExtMap m) = [| ExtMap $(lift m) |] -- |'QuasiQuoter' for 'ExtMap' reading Apache @mime.types@. -- @@ -104,7 +104,7 @@ parseExtMap src "pair" ext ∷ Parser Text - ext = (decodeUtf8 <$> P.takeWhile1 isAlphaNum) + ext = (decodeUtf8 <$> takeWhile1 isAlphaNum) "ext" @@ -118,7 +118,7 @@ parseExtMap src "linebreak" compile ∷ Ord k ⇒ [(v, [k])] → Either (k, v, v) (Map k v) -compile = go (∅) ∘ concat ∘ map tr +compile = go (∅) ∘ concat ∘ (tr <$>) where tr ∷ (v, [k]) → [(k, v)] tr (v, ks) = [(k, v) | k ← ks] @@ -138,4 +138,4 @@ guessTypeByFileName ∷ ExtMap → FilePath → Maybe MIMEType guessTypeByFileName (ExtMap m) fpath = case takeExtension fpath of [] → Nothing - (_:ext) → M.lookup (T.pack ext) m + (_:ext) → M.lookup (cs ext) m