{-# OPTIONS_GHC -fno-warn-orphans #-}
module BishBosh.Text.Encoding (
tag,
range
) where
import qualified Data.Default
import qualified Data.List.Extra
import qualified Text.XML.HXT.Arrow.Pickle as HXT
import qualified Text.XML.HXT.Arrow.Pickle.Schema
import qualified System.IO
tag :: String
tag = "textEncoding"
instance Eq System.IO.TextEncoding where
l == r = show l == show r
instance Read System.IO.TextEncoding where
readsPrec _ s = case Data.List.Extra.trimStart s of
'I':'S':'O':'8':'8':'5':'9':'-':'1':remainder -> return . (,) System.IO.latin1 $ case remainder of
'(':'c':'h':'e':'c':'k':'e':'d':')':remainder2 -> remainder2
_ -> remainder
'U':'T':'F':'-':'8':remainder -> [(System.IO.utf8, remainder)]
'U':'T':'F':'-':'1':'6':remainder -> [(System.IO.utf16, remainder)]
'U':'T':'F':'-':'3':'2':remainder -> [(System.IO.utf32, remainder)]
_ -> []
instance HXT.XmlPickler System.IO.TextEncoding where
xpickle = HXT.xpDefault Data.Default.def . HXT.xpWrap (read, show) . HXT.xpAttr tag . HXT.xpTextDT . Text.XML.HXT.Arrow.Pickle.Schema.scEnum $ map show range
instance Data.Default.Default System.IO.TextEncoding where
def = System.IO.utf8
range :: [System.IO.TextEncoding]
range = [
System.IO.latin1,
System.IO.utf8,
System.IO.utf16,
System.IO.utf32
]