module Data.Bitmap.Util
( tablespoon
, subStr
, padByte
) where
import Control.Exception
import qualified Data.String.Class as S
import Data.Word
import System.IO.Unsafe (unsafePerformIO)
handlers :: [Handler (Either String a)]
handlers = [ Handler $ \(e :: ArithException) -> return . Left . show $ e
, Handler $ \(e :: ArrayException) -> return . Left . show $ e
, Handler $ \(e :: ErrorCall) -> return . Left . show $ e
, Handler $ \(e :: PatternMatchFail) -> return . Left . show $ e
, Handler $ \(e :: SomeException) -> throwIO e
]
tablespoon :: a -> Either String a
tablespoon x = unsafePerformIO $ (Right `fmap` evaluate x) `catches` handlers
subStr :: (S.StringCells s) => Int -> Int -> s -> s
subStr index length_ = S.take length_ . S.drop index
padByte :: Word8
padByte = 0x00