@@ -915,38 +915,33 @@ breakEnd pat src = let (a,b) = break (reverse pat) (reverse src)
915915{-# INLINE breakEnd #-}
916916
917917-- | /O(n+m)/ Find all non-overlapping instances of @needle@ in
918−-- @haystack@. The first element of the returned pair is the prefix
919−-- of @haystack@ prior to any matches of @needle@. The second is a
920−-- list of pairs.
918+-- @haystack@. Each element of the returned list consists of a triple:
921919--
922−-- The first element of each pair in the list is a span from the
923−-- beginning of a match to the beginning of the next match, while the
924−-- second is a span from the beginning of the match to the end of the
925−-- input.
920+-- * The entire string prior to the /k/th match
921+--
922+-- * The /k/th match
923+--
924+-- * The entire string following the /k/th match
926925--
927926-- Examples:
928927--
929928-- > find "::" ""
930−-- > ==> ("", [])
931−-- > find "/" "a/b/c/d"
932−-- > ==> ("a", [("/b","/b/c/d"), ("/c","/c/d"), ("/d","/d")])
929+-- > ==> []
930+-- > find "/" "a/b/c/"
931+-- > ==> [("a", "/", "b/c/"), ("a/b", "/", "c/"), ("a/b/c", "/", "")]
933932--
934933-- This function is strict in its first argument, and lazy in its
935934-- second.
936935--
937936-- In (unlikely) bad cases, this function's time complexity degrades
938937-- towards /O(n*m)/.
939−find :: Text -> Text -> (Text, [(Text, Text)])
938+find :: Text -> Text -> [(Text, Text, Text)]
940939find pat src
941940 | null pat = emptyError "find"
942− | otherwise = case indices pat src of
943− [] -> (src, [])
944− (x:xs) -> let h :*: t = splitAtWord x src
945− in (h, go x xs t)
941+ | otherwise = L.map step (indices pat src)
946942 where
947− go !i (x:xs) cs = let h :*: t = splitAtWord (x-i) cs
948− in (h, cs) : go x xs t
949− go _ _ cs = [(cs,cs)]
943+ step x = (take x src, pat, drop (x + l) pat)
944+ l = length pat
950945
951946-- | /O(n)/ 'breakBy' is like 'spanBy', but the prefix returned is over
952947-- elements that fail the predicate @p@.