]> git.rkrishnan.org Git - functorrent.git/commitdiff
rearrange and refactor code for readability and comprehension.
authorRamakrishnan Muthukrishnan <ram@rkrishnan.org>
Wed, 4 Feb 2015 11:05:24 +0000 (16:35 +0530)
committerRamakrishnan Muthukrishnan <ram@rkrishnan.org>
Wed, 4 Feb 2015 11:07:26 +0000 (16:37 +0530)
src/Bencode.hs

index 1fb2a31be5856b031a36cb503bdf7c9dd83d170d..0da372bf07b0cc29a2be5bb754603f9e3d41d5b4 100644 (file)
@@ -60,11 +60,10 @@ bencInt = do _ <- spaces
                where numbers = do d' <- (char '-' <|> digit)
                                   ds' <- many digit
                                   parseNumber d' ds'
-                     parseNumber '0' []  = return ['0']
+                     parseNumber '0' []  = return "0"
+                     parseNumber '0' _ = unexpected "numbers cannot be left-padded with zeros"
                      parseNumber '-' []  = unexpected "sign without any digits"
-                     parseNumber '0' ds'' = unexpected "numbers cannot be left-padded with zeros"
-                     parseNumber '-' (d'':ds'') | d'' == '0' = unexpected "numbers cannot be left-padded with zeros"
-                     parseNumber '-' ds'' = return ('-':ds'')
+                     parseNumber '-' (d'':_) | d'' == '0' = unexpected "numbers cannot be left-padded with zeros"
                      parseNumber d'' ds'' = return (d'':ds'')
 
 bencParser :: ParsecBS.Parser BVal