@@ -110,7 +110,7 @@ module Data.Text
111 -- ** Breaking into lines and words
111 -- ** Breaking into lines and words
113− -- , lines
113+ , lines
115 -- * Predicates
115 -- * Predicates
116 -- , isPrefixOf
116 -- , isPrefixOf
@@ -626,6 +626,8 @@ elemIndex c t = S.elemIndex c (stream t)
626zipWith :: (Char -> Char -> Char) -> Text -> Text -> Text
626zipWith :: (Char -> Char -> Char) -> Text -> Text -> Text
627zipWith f t1 t2 = unstream (S.zipWith f (stream t1) (stream t2))
627zipWith f t1 t2 = unstream (S.zipWith f (stream t1) (stream t2))
629+-- | /O(n)/ Breaks a 'Text' up into a list of words, delimited by 'Char's
630+-- representing white space.
629words :: Text -> [Text]
631words :: Text -> [Text]
630words (Text arr off len) = loop0 off off
632words (Text arr off len) = loop0 off off
@@ -641,5 +643,17 @@ words (Text arr off len) = loop0 off off
641 c = arr `A.unsafeIndex` n
643 c = arr `A.unsafeIndex` n
642{-# INLINE words #-}
644{-# INLINE words #-}
646+-- | /O(n)/ Breaks a 'Text' up into a list of 'Text's at
647+-- newline 'Char's. The resulting strings do not contain newlines.
649+lines :: Text -> [Text]
652+ | otherwise = case search ps of
654+ Just n -> take n ps : lines (drop (n+1) ps)
655+ where search = elemIndex '\n'
644errorEmptyList :: String -> a
658errorEmptyList :: String -> a
645errorEmptyList fun = error ("Data.Text." ++ fun ++ ": empty list")
659errorEmptyList fun = error ("Data.Text." ++ fun ++ ": empty list")