Commits

Bryan O'Sullivan committed 2c4394c

Make the split* functions undefined over empty delimiters as inputs.

  • Participants
  • Parent commits 3fb7d2c

Comments (0)

Files changed (1)

File Data/Text/Lazy.hs

 -- | /O(n*m)/ 'replicate' @n@ @t@ is a 'Text' consisting of the input
 -- @t@ repeated @n@ times. Subject to fusion.
 replicate :: Int64 -> Text -> Text
-replicate n t = unstream (S.replicateI (fromIntegral n) (S.stream t))
+replicate n t = unstream (S.replicateI n (S.stream t))
 {-# INLINE replicate #-}
 
 -- | /O(n)/ 'replicateChar' @n@ @c@ is a 'Text' of length @n@ with @c@ the
 -- are slices of the original.
 
 -- | /O(m)*O(n)/ Break a 'Text' into pieces separated by the first
--- 'Text' argument, consuming the delimiter. Examples:
+-- 'Text' argument, consuming the delimiter.  An empty delimiter is
+-- invalid, and will cause an error to be raised.
+--
+-- Examples:
 --
 -- > split "\r\n" "a\r\nb\r\nd\r\ne" == ["a","b","d","e"]
 -- > split "aaa"  "aaaXaaaXaaaXaaa"  == ["","X","X","X",""]
       -> Text                   -- ^ Input text
       -> [Text]
 split pat src0
-    | l == 0    = [src0]
+    | l == 0    = emptyError "split"
     | l == 1    = splitWith (== (head pat)) src0
     | otherwise = go src0
   where
 -- and consuming the delimiter.  The last element of the list contains
 -- the remaining text after the number of times to split has been
 -- reached.  A value of zero or less for @k@ causes no splitting to
--- occur.
+-- occur.  An empty delimiter is invalid, and will cause an error to
+-- be raised.
 --
 -- Examples:
 --
            -> Text              -- ^ Input text
            -> [Text]
 splitTimes k pat src0
-    | k <= 0 || l == 0 = [src0]
-    | otherwise        = go k src0
+    | k <= 0    = [src0]
+    | l == 0    = emptyError "splitTimes"
+    | otherwise = go k src0
   where
     l         = length pat
     go !i src = search 0 src