implemented escapeString
This commit is contained in:
@@ -25,9 +25,11 @@ License along with this program. If not, see
|
||||
-}
|
||||
|
||||
module Network.GemServ (
|
||||
encodeRequest
|
||||
encodeRequest,
|
||||
escapeString
|
||||
) where
|
||||
|
||||
import Data.Char (ord)
|
||||
import Data.List (intercalate)
|
||||
|
||||
import Network.GemServ.Types
|
||||
@@ -45,4 +47,21 @@ encodeRequest req =
|
||||
"" -> ""
|
||||
q -> '?' : q
|
||||
|
||||
-- | add required escape sequences to a string
|
||||
escapeString :: String -> String
|
||||
escapeString = concatMap $ \ch ->
|
||||
if ch `elem` unescaped
|
||||
then [ch]
|
||||
else '%' : toHex ch
|
||||
where
|
||||
unescaped = ['0'..'9'] ++ ['A'..'Z'] ++ ['a'..'z'] ++ "~-_."
|
||||
toHex ch = let
|
||||
n = ord ch
|
||||
high = n `div` 16
|
||||
low = n `mod` 16
|
||||
in [hexDigits !! high, hexDigits !! low]
|
||||
|
||||
hexDigits :: String
|
||||
hexDigits = ['0'..'9'] ++ ['a'..'f']
|
||||
|
||||
--jl
|
||||
|
||||
Reference in New Issue
Block a user