on master help sign in
Implement findAll.
37b81cfBryan O'Sullivan
Data/Text.hs+16
@@ -144,6 +144,7 @@ module Data.Text
144 -- * Searching
144 -- * Searching
145 , elem
145 , elem
146 , filter
146 , filter
147+ , findAll
147 , find
148 , find
148 , partition
149 , partition
149
150
@@ -1051,6 +1052,21 @@ filter :: (Char -> Bool) -> Text -> Text
1051filter p t = unstream (S.filter p (stream t))
1052filter p t = unstream (S.filter p (stream t))
1052{-# INLINE filter #-}
1053{-# INLINE filter #-}
1053
1054
1055+findAll :: Text -> Text -> (Text, [Text])
1056+findAll pat@(Text _ _ plen) src@(Text sarr soff slen)
1057+ | plen == 0 = emptyError "findAll"
1058+ | otherwise = (h,t)
1059+ where
1060+ (h:t) = go 0 (search 0)
1061+ go !k (x:xs) = Text sarr k (x-k) : go x xs
1062+ go _ [] = []
1063+ search !i
1064+ | i >= slen = [slen] -- not found
1065+ | pat `isPrefixOf` s = i : search (i+d+plen)
1066+ | otherwise = search (i+d)
1067+ where s = Text sarr (soff+i) (slen-i)
1068+ d = iter_ src i
1069+
1054
1070
1055-------------------------------------------------------------------------------
1071-------------------------------------------------------------------------------
1056-- ** Indexing 'Text's
1072-- ** Indexing 'Text's