Skip to content

Commit

Permalink
Revert "Use TX.span to implement lines'"
Browse files Browse the repository at this point in the history
  • Loading branch information
ethercrow committed Sep 9, 2017
1 parent 689bd6d commit 30101de
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/Yi/Rope.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions test/Yi/RopeSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 30101de

Please sign in to comment.