Make number parsing case-independent

This commit is contained in:
Tissevert 2020-08-26 11:40:09 +02:00
parent f56f5f9569
commit 28cfbde7ec

View file

@ -8,6 +8,7 @@ module Data.RomanNum (
, validate , validate
) where ) where
import Data.Char (toUpper)
import Data.Map (Map, (!)) import Data.Map (Map, (!))
import qualified Data.Map as Map (fromList) import qualified Data.Map as Map (fromList)
import Text.Read (readMaybe) import Text.Read (readMaybe)
@ -55,7 +56,7 @@ validate :: String -> Bool
validate = either (\_ -> False) (\_ -> True) . parse validate = either (\_ -> False) (\_ -> True) . parse
readDigit :: Char -> Either String Int readDigit :: Char -> Either String Int
readDigit c = maybe errMsg (Right . (values !)) $ readMaybe [c] readDigit c = maybe errMsg (Right . (values !)) $ readMaybe [toUpper c]
where where
errMsg = Left $ "Not a roman digit: «" ++ c:"»" errMsg = Left $ "Not a roman digit: «" ++ c:"»"