    {-# LANGUAGE DeriveDataTypeable #-}
    {- | Implements ISO\/IEC 8859-1 alias latin-1 encoding. See <http://en.wikipedia.org/wiki/ISO/IEC_8859-1> for further information.
     -}
    module Data.Encoding.ISO88591 where

    import Control.Throws
    import Data.Encoding.Base
    import Data.Encoding.Exception
    import Data.Encoding.ByteSource
    import Data.Encoding.ByteSink
    import Data.Char (ord,chr)
    import Data.Typeable

    data ISO88591 = ISO88591 deriving (Int -> ISO88591 -> ShowS
    [ISO88591] -> ShowS
    ISO88591 -> String
    (Int -> ISO88591 -> ShowS)
    -> (ISO88591 -> String) -> ([ISO88591] -> ShowS) -> Show ISO88591
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> ISO88591 -> ShowS
    showsPrec :: Int -> ISO88591 -> ShowS
    $cshow :: ISO88591 -> String
    show :: ISO88591 -> String
    $cshowList :: [ISO88591] -> ShowS
    showList :: [ISO88591] -> ShowS
    Show,ISO88591 -> ISO88591 -> Bool
    (ISO88591 -> ISO88591 -> Bool)
    -> (ISO88591 -> ISO88591 -> Bool) -> Eq ISO88591
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: ISO88591 -> ISO88591 -> Bool
    == :: ISO88591 -> ISO88591 -> Bool
    $c/= :: ISO88591 -> ISO88591 -> Bool
    /= :: ISO88591 -> ISO88591 -> Bool
    Eq,Typeable)

    instance Encoding ISO88591 where
        encodeChar :: forall (m :: * -> *). ByteSink m => ISO88591 -> Char -> m ()
    encodeChar ISO88591
    _ Char
    c
                   | Char
    c Char -> Char -> Bool
    forall a. Ord a => a -> a -> Bool
    > Char
    '\255' = EncodingException -> m ()
    forall a. EncodingException -> m a
    forall e (m :: * -> *) a. Throws e m => e -> m a
    throwException (Char -> EncodingException
    HasNoRepresentation Char
    c)
                   | Bool
    otherwise = Word8 -> m ()
    forall (m :: * -> *). ByteSink m => Word8 -> m ()
    pushWord8 (Int -> Word8
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral (Int -> Word8) -> Int -> Word8
    forall a b. (a -> b) -> a -> b
    $ Char -> Int
    ord Char
    c)
        decodeChar :: forall (m :: * -> *). ByteSource m => ISO88591 -> m Char
    decodeChar ISO88591
    _ = do
          w <- m Word8
    forall (m :: * -> *). ByteSource m => m Word8
    fetchWord8
          return (chr $ fromIntegral w)
        encodeable :: ISO88591 -> Char -> Bool
    encodeable ISO88591
    _ Char
    c = Char
    c Char -> Char -> Bool
    forall a. Ord a => a -> a -> Bool
    <= Char
    '\255'