@@ -1086,34 +1086,30 @@ breakEnd pat src = let (a,b) = break (reverse pat) (reverse src)
10861086{-# INLINE breakEnd #-}
10871087
10881088-- | /O(n+m)/ Find all non-overlapping instances of @needle@ in
1089−-- @haystack@. The first element of the returned pair is the prefix
1090−-- of @haystack@ prior to any matches of @needle@. The second is a
1091−-- list of pairs.
1089+-- @haystack@. Each element of the returned list consists of a triple:
10921090--
1093−-- The first element of each pair in the list is a span from the
1094−-- beginning of a match to the beginning of the next match, while the
1095−-- second is a span from the beginning of the match to the end of the
1096−-- input.
1091+-- * The entire string prior to the /k/th match
1092+--
1093+-- * The /k/th match
1094+--
1095+-- * The entire string following the /k/th match
10971096--
10981097-- Examples:
10991098--
11001099-- > find "::" ""
1101−-- > ==> ("", [])
1102−-- > find "/" "a/b/c/d"
1103−-- > ==> ("a", [("/b","/b/c/d"), ("/c","/c/d"), ("/d","/d")])
1100+-- > ==> []
1101+-- > find "/" "a/b/c/"
1102+-- > ==> [("a", "/", "b/c/"), ("a/b", "/", "c/"), ("a/b/c", "/", "")]
11041103--
11051104-- In (unlikely) bad cases, this function's time complexity degrades
11061105-- towards /O(n*m)/.
1107−find :: Text -> Text -> (Text, [(Text, Text)])
1108−find pat src@(Text arr off len)
1106+find :: Text -> Text -> [(Text, Text, Text)]
1107+find pat@(Text _ _ plen) src@(Text arr off slen)
11091108 | null pat = emptyError "find"
1110− | otherwise = case indices pat src of
1111− [] -> (src, [])
1112− (x:xs) -> (chunk 0 x, go x xs)
1109+ | otherwise = L.map step (indices pat src)
11131110 where
1114− go !s (x:xs) = (chunk s (x-s), chunk s (len-s)) : go x xs
1115− go s _ = let c = chunk s (len-s)
1116− in [(c,c)]
1111+ step x = (chunk 0 x, chunk x plen, chunk (x+plen) (stop-x))
1112+ stop = slen - plen
11171113 chunk !n !l = textP arr (n+off) l
11181114{-# INLINE find #-}
11191115