Skip to content

Commit

Permalink
Implement and test lazy lines
Browse files Browse the repository at this point in the history
--HG--
extra : convert_revision : 6c7cd42170da660978de361adfd032c1fa0fca48
  • Loading branch information
bos committed Mar 8, 2009
1 parent 1fde6e9 commit 6273f4b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Data/Text/Lazy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ module Data.Text.Lazy
-- , breakSubstring

-- ** Breaking into lines and words
-- , lines
, lines
--, lines'
-- , words
-- , unlines
Expand Down Expand Up @@ -717,6 +717,14 @@ splitWith p (Chunk t0 ts0) = comb [] (T.splitWith p t0) ts0
comb acc (s:ss) ts = revChunks (s:acc) : comb [] ss ts
{-# INLINE splitWith #-}

-- | /O(n)/ Breaks a 'Text' up into a list of 'Text's at
-- newline 'Char's. The resulting strings do not contain newlines.
lines :: Text -> [Text]
lines Empty = []
lines t = let (l,t') = break ((==) '\n') t
in l : if null t' then []
else lines (tail t')

revChunks :: [T.Text] -> Text
revChunks = L.foldl' (flip chunk) Empty

Expand Down
2 changes: 2 additions & 0 deletions tests/Properties.hs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ prop_T_breakSubstringC c
(unpack2 . T.breakSubstring (T.singleton c))

prop_T_lines = L.lines `eqP` (map unpackT . T.lines)
prop_TL_lines = L.lines `eqP` (map unpackT . TL.lines)
{-
prop_T_lines' = lines' `eqP` (map unpackT . T.lines')
where lines' "" = []
Expand Down Expand Up @@ -484,6 +485,7 @@ tests = [
("prop_T_breakSubstring_isInfixOf", mytest prop_T_breakSubstring_isInfixOf),

("prop_T_lines", mytest prop_T_lines),
("prop_TL_lines", mytest prop_TL_lines),
--("prop_T_lines'", mytest prop_T_lines'),
("prop_T_words", mytest prop_T_words),
("prop_T_unlines", mytest prop_T_unlines),
Expand Down

0 comments on commit 6273f4b

Please sign in to comment.