packages feed

rope-0.6.4 / Data / Rope / Body.hs

{-# LANGUAGE GeneralizedNewtypeDeriving, DeriveDataTypeable, MultiParamTypeClasses, FlexibleContexts, TypeSynonymInstances #-}module Data.Rope.Body    ( Body    , Offset(..)    , Chunk(..)    , measureBody    , consBody    , snocBody    , packBody    ) whereimport Prelude hiding (null, length)import Data.FingerTree (FingerTree,(<|),(|>),Measured,measure,empty, singleton)import Data.Dataimport Data.Monoidimport Data.ByteString (ByteString, null, length)newtype Offset = Offset { getOffset :: Int } deriving (Eq,Ord,Num,Show,Read,Enum,Data,Typeable)instance Monoid Offset where    mempty = 0    mappend = (+)newtype Chunk = Chunk { unchunk :: ByteString } deriving (Eq,Ord,Show,Read,Data,Typeable)instance Measured Offset Chunk where    measure = Offset . length . unchunktype Body = FingerTree Offset Chunk measureBody :: Measured Offset a => FingerTree Offset a -> IntmeasureBody = getOffset . measureconsBody :: ByteString -> Body -> Bodyb `consBody` t | null b = t           | otherwise = Chunk b <| tsnocBody :: Body -> ByteString -> Bodyt `snocBody` b | null b = t           | otherwise = t |> Chunk bpackBody :: ByteString -> FingerTree Offset ChunkpackBody b | null b = empty           | otherwise = singleton (Chunk b)