on master help sign in
Implement and test lazy lines

--HG-- extra : convert_revision : 6c7cd42170da660978de361adfd032c1fa0fca48

commit6273f4b30379415afb131b67a826256780238d46 authorBryan O'Sullivan <bos@serpentine.com> dateSun 8 Mar 2009, 01:38 (18 years ago) parent1fde6e9
2 files changed+11−1
Data/Text/Lazy.hs+9−1 tests/Properties.hs+2
Data/Text/Lazy.hs+9−1
@@ -114,7 +114,7 @@ module Data.Text.Lazy
114114 -- , breakSubstring
115115
116116 -- ** Breaking into lines and words
117− -- , lines
117+ , lines
118118 --, lines'
119119 -- , words
120120 -- , unlines
@@ -717,6 +717,14 @@ splitWith p (Chunk t0 ts0) = comb [] (T.splitWith p t0) ts0
717717 comb acc (s:ss) ts = revChunks (s:acc) : comb [] ss ts
718718{-# INLINE splitWith #-}
719719
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+
720728revChunks :: [T.Text] -> Text
721729revChunks = L.foldl' (flip chunk) Empty
722730
tests/Properties.hs+2
@@ -282,6 +282,7 @@ prop_T_breakSubstringC c
282282 (unpack2 . T.breakSubstring (T.singleton c))
283283
284284prop_T_lines = L.lines `eqP` (map unpackT . T.lines)
285+prop_TL_lines = L.lines `eqP` (map unpackT . TL.lines)
285286{-
286287prop_T_lines' = lines' `eqP` (map unpackT . T.lines')
287288 where lines' "" = []
@@ -484,6 +485,7 @@ tests = [
484485 ("prop_T_breakSubstring_isInfixOf", mytest prop_T_breakSubstring_isInfixOf),
485486
486487 ("prop_T_lines", mytest prop_T_lines),
488+ ("prop_TL_lines", mytest prop_TL_lines),
487489--("prop_T_lines'", mytest prop_T_lines'),
488490 ("prop_T_words", mytest prop_T_words),
489491 ("prop_T_unlines", mytest prop_T_unlines),