17 import qualified Codec.Binary.Url as Url
19 import Control.Arrow.ArrowList
20 import qualified Data.ByteString as BS
21 import qualified Data.ByteString.Lazy as LS
22 import qualified Data.ByteString.Lazy.Char8 as L8
24 import qualified Data.Text as T
25 import Data.Text.Encoding
26 import Network.HTTP.Lucu
28 import Prelude.Unicode
29 import System.IO.Unsafe
32 yesOrNo ∷ Bool → String
37 trueOrFalse ∷ Bool → String
38 trueOrFalse True = "true"
39 trueOrFalse False = "false"
42 parseYesOrNo ∷ ArrowChoice a => a String Bool
44 = proc str → do case str of
45 "yes" → returnA -< True
46 "no" → returnA -< False
47 _ → returnA -< error ("Expected yes or no: " ⧺ str)
50 maybeA ∷ (ArrowList a, ArrowChoice a) => a b c → a b (Maybe c)
54 [] → returnA -< Nothing
55 (x:_) → returnA -< Just x
58 deleteIfEmpty ∷ (ArrowList a, ArrowChoice a) => a String String
60 = proc str → do case str of
65 chomp ∷ String → String
66 chomp = reverse . snd . break (/= '\n') . reverse
69 guessMIMEType ∷ LS.ByteString → MIMEType
70 guessMIMEType = read . unsafePerformIO . magicString magic . L8.unpack
73 magic = unsafePerformIO
74 $ do m <- magicOpen [MagicMime]
79 isSafeChar ∷ Char → Bool
82 | isReserved c = False
83 | isUnreserved c = True
87 mkQueryString ∷ [(T.Text, T.Text)] → String
88 {-# INLINEABLE mkQueryString #-}
89 mkQueryString = intercalate ";" ∘ map pairToStr
91 pairToStr ∷ (T.Text, T.Text) → String
92 {-# INLINE pairToStr #-}
94 = encode k ⧺ ('=':encode v)
96 encode ∷ T.Text → String
98 encode = Url.encode ∘ BS.unpack ∘ encodeUtf8