Movatterモバイル変換


[0]ホーム

URL:


{-# LANGUAGE Trustworthy #-}{-# LANGUAGE NoImplicitPrelude           , BangPatterns           , NondecreasingIndentation  #-}{-# OPTIONS_GHC  -funbox-strict-fields #-}------------------------------------------------------------------------------- |-- Module      :  GHC.IO.Encoding.Latin1-- Copyright   :  (c) The University of Glasgow, 2009-- License     :  see libraries/base/LICENSE---- Maintainer  :  libraries@haskell.org-- Stability   :  internal-- Portability :  non-portable---- Single-byte encodings that map directly to Unicode code points.---- Portions Copyright   : (c) Tom Harper 2008-2009,--                        (c) Bryan O'Sullivan 2009,--                        (c) Duncan Coutts 2009-------------------------------------------------------------------------------moduleGHC.IO.Encoding.Latin1(latin1,mkLatin1,latin1_checked,mkLatin1_checked,ascii,mkAscii,latin1_decode,ascii_decode,latin1_encode,latin1_checked_encode,ascii_encode,)whereimportGHC.BaseimportGHC.RealimportGHC.Num-- import GHC.IOimportGHC.IO.BufferimportGHC.IO.Encoding.FailureimportGHC.IO.Encoding.Types-- ------------------------------------------------------------------------------- Latin1latin1::TextEncodinglatin1=mkLatin1ErrorOnCodingFailure-- | @since 4.4.0.0mkLatin1::CodingFailureMode->TextEncodingmkLatin1cfm=TextEncoding{textEncodingName="ISO-8859-1",mkTextDecoder=latin1_DFcfm,mkTextEncoder=latin1_EFcfm}latin1_DF::CodingFailureMode->IO(TextDecoder())latin1_DFcfm=return(BufferCodec{encode=latin1_decode,recover=recoverDecodecfm,close=return(),getState=return(),setState=const$return()})latin1_EF::CodingFailureMode->IO(TextEncoder())latin1_EFcfm=return(BufferCodec{encode=latin1_encode,recover=recoverEncodecfm,close=return(),getState=return(),setState=const$return()})latin1_checked::TextEncodinglatin1_checked=mkLatin1_checkedErrorOnCodingFailure-- | @since 4.4.0.0mkLatin1_checked::CodingFailureMode->TextEncodingmkLatin1_checkedcfm=TextEncoding{textEncodingName="ISO-8859-1",mkTextDecoder=latin1_DFcfm,mkTextEncoder=latin1_checked_EFcfm}latin1_checked_EF::CodingFailureMode->IO(TextEncoder())latin1_checked_EFcfm=return(BufferCodec{encode=latin1_checked_encode,recover=recoverEncodecfm,close=return(),getState=return(),setState=const$return()})-- ------------------------------------------------------------------------------- ASCII-- | @since 4.9.0.0ascii::TextEncodingascii=mkAsciiErrorOnCodingFailure-- | @since 4.9.0.0mkAscii::CodingFailureMode->TextEncodingmkAsciicfm=TextEncoding{textEncodingName="ASCII",mkTextDecoder=ascii_DFcfm,mkTextEncoder=ascii_EFcfm}ascii_DF::CodingFailureMode->IO(TextDecoder())ascii_DFcfm=return(BufferCodec{encode=ascii_decode,recover=recoverDecodecfm,close=return(),getState=return(),setState=const$return()})ascii_EF::CodingFailureMode->IO(TextEncoder())ascii_EFcfm=return(BufferCodec{encode=ascii_encode,recover=recoverEncodecfm,close=return(),getState=return(),setState=const$return()})-- ------------------------------------------------------------------------------- The actual decoders and encoders-- TODO: Eliminate code duplication between the checked and unchecked-- versions of the decoder or encoder (but don't change the Core!)latin1_decode::DecodeBufferlatin1_decodeinput@Buffer{bufRaw=iraw,bufL=ir0,bufR=iw,bufSize=_}output@Buffer{bufRaw=oraw,bufL=_,bufR=ow0,bufSize=os}=letloop!ir!ow|ow>=os=doneOutputUnderflowirow|ir>=iw=doneInputUnderflowirow|otherwise=doc0<-readWord8Bufirawirow'<-writeCharBuforawow(unsafeChr(fromIntegralc0))loop(ir+1)ow'-- lambda-lifted, to avoid thunks being built in the inner-loop:donewhy!ir!ow=return(why,ifir==iwtheninput{bufL=0,bufR=0}elseinput{bufL=ir},output{bufR=ow})inloopir0ow0ascii_decode::DecodeBufferascii_decodeinput@Buffer{bufRaw=iraw,bufL=ir0,bufR=iw,bufSize=_}output@Buffer{bufRaw=oraw,bufL=_,bufR=ow0,bufSize=os}=letloop!ir!ow|ow>=os=doneOutputUnderflowirow|ir>=iw=doneInputUnderflowirow|otherwise=doc0<-readWord8Bufirawirifc0>0x7ftheninvalidelsedoow'<-writeCharBuforawow(unsafeChr(fromIntegralc0))loop(ir+1)ow'whereinvalid=doneInvalidSequenceirow-- lambda-lifted, to avoid thunks being built in the inner-loop:donewhy!ir!ow=return(why,ifir==iwtheninput{bufL=0,bufR=0}elseinput{bufL=ir},output{bufR=ow})inloopir0ow0latin1_encode::EncodeBufferlatin1_encodeinput@Buffer{bufRaw=iraw,bufL=ir0,bufR=iw,bufSize=_}output@Buffer{bufRaw=oraw,bufL=_,bufR=ow0,bufSize=os}=letdonewhy!ir!ow=return(why,ifir==iwtheninput{bufL=0,bufR=0}elseinput{bufL=ir},output{bufR=ow})loop!ir!ow|ow>=os=doneOutputUnderflowirow|ir>=iw=doneInputUnderflowirow|otherwise=do(c,ir')<-readCharBufirawirwriteWord8Buforawow(fromIntegral(ordc))loopir'(ow+1)inloopir0ow0latin1_checked_encode::EncodeBufferlatin1_checked_encodeinputoutput=single_byte_checked_encode0xffinputoutputascii_encode::EncodeBufferascii_encodeinputoutput=single_byte_checked_encode0x7finputoutputsingle_byte_checked_encode::Int->EncodeBuffersingle_byte_checked_encodemax_legal_charinput@Buffer{bufRaw=iraw,bufL=ir0,bufR=iw,bufSize=_}output@Buffer{bufRaw=oraw,bufL=_,bufR=ow0,bufSize=os}=letdonewhy!ir!ow=return(why,ifir==iwtheninput{bufL=0,bufR=0}elseinput{bufL=ir},output{bufR=ow})loop!ir!ow|ow>=os=doneOutputUnderflowirow|ir>=iw=doneInputUnderflowirow|otherwise=do(c,ir')<-readCharBufirawirifordc>max_legal_chartheninvalidelsedowriteWord8Buforawow(fromIntegral(ordc))loopir'(ow+1)whereinvalid=doneInvalidSequenceirowinloopir0ow0{-# INLINEsingle_byte_checked_encode#-}

[8]ページ先頭

©2009-2025 Movatter.jp