X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=Lucu.git;a=blobdiff_plain;f=Network%2FHTTP%2FLucu%2FUtils.hs;fp=Network%2FHTTP%2FLucu%2FUtils.hs;h=7537eafcffacf7d8edf755e2bb8fea30cd636547;hp=297ea3a762ef64992466469a3845053ffb86d7af;hb=c9a269666f2d60d9c5ba817e1c43b45f6d77de22;hpb=bc7c6c8fc24ca3c35cea6007d87df8e6a5fd1240 diff --git a/Network/HTTP/Lucu/Utils.hs b/Network/HTTP/Lucu/Utils.hs index 297ea3a..7537eaf 100644 --- a/Network/HTTP/Lucu/Utils.hs +++ b/Network/HTTP/Lucu/Utils.hs @@ -36,11 +36,12 @@ import Data.Char import Data.Collections import Data.Collections.BaseInstances () import Data.Convertible.Base +import Data.Convertible.Instances.Ascii () +import Data.Convertible.Instances.Text () import Data.Convertible.Instances.Time () import Data.Maybe import Data.Monoid.Unicode import Data.Text (Text) -import qualified Data.Text as T import Data.Time import Network.URI import Prelude hiding (last, mapM, null, reverse) @@ -73,9 +74,9 @@ splitBy isSep src -- >>> quoteStr "ab\"c" -- "\"ab\\\"c\"" quoteStr ∷ Ascii → AsciiBuilder -quoteStr str = A.toAsciiBuilder "\"" ⊕ - go (A.toByteString str) (∅) ⊕ - A.toAsciiBuilder "\"" +quoteStr str = cs ("\"" ∷ Ascii) ⊕ + go (cs str) (∅) ⊕ + cs ("\"" ∷ Ascii) where go ∷ ByteString → AsciiBuilder → AsciiBuilder go bs ab @@ -85,10 +86,10 @@ quoteStr str = A.toAsciiBuilder "\"" ⊕ → ab ⊕ b2ab x | otherwise → go (BS.tail y) - (ab ⊕ b2ab x ⊕ A.toAsciiBuilder "\\\"") + (ab ⊕ b2ab x ⊕ cs ("\\\"" ∷ Ascii)) b2ab ∷ ByteString → AsciiBuilder - b2ab = A.toAsciiBuilder ∘ A.unsafeFromByteString + b2ab = cs ∘ A.unsafeFromByteString -- |>>> parseWWWFormURLEncoded "aaa=bbb&ccc=ddd" -- [("aaa", "bbb"), ("ccc", "ddd")] @@ -97,7 +98,7 @@ parseWWWFormURLEncoded src -- THINKME: We could gain some performance by using attoparsec -- here. | src ≡ "" = [] - | otherwise = do pairStr ← splitBy (\ c → c ≡ ';' ∨ c ≡ '&') (A.toString src) + | otherwise = do pairStr ← splitBy (\ c → c ≡ ';' ∨ c ≡ '&') (cs src) let (key, value) = break (≡ '=') pairStr return ( unescape key , unescape $ case value of @@ -116,7 +117,7 @@ parseWWWFormURLEncoded src -- "example.com" uriHost ∷ URI → Host {-# INLINE uriHost #-} -uriHost = CI.mk ∘ T.pack ∘ uriRegName ∘ fromJust ∘ uriAuthority +uriHost = CI.mk ∘ cs ∘ uriRegName ∘ fromJust ∘ uriAuthority -- |>>> uriPathSegments "http://example.com/foo/bar" -- ["foo", "bar"]