encoding/Data/Encoding/ISO88592.hs
Henning Guenther cb81698b7e Derived all encodings from Show
This way, we can declare DynEncoding an instance of Show

darcs-hash:20070827020833-a4fee-a84635bf911573022b780c17b2085ff814302b3e
2007-08-26 19:08:33 -07:00

37 lines
931 B
Haskell

{- | Implements ISO\/IEC 8859-2 alias latin-2 encoding. See
<http://en.wikipedia.org/wiki/ISO/IEC_8859-2> for further informations.
-}
module Data.Encoding.ISO88592
(ISO88592(..)) where
import Data.Array
import Data.Map hiding ((!))
import Data.Word
import Data.Encoding.Base
import Data.ByteString hiding (length,map)
import Prelude hiding (lookup,all)
import Control.Exception
data ISO88592 = ISO88592 deriving Show
enc :: Char -> Word8
enc c = case lookup c encodeMap of
Just v -> v
Nothing -> throwDyn (HasNoRepresentation c)
instance Encoding ISO88592 where
encode _ = encodeSinglebyte enc
encodeLazy _ = encodeSinglebyteLazy enc
encodable _ c = member c encodeMap
decode _ = decodeSinglebyte (\w -> decodeArr!w)
decodeArr :: Array Word8 Char
#ifndef __HADDOCK__
decodeArr = $(decodingArray "8859-2.TXT")
#endif
encodeMap :: Map Char Word8
#ifndef __HADDOCK__
encodeMap = $(encodingMap "8859-2.TXT")
#endif