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