@@ -1052,21 +1052,38 @@ filter :: (Char -> Bool) -> Text -> Text
1052filter p t = unstream (S.filter p (stream t))
1052filter p t = unstream (S.filter p (stream t))
1053{-# INLINE filter #-}
1053{-# INLINE filter #-}
1055+-- /O(n*m)/ Find all non-overlapping instances of @needle@ in
1056+-- @haystack@. The first element of the returned tuple is the prefix
1057+-- of @haystack@ before any matches of @needle@. The second element
1058+-- of the tuple is a list of non-overlapping substrings from
1059+-- @haystack@. Each begins with @needle@ and ends just before the
1060+-- following match. If @needle@ is not present in @haystack@, the
1061+-- list will be empty.
1065+-- > findAll "::" "a::b::c" ==> ("a", ["::b", "::c"])
1066+-- > findAll "/" "foobar" ==> ("foobar", [])
1070+-- > concat (prefix : matches) == haystack
1071+-- > where (prefix, matches) = findAll needle haystack
1055findAll :: Text -> Text -> (Text, [Text])
1072findAll :: Text -> Text -> (Text, [Text])
1056findAll pat@(Text _ _ plen) src@(Text sarr soff slen)
1073findAll pat@(Text _ _ plen) src@(Text sarr soff slen)
1057 | plen <= 0 = emptyError "findAll"
1074 | plen <= 0 = emptyError "findAll"
1058 | otherwise = (h,t)
1075 | otherwise = (h,t)
1060− (h:t) = go 0 (search 0)
1077+ (h:t) = go 0 (search 0)
1061− go !k (x:xs) = Text sarr k (x-k) : go x xs
1078+ go k (x:xs) = Text sarr k (x-k) : go x xs
1062− go _ [] = []
1079+ go _ [] = []
1063− search !i
1080+ search i
1064 | i >= slen = [slen] -- not found
1081 | i >= slen = [slen] -- not found
1065− | pat `isPrefixOf` s = i : search (i+d+plen)
1082+ | pat `isPrefixOf` s = i : search (i+plen)
1066 | otherwise = search (i+d)
1083 | otherwise = search (i+d)
1084+ where d = iter_ src i
1067− where s = Text sarr (soff+i) (slen-i)
1085+ s = Text sarr (soff+i) (slen-i)
1068− d = iter_ src i
1086+{-# INLINE findAll #-}
1071-------------------------------------------------------------------------------
1088-------------------------------------------------------------------------------
1072-- ** Indexing 'Text's
1089-- ** Indexing 'Text's