module ATerm.Base64
( toBase64Int
, toBase64Char
, isBase64Char
, ord0
) where
import Data.Char
toBase64Int :: Char -> Int
toBase64Int c
| isUpper c = ord c ordA
| isLower c = ord c i71
| isDigit c = ord c + i4
| c == '+' = 62
| c == '/' = 63
| otherwise = error "toBase64Int"
toBase64Char :: Int -> Char
toBase64Char i
| i < 26 = chr (ordA + i)
| i < 52 = chr (i71 + i)
| i < 62 = chr (i i4)
| i == 62 = '+'
| i == 63 = '/'
| otherwise = error "toBase64Char"
isBase64Char :: Char -> Bool
isBase64Char c = isAscii c && (isAlphaNum c || c == '+' || c == '/')
ordA :: Int
ordA = ord 'A'
i71 :: Int
i71 = ord 'a' 26
ord0 :: Int
ord0 = ord '0'
i4 :: Int
i4 = 52 ord0