19 import qualified Codec.Binary.UTF8.String as UTF8
21 import Control.Arrow.ArrowList
22 import qualified Data.ByteString.Lazy as Lazy (ByteString)
23 import qualified Data.ByteString.Lazy.Char8 as L8 hiding (ByteString)
24 import Data.Monoid.Unicode
27 import Network.HTTP.Lucu
29 import Prelude.Unicode
30 import System.IO.Unsafe
32 yesOrNo ∷ Bool → String
36 trueOrFalse ∷ Bool → String
37 trueOrFalse True = "true"
38 trueOrFalse False = "false"
40 parseYesOrNo ∷ (Eq s, Show s, IsString s, ArrowChoice (⇝)) ⇒ s ⇝ Bool
44 _ | str ≡ "yes" → returnA ⤙ True
45 | str ≡ "no" → returnA ⤙ False
46 | otherwise → returnA ⤙ error ("Expected yes or no: " ⊕ show str)
48 maybeA :: (ArrowList a, ArrowChoice a) => a b c -> a b (Maybe c)
52 [] -> returnA -< Nothing
53 (x:_) -> returnA -< Just x
56 deleteIfEmpty :: (ArrowList a, ArrowChoice a) => a String String
58 = proc str -> do case str of
63 chomp :: String -> String
64 chomp = reverse . snd . break (/= '\n') . reverse
67 guessMIMEType :: Lazy.ByteString -> MIMEType
68 guessMIMEType = read . unsafePerformIO . magicString magic . L8.unpack
71 magic = unsafePerformIO
72 $ do m <- magicOpen [MagicMime]
77 isSafeChar :: Char -> Bool
80 | isReserved c = False
81 | c > ' ' && c <= '~' = True
85 mkQueryString :: [(String, String)] -> String
87 mkQueryString ((k, v) : xs) = encode k ++ "=" ++ encode v ++
91 ';' : mkQueryString(xs)
93 encode :: String -> String
94 encode = escapeURIString isSafeChar . UTF8.encodeString