module Data.Machines.Encoding.Text
( decodeLatin1
, encodeUtf8, decodeUtf8
) where
import Data.ByteString (ByteString)
import Data.Machine
import Data.Text (Text)
import qualified Data.Text.Encoding as TE
decodeLatin1 :: Process ByteString Text
decodeLatin1 = auto TE.decodeLatin1
{-# INLINE decodeLatin1 #-}
encodeUtf8 :: Process Text ByteString
encodeUtf8 = auto TE.encodeUtf8
{-# LANGUAGE encodeUtf8 #-}
decodeUtf8 :: Process ByteString Text
decodeUtf8 = auto . Mealy $ runDecode . TE.streamDecodeUtf8
where
runDecode :: TE.Decoding -> (Text, Mealy ByteString Text)
runDecode (TE.Some r _ c) = (r, Mealy $ runDecode . c)
{-# INLINE runDecode #-}
{-# INLINE decodeUtf8 #-}