]> git.rkrishnan.org Git - functorrent.git/commitdiff
refactor urlEncode
authorRamakrishnan Muthukrishnan <ram@rkrishnan.org>
Sun, 15 Feb 2015 10:17:32 +0000 (15:47 +0530)
committerRamakrishnan Muthukrishnan <ram@rkrishnan.org>
Sun, 15 Feb 2015 10:17:32 +0000 (15:47 +0530)
src/Tracker.hs

index 75c3a00c09505ab737e34fcdf6f97e912a608a1d..51877d72963352a19e704c33e2b4a7dd662cacda 100644 (file)
@@ -22,15 +22,12 @@ urlEncode bs = concatMap (encode . BC.unpack) (splitN 2 bs)
                                   in
                                    escape c c1 c2
         encode _ = ""
-        escape i c1 c2 | isAsciiUpper i ||
-                         isAsciiLower i ||
-                         isDigit i ||
-                         i == '-' ||
-                         i == '_' ||
-                         i == '.' ||
-                         i == '~'
-                         = [i]
+        escape i c1 c2 | i `elem` nonSpecialChars = [i]
                        | otherwise = "%" ++ [c1] ++ [c2]
+          where nonSpecialChars = ['A'..'Z'] ++
+                                  ['a'..'z'] ++
+                                  ['0'..'9'] ++
+                                  ['-', '_', '.', '~']
 
 -- (chr . read . ("0x" ++) . BC.unpack)
 -- connect :: Url -> String -> IO (Benc.BVal)