Movatterモバイル変換


[0]ホーム

URL:


{-# LANGUAGE Trustworthy #-}{-# LANGUAGE CPP, BangPatterns, NoImplicitPrelude,             NondecreasingIndentation, MagicHash #-}moduleGHC.IO.Encoding.CodePage(#if defined(mingw32_HOST_OS)codePageEncoding,mkCodePageEncoding,localeEncoding,mkLocaleEncoding#endif)where#if !defined(mingw32_HOST_OS)importGHC.Base()-- Build ordering#elseimportGHC.BaseimportGHC.ShowimportGHC.NumimportGHC.EnumimportGHC.WordimportGHC.IO(unsafePerformIO)importGHC.IO.Encoding.FailureimportGHC.IO.Encoding.TypesimportGHC.IO.BufferimportData.BitsimportData.MaybeimportData.OldList(lookup)importqualifiedGHC.IO.Encoding.CodePage.APIasAPIimportGHC.IO.Encoding.CodePage.TableimportGHC.IO.Encoding.UTF8(mkUTF8)importGHC.IO.Encoding.UTF16(mkUTF16le,mkUTF16be)importGHC.IO.Encoding.UTF32(mkUTF32le,mkUTF32be)#if defined(mingw32_HOST_OS)# if defined(i386_HOST_ARCH)#  define WINDOWS_CCONV stdcall# elif defined(x86_64_HOST_ARCH)#  define WINDOWS_CCONV ccall# else#  error Unknown mingw32 arch# endif#endif-- note CodePage = UInt which might not work on Win64.  But the Win32 package-- also has this issue.getCurrentCodePage::IOWord32getCurrentCodePage=doconCP<-getConsoleCPifconCP>0thenreturnconCPelsegetACP-- Since the Win32 package depends on base, we have to import these ourselves:foreignimportWINDOWS_CCONVunsafe"windows.h GetConsoleCP"getConsoleCP::IOWord32foreignimportWINDOWS_CCONVunsafe"windows.h GetACP"getACP::IOWord32{-# NOINLINEcurrentCodePage#-}currentCodePage::Word32currentCodePage=unsafePerformIOgetCurrentCodePagelocaleEncoding::TextEncodinglocaleEncoding=mkLocaleEncodingErrorOnCodingFailuremkLocaleEncoding::CodingFailureMode->TextEncodingmkLocaleEncodingcfm=mkCodePageEncodingcfmcurrentCodePagecodePageEncoding::Word32->TextEncodingcodePageEncoding=mkCodePageEncodingErrorOnCodingFailuremkCodePageEncoding::CodingFailureMode->Word32->TextEncodingmkCodePageEncodingcfm65001=mkUTF8cfmmkCodePageEncodingcfm1200=mkUTF16lecfmmkCodePageEncodingcfm1201=mkUTF16becfmmkCodePageEncodingcfm12000=mkUTF32lecfmmkCodePageEncodingcfm12001=mkUTF32becfmmkCodePageEncodingcfmcp=maybe(API.mkCodePageEncodingcfmcp)(buildEncodingcfmcp)(lookupcpcodePageMap)buildEncoding::CodingFailureMode->Word32->CodePageArrays->TextEncodingbuildEncodingcfmcpSingleByteCP{decoderArray=dec,encoderArray=enc}=TextEncoding{textEncodingName="CP"++showcp,mkTextDecoder=return$simpleCodec(recoverDecodecfm)$decodeFromSingleBytedec,mkTextEncoder=return$simpleCodec(recoverEncodecfm)$encodeToSingleByteenc}simpleCodec::(Bufferfrom->Bufferto->IO(Bufferfrom,Bufferto))->(Bufferfrom->Bufferto->IO(CodingProgress,Bufferfrom,Bufferto))->BufferCodecfromto()simpleCodecrf=BufferCodec{encode=f,recover=r,close=return(),getState=return(),setState=return}decodeFromSingleByte::ConvArrayChar->DecodeBufferdecodeFromSingleByteconvArrinput@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=dob<-readWord8Bufirawirletc=lookupConvconvArrbifc=='\0'&&b/=0theninvalidelsedoow'<-writeCharBuforawowcloop(ir+1)ow'whereinvalid=doneInvalidSequenceirowinloopir0ow0encodeToSingleByte::CompactArrayCharWord8->EncodeBufferencodeToSingleByteCompactArray{encoderMax=maxChar,encoderIndices=indices,encoderValues=values}input@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')<-readCharBufirawircaselookupCompactmaxCharindicesvaluescofNothing->invalidJust0|c/='\0'->invalidJustb->dowriteWord8Buforawowbloopir'(ow+1)whereinvalid=doneInvalidSequenceirowinloopir0ow0---------------------------------------------- Array access functions-- {-# INLINE lookupConv #-}lookupConv::ConvArrayChar->Word8->CharlookupConva=indexChara.fromEnum{-# INLINElookupCompact#-}lookupCompact::Char->ConvArrayInt->ConvArrayWord8->Char->MaybeWord8lookupCompactmaxValindexesvaluesx|x>maxVal=Nothing|otherwise=Just$indexWord8values$j+(i.&.mask)wherei=fromEnumxmask=(1`shiftL`n)-1k=i`shiftR`nj=indexIntindexeskn=blockBitSize{-# INLINEindexInt#-}indexInt::ConvArrayInt->Int->IntindexInt(ConvArrayp)(I#i)=I#(indexInt16OffAddr#pi){-# INLINEindexWord8#-}indexWord8::ConvArrayWord8->Int->Word8indexWord8(ConvArrayp)(I#i)=W8#(indexWord8OffAddr#pi){-# INLINEindexChar#-}indexChar::ConvArrayChar->Int->CharindexChar(ConvArrayp)(I#i)=C#(chr#(indexInt16OffAddr#pi))#endif

[8]ページ先頭

©2009-2025 Movatter.jp