diff --git a/Data/Encoding/ASCII.hs b/Data/Encoding/ASCII.hs index 990ae2d..e261df1 100644 --- a/Data/Encoding/ASCII.hs +++ b/Data/Encoding/ASCII.hs @@ -1,10 +1,12 @@ {-# LANGUAGE DeriveDataTypeable #-} module Data.Encoding.ASCII where +import Control.Throws import Data.Char import Data.Encoding.Base import Data.Encoding.ByteSource import Data.Encoding.ByteSink +import Data.Encoding.Exception import Data.Typeable data ASCII = ASCII deriving (Show,Eq,Typeable) @@ -13,6 +15,7 @@ instance Encoding ASCII where decodeChar _ = do w <- fetchWord8 return $ chr $ fromIntegral w - encodeChar _ c = do - pushWord8 $ fromIntegral $ ord c + encodeChar enc c + | encodeable enc c = pushWord8 . fromIntegral . ord $ c + | otherwise = throwException . HasNoRepresentation $ c encodeable _ c = c < '\128' \ No newline at end of file