Movatterモバイル変換
[0]ホーム
{-# LANGUAGE Trustworthy #-}{-# LANGUAGE NoImplicitPrelude , BangPatterns , NondecreasingIndentation , MagicHash , UnboxedTuples #-}{-# OPTIONS_GHC -funbox-strict-fields #-}------------------------------------------------------------------------------- |-- Module : GHC.IO.Encoding.UTF32-- Copyright : (c) The University of Glasgow, 2009-- License : see libraries/base/LICENSE---- Maintainer : libraries@haskell.org-- Stability : internal-- Portability : non-portable---- UTF-32 Codecs for the IO library---- Portions Copyright : (c) Tom Harper 2008-2009,-- (c) Bryan O'Sullivan 2009,-- (c) Duncan Coutts 2009-------------------------------------------------------------------------------moduleGHC.IO.Encoding.UTF32(utf32,mkUTF32,utf32_decode,utf32_encode,utf32be,mkUTF32be,utf32be_decode,utf32be_encode,utf32le,mkUTF32le,utf32le_decode,utf32le_encode,)whereimportGHC.BaseimportGHC.RealimportGHC.Num-- import GHC.IOimportGHC.IO.BufferimportGHC.IO.Encoding.FailureimportGHC.IO.Encoding.TypesimportGHC.WordimportData.BitsimportGHC.IORef-- ------------------------------------------------------------------------------- The UTF-32 codec: either UTF-32BE or UTF-32LE with a BOMutf32::TextEncodingutf32 :: TextEncodingutf32=CodingFailureMode -> TextEncodingmkUTF32CodingFailureModeErrorOnCodingFailure-- | @since 4.4.0.0mkUTF32::CodingFailureMode->TextEncodingmkUTF32 :: CodingFailureMode -> TextEncodingmkUTF32CodingFailureModecfm=TextEncoding{textEncodingName :: StringtextEncodingName=String"UTF-32",mkTextDecoder :: IO (TextDecoder (Maybe DecodeBuffer#))mkTextDecoder=CodingFailureMode -> IO (TextDecoder (Maybe DecodeBuffer#))utf32_DFCodingFailureModecfm,mkTextEncoder :: IO (TextEncoder Bool)mkTextEncoder=CodingFailureMode -> IO (TextEncoder Bool)utf32_EFCodingFailureModecfm}utf32_DF::CodingFailureMode->IO(TextDecoder(MaybeDecodeBuffer#))utf32_DF :: CodingFailureMode -> IO (TextDecoder (Maybe DecodeBuffer#))utf32_DFCodingFailureModecfm=doIORef (Maybe DecodeBuffer#)seen_bom<-Maybe DecodeBuffer# -> IO (IORef (Maybe DecodeBuffer#))forall a. a -> IO (IORef a)newIORefMaybe DecodeBuffer#forall a. Maybe aNothingTextDecoder (Maybe DecodeBuffer#)-> IO (TextDecoder (Maybe DecodeBuffer#))forall a. a -> IO aforall (m :: * -> *) a. Monad m => a -> m areturn(BufferCodec#{encode# :: DecodeBuffer#encode#=IORef (Maybe DecodeBuffer#) -> DecodeBuffer#utf32_decodeIORef (Maybe DecodeBuffer#)seen_bom,recover# :: Buffer Word8-> Buffer Char-> State# RealWorld-> (# State# RealWorld, Buffer Word8, Buffer Char #)recover#=CodingFailureMode-> Buffer Word8-> Buffer Char-> State# RealWorld-> (# State# RealWorld, Buffer Word8, Buffer Char #)recoverDecode#CodingFailureModecfm,close# :: IO ()close#=() -> IO ()forall a. a -> IO aforall (m :: * -> *) a. Monad m => a -> m areturn(),getState# :: IO (Maybe DecodeBuffer#)getState#=IORef (Maybe DecodeBuffer#) -> IO (Maybe DecodeBuffer#)forall a. IORef a -> IO areadIORefIORef (Maybe DecodeBuffer#)seen_bom,setState# :: Maybe DecodeBuffer# -> IO ()setState#=IORef (Maybe DecodeBuffer#) -> Maybe DecodeBuffer# -> IO ()forall a. IORef a -> a -> IO ()writeIORefIORef (Maybe DecodeBuffer#)seen_bom})utf32_EF::CodingFailureMode->IO(TextEncoderBool)utf32_EF :: CodingFailureMode -> IO (TextEncoder Bool)utf32_EFCodingFailureModecfm=doIORef Booldone_bom<-Bool -> IO (IORef Bool)forall a. a -> IO (IORef a)newIORefBoolFalseTextEncoder Bool -> IO (TextEncoder Bool)forall a. a -> IO aforall (m :: * -> *) a. Monad m => a -> m areturn(BufferCodec#{encode# :: CodeBuffer# Char Word8encode#=IORef Bool -> CodeBuffer# Char Word8utf32_encodeIORef Booldone_bom,recover# :: Buffer Char-> Buffer Word8-> State# RealWorld-> (# State# RealWorld, Buffer Char, Buffer Word8 #)recover#=CodingFailureMode-> Buffer Char-> Buffer Word8-> State# RealWorld-> (# State# RealWorld, Buffer Char, Buffer Word8 #)recoverEncode#CodingFailureModecfm,close# :: IO ()close#=() -> IO ()forall a. a -> IO aforall (m :: * -> *) a. Monad m => a -> m areturn(),getState# :: IO BoolgetState#=IORef Bool -> IO Boolforall a. IORef a -> IO areadIORefIORef Booldone_bom,setState# :: Bool -> IO ()setState#=IORef Bool -> Bool -> IO ()forall a. IORef a -> a -> IO ()writeIORefIORef Booldone_bom})utf32_encode::IORefBool->EncodeBuffer#utf32_encode :: IORef Bool -> CodeBuffer# Char Word8utf32_encodeIORef Booldone_bomBuffer Charinputoutput :: Buffer Word8output@Buffer{bufRaw :: forall e. Buffer e -> RawBuffer ebufRaw=RawBuffer Word8oraw,bufL :: forall e. Buffer e -> IntbufL=Int_,bufR :: forall e. Buffer e -> IntbufR=Intow,bufSize :: forall e. Buffer e -> IntbufSize=Intos}State# RealWorldst0=dolet!(#State# RealWorldst1,Boolb#)=IO Bool -> State# RealWorld -> (# State# RealWorld, Bool #)forall a. IO a -> State# RealWorld -> (# State# RealWorld, a #)unIO(IORef Bool -> IO Boolforall a. IORef a -> IO areadIORefIORef Booldone_bom)State# RealWorldst0ifBoolbthenCodeBuffer# Char Word8utf32_native_encodeBuffer CharinputBuffer Word8outputState# RealWorldst1elseifIntosInt -> Int -> Intforall a. Num a => a -> a -> a-IntowInt -> Int -> Boolforall a. Ord a => a -> a -> Bool<Int4then(#State# RealWorldst1,CodingProgressOutputUnderflow,Buffer Charinput,Buffer Word8output#)elsedolet!(#State# RealWorldst2,()#)=IO () -> State# RealWorld -> (# State# RealWorld, () #)forall a. IO a -> State# RealWorld -> (# State# RealWorld, a #)unIO(IORef Bool -> Bool -> IO ()forall a. IORef a -> a -> IO ()writeIORefIORef Booldone_bomBoolTrue)State# RealWorldst1!(#State# RealWorldst3,()#)=IO () -> State# RealWorld -> (# State# RealWorld, () #)forall a. IO a -> State# RealWorld -> (# State# RealWorld, a #)unIO(RawBuffer Word8 -> Int -> Word8 -> IO ()writeWord8BufRawBuffer Word8orawIntowWord8bom0)State# RealWorldst2!(#State# RealWorldst4,()#)=IO () -> State# RealWorld -> (# State# RealWorld, () #)forall a. IO a -> State# RealWorld -> (# State# RealWorld, a #)unIO(RawBuffer Word8 -> Int -> Word8 -> IO ()writeWord8BufRawBuffer Word8oraw(IntowInt -> Int -> Intforall a. Num a => a -> a -> a+Int1)Word8bom1)State# RealWorldst3!(#State# RealWorldst5,()#)=IO () -> State# RealWorld -> (# State# RealWorld, () #)forall a. IO a -> State# RealWorld -> (# State# RealWorld, a #)unIO(RawBuffer Word8 -> Int -> Word8 -> IO ()writeWord8BufRawBuffer Word8oraw(IntowInt -> Int -> Intforall a. Num a => a -> a -> a+Int2)Word8bom2)State# RealWorldst4!(#State# RealWorldst6,()#)=IO () -> State# RealWorld -> (# State# RealWorld, () #)forall a. IO a -> State# RealWorld -> (# State# RealWorld, a #)unIO(RawBuffer Word8 -> Int -> Word8 -> IO ()writeWord8BufRawBuffer Word8oraw(IntowInt -> Int -> Intforall a. Num a => a -> a -> a+Int3)Word8bom3)State# RealWorldst5CodeBuffer# Char Word8utf32_native_encodeBuffer CharinputBuffer Word8output{bufR=ow+4}State# RealWorldst6utf32_decode::IORef(MaybeDecodeBuffer#)->DecodeBuffer#utf32_decode :: IORef (Maybe DecodeBuffer#) -> DecodeBuffer#utf32_decodeIORef (Maybe DecodeBuffer#)seen_bominput :: Buffer Word8input@Buffer{bufRaw :: forall e. Buffer e -> RawBuffer ebufRaw=RawBuffer Word8iraw,bufL :: forall e. Buffer e -> IntbufL=Intir,bufR :: forall e. Buffer e -> IntbufR=Intiw,bufSize :: forall e. Buffer e -> IntbufSize=Int_}Buffer CharoutputState# RealWorldst0=dolet!(#State# RealWorldst1,Maybe DecodeBuffer#mb#)=IO (Maybe DecodeBuffer#)-> State# RealWorld -> (# State# RealWorld, Maybe DecodeBuffer# #)forall a. IO a -> State# RealWorld -> (# State# RealWorld, a #)unIO(IORef (Maybe DecodeBuffer#) -> IO (Maybe DecodeBuffer#)forall a. IORef a -> IO areadIORefIORef (Maybe DecodeBuffer#)seen_bom)State# RealWorldst0caseMaybe DecodeBuffer#mbofJustDecodeBuffer#decode->DecodeBuffer#decodeBuffer Word8inputBuffer CharoutputState# RealWorldst1Maybe DecodeBuffer#Nothing->ifIntiwInt -> Int -> Intforall a. Num a => a -> a -> a-IntirInt -> Int -> Boolforall a. Ord a => a -> a -> Bool<Int4then(#State# RealWorldst1,CodingProgressInputUnderflow,Buffer Word8input,Buffer Charoutput#)elsedolet!(#State# RealWorldst2,Word8c0#)=IO Word8 -> State# RealWorld -> (# State# RealWorld, Word8 #)forall a. IO a -> State# RealWorld -> (# State# RealWorld, a #)unIO(RawBuffer Word8 -> Int -> IO Word8readWord8BufRawBuffer Word8irawIntir)State# RealWorldst1!(#State# RealWorldst3,Word8c1#)=IO Word8 -> State# RealWorld -> (# State# RealWorld, Word8 #)forall a. IO a -> State# RealWorld -> (# State# RealWorld, a #)unIO(RawBuffer Word8 -> Int -> IO Word8readWord8BufRawBuffer Word8iraw(IntirInt -> Int -> Intforall a. Num a => a -> a -> a+Int1))State# RealWorldst2!(#State# RealWorldst4,Word8c2#)=IO Word8 -> State# RealWorld -> (# State# RealWorld, Word8 #)forall a. IO a -> State# RealWorld -> (# State# RealWorld, a #)unIO(RawBuffer Word8 -> Int -> IO Word8readWord8BufRawBuffer Word8iraw(IntirInt -> Int -> Intforall a. Num a => a -> a -> a+Int2))State# RealWorldst3!(#State# RealWorldst5,Word8c3#)=IO Word8 -> State# RealWorld -> (# State# RealWorld, Word8 #)forall a. IO a -> State# RealWorld -> (# State# RealWorld, a #)unIO(RawBuffer Word8 -> Int -> IO Word8readWord8BufRawBuffer Word8iraw(IntirInt -> Int -> Intforall a. Num a => a -> a -> a+Int3))State# RealWorldst4case()of()_|Word8c0Word8 -> Word8 -> Boolforall a. Eq a => a -> a -> Bool==Word8bom0Bool -> Bool -> Bool&&Word8c1Word8 -> Word8 -> Boolforall a. Eq a => a -> a -> Bool==Word8bom1Bool -> Bool -> Bool&&Word8c2Word8 -> Word8 -> Boolforall a. Eq a => a -> a -> Bool==Word8bom2Bool -> Bool -> Bool&&Word8c3Word8 -> Word8 -> Boolforall a. Eq a => a -> a -> Bool==Word8bom3->let!(#State# RealWorldst6,()#)=IO () -> State# RealWorld -> (# State# RealWorld, () #)forall a. IO a -> State# RealWorld -> (# State# RealWorld, a #)unIO(IORef (Maybe DecodeBuffer#) -> Maybe DecodeBuffer# -> IO ()forall a. IORef a -> a -> IO ()writeIORefIORef (Maybe DecodeBuffer#)seen_bom(DecodeBuffer# -> Maybe DecodeBuffer#forall a. a -> Maybe aJustDecodeBuffer#utf32be_decode))State# RealWorldst5inDecodeBuffer#utf32be_decodeBuffer Word8input{bufL=ir+4}Buffer CharoutputState# RealWorldst6()_|Word8c0Word8 -> Word8 -> Boolforall a. Eq a => a -> a -> Bool==Word8bom3Bool -> Bool -> Bool&&Word8c1Word8 -> Word8 -> Boolforall a. Eq a => a -> a -> Bool==Word8bom2Bool -> Bool -> Bool&&Word8c2Word8 -> Word8 -> Boolforall a. Eq a => a -> a -> Bool==Word8bom1Bool -> Bool -> Bool&&Word8c3Word8 -> Word8 -> Boolforall a. Eq a => a -> a -> Bool==Word8bom0->let!(#State# RealWorldst6,()#)=IO () -> State# RealWorld -> (# State# RealWorld, () #)forall a. IO a -> State# RealWorld -> (# State# RealWorld, a #)unIO(IORef (Maybe DecodeBuffer#) -> Maybe DecodeBuffer# -> IO ()forall a. IORef a -> a -> IO ()writeIORefIORef (Maybe DecodeBuffer#)seen_bom(DecodeBuffer# -> Maybe DecodeBuffer#forall a. a -> Maybe aJustDecodeBuffer#utf32le_decode))State# RealWorldst5inDecodeBuffer#utf32le_decodeBuffer Word8input{bufL=ir+4}Buffer CharoutputState# RealWorldst6|Boolotherwise->let!(#State# RealWorldst6,()#)=IO () -> State# RealWorld -> (# State# RealWorld, () #)forall a. IO a -> State# RealWorld -> (# State# RealWorld, a #)unIO(IORef (Maybe DecodeBuffer#) -> Maybe DecodeBuffer# -> IO ()forall a. IORef a -> a -> IO ()writeIORefIORef (Maybe DecodeBuffer#)seen_bom(DecodeBuffer# -> Maybe DecodeBuffer#forall a. a -> Maybe aJustDecodeBuffer#utf32_native_decode))State# RealWorldst5inDecodeBuffer#utf32_native_decodeBuffer Word8inputBuffer CharoutputState# RealWorldst6bom0,bom1,bom2,bom3::Word8bom0 :: Word8bom0=Word80bom1 :: Word8bom1=Word80bom2 :: Word8bom2=Word80xfebom3 :: Word8bom3=Word80xff-- choose UTF-32BE by default for UTF-32 outpututf32_native_decode::DecodeBuffer#utf32_native_decode :: DecodeBuffer#utf32_native_decode=DecodeBuffer#utf32be_decodeutf32_native_encode::EncodeBuffer#utf32_native_encode :: CodeBuffer# Char Word8utf32_native_encode=CodeBuffer# Char Word8utf32be_encode-- ------------------------------------------------------------------------------- UTF32LE and UTF32BEutf32be::TextEncodingutf32be :: TextEncodingutf32be=CodingFailureMode -> TextEncodingmkUTF32beCodingFailureModeErrorOnCodingFailure-- | @since 4.4.0.0mkUTF32be::CodingFailureMode->TextEncodingmkUTF32be :: CodingFailureMode -> TextEncodingmkUTF32beCodingFailureModecfm=TextEncoding{textEncodingName :: StringtextEncodingName=String"UTF-32BE",mkTextDecoder :: IO (TextDecoder ())mkTextDecoder=CodingFailureMode -> IO (TextDecoder ())utf32be_DFCodingFailureModecfm,mkTextEncoder :: IO (TextEncoder ())mkTextEncoder=CodingFailureMode -> IO (TextEncoder ())utf32be_EFCodingFailureModecfm}utf32be_DF::CodingFailureMode->IO(TextDecoder())utf32be_DF :: CodingFailureMode -> IO (TextDecoder ())utf32be_DFCodingFailureModecfm=TextDecoder () -> IO (TextDecoder ())forall a. a -> IO aforall (m :: * -> *) a. Monad m => a -> m areturn(BufferCodec#{encode# :: DecodeBuffer#encode#=DecodeBuffer#utf32be_decode,recover# :: Buffer Word8-> Buffer Char-> State# RealWorld-> (# State# RealWorld, Buffer Word8, Buffer Char #)recover#=CodingFailureMode-> Buffer Word8-> Buffer Char-> State# RealWorld-> (# State# RealWorld, Buffer Word8, Buffer Char #)recoverDecode#CodingFailureModecfm,close# :: IO ()close#=() -> IO ()forall a. a -> IO aforall (m :: * -> *) a. Monad m => a -> m areturn(),getState# :: IO ()getState#=() -> IO ()forall a. a -> IO aforall (m :: * -> *) a. Monad m => a -> m areturn(),setState# :: () -> IO ()setState#=IO () -> () -> IO ()forall a b. a -> b -> aconst(IO () -> () -> IO ()) -> IO () -> () -> IO ()forall a b. (a -> b) -> a -> b$() -> IO ()forall a. a -> IO aforall (m :: * -> *) a. Monad m => a -> m areturn()})utf32be_EF::CodingFailureMode->IO(TextEncoder())utf32be_EF :: CodingFailureMode -> IO (TextEncoder ())utf32be_EFCodingFailureModecfm=TextEncoder () -> IO (TextEncoder ())forall a. a -> IO aforall (m :: * -> *) a. Monad m => a -> m areturn(BufferCodec#{encode# :: CodeBuffer# Char Word8encode#=CodeBuffer# Char Word8utf32be_encode,recover# :: Buffer Char-> Buffer Word8-> State# RealWorld-> (# State# RealWorld, Buffer Char, Buffer Word8 #)recover#=CodingFailureMode-> Buffer Char-> Buffer Word8-> State# RealWorld-> (# State# RealWorld, Buffer Char, Buffer Word8 #)recoverEncode#CodingFailureModecfm,close# :: IO ()close#=() -> IO ()forall a. a -> IO aforall (m :: * -> *) a. Monad m => a -> m areturn(),getState# :: IO ()getState#=() -> IO ()forall a. a -> IO aforall (m :: * -> *) a. Monad m => a -> m areturn(),setState# :: () -> IO ()setState#=IO () -> () -> IO ()forall a b. a -> b -> aconst(IO () -> () -> IO ()) -> IO () -> () -> IO ()forall a b. (a -> b) -> a -> b$() -> IO ()forall a. a -> IO aforall (m :: * -> *) a. Monad m => a -> m areturn()})utf32le::TextEncodingutf32le :: TextEncodingutf32le=CodingFailureMode -> TextEncodingmkUTF32leCodingFailureModeErrorOnCodingFailure-- | @since 4.4.0.0mkUTF32le::CodingFailureMode->TextEncodingmkUTF32le :: CodingFailureMode -> TextEncodingmkUTF32leCodingFailureModecfm=TextEncoding{textEncodingName :: StringtextEncodingName=String"UTF-32LE",mkTextDecoder :: IO (TextDecoder ())mkTextDecoder=CodingFailureMode -> IO (TextDecoder ())utf32le_DFCodingFailureModecfm,mkTextEncoder :: IO (TextEncoder ())mkTextEncoder=CodingFailureMode -> IO (TextEncoder ())utf32le_EFCodingFailureModecfm}utf32le_DF::CodingFailureMode->IO(TextDecoder())utf32le_DF :: CodingFailureMode -> IO (TextDecoder ())utf32le_DFCodingFailureModecfm=TextDecoder () -> IO (TextDecoder ())forall a. a -> IO aforall (m :: * -> *) a. Monad m => a -> m areturn(BufferCodec#{encode# :: DecodeBuffer#encode#=DecodeBuffer#utf32le_decode,recover# :: Buffer Word8-> Buffer Char-> State# RealWorld-> (# State# RealWorld, Buffer Word8, Buffer Char #)recover#=CodingFailureMode-> Buffer Word8-> Buffer Char-> State# RealWorld-> (# State# RealWorld, Buffer Word8, Buffer Char #)recoverDecode#CodingFailureModecfm,close# :: IO ()close#=() -> IO ()forall a. a -> IO aforall (m :: * -> *) a. Monad m => a -> m areturn(),getState# :: IO ()getState#=() -> IO ()forall a. a -> IO aforall (m :: * -> *) a. Monad m => a -> m areturn(),setState# :: () -> IO ()setState#=IO () -> () -> IO ()forall a b. a -> b -> aconst(IO () -> () -> IO ()) -> IO () -> () -> IO ()forall a b. (a -> b) -> a -> b$() -> IO ()forall a. a -> IO aforall (m :: * -> *) a. Monad m => a -> m areturn()})utf32le_EF::CodingFailureMode->IO(TextEncoder())utf32le_EF :: CodingFailureMode -> IO (TextEncoder ())utf32le_EFCodingFailureModecfm=TextEncoder () -> IO (TextEncoder ())forall a. a -> IO aforall (m :: * -> *) a. Monad m => a -> m areturn(BufferCodec#{encode# :: CodeBuffer# Char Word8encode#=CodeBuffer# Char Word8utf32le_encode,recover# :: Buffer Char-> Buffer Word8-> State# RealWorld-> (# State# RealWorld, Buffer Char, Buffer Word8 #)recover#=CodingFailureMode-> Buffer Char-> Buffer Word8-> State# RealWorld-> (# State# RealWorld, Buffer Char, Buffer Word8 #)recoverEncode#CodingFailureModecfm,close# :: IO ()close#=() -> IO ()forall a. a -> IO aforall (m :: * -> *) a. Monad m => a -> m areturn(),getState# :: IO ()getState#=() -> IO ()forall a. a -> IO aforall (m :: * -> *) a. Monad m => a -> m areturn(),setState# :: () -> IO ()setState#=IO () -> () -> IO ()forall a b. a -> b -> aconst(IO () -> () -> IO ()) -> IO () -> () -> IO ()forall a b. (a -> b) -> a -> b$() -> IO ()forall a. a -> IO aforall (m :: * -> *) a. Monad m => a -> m areturn()})utf32be_decode::DecodeBuffer#utf32be_decode :: DecodeBuffer#utf32be_decodeinput :: Buffer Word8input@Buffer{bufRaw :: forall e. Buffer e -> RawBuffer ebufRaw=RawBuffer Word8iraw,bufL :: forall e. Buffer e -> IntbufL=Intir0,bufR :: forall e. Buffer e -> IntbufR=Intiw,bufSize :: forall e. Buffer e -> IntbufSize=Int_}output :: Buffer Charoutput@Buffer{bufRaw :: forall e. Buffer e -> RawBuffer ebufRaw=RawBuffer Charoraw,bufL :: forall e. Buffer e -> IntbufL=Int_,bufR :: forall e. Buffer e -> IntbufR=Intow0,bufSize :: forall e. Buffer e -> IntbufSize=Intos}State# RealWorldst=letloop::Int->Int->DecodingBuffer#loop :: Int -> Int -> DecodingBuffer#loop!Intir!IntowState# RealWorldst0|IntowInt -> Int -> Boolforall a. Ord a => a -> a -> Bool>=Intos=CodingProgress -> Int -> Int -> DecodingBuffer#doneCodingProgressOutputUnderflowIntirIntowState# RealWorldst0|IntiwInt -> Int -> Intforall a. Num a => a -> a -> a-IntirInt -> Int -> Boolforall a. Ord a => a -> a -> Bool<Int4=CodingProgress -> Int -> Int -> DecodingBuffer#doneCodingProgressInputUnderflowIntirIntowState# RealWorldst0|Boolotherwise=dolet!(#State# RealWorldst1,Word8c0#)=IO Word8 -> State# RealWorld -> (# State# RealWorld, Word8 #)forall a. IO a -> State# RealWorld -> (# State# RealWorld, a #)unIO(RawBuffer Word8 -> Int -> IO Word8readWord8BufRawBuffer Word8irawIntir)State# RealWorldst0!(#State# RealWorldst2,Word8c1#)=IO Word8 -> State# RealWorld -> (# State# RealWorld, Word8 #)forall a. IO a -> State# RealWorld -> (# State# RealWorld, a #)unIO(RawBuffer Word8 -> Int -> IO Word8readWord8BufRawBuffer Word8iraw(IntirInt -> Int -> Intforall a. Num a => a -> a -> a+Int1))State# RealWorldst1!(#State# RealWorldst3,Word8c2#)=IO Word8 -> State# RealWorld -> (# State# RealWorld, Word8 #)forall a. IO a -> State# RealWorld -> (# State# RealWorld, a #)unIO(RawBuffer Word8 -> Int -> IO Word8readWord8BufRawBuffer Word8iraw(IntirInt -> Int -> Intforall a. Num a => a -> a -> a+Int2))State# RealWorldst2!(#State# RealWorldst4,Word8c3#)=IO Word8 -> State# RealWorld -> (# State# RealWorld, Word8 #)forall a. IO a -> State# RealWorld -> (# State# RealWorld, a #)unIO(RawBuffer Word8 -> Int -> IO Word8readWord8BufRawBuffer Word8iraw(IntirInt -> Int -> Intforall a. Num a => a -> a -> a+Int3))State# RealWorldst3letx1 :: Charx1=Word8 -> Word8 -> Word8 -> Word8 -> Charchr4Word8c0Word8c1Word8c2Word8c3ifBool -> Boolnot(Char -> BoolvalidateCharx1)thenDecodingBuffer#invalidState# RealWorldst4elsedolet!(#State# RealWorldst5,Intow'#)=IO Int -> State# RealWorld -> (# State# RealWorld, Int #)forall a. IO a -> State# RealWorld -> (# State# RealWorld, a #)unIO(RawBuffer Char -> Int -> Char -> IO IntwriteCharBufRawBuffer CharorawIntowCharx1)State# RealWorldst4Int -> Int -> DecodingBuffer#loop(IntirInt -> Int -> Intforall a. Num a => a -> a -> a+Int4)Intow'State# RealWorldst5whereinvalid::DecodingBuffer#invalid :: DecodingBuffer#invalidState# RealWorldst'=CodingProgress -> Int -> Int -> DecodingBuffer#doneCodingProgressInvalidSequenceIntirIntowState# RealWorldst'-- lambda-lifted, to avoid thunks being built in the inner-loop:{-# NOINLINEdone#-}done::CodingProgress->Int->Int->DecodingBuffer#done :: CodingProgress -> Int -> Int -> DecodingBuffer#doneCodingProgresswhy!Intir!IntowState# RealWorldst'=let!ri :: Buffer Word8ri=ifIntirInt -> Int -> Boolforall a. Eq a => a -> a -> Bool==IntiwthenBuffer Word8input{bufL=0,bufR=0}elseBuffer Word8input{bufL=ir}!ro :: Buffer Charro=Buffer Charoutput{bufR=ow}in(#State# RealWorldst',CodingProgresswhy,Buffer Word8ri,Buffer Charro#)inInt -> Int -> DecodingBuffer#loopIntir0Intow0State# RealWorldstutf32le_decode::DecodeBuffer#utf32le_decode :: DecodeBuffer#utf32le_decodeinput :: Buffer Word8input@Buffer{bufRaw :: forall e. Buffer e -> RawBuffer ebufRaw=RawBuffer Word8iraw,bufL :: forall e. Buffer e -> IntbufL=Intir0,bufR :: forall e. Buffer e -> IntbufR=Intiw,bufSize :: forall e. Buffer e -> IntbufSize=Int_}output :: Buffer Charoutput@Buffer{bufRaw :: forall e. Buffer e -> RawBuffer ebufRaw=RawBuffer Charoraw,bufL :: forall e. Buffer e -> IntbufL=Int_,bufR :: forall e. Buffer e -> IntbufR=Intow0,bufSize :: forall e. Buffer e -> IntbufSize=Intos}State# RealWorldst=letloop::Int->Int->DecodingBuffer#loop :: Int -> Int -> DecodingBuffer#loop!Intir!IntowState# RealWorldst0|IntowInt -> Int -> Boolforall a. Ord a => a -> a -> Bool>=Intos=CodingProgress -> Int -> Int -> DecodingBuffer#doneCodingProgressOutputUnderflowIntirIntowState# RealWorldst0|IntiwInt -> Int -> Intforall a. Num a => a -> a -> a-IntirInt -> Int -> Boolforall a. Ord a => a -> a -> Bool<Int4=CodingProgress -> Int -> Int -> DecodingBuffer#doneCodingProgressInputUnderflowIntirIntowState# RealWorldst0|Boolotherwise=dolet!(#State# RealWorldst1,Word8c0#)=IO Word8 -> State# RealWorld -> (# State# RealWorld, Word8 #)forall a. IO a -> State# RealWorld -> (# State# RealWorld, a #)unIO(RawBuffer Word8 -> Int -> IO Word8readWord8BufRawBuffer Word8irawIntir)State# RealWorldst0!(#State# RealWorldst2,Word8c1#)=IO Word8 -> State# RealWorld -> (# State# RealWorld, Word8 #)forall a. IO a -> State# RealWorld -> (# State# RealWorld, a #)unIO(RawBuffer Word8 -> Int -> IO Word8readWord8BufRawBuffer Word8iraw(IntirInt -> Int -> Intforall a. Num a => a -> a -> a+Int1))State# RealWorldst1!(#State# RealWorldst3,Word8c2#)=IO Word8 -> State# RealWorld -> (# State# RealWorld, Word8 #)forall a. IO a -> State# RealWorld -> (# State# RealWorld, a #)unIO(RawBuffer Word8 -> Int -> IO Word8readWord8BufRawBuffer Word8iraw(IntirInt -> Int -> Intforall a. Num a => a -> a -> a+Int2))State# RealWorldst2!(#State# RealWorldst4,Word8c3#)=IO Word8 -> State# RealWorld -> (# State# RealWorld, Word8 #)forall a. IO a -> State# RealWorld -> (# State# RealWorld, a #)unIO(RawBuffer Word8 -> Int -> IO Word8readWord8BufRawBuffer Word8iraw(IntirInt -> Int -> Intforall a. Num a => a -> a -> a+Int3))State# RealWorldst3letx1 :: Charx1=Word8 -> Word8 -> Word8 -> Word8 -> Charchr4Word8c3Word8c2Word8c1Word8c0ifBool -> Boolnot(Char -> BoolvalidateCharx1)thenDecodingBuffer#invalidState# RealWorldst4elsedolet!(#State# RealWorldst5,Intow'#)=IO Int -> State# RealWorld -> (# State# RealWorld, Int #)forall a. IO a -> State# RealWorld -> (# State# RealWorld, a #)unIO(RawBuffer Char -> Int -> Char -> IO IntwriteCharBufRawBuffer CharorawIntowCharx1)State# RealWorldst4Int -> Int -> DecodingBuffer#loop(IntirInt -> Int -> Intforall a. Num a => a -> a -> a+Int4)Intow'State# RealWorldst5whereinvalid::DecodingBuffer#invalid :: DecodingBuffer#invalidState# RealWorldst'=CodingProgress -> Int -> Int -> DecodingBuffer#doneCodingProgressInvalidSequenceIntirIntowState# RealWorldst'-- lambda-lifted, to avoid thunks being built in the inner-loop:{-# NOINLINEdone#-}done::CodingProgress->Int->Int->DecodingBuffer#done :: CodingProgress -> Int -> Int -> DecodingBuffer#doneCodingProgresswhy!Intir!IntowState# RealWorldst'=let!ri :: Buffer Word8ri=ifIntirInt -> Int -> Boolforall a. Eq a => a -> a -> Bool==IntiwthenBuffer Word8input{bufL=0,bufR=0}elseBuffer Word8input{bufL=ir}!ro :: Buffer Charro=Buffer Charoutput{bufR=ow}in(#State# RealWorldst',CodingProgresswhy,Buffer Word8ri,Buffer Charro#)inInt -> Int -> DecodingBuffer#loopIntir0Intow0State# RealWorldstutf32be_encode::EncodeBuffer#utf32be_encode :: CodeBuffer# Char Word8utf32be_encodeinput :: Buffer Charinput@Buffer{bufRaw :: forall e. Buffer e -> RawBuffer ebufRaw=RawBuffer Chariraw,bufL :: forall e. Buffer e -> IntbufL=Intir0,bufR :: forall e. Buffer e -> IntbufR=Intiw,bufSize :: forall e. Buffer e -> IntbufSize=Int_}output :: Buffer Word8output@Buffer{bufRaw :: forall e. Buffer e -> RawBuffer ebufRaw=RawBuffer Word8oraw,bufL :: forall e. Buffer e -> IntbufL=Int_,bufR :: forall e. Buffer e -> IntbufR=Intow0,bufSize :: forall e. Buffer e -> IntbufSize=Intos}State# RealWorldst=let{-# NOINLINEdone#-}done::CodingProgress->Int->Int->EncodingBuffer#done :: CodingProgress -> Int -> Int -> EncodingBuffer#doneCodingProgresswhy!Intir!IntowState# RealWorldst'=let!ri :: Buffer Charri=ifIntirInt -> Int -> Boolforall a. Eq a => a -> a -> Bool==IntiwthenBuffer Charinput{bufL=0,bufR=0}elseBuffer Charinput{bufL=ir}!ro :: Buffer Word8ro=Buffer Word8output{bufR=ow}in(#State# RealWorldst',CodingProgresswhy,Buffer Charri,Buffer Word8ro#)loop::Int->Int->EncodingBuffer#loop :: Int -> Int -> EncodingBuffer#loop!Intir!IntowState# RealWorldst0|IntirInt -> Int -> Boolforall a. Ord a => a -> a -> Bool>=Intiw=CodingProgress -> Int -> Int -> EncodingBuffer#doneCodingProgressInputUnderflowIntirIntowState# RealWorldst0|IntosInt -> Int -> Intforall a. Num a => a -> a -> a-IntowInt -> Int -> Boolforall a. Ord a => a -> a -> Bool<Int4=CodingProgress -> Int -> Int -> EncodingBuffer#doneCodingProgressOutputUnderflowIntirIntowState# RealWorldst0|Boolotherwise=dolet!(#State# RealWorldst1,(Charc,Intir')#)=IO (Char, Int)-> State# RealWorld -> (# State# RealWorld, (Char, Int) #)forall a. IO a -> State# RealWorld -> (# State# RealWorld, a #)unIO(RawBuffer Char -> Int -> IO (Char, Int)readCharBufRawBuffer CharirawIntir)State# RealWorldst0ifChar -> BoolisSurrogateCharcthenCodingProgress -> Int -> Int -> EncodingBuffer#doneCodingProgressInvalidSequenceIntirIntowState# RealWorldst1elsedolet(Word8c0,Word8c1,Word8c2,Word8c3)=Char -> (Word8, Word8, Word8, Word8)ord4Charc!(#State# RealWorldst2,()#)=IO () -> State# RealWorld -> (# State# RealWorld, () #)forall a. IO a -> State# RealWorld -> (# State# RealWorld, a #)unIO(RawBuffer Word8 -> Int -> Word8 -> IO ()writeWord8BufRawBuffer Word8orawIntowWord8c0)State# RealWorldst1!(#State# RealWorldst3,()#)=IO () -> State# RealWorld -> (# State# RealWorld, () #)forall a. IO a -> State# RealWorld -> (# State# RealWorld, a #)unIO(RawBuffer Word8 -> Int -> Word8 -> IO ()writeWord8BufRawBuffer Word8oraw(IntowInt -> Int -> Intforall a. Num a => a -> a -> a+Int1)Word8c1)State# RealWorldst2!(#State# RealWorldst4,()#)=IO () -> State# RealWorld -> (# State# RealWorld, () #)forall a. IO a -> State# RealWorld -> (# State# RealWorld, a #)unIO(RawBuffer Word8 -> Int -> Word8 -> IO ()writeWord8BufRawBuffer Word8oraw(IntowInt -> Int -> Intforall a. Num a => a -> a -> a+Int2)Word8c2)State# RealWorldst3!(#State# RealWorldst5,()#)=IO () -> State# RealWorld -> (# State# RealWorld, () #)forall a. IO a -> State# RealWorld -> (# State# RealWorld, a #)unIO(RawBuffer Word8 -> Int -> Word8 -> IO ()writeWord8BufRawBuffer Word8oraw(IntowInt -> Int -> Intforall a. Num a => a -> a -> a+Int3)Word8c3)State# RealWorldst4Int -> Int -> EncodingBuffer#loopIntir'(IntowInt -> Int -> Intforall a. Num a => a -> a -> a+Int4)State# RealWorldst5inInt -> Int -> EncodingBuffer#loopIntir0Intow0State# RealWorldstutf32le_encode::EncodeBuffer#utf32le_encode :: CodeBuffer# Char Word8utf32le_encodeinput :: Buffer Charinput@Buffer{bufRaw :: forall e. Buffer e -> RawBuffer ebufRaw=RawBuffer Chariraw,bufL :: forall e. Buffer e -> IntbufL=Intir0,bufR :: forall e. Buffer e -> IntbufR=Intiw,bufSize :: forall e. Buffer e -> IntbufSize=Int_}output :: Buffer Word8output@Buffer{bufRaw :: forall e. Buffer e -> RawBuffer ebufRaw=RawBuffer Word8oraw,bufL :: forall e. Buffer e -> IntbufL=Int_,bufR :: forall e. Buffer e -> IntbufR=Intow0,bufSize :: forall e. Buffer e -> IntbufSize=Intos}State# RealWorldst=letdone::CodingProgress->Int->Int->EncodingBuffer#done :: CodingProgress -> Int -> Int -> EncodingBuffer#doneCodingProgresswhy!Intir!IntowState# RealWorldst'=let!ri :: Buffer Charri=ifIntirInt -> Int -> Boolforall a. Eq a => a -> a -> Bool==IntiwthenBuffer Charinput{bufL=0,bufR=0}elseBuffer Charinput{bufL=ir}!ro :: Buffer Word8ro=Buffer Word8output{bufR=ow}in(#State# RealWorldst',CodingProgresswhy,Buffer Charri,Buffer Word8ro#)loop::Int->Int->EncodingBuffer#loop :: Int -> Int -> EncodingBuffer#loop!Intir!IntowState# RealWorldst0|IntirInt -> Int -> Boolforall a. Ord a => a -> a -> Bool>=Intiw=CodingProgress -> Int -> Int -> EncodingBuffer#doneCodingProgressInputUnderflowIntirIntowState# RealWorldst0|IntosInt -> Int -> Intforall a. Num a => a -> a -> a-IntowInt -> Int -> Boolforall a. Ord a => a -> a -> Bool<Int4=CodingProgress -> Int -> Int -> EncodingBuffer#doneCodingProgressOutputUnderflowIntirIntowState# RealWorldst0|Boolotherwise=dolet!(#State# RealWorldst1,(Charc,Intir')#)=IO (Char, Int)-> State# RealWorld -> (# State# RealWorld, (Char, Int) #)forall a. IO a -> State# RealWorld -> (# State# RealWorld, a #)unIO(RawBuffer Char -> Int -> IO (Char, Int)readCharBufRawBuffer CharirawIntir)State# RealWorldst0ifChar -> BoolisSurrogateCharcthenCodingProgress -> Int -> Int -> EncodingBuffer#doneCodingProgressInvalidSequenceIntirIntowState# RealWorldst1elsedolet(Word8c0,Word8c1,Word8c2,Word8c3)=Char -> (Word8, Word8, Word8, Word8)ord4Charc!(#State# RealWorldst2,()#)=IO () -> State# RealWorld -> (# State# RealWorld, () #)forall a. IO a -> State# RealWorld -> (# State# RealWorld, a #)unIO(RawBuffer Word8 -> Int -> Word8 -> IO ()writeWord8BufRawBuffer Word8orawIntowWord8c3)State# RealWorldst1!(#State# RealWorldst3,()#)=IO () -> State# RealWorld -> (# State# RealWorld, () #)forall a. IO a -> State# RealWorld -> (# State# RealWorld, a #)unIO(RawBuffer Word8 -> Int -> Word8 -> IO ()writeWord8BufRawBuffer Word8oraw(IntowInt -> Int -> Intforall a. Num a => a -> a -> a+Int1)Word8c2)State# RealWorldst2!(#State# RealWorldst4,()#)=IO () -> State# RealWorld -> (# State# RealWorld, () #)forall a. IO a -> State# RealWorld -> (# State# RealWorld, a #)unIO(RawBuffer Word8 -> Int -> Word8 -> IO ()writeWord8BufRawBuffer Word8oraw(IntowInt -> Int -> Intforall a. Num a => a -> a -> a+Int2)Word8c1)State# RealWorldst3!(#State# RealWorldst5,()#)=IO () -> State# RealWorld -> (# State# RealWorld, () #)forall a. IO a -> State# RealWorld -> (# State# RealWorld, a #)unIO(RawBuffer Word8 -> Int -> Word8 -> IO ()writeWord8BufRawBuffer Word8oraw(IntowInt -> Int -> Intforall a. Num a => a -> a -> a+Int3)Word8c0)State# RealWorldst4Int -> Int -> EncodingBuffer#loopIntir'(IntowInt -> Int -> Intforall a. Num a => a -> a -> a+Int4)State# RealWorldst5inInt -> Int -> EncodingBuffer#loopIntir0Intow0State# RealWorldstchr4::Word8->Word8->Word8->Word8->Charchr4 :: Word8 -> Word8 -> Word8 -> Word8 -> Charchr4(W8#Word8#x1#)(W8#Word8#x2#)(W8#Word8#x3#)(W8#Word8#x4#)=Char# -> CharC#(Int# -> Char#chr#(Int#z1#Int# -> Int# -> Int#+#Int#z2#Int# -> Int# -> Int#+#Int#z3#Int# -> Int# -> Int#+#Int#z4#))where!y1# :: Int#y1#=Word# -> Int#word2Int#(Word8# -> Word#word8ToWord#Word8#x1#)!y2# :: Int#y2#=Word# -> Int#word2Int#(Word8# -> Word#word8ToWord#Word8#x2#)!y3# :: Int#y3#=Word# -> Int#word2Int#(Word8# -> Word#word8ToWord#Word8#x3#)!y4# :: Int#y4#=Word# -> Int#word2Int#(Word8# -> Word#word8ToWord#Word8#x4#)!z1# :: Int#z1#=Int# -> Int# -> Int#uncheckedIShiftL#Int#y1#Int#24#!z2# :: Int#z2#=Int# -> Int# -> Int#uncheckedIShiftL#Int#y2#Int#16#!z3# :: Int#z3#=Int# -> Int# -> Int#uncheckedIShiftL#Int#y3#Int#8#!z4# :: Int#z4#=Int#y4#{-# INLINEchr4#-}ord4::Char->(Word8,Word8,Word8,Word8)ord4 :: Char -> (Word8, Word8, Word8, Word8)ord4Charc=(Int -> Word8forall a b. (Integral a, Num b) => a -> bfromIntegral(IntxInt -> Int -> Intforall a. Bits a => a -> Int -> a`shiftR`Int24),Int -> Word8forall a b. (Integral a, Num b) => a -> bfromIntegral(IntxInt -> Int -> Intforall a. Bits a => a -> Int -> a`shiftR`Int16),Int -> Word8forall a b. (Integral a, Num b) => a -> bfromIntegral(IntxInt -> Int -> Intforall a. Bits a => a -> Int -> a`shiftR`Int8),Int -> Word8forall a b. (Integral a, Num b) => a -> bfromIntegralIntx)wherex :: Intx=Char -> IntordCharc{-# INLINEord4#-}validate::Char->Boolvalidate :: Char -> BoolvalidateCharc=(Intx1Int -> Int -> Boolforall a. Ord a => a -> a -> Bool>=Int0x0Bool -> Bool -> Bool&&Intx1Int -> Int -> Boolforall a. Ord a => a -> a -> Bool<Int0xD800)Bool -> Bool -> Bool||(Intx1Int -> Int -> Boolforall a. Ord a => a -> a -> Bool>Int0xDFFFBool -> Bool -> Bool&&Intx1Int -> Int -> Boolforall a. Ord a => a -> a -> Bool<=Int0x10FFFF)wherex1 :: Intx1=Char -> IntordCharc{-# INLINEvalidate#-}
[8]ページ先頭