diff --git a/src/Yi/Rope.hs b/src/Yi/Rope.hs index b3dceda..6b6caab 100644 --- a/src/Yi/Rope.hs +++ b/src/Yi/Rope.hs @@ -69,7 +69,6 @@ import qualified Data.ByteString.Lazy as BSL import Data.Char (isSpace) import qualified Data.FingerTree as T import Data.FingerTree hiding (null, empty, reverse, split) -import Data.Function (fix) import qualified Data.List as L (foldl') import Data.Maybe import Data.Monoid @@ -583,15 +582,13 @@ lines = fmap fromText . TX.lines . toText -- -- > 'toText' . 'concat' . 'lines'' ≡ 'toText' -- +-- but the underlying structure might change: notably, chunks will +-- most likely change sizes. lines' :: YiString -> [YiString] -lines' = splitByKeepingDelim '\n' - -splitByKeepingDelim :: Char -> YiString -> [YiString] -splitByKeepingDelim x = fmap fromText . fix go x . toText - where - go :: (Char -> TX.Text -> [TX.Text]) -> Char -> TX.Text -> [TX.Text] - go _ c (TX.span (/=c) -> (_, TX.null -> True)) = [] - go f c (TX.span (/=c) -> (a,b)) = a `TX.snoc` c : f c (TX.tail b) +lines' t = let (YiString f, YiString s) = splitAtLine' 0 t + in if T.null s + then if T.null f then [] else [YiString f] + else YiString f : lines' (YiString s) -- | Joins up lines by a newline character. It does not leave a -- newline after the last line. If you want a more classical diff --git a/test/Yi/RopeSpec.hs b/test/Yi/RopeSpec.hs index 56c21ff..fef435e 100644 --- a/test/Yi/RopeSpec.hs +++ b/test/Yi/RopeSpec.hs @@ -37,6 +37,8 @@ spec = modifyMaxSize (const 1000) $ do prop "R.length ~ T.length" $ R.length `isLike` T.length prop "R.null ~ T.null" $ R.null `isLike` T.null prop "R.countNewLines ~ T.count \\n" $ R.countNewLines `isLike` T.count "\n" + prop "R.concat . R.lines' = id" $ (R.toText . R.concat . R.lines') `isLike` id + prop "R.lines ~ T.lines" $ (fmap R.toText . R.lines) `isLike` T.lines prop "R.empty ~ T.empty" $ R.toText R.empty `shouldBe` T.empty prop "fst . R.splitAt ~ fst . T.splitAt" $ \i -> fst . R.splitAt i `isLikeT` fst . T.splitAt i