{-# OPTIONS_HADDOCK show-extensions #-}-- |-- Module : Yi.Rope-- License : GPL-2-- Maintainer : yi-devel@googlegroups.com-- Stability : experimental-- Portability : portable---- A work in progress module that aims to be a more efficient-- replacement for "Yi.OldRope". For now, please import "Yi.OldRope"!module Yi.Rope (Rope, fromString, toString, toReverseString, null, empty, Yi.Rope.take, Yi.Rope.drop, Yi.Rope.length, reverse, countNewLines, Yi.Rope.split, Yi.Rope.splitAt, Yi.Rope.splitAtLine, Yi.Rope.append, Yi.Rope.concat, Yi.Rope.readFile, Yi.Rope.writeFile) whereimport qualified Codec.Binary.UTF8.Generic as Gimport Data.Binaryimport qualified Data.ByteString.Lazy as LB (readFile, split, count)import Data.Monoidimport Data.Ropeimport qualified Prelude as Pimport Prelude hiding (null, take, drop, reverse)import System.IO.Cautious (writeFileL)toReverseString :: Rope -> StringtoReverseString = P.reverse . toStringreverse :: Rope -> Ropereverse = fromString . P.reverse . toStringcountNewLines :: Rope -> IntcountNewLines = fromIntegral . LB.count 10 . toLazyByteStringsplit :: Word8 -> Rope -> [Rope]split c = map fromLazyByteString . LB.split c . toLazyByteStringsplitAt :: Int -> Rope -> (Rope, Rope)splitAt = G.splitAt-- | Split before the specified line. Lines are indexed from 0.splitAtLine :: Int -> Rope -> (Rope, Rope)splitAtLine n r | n <= 0 = (mempty, r) | otherwise = splitAtLine' (n - 1) r-- | Split after the specified line. Lines are indexed from 0.splitAtLine' :: Int -> Rope -> (Rope, Rope)splitAtLine' n r = let ls = P.take (n + 1) (G.lines' r) in G.splitAt (sum $ map G.length ls) rappend :: Rope -> Rope -> Ropeappend = (<>)concat :: [Rope] -> Ropeconcat = mconcatwriteFile :: FilePath -> Rope -> IO ()writeFile f = writeFileL f . toLazyByteStringreadFile :: FilePath -> IO RopereadFile f = fromLazyByteString `fmap` LB.readFile fdrop, take :: Int -> Rope -> Ropetake i = fst . G.splitAt idrop i = snd . G.splitAt ilength :: Rope -> Intlength = G.length