encodeForQuery :: String -> String
encodeForQuery = concatMap (\ c -> let n = ord c in case c of
  _ | isAscii c && isAlphaNum c || elem c "_.-" -> [c]
  ' ' -> "+"
  _ | n <= 255 -> '%' : (if n < 16 then "0" else "") ++ showHex n ""
  _ -> "")
encodeForQuery :: String -> String
encodeForQuery = concatMap (\ c -> let n = ord c in case c of
  _ | isAscii c && isAlphaNum c || elem c "_.-" -> [c]
  ' ' -> "+"
  _ | n <= 255 -> '%' : (if n < 16 then "0" else "") ++ showHex n ""
  _ -> "")
encodeForQuery = concatMap (\ c -> let n = ord c in case c of
  _ | isAscii c && isAlphaNum c || elem c "_.-" -> [c]
  ' ' -> "+"
  _ | n <= 255 -> '%' : (if n < 16 then "0" else "") ++ showHex n ""
  _ -> "")