on master help sign in
Clarify the precondition for splitOn (gh-92)
a47bb70Bryan O'Sullivan
Data/Text.hs+18−7
@@ -689,9 +689,13 @@ reverse t = S.reverse (stream t)
689--
689--
690-- In (unlikely) bad cases, this function's time complexity degrades
690-- In (unlikely) bad cases, this function's time complexity degrades
691-- towards /O(n*m)/.
691-- towards /O(n*m)/.
692−replace :: Text -- ^ @needle@ to search for
692+replace :: Text
693+ -- ^ @needle@ to search for. If this string is empty, an
694+ -- error will occur.
695+ -> Text
693− -> Text -- ^ @replacement@ to replace @needle@ with
696+ -- ^ @replacement@ to replace @needle@ with.
697+ -> Text
694− -> Text -- ^ @haystack@ in which to search
698+ -- ^ @haystack@ in which to search.
695 -> Text
699 -> Text
696replace needle@(Text _ _ neeLen)
700replace needle@(Text _ _ neeLen)
697 (Text repArr repOff repLen)
701 (Text repArr repOff repLen)
@@ -1299,9 +1303,9 @@ tails t | null t = [empty]
1299-- copies to create substrings; they just construct new 'Text's that
1303-- copies to create substrings; they just construct new 'Text's that
1300-- are slices of the original.
1304-- are slices of the original.
1301
1305
1302−-- | /O(m+n)/ Break a 'Text' into pieces separated by the first
1306+-- | /O(m+n)/ Break a 'Text' into pieces separated by the first 'Text'
1303−-- 'Text' argument, consuming the delimiter. An empty delimiter is
1307+-- argument (which cannot be empty), consuming the delimiter. An empty
1304−-- invalid, and will cause an error to be raised.
1308+-- delimiter is invalid, and will cause an error to be raised.
1305--
1309--
1306-- Examples:
1310-- Examples:
1307--
1311--
@@ -1314,9 +1318,16 @@ tails t | null t = [empty]
1314-- > intercalate s . splitOn s == id
1318-- > intercalate s . splitOn s == id
1315-- > splitOn (singleton c) == split (==c)
1319-- > splitOn (singleton c) == split (==c)
1316--
1320--
1321+-- (Note: the string @s@ to split on above cannot be empty.)
1322+--
1317-- In (unlikely) bad cases, this function's time complexity degrades
1323-- In (unlikely) bad cases, this function's time complexity degrades
1318-- towards /O(n*m)/.
1324-- towards /O(n*m)/.
1319−splitOn :: Text -> Text -> [Text]
1325+splitOn :: Text
1326+ -- ^ String to split on. If this string is empty, an error
1327+ -- will occur.
1328+ -> Text
1329+ -- ^ Input text.
1330+ -> [Text]
1320splitOn pat@(Text _ _ l) src@(Text arr off len)
1331splitOn pat@(Text _ _ l) src@(Text arr off len)
1321 | l <= 0 = emptyError "splitOn"
1332 | l <= 0 = emptyError "splitOn"
1322 | isSingleton pat = split (== unsafeHead pat) src
1333 | isSingleton pat = split (== unsafeHead pat) src
Data/Text/Lazy.hs+18−8
@@ -686,9 +686,13 @@ reverse = rev Empty
686--
686--
687-- In (unlikely) bad cases, this function's time complexity degrades
687-- In (unlikely) bad cases, this function's time complexity degrades
688-- towards /O(n*m)/.
688-- towards /O(n*m)/.
689−replace :: Text -- ^ Text to search for
689+replace :: Text
690− -> Text -- ^ Replacement text
690+ -- ^ @needle@ to search for. If this string is empty, an
691+ -- error will occur.
692+ -> Text
693+ -- ^ @replacement@ to replace @needle@ with.
691− -> Text -- ^ Input text
694+ -> Text
695+ -- ^ @haystack@ in which to search.
692 -> Text
696 -> Text
693replace s d = intercalate d . splitOn s
697replace s d = intercalate d . splitOn s
694{-# INLINE replace #-}
698{-# INLINE replace #-}
@@ -1299,9 +1303,10 @@ tails ts@(Chunk t ts')
1299-- copies to create substrings; they just construct new 'Text's that
1303-- copies to create substrings; they just construct new 'Text's that
1300-- are slices of the original.
1304-- are slices of the original.
1301
1305
1302−-- | /O(m+n)/ Break a 'Text' into pieces separated by the first
1306+-- | /O(m+n)/ Break a 'Text' into pieces separated by the first 'Text'
1303−-- 'Text' argument, consuming the delimiter. An empty delimiter is
1307+-- argument (which cannot be an empty string), consuming the
1304−-- invalid, and will cause an error to be raised.
1308+-- delimiter. An empty delimiter is invalid, and will cause an error
1309+-- to be raised.
1305--
1310--
1306-- Examples:
1311-- Examples:
1307--
1312--
@@ -1314,13 +1319,18 @@ tails ts@(Chunk t ts')
1314-- > intercalate s . splitOn s == id
1319-- > intercalate s . splitOn s == id
1315-- > splitOn (singleton c) == split (==c)
1320-- > splitOn (singleton c) == split (==c)
1316--
1321--
1322+-- (Note: the string @s@ to split on above cannot be empty.)
1323+--
1317-- This function is strict in its first argument, and lazy in its
1324-- This function is strict in its first argument, and lazy in its
1318-- second.
1325-- second.
1319--
1326--
1320-- In (unlikely) bad cases, this function's time complexity degrades
1327-- In (unlikely) bad cases, this function's time complexity degrades
1321-- towards /O(n*m)/.
1328-- towards /O(n*m)/.
1322−splitOn :: Text -- ^ Text to split on
1329+splitOn :: Text
1330+ -- ^ String to split on. If this string is empty, an error
1331+ -- will occur.
1332+ -> Text
1323− -> Text -- ^ Input text
1333+ -- ^ Input text.
1324 -> [Text]
1334 -> [Text]
1325splitOn pat src
1335splitOn pat src
1326 | null pat = emptyError "splitOn"
1336 | null pat = emptyError "splitOn"