0 | module Network.URL.Internal.PercentEncoding
9 | isUnreserved : Char -> Bool
10 | isUnreserved c = isAlphaNum c || c == '-' || c == '_' || c == '.' || c == '~'
14 | toHex : Int -> String
15 | toHex n = let hex = unpack "0123456789ABCDEF"
18 | in singleton (index hex (cast hi)) ++ singleton (index hex (cast lo))
20 | index : List Char -> Nat -> Char
21 | index xs i = case drop i xs of
27 | fromHex : Char -> Char -> Int
28 | fromHex a b = hexVal a * 16 + hexVal b
30 | hexVal : Char -> Int
31 | hexVal c = case c of
59 | percentEncode : String -> String
60 | percentEncode s = concatMap encodeChar (unpack s)
62 | encodeChar : Char -> String
63 | encodeChar c = if isUnreserved c then singleton c else "%" ++ toHex (ord c)
68 | percentDecode : String -> String
69 | percentDecode s = decode (unpack s)
71 | decode : List Char -> String
73 | decode ('%' :: a :: b :: xs) =
74 | let n = fromHex a b in singleton (chr n) ++ decode xs
75 | decode (x :: xs) = singleton x ++ decode xs