diff options
Diffstat (limited to 'app/Data/Iban.hs')
-rw-r--r-- | app/Data/Iban.hs | 10 |
1 files changed, 5 insertions, 5 deletions
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 ((<|>)) | |||
4 | import Data.Attoparsec.Text as AP | 4 | import Data.Attoparsec.Text as AP |
5 | import Data.Char | 5 | import Data.Char |
6 | ( digitToInt, | 6 | ( digitToInt, |
7 | isAscii, | ||
8 | isDigit, | ||
7 | ord, | 9 | ord, |
8 | toUpper, | 10 | toUpper, |
9 | ) | 11 | ) |
@@ -24,7 +26,7 @@ validateIban = AP.parseOnly $ do | |||
24 | then | 26 | then |
25 | if valid countryCode checkDigits chars | 27 | if valid countryCode checkDigits chars |
26 | then return () | 28 | then return () |
27 | else fail $ "IBAN checksum does not match (" <> countryCode <> checkDigits <> chars <> ")" | 29 | else fail $ "IBAN checksum does not match (" ++ countryCode ++ checkDigits ++ chars ++ ")" |
28 | else fail "IBAN has more than 34 characters" | 30 | else fail "IBAN has more than 34 characters" |
29 | where | 31 | where |
30 | letterToInt c = ord (toUpper c) - ord 'A' + 10 | 32 | letterToInt c = ord (toUpper c) - ord 'A' + 10 |
@@ -32,10 +34,8 @@ validateIban = AP.parseOnly $ do | |||
32 | foldl' | 34 | foldl' |
33 | ( \acc -> \case | 35 | ( \acc -> \case |
34 | d | 36 | d |
35 | | '0' <= d && d <= '9' -> acc * 10 + toInteger (digitToInt d) | 37 | | isDigit d -> acc * 10 + toInteger (digitToInt d) |
36 | | 'A' <= d && d <= 'Z' | 38 | | isAscii d -> acc * 100 + toInteger (letterToInt d) |
37 | || 'a' <= d && d <= 'z' -> | ||
38 | acc * 100 + toInteger (letterToInt d) | ||
39 | | otherwise -> error "unreachable" | 39 | | otherwise -> error "unreachable" |
40 | ) | 40 | ) |
41 | 0 | 41 | 0 |