From cb81698b7e78aa5e342f63fe32a6db5a798477a8 Mon Sep 17 00:00:00 2001 From: Henning Guenther Date: Sun, 26 Aug 2007 19:08:33 -0700 Subject: [PATCH] Derived all encodings from Show This way, we can declare DynEncoding an instance of Show darcs-hash:20070827020833-a4fee-a84635bf911573022b780c17b2085ff814302b3e --- Data/Encoding.hs | 5 ++++- Data/Encoding/ASCII.hs | 2 +- Data/Encoding/CP1250.hs | 2 +- Data/Encoding/CP1251.hs | 2 +- Data/Encoding/CP1252.hs | 2 +- Data/Encoding/CP1253.hs | 2 +- Data/Encoding/CP1254.hs | 2 +- Data/Encoding/CP1255.hs | 2 +- Data/Encoding/CP1256.hs | 2 +- Data/Encoding/CP1257.hs | 2 +- Data/Encoding/CP1258.hs | 2 +- Data/Encoding/GB18030.hs | 2 +- Data/Encoding/ISO88591.hs | 2 +- Data/Encoding/ISO885910.hs | 2 +- Data/Encoding/ISO885911.hs | 2 +- Data/Encoding/ISO885913.hs | 2 +- Data/Encoding/ISO885914.hs | 2 +- Data/Encoding/ISO885915.hs | 2 +- Data/Encoding/ISO885916.hs | 2 +- Data/Encoding/ISO88592.hs | 2 +- Data/Encoding/ISO88593.hs | 2 +- Data/Encoding/ISO88594.hs | 2 +- Data/Encoding/ISO88595.hs | 2 +- Data/Encoding/ISO88596.hs | 2 +- Data/Encoding/ISO88597.hs | 2 +- Data/Encoding/ISO88598.hs | 2 +- Data/Encoding/ISO88599.hs | 2 +- Data/Encoding/KOI8R.hs | 2 +- Data/Encoding/UTF16.hs | 2 +- Data/Encoding/UTF32.hs | 2 +- Data/Encoding/UTF8.hs | 2 +- 31 files changed, 34 insertions(+), 31 deletions(-) diff --git a/Data/Encoding.hs b/Data/Encoding.hs index dd9cbe5..380a237 100644 --- a/Data/Encoding.hs +++ b/Data/Encoding.hs @@ -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) diff --git a/Data/Encoding/ASCII.hs b/Data/Encoding/ASCII.hs index 1a2acda..d26ddb0 100644 --- a/Data/Encoding/ASCII.hs +++ b/Data/Encoding/ASCII.hs @@ -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' diff --git a/Data/Encoding/CP1250.hs b/Data/Encoding/CP1250.hs index d34a281..6e89d19 100644 --- a/Data/Encoding/CP1250.hs +++ b/Data/Encoding/CP1250.hs @@ -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 diff --git a/Data/Encoding/CP1251.hs b/Data/Encoding/CP1251.hs index 1d7075a..b47ab76 100644 --- a/Data/Encoding/CP1251.hs +++ b/Data/Encoding/CP1251.hs @@ -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 diff --git a/Data/Encoding/CP1252.hs b/Data/Encoding/CP1252.hs index 4e20fc3..e8cc2bc 100644 --- a/Data/Encoding/CP1252.hs +++ b/Data/Encoding/CP1252.hs @@ -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 diff --git a/Data/Encoding/CP1253.hs b/Data/Encoding/CP1253.hs index 4c97b34..de16de2 100644 --- a/Data/Encoding/CP1253.hs +++ b/Data/Encoding/CP1253.hs @@ -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 diff --git a/Data/Encoding/CP1254.hs b/Data/Encoding/CP1254.hs index d74b33e..0e58dab 100644 --- a/Data/Encoding/CP1254.hs +++ b/Data/Encoding/CP1254.hs @@ -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 diff --git a/Data/Encoding/CP1255.hs b/Data/Encoding/CP1255.hs index 37e3792..d0f6f55 100644 --- a/Data/Encoding/CP1255.hs +++ b/Data/Encoding/CP1255.hs @@ -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 diff --git a/Data/Encoding/CP1256.hs b/Data/Encoding/CP1256.hs index f2ca702..b0eaf89 100644 --- a/Data/Encoding/CP1256.hs +++ b/Data/Encoding/CP1256.hs @@ -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 diff --git a/Data/Encoding/CP1257.hs b/Data/Encoding/CP1257.hs index e542a5c..ec73ae1 100644 --- a/Data/Encoding/CP1257.hs +++ b/Data/Encoding/CP1257.hs @@ -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 diff --git a/Data/Encoding/CP1258.hs b/Data/Encoding/CP1258.hs index f466f26..29b18c3 100644 --- a/Data/Encoding/CP1258.hs +++ b/Data/Encoding/CP1258.hs @@ -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 diff --git a/Data/Encoding/GB18030.hs b/Data/Encoding/GB18030.hs index f1e91eb..b3ca5f5 100644 --- a/Data/Encoding/GB18030.hs +++ b/Data/Encoding/GB18030.hs @@ -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 diff --git a/Data/Encoding/ISO88591.hs b/Data/Encoding/ISO88591.hs index 6c9be94..f1945fa 100644 --- a/Data/Encoding/ISO88591.hs +++ b/Data/Encoding/ISO88591.hs @@ -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 diff --git a/Data/Encoding/ISO885910.hs b/Data/Encoding/ISO885910.hs index de56f3f..57eac4f 100644 --- a/Data/Encoding/ISO885910.hs +++ b/Data/Encoding/ISO885910.hs @@ -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 diff --git a/Data/Encoding/ISO885911.hs b/Data/Encoding/ISO885911.hs index acd573b..0ace8a0 100644 --- a/Data/Encoding/ISO885911.hs +++ b/Data/Encoding/ISO885911.hs @@ -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 diff --git a/Data/Encoding/ISO885913.hs b/Data/Encoding/ISO885913.hs index 52d56cb..4d8a606 100644 --- a/Data/Encoding/ISO885913.hs +++ b/Data/Encoding/ISO885913.hs @@ -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 diff --git a/Data/Encoding/ISO885914.hs b/Data/Encoding/ISO885914.hs index abd676a..cda80fc 100644 --- a/Data/Encoding/ISO885914.hs +++ b/Data/Encoding/ISO885914.hs @@ -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 diff --git a/Data/Encoding/ISO885915.hs b/Data/Encoding/ISO885915.hs index e2055fe..9d0510a 100644 --- a/Data/Encoding/ISO885915.hs +++ b/Data/Encoding/ISO885915.hs @@ -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 diff --git a/Data/Encoding/ISO885916.hs b/Data/Encoding/ISO885916.hs index 0f11d5d..4825cb1 100644 --- a/Data/Encoding/ISO885916.hs +++ b/Data/Encoding/ISO885916.hs @@ -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 diff --git a/Data/Encoding/ISO88592.hs b/Data/Encoding/ISO88592.hs index b75c4d4..845262a 100644 --- a/Data/Encoding/ISO88592.hs +++ b/Data/Encoding/ISO88592.hs @@ -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 diff --git a/Data/Encoding/ISO88593.hs b/Data/Encoding/ISO88593.hs index 18f196b..0785042 100644 --- a/Data/Encoding/ISO88593.hs +++ b/Data/Encoding/ISO88593.hs @@ -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 diff --git a/Data/Encoding/ISO88594.hs b/Data/Encoding/ISO88594.hs index 98ed51f..8d7b067 100644 --- a/Data/Encoding/ISO88594.hs +++ b/Data/Encoding/ISO88594.hs @@ -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 diff --git a/Data/Encoding/ISO88595.hs b/Data/Encoding/ISO88595.hs index 8563cdd..c5ec887 100644 --- a/Data/Encoding/ISO88595.hs +++ b/Data/Encoding/ISO88595.hs @@ -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 diff --git a/Data/Encoding/ISO88596.hs b/Data/Encoding/ISO88596.hs index 54e5c6e..b0888d4 100644 --- a/Data/Encoding/ISO88596.hs +++ b/Data/Encoding/ISO88596.hs @@ -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 diff --git a/Data/Encoding/ISO88597.hs b/Data/Encoding/ISO88597.hs index 67de70c..0d8c22f 100644 --- a/Data/Encoding/ISO88597.hs +++ b/Data/Encoding/ISO88597.hs @@ -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 diff --git a/Data/Encoding/ISO88598.hs b/Data/Encoding/ISO88598.hs index 9bce140..5ef32e6 100644 --- a/Data/Encoding/ISO88598.hs +++ b/Data/Encoding/ISO88598.hs @@ -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 diff --git a/Data/Encoding/ISO88599.hs b/Data/Encoding/ISO88599.hs index 9cc0175..0c7187f 100644 --- a/Data/Encoding/ISO88599.hs +++ b/Data/Encoding/ISO88599.hs @@ -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 diff --git a/Data/Encoding/KOI8R.hs b/Data/Encoding/KOI8R.hs index 8172210..ccb8335 100644 --- a/Data/Encoding/KOI8R.hs +++ b/Data/Encoding/KOI8R.hs @@ -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 diff --git a/Data/Encoding/UTF16.hs b/Data/Encoding/UTF16.hs index 0b1f633..19f5bd5 100644 --- a/Data/Encoding/UTF16.hs +++ b/Data/Encoding/UTF16.hs @@ -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 diff --git a/Data/Encoding/UTF32.hs b/Data/Encoding/UTF32.hs index c4db400..3e0fe5d 100644 --- a/Data/Encoding/UTF32.hs +++ b/Data/Encoding/UTF32.hs @@ -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 diff --git a/Data/Encoding/UTF8.hs b/Data/Encoding/UTF8.hs index fc10726..696d216 100644 --- a/Data/Encoding/UTF8.hs +++ b/Data/Encoding/UTF8.hs @@ -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