{-# 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':remainder -> case remainder of
'8':'8':'5':'9':'-':'1':remainder2 -> return . (,) System.IO.latin1 $ case remainder2 of
'(':'c':'h':'e':'c':'k':'e':'d':')':remainder3 -> remainder3
_ -> remainder2
'-':'8':'8':'5':'9':'-':'1':remainder2 -> return . (,) System.IO.latin1 $ case remainder2 of
'(':'c':'h':'e':'c':'k':'e':'d':')':remainder3 -> remainder3
_ -> remainder2
_ -> []
'U':'T':'F':'-':remainder -> case remainder of
'8':remainder2 -> [(System.IO.utf8, remainder2)]
'1':'6':remainder2 -> [(System.IO.utf16, remainder2)]
'3':'2':remainder2 -> [(System.IO.utf32, remainder2)]
_ -> []
_ -> []
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
]