From 5493329b2eed7e151f4a323c108caad2253b08bb Mon Sep 17 00:00:00 2001 From: Rutger Broekhoff Date: Sat, 22 Mar 2025 14:52:35 +0100 Subject: Refactor parser for current account statement --- app/Data/Iban.hs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'app/Data/Iban.hs') diff --git a/app/Data/Iban.hs b/app/Data/Iban.hs index 45343ec..412577a 100644 --- a/app/Data/Iban.hs +++ b/app/Data/Iban.hs @@ -4,6 +4,8 @@ import Control.Applicative ((<|>)) import Data.Attoparsec.Text as AP import Data.Char ( digitToInt, + isAscii, + isDigit, ord, toUpper, ) @@ -24,7 +26,7 @@ validateIban = AP.parseOnly $ do then if valid countryCode checkDigits chars then return () - else fail $ "IBAN checksum does not match (" <> countryCode <> checkDigits <> chars <> ")" + else fail $ "IBAN checksum does not match (" ++ countryCode ++ checkDigits ++ chars ++ ")" else fail "IBAN has more than 34 characters" where letterToInt c = ord (toUpper c) - ord 'A' + 10 @@ -32,10 +34,8 @@ validateIban = AP.parseOnly $ do foldl' ( \acc -> \case d - | '0' <= d && d <= '9' -> acc * 10 + toInteger (digitToInt d) - | 'A' <= d && d <= 'Z' - || 'a' <= d && d <= 'z' -> - acc * 100 + toInteger (letterToInt d) + | isDigit d -> acc * 10 + toInteger (digitToInt d) + | isAscii d -> acc * 100 + toInteger (letterToInt d) | otherwise -> error "unreachable" ) 0 -- cgit v1.2.3