GHC/IO/Encoding/Types.hs (original) (raw)

module GHC.IO.Encoding.Types ( BufferCodec(..), TextEncoding(..), TextEncoder, TextDecoder, EncodeBuffer, DecodeBuffer, CodingProgress(..) ) where

import GHC.Base import GHC.Word import GHC.Show

import GHC.IO.Buffer

data BufferCodec from to state = BufferCodec { encode :: Buffer from -> Buffer to -> IO (CodingProgress, Buffer from, Buffer to),

recover :: Buffer from -> Buffer to -> IO (Buffer from, Buffer to),

close :: IO (),

getState :: IO state,

setState :: state -> IO ()

}

type DecodeBuffer = Buffer Word8 -> Buffer Char -> IO (CodingProgress, Buffer Word8, Buffer Char)

type EncodeBuffer = Buffer Char -> Buffer Word8 -> IO (CodingProgress, Buffer Char, Buffer Word8)

type TextDecoder state = BufferCodec Word8 CharBufElem state type TextEncoder state = BufferCodec CharBufElem Word8 state

data TextEncoding = forall dstate estate . TextEncoding { textEncodingName :: String,

    mkTextDecoder :: IO (TextDecoder dstate),
               
               
    mkTextEncoder :: IO (TextEncoder estate)
               
               

}

instance Show TextEncoding where

show te = textEncodingName te

data CodingProgress = InputUnderflow

                | OutputUnderflow 
                | InvalidSequence 
                                  
                                  
                deriving (Eq, Show)