Derived all encodings from Show
This way, we can declare DynEncoding an instance of Show darcs-hash:20070827020833-a4fee-a84635bf911573022b780c17b2085ff814302b3e
This commit is contained in:
parent
ece4c7e788
commit
cb81698b7e
@ -44,7 +44,7 @@ import Data.Encoding.KOI8R
|
||||
import Data.Encoding.GB18030
|
||||
|
||||
-- | An untyped encoding. Used in 'System.IO.Encoding.getSystemEncoding'.
|
||||
data DynEncoding = forall t. Encoding t => DynEncoding t
|
||||
data DynEncoding = forall t. (Encoding t,Show t) => DynEncoding t
|
||||
|
||||
instance Encoding DynEncoding where
|
||||
encode (DynEncoding enc) = encode enc
|
||||
@ -54,6 +54,9 @@ instance Encoding DynEncoding where
|
||||
decodeLazy (DynEncoding enc) = decodeLazy enc
|
||||
decodable (DynEncoding enc) = decodable enc
|
||||
|
||||
instance Show DynEncoding where
|
||||
show (DynEncoding enc) = "DynEncoding "++show enc
|
||||
|
||||
-- | This decodes a string from one encoding and encodes it into another.
|
||||
recode :: (Encoding from,Encoding to) => from -> to -> ByteString -> ByteString
|
||||
recode enc_f enc_t bs = encode enc_t (decode enc_f bs)
|
||||
|
||||
@ -14,7 +14,7 @@ import qualified Data.ByteString.Lazy as Lazy
|
||||
import Data.Encoding.Base
|
||||
import Data.Word
|
||||
|
||||
data ASCII = ASCII
|
||||
data ASCII = ASCII deriving Show
|
||||
|
||||
charToASCII :: Char -> Word8
|
||||
charToASCII ch = if ch < '\128'
|
||||
|
||||
@ -9,7 +9,7 @@ import Data.Encoding.Base
|
||||
import Prelude hiding (lookup,all)
|
||||
import Control.Exception (throwDyn)
|
||||
|
||||
data CP1250 = CP1250
|
||||
data CP1250 = CP1250 deriving Show
|
||||
|
||||
instance Encoding CP1250 where
|
||||
encode _ = encodeSinglebyte (\c -> case lookup c encodeMap of
|
||||
|
||||
@ -9,7 +9,7 @@ import Data.Encoding.Base
|
||||
import Prelude hiding (lookup,all)
|
||||
import Control.Exception (throwDyn)
|
||||
|
||||
data CP1251 = CP1251
|
||||
data CP1251 = CP1251 deriving Show
|
||||
|
||||
instance Encoding CP1251 where
|
||||
encode _ = encodeSinglebyte (\c -> case lookup c encodeMap of
|
||||
|
||||
@ -9,7 +9,7 @@ import Data.Encoding.Base
|
||||
import Prelude hiding (lookup,all)
|
||||
import Control.Exception (throwDyn)
|
||||
|
||||
data CP1252 = CP1252
|
||||
data CP1252 = CP1252 deriving Show
|
||||
|
||||
instance Encoding CP1252 where
|
||||
encode _ = encodeSinglebyte (\c -> case lookup c encodeMap of
|
||||
|
||||
@ -9,7 +9,7 @@ import Data.Encoding.Base
|
||||
import Prelude hiding (lookup,all)
|
||||
import Control.Exception (throwDyn)
|
||||
|
||||
data CP1253 = CP1253
|
||||
data CP1253 = CP1253 deriving Show
|
||||
|
||||
instance Encoding CP1253 where
|
||||
encode _ = encodeSinglebyte (\c -> case lookup c encodeMap of
|
||||
|
||||
@ -9,7 +9,7 @@ import Data.Encoding.Base
|
||||
import Prelude hiding (lookup,all)
|
||||
import Control.Exception (throwDyn)
|
||||
|
||||
data CP1254 = CP1254
|
||||
data CP1254 = CP1254 deriving Show
|
||||
|
||||
instance Encoding CP1254 where
|
||||
encode _ = encodeSinglebyte (\c -> case lookup c encodeMap of
|
||||
|
||||
@ -9,7 +9,7 @@ import Data.Encoding.Base
|
||||
import Prelude hiding (lookup,all)
|
||||
import Control.Exception (throwDyn)
|
||||
|
||||
data CP1255 = CP1255
|
||||
data CP1255 = CP1255 deriving Show
|
||||
|
||||
instance Encoding CP1255 where
|
||||
encode _ = encodeSinglebyte (\c -> case lookup c encodeMap of
|
||||
|
||||
@ -9,7 +9,7 @@ import Data.Encoding.Base
|
||||
import Prelude hiding (lookup,all)
|
||||
import Control.Exception (throwDyn)
|
||||
|
||||
data CP1256 = CP1256
|
||||
data CP1256 = CP1256 deriving Show
|
||||
|
||||
instance Encoding CP1256 where
|
||||
encode _ = encodeSinglebyte (\c -> case lookup c encodeMap of
|
||||
|
||||
@ -9,7 +9,7 @@ import Data.Encoding.Base
|
||||
import Prelude hiding (lookup,all)
|
||||
import Control.Exception (throwDyn)
|
||||
|
||||
data CP1257 = CP1257
|
||||
data CP1257 = CP1257 deriving Show
|
||||
|
||||
instance Encoding CP1257 where
|
||||
encode _ = encodeSinglebyte (\c -> case lookup c encodeMap of
|
||||
|
||||
@ -9,7 +9,7 @@ import Data.Encoding.Base
|
||||
import Prelude hiding (lookup,all)
|
||||
import Control.Exception (throwDyn)
|
||||
|
||||
data CP1258 = CP1258
|
||||
data CP1258 = CP1258 deriving Show
|
||||
|
||||
instance Encoding CP1258 where
|
||||
encode _ = encodeSinglebyte (\c -> case lookup c encodeMap of
|
||||
|
||||
@ -16,7 +16,7 @@ import Data.ByteString.Base (ByteString,c2w,w2c,unsafeIndex)
|
||||
|
||||
import Data.Encoding.GB18030Data
|
||||
|
||||
data GB18030 = GB18030
|
||||
data GB18030 = GB18030 deriving Show
|
||||
|
||||
instance Encoding GB18030 where
|
||||
encode _ = encodeMultibyte encodeGB
|
||||
|
||||
@ -11,7 +11,7 @@ import Data.Char(ord,chr)
|
||||
import Data.Word
|
||||
import Control.Exception
|
||||
|
||||
data ISO88591 = ISO88591
|
||||
data ISO88591 = ISO88591 deriving Show
|
||||
|
||||
enc :: Char -> Word8
|
||||
enc c = if ord c < 256
|
||||
|
||||
@ -8,7 +8,7 @@ import Data.Encoding.Base
|
||||
import Prelude hiding (lookup)
|
||||
import Control.Exception (throwDyn)
|
||||
|
||||
data ISO885910 = ISO885910
|
||||
data ISO885910 = ISO885910 deriving Show
|
||||
|
||||
enc :: Char -> Word8
|
||||
enc c = case lookup c encodeMap of
|
||||
|
||||
@ -8,7 +8,7 @@ import Data.Encoding.Base
|
||||
import Prelude hiding (lookup)
|
||||
import Control.Exception (throwDyn)
|
||||
|
||||
data ISO885911 = ISO885911
|
||||
data ISO885911 = ISO885911 deriving Show
|
||||
|
||||
enc :: Char -> Word8
|
||||
enc c = case lookup c encodeMap of
|
||||
|
||||
@ -8,7 +8,7 @@ import Data.Encoding.Base
|
||||
import Prelude hiding (lookup)
|
||||
import Control.Exception (throwDyn)
|
||||
|
||||
data ISO885913 = ISO885913
|
||||
data ISO885913 = ISO885913 deriving Show
|
||||
|
||||
enc :: Char -> Word8
|
||||
enc c = case lookup c encodeMap of
|
||||
|
||||
@ -8,7 +8,7 @@ import Data.Encoding.Base
|
||||
import Prelude hiding (lookup)
|
||||
import Control.Exception (throwDyn)
|
||||
|
||||
data ISO885914 = ISO885914
|
||||
data ISO885914 = ISO885914 deriving Show
|
||||
|
||||
enc :: Char -> Word8
|
||||
enc c = case lookup c encodeMap of
|
||||
|
||||
@ -8,7 +8,7 @@ import Data.Encoding.Base
|
||||
import Prelude hiding (lookup)
|
||||
import Control.Exception (throwDyn)
|
||||
|
||||
data ISO885915 = ISO885915
|
||||
data ISO885915 = ISO885915 deriving Show
|
||||
|
||||
enc :: Char -> Word8
|
||||
enc c = case lookup c encodeMap of
|
||||
|
||||
@ -8,7 +8,7 @@ import Data.Encoding.Base
|
||||
import Prelude hiding (lookup)
|
||||
import Control.Exception (throwDyn)
|
||||
|
||||
data ISO885916 = ISO885916
|
||||
data ISO885916 = ISO885916 deriving Show
|
||||
|
||||
enc :: Char -> Word8
|
||||
enc c = case lookup c encodeMap of
|
||||
|
||||
@ -12,7 +12,7 @@ import Data.ByteString hiding (length,map)
|
||||
import Prelude hiding (lookup,all)
|
||||
import Control.Exception
|
||||
|
||||
data ISO88592 = ISO88592
|
||||
data ISO88592 = ISO88592 deriving Show
|
||||
|
||||
enc :: Char -> Word8
|
||||
enc c = case lookup c encodeMap of
|
||||
|
||||
@ -10,7 +10,7 @@ import Data.Encoding.Base
|
||||
import Prelude hiding (lookup)
|
||||
import Control.Exception (throwDyn)
|
||||
|
||||
data ISO88593 = ISO88593
|
||||
data ISO88593 = ISO88593 deriving Show
|
||||
|
||||
enc :: Char -> Word8
|
||||
enc c = case lookup c encodeMap of
|
||||
|
||||
@ -8,7 +8,7 @@ import Data.Encoding.Base
|
||||
import Prelude hiding (lookup)
|
||||
import Control.Exception (throwDyn)
|
||||
|
||||
data ISO88594 = ISO88594
|
||||
data ISO88594 = ISO88594 deriving Show
|
||||
|
||||
enc :: Char -> Word8
|
||||
enc c = case lookup c encodeMap of
|
||||
|
||||
@ -8,7 +8,7 @@ import Data.Encoding.Base
|
||||
import Prelude hiding (lookup)
|
||||
import Control.Exception (throwDyn)
|
||||
|
||||
data ISO88595 = ISO88595
|
||||
data ISO88595 = ISO88595 deriving Show
|
||||
|
||||
instance Encoding ISO88595 where
|
||||
encode _ = encodeSinglebyte (\c -> case lookup c encodeMap of
|
||||
|
||||
@ -8,7 +8,7 @@ import Data.Encoding.Base
|
||||
import Prelude hiding (lookup)
|
||||
import Control.Exception (throwDyn)
|
||||
|
||||
data ISO88596 = ISO88596
|
||||
data ISO88596 = ISO88596 deriving Show
|
||||
|
||||
instance Encoding ISO88596 where
|
||||
encode _ = encodeSinglebyte (\c -> case lookup c encodeMap of
|
||||
|
||||
@ -8,7 +8,7 @@ import Data.Encoding.Base
|
||||
import Prelude hiding (lookup)
|
||||
import Control.Exception (throwDyn)
|
||||
|
||||
data ISO88597 = ISO88597
|
||||
data ISO88597 = ISO88597 deriving Show
|
||||
|
||||
instance Encoding ISO88597 where
|
||||
encode _ = encodeSinglebyte (\c -> case lookup c encodeMap of
|
||||
|
||||
@ -8,7 +8,7 @@ import Data.Encoding.Base
|
||||
import Prelude hiding (lookup)
|
||||
import Control.Exception (throwDyn)
|
||||
|
||||
data ISO88598 = ISO88598
|
||||
data ISO88598 = ISO88598 deriving Show
|
||||
|
||||
instance Encoding ISO88598 where
|
||||
encode _ = encodeSinglebyte (\c -> case lookup c encodeMap of
|
||||
|
||||
@ -8,7 +8,7 @@ import Data.Encoding.Base
|
||||
import Prelude hiding (lookup)
|
||||
import Control.Exception (throwDyn)
|
||||
|
||||
data ISO88599 = ISO88599
|
||||
data ISO88599 = ISO88599 deriving Show
|
||||
|
||||
instance Encoding ISO88599 where
|
||||
encode _ = encodeSinglebyte (\c -> case lookup c encodeMap of
|
||||
|
||||
@ -11,7 +11,7 @@ import Prelude hiding (lookup)
|
||||
|
||||
import Data.Encoding.Base
|
||||
|
||||
data KOI8R = KOI8R
|
||||
data KOI8R = KOI8R deriving Show
|
||||
|
||||
koi8rArr :: UArray Word8 Char
|
||||
koi8rArr = listArray (128,255) koi8rList
|
||||
|
||||
@ -16,7 +16,7 @@ import Prelude hiding (length)
|
||||
import Control.Exception
|
||||
import Data.Dynamic (toDyn)
|
||||
|
||||
data UTF16 = UTF16
|
||||
data UTF16 = UTF16 deriving Show
|
||||
|
||||
utf16enc :: (EncodeState,String) -> Maybe (Word8,(EncodeState,String))
|
||||
utf16enc (Done,[]) = Nothing
|
||||
|
||||
@ -8,7 +8,7 @@ import Data.Encoding.Base
|
||||
import Data.Word
|
||||
import Control.Exception (throwDyn)
|
||||
|
||||
data UTF32 = UTF32
|
||||
data UTF32 = UTF32 deriving Show
|
||||
|
||||
instance Encoding UTF32 where
|
||||
encode _ = encodeMultibyte encodeUTF32
|
||||
|
||||
@ -12,7 +12,7 @@ import Data.Word
|
||||
import Prelude hiding (length)
|
||||
import Control.Exception
|
||||
|
||||
data UTF8 = UTF8
|
||||
data UTF8 = UTF8 deriving Show
|
||||
|
||||
encodeUTF8 :: Char -> (Word8,EncodeState)
|
||||
encodeUTF8 x
|
||||
|
||||
Loading…
Reference in New Issue
Block a user