in show (length s) ++ ":" ++ s
encode (Bint i) = "i" ++ show i ++ "e"
encode (Blist xs) = "l" ++ encodeList xs ++ "e"
- where encodeList = foldr (++ encode x) ""
+ where encodeList = foldr (\x -> (++ encode x)) ""
encode (Bdict d) = "d" ++ encodeDict d ++ "e"
where encodeDict m = concat [encode k ++ encode (m M.! k) | k <- M.keys m]
-- "%124Vx%9a%bc%de%f1%23Eg%89%ab%cd%ef%124Vx%9a"
urlEncode :: BC.ByteString -> String
urlEncode bs = concatMap (encode . BC.unpack) (U.splitN 2 bs)
- where encode b@[c1 : c2] = let c = chr (read ("0x" ++ b))
- in
- escape c c1 c2
+ where encode b@(c1 : c2 : []) = let c = chr (read ("0x" ++ b))
+ in
+ escape c c1 c2
encode _ = ""
escape i c1 c2 | i `elem` nonSpecialChars = [i]
| otherwise = "%" ++ [c1] ++ [c2]