on master help sign in
Implement findAll.

--HG-- extra : convert_revision : ca28d333f39d165715b57e08382df24ef6604110

commit37b81cf44eba64535cb5cae8e20da1d51566b24d authorBryan O'Sullivan <bos@serpentine.com> dateMon 17 Aug 2009, 00:47 (17 years ago) parentd71ea9f
1 file changed+16
Data/Text.hs+16
Data/Text.hs+16
@@ -144,6 +144,7 @@ module Data.Text
144144 -- * Searching
145145 , elem
146146 , filter
147+ , findAll
147148 , find
148149 , partition
149150
@@ -1051,6 +1052,21 @@ filter :: (Char -> Bool) -> Text -> Text
10511052filter p t = unstream (S.filter p (stream t))
10521053{-# INLINE filter #-}
10531054
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+
10541070
10551071-------------------------------------------------------------------------------
10561072-- ** Indexing 'Text's