on master help sign in
Implement and test lazy words

--HG-- extra : convert_revision : 48f40a1f821cb1bb1df75a5872a07007f3746f12

commit184a502b882bfd0357e4286a2b8836950c14dce0 authorBryan O'Sullivan <bos@serpentine.com> dateSun 8 Mar 2009, 01:43 (18 years ago) parent6273f4b
2 files changed+10−2
Data/Text/Lazy.hs+8−2 tests/Properties.hs+2
Data/Text/Lazy.hs+8−2
@@ -115,8 +115,7 @@ module Data.Text.Lazy
115115
116116 -- ** Breaking into lines and words
117117 , lines
118− --, lines'
119− -- , words
118+ , words
120119 -- , unlines
121120 -- , unwords
122121
@@ -156,6 +155,7 @@ import Prelude (Char, Bool(..), Functor(..), Int, Maybe(..), String,
156155import qualified Prelude as P
157156import Data.Int (Int64)
158157import qualified Data.List as L
158+import Data.Char (isSpace)
159159import Data.String (IsString(..))
160160import qualified Data.Text as T
161161import qualified Data.Text.Fusion.Common as S
@@ -725,6 +725,12 @@ lines t = let (l,t') = break ((==) '\n') t
725725 in l : if null t' then []
726726 else lines (tail t')
727727
728+-- | /O(n)/ Breaks a 'Text' up into a list of words, delimited by 'Char's
729+-- representing white space.
730+words :: Text -> [Text]
731+words = L.filter (not . null) . splitWith isSpace
732+{-# INLINE words #-}
733+
728734revChunks :: [T.Text] -> Text
729735revChunks = L.foldl' (flip chunk) Empty
730736
tests/Properties.hs+2
@@ -294,6 +294,7 @@ prop_T_lines' = lines' `eqP` (map unpackT . T.lines')
294294 eol c = c == '\r' || c == '\n'
295295-}
296296prop_T_words = L.words `eqP` (map unpackT . T.words)
297+prop_TL_words = L.words `eqP` (map unpackT . TL.words)
297298prop_T_unlines = L.unlines `eq` (unpackT . T.unlines . map T.pack)
298299prop_T_unwords = L.unwords `eq` (unpackT . T.unwords . map T.pack)
299300
@@ -488,6 +489,7 @@ tests = [
488489 ("prop_TL_lines", mytest prop_TL_lines),
489490--("prop_T_lines'", mytest prop_T_lines'),
490491 ("prop_T_words", mytest prop_T_words),
492+ ("prop_TL_words", mytest prop_TL_words),
491493 ("prop_T_unlines", mytest prop_T_unlines),
492494 ("prop_T_unwords", mytest prop_T_unwords),
493495