on master help sign in
Fix string to positive number conversion (#3129)
ea0966eSaurabh Rawat
libs/base/Data/String.idr+5−3
@@ -23,10 +23,12 @@ parsePositive s = parsePosTrimmed (trim s)
23 where
23 where
24 parsePosTrimmed s with (strM s)
24 parsePosTrimmed s with (strM s)
25 parsePosTrimmed "" | StrNil = Nothing
25 parsePosTrimmed "" | StrNil = Nothing
26+ parsePosTrimmed (strCons '+' xs) | (StrCons '+' xs) =
27+ map fromInteger (parseNumWithoutSign (unpack xs) 0)
26 parsePosTrimmed (strCons x xs) | (StrCons x xs) =
28 parsePosTrimmed (strCons x xs) | (StrCons x xs) =
27− if (x == '+')
29+ if (x >= '0' && x <= '9')
28− then map fromInteger (parseNumWithoutSign (unpack xs) 0)
29− else map fromInteger (parseNumWithoutSign (unpack xs) (cast (ord x - ord '0')))
30+ then map fromInteger (parseNumWithoutSign (unpack xs) (cast (ord x - ord '0')))
31+ else Nothing
30
32
31
33
32||| Convert a number string to a Num.
34||| Convert a number string to a Num.