on master help sign in
Implement and test lazy lines
6273f4bBryan O'Sullivan
Data/Text/Lazy.hs+9−1
@@ -114,7 +114,7 @@ module Data.Text.Lazy
114 -- , breakSubstring
114 -- , breakSubstring
115
115
116 -- ** Breaking into lines and words
116 -- ** Breaking into lines and words
117− -- , lines
117+ , lines
118 --, lines'
118 --, lines'
119 -- , words
119 -- , words
120 -- , unlines
120 -- , unlines
@@ -717,6 +717,14 @@ splitWith p (Chunk t0 ts0) = comb [] (T.splitWith p t0) ts0
717 comb acc (s:ss) ts = revChunks (s:acc) : comb [] ss ts
717 comb acc (s:ss) ts = revChunks (s:acc) : comb [] ss ts
718{-# INLINE splitWith #-}
718{-# INLINE splitWith #-}
719
719
720+-- | /O(n)/ Breaks a 'Text' up into a list of 'Text's at
721+-- newline 'Char's. The resulting strings do not contain newlines.
722+lines :: Text -> [Text]
723+lines Empty = []
724+lines t = let (l,t') = break ((==) '\n') t
725+ in l : if null t' then []
726+ else lines (tail t')
727+
720revChunks :: [T.Text] -> Text
728revChunks :: [T.Text] -> Text
721revChunks = L.foldl' (flip chunk) Empty
729revChunks = L.foldl' (flip chunk) Empty
722
730
tests/Properties.hs+2
@@ -282,6 +282,7 @@ prop_T_breakSubstringC c
282 (unpack2 . T.breakSubstring (T.singleton c))
282 (unpack2 . T.breakSubstring (T.singleton c))
283
283
284prop_T_lines = L.lines `eqP` (map unpackT . T.lines)
284prop_T_lines = L.lines `eqP` (map unpackT . T.lines)
285+prop_TL_lines = L.lines `eqP` (map unpackT . TL.lines)
285{-
286{-
286prop_T_lines' = lines' `eqP` (map unpackT . T.lines')
287prop_T_lines' = lines' `eqP` (map unpackT . T.lines')
287 where lines' "" = []
288 where lines' "" = []
@@ -484,6 +485,7 @@ tests = [
484 ("prop_T_breakSubstring_isInfixOf", mytest prop_T_breakSubstring_isInfixOf),
485 ("prop_T_breakSubstring_isInfixOf", mytest prop_T_breakSubstring_isInfixOf),
485
486
486 ("prop_T_lines", mytest prop_T_lines),
487 ("prop_T_lines", mytest prop_T_lines),
488+ ("prop_TL_lines", mytest prop_TL_lines),
487--("prop_T_lines'", mytest prop_T_lines'),
489--("prop_T_lines'", mytest prop_T_lines'),
488 ("prop_T_words", mytest prop_T_words),
490 ("prop_T_words", mytest prop_T_words),
489 ("prop_T_unlines", mytest prop_T_unlines),
491 ("prop_T_unlines", mytest prop_T_unlines),