{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, BangPatterns #-}moduleData.Iteratee.WrappedByteString(WrappedByteString(..))whereimportqualifiedData.Iteratee.Base.StreamChunkasSCimportqualifiedData.ByteStringasBWimportqualifiedData.ByteString.Char8asBCimportqualifiedData.ByteString.InternalasBBaseimportqualifiedData.ListLikeasLLimportData.WordimportData.MonoidimportForeign.PtrimportControl.Monad-- |Wrap a Data.ByteString ByteStringnewtypeWrappedByteStringa=WrapBS{unWrap::BBase.ByteString}instanceMonoid(WrappedByteStringWord8)wheremempty=WrapBSBW.emptymappenda1a2=WrapBS(BW.append(unWrapa1)(unWrapa2))instanceLL.FoldableLL(WrappedByteStringWord8)Word8wherefoldlfz=BW.foldlfz.unWrapfoldrfz=BW.foldrfz.unWrap-- Thanks to Echo Nolan for indicating that the bytestring must copy-- data to a new ptr to preserve referential transparency.instanceSC.ReadableChunkWrappedByteStringWord8wherereadFromPtrbufl=letcsl=(castPtrbuf,l)inliftMWrapBS$BW.packCStringLencslinstanceSC.ReadableChunkWrappedByteStringCharwherereadFromPtrbufl=letcsl=(castPtrbuf,l)inliftMWrapBS$BC.packCStringLencslinstanceLL.ListLike(WrappedByteStringWord8)Word8wherelength=BW.length.unWrapnull=BW.null.unWrapsingleton=WrapBS.BW.singletonconsa=WrapBS.BW.consa.unWraphead=BW.head.unWraptail=WrapBS.BW.tail.unWrapfindIndexp=BW.findIndexp.unWrapsplitAtis=let(a1,a2)=BW.splitAti$unWrapsin(WrapBSa1,WrapBSa2)dropWhilep=WrapBS.BW.dropWhilep.unWrapfromList=WrapBS.BW.packtoList=BW.unpack.unWraprigidMapf=WrapBS.BW.mapf.unWrapinstanceSC.StreamChunkWrappedByteStringWord8wherecMap=bwmapbwmap::(SC.StreamChunks'el')=>(Word8->el')->WrappedByteStringWord8->s'el'bwmapfxs=stepxswherestepbs|LL.nullbs=mempty|True=f(LL.headbs)`LL.cons`step(LL.tailbs)-- Now the Char instanceinstanceMonoid(WrappedByteStringChar)wheremempty=WrapBSBW.emptymappenda1a2=WrapBS(BW.append(unWrapa1)(unWrapa2))instanceLL.FoldableLL(WrappedByteStringChar)Charwherefoldlfz=BC.foldlfz.unWrapfoldrfz=BC.foldrfz.unWrapinstanceLL.ListLike(WrappedByteStringChar)Charwherelength=BC.length.unWrapnull=BC.null.unWrapsingleton=WrapBS.BC.singletonconsa=WrapBS.BC.consa.unWraphead=BC.head.unWraptail=WrapBS.BC.tail.unWrapfindIndexp=BC.findIndexp.unWrapsplitAtis=let(a1,a2)=BC.splitAti$unWrapsin(WrapBSa1,WrapBSa2)dropWhilep=WrapBS.BC.dropWhilep.unWrapfromList=WrapBS.BC.packtoList=BC.unpack.unWraprigidMapf=WrapBS.BC.mapf.unWrapinstanceLL.StringLike(WrappedByteStringChar)wheretoString=BC.unpack.unWrapfromString=WrapBS.BC.packlines=LL.fromList.mapWrapBS.BC.lines.unWrapwords=LL.fromList.mapWrapBS.BC.words.unWrapinstanceSC.StreamChunkWrappedByteStringCharwherecMap=bcmapbcmap::(SC.StreamChunks'el')=>(Char->el')->WrappedByteStringChar->s'el'bcmapfxs=stepxswherestepbs|LL.nullbs=mempty|True=f(LL.headbs)`LL.cons`step(LL.tailbs)