{-# LANGUAGE TypeFamilies, MultiParamTypeClasses, FlexibleInstances, BangPatterns, PatternGuards #-}moduleText.Trifecta.Rope.Prim(Rope(..),rope,Strand(..),strand,strands,grabRest,grabLine)whereimportData.SemigroupimportData.Semigroup.ReducerimportData.ByteString(ByteString)importqualifiedData.ByteStringasStrictimportqualifiedData.ByteString.LazyasLazyimportqualifiedData.ByteString.UTF8asUTF8importData.FingerTreeasFingerTreeimportData.Foldable(toList)importData.HashableimportData.Int(Int64)importText.Trifecta.UtilasUtilimportText.Trifecta.Rope.BytesimportText.Trifecta.Rope.DeltadataStrand=Strand{-# UNPACK #-}!ByteString!Delta|LineDirective{-# UNPACK #-}!ByteString{-# UNPACK #-}!Int64derivingShowstrand::ByteString->Strandstrandbs=Strandbs(deltabs)instanceMeasuredDeltaStrandwheremeasure(Strand_s)=deltasmeasure(LineDirectivepl)=delta(Directedpl000)instanceHashableStrandwherehash(Strandh_)=hashWithSalt0hhash(LineDirectivepl)=hashl`hashWithSalt`pinstanceHasDeltaStrandwheredelta=measureinstanceHasBytesStrandwherebytes(Strand_d)=bytesdbytes_=0dataRope=Rope!Delta!(FingerTreeDeltaStrand)derivingShowrope::FingerTreeDeltaStrand->Roperoper=Rope(measurer)rstrands::Rope->FingerTreeDeltaStrandstrands(Rope_r)=r-- | grab a the contents of a rope from a given location up to a newlinegrabRest::Delta->Rope->r->(Delta->Lazy.ByteString->r)->rgrabRestitkfks=trim(deltal)(bytesi-bytesl)(toListr)wheretrimj0(Strandh_:xs)=gojhxstrim_k(Strandh_:xs)=goi(Strict.drop(fromIntegralk)h)xstrimjk(p:xs)=trim(j<>deltap)kxstrim__[]=kfgojhs=ksj$Lazy.fromChunks$h:[a|Stranda_<-s](l,r)=FingerTree.split(\b->bytesb>bytesi)$strandst-- | grab a the contents of a rope from a given location up to a newlinegrabLine::Delta->Rope->r->(Delta->Strict.ByteString->r)->rgrabLineitkfks=grabRestitkf$\c->ksc.Util.fromLazy.Util.takeLineinstanceHasBytesRopewherebytes=bytes.measureinstanceHasDeltaRopewheredelta=measureinstanceMeasuredDeltaRopewheremeasure(Ropes_)=sinstanceMonoidRopewheremempty=Ropememptymemptymappend=(<>)instanceSemigroupRopewhereRopemxx<>Ropemyy=Rope(mx<>my)(x`mappend`y)instanceReducerRopeRopewhereunit=idinstanceReducerStrandRopewhereunits=rope(FingerTree.singletons)conss(Ropemtt)=Rope(deltas`mappend`mt)(s<|t)snoc(Ropemtt)!s=Rope(mt`mappend`deltas)(t|>s)instanceReducerStrict.ByteStringRopewhereunit=unit.strandcons=cons.strandsnocr=snocr.strandinstanceReducer[Char]Ropewhereunit=unit.strand.UTF8.fromStringcons=cons.strand.UTF8.fromStringsnocr=snocr.strand.UTF8.fromString