on master help sign in
Rename findBy back to find
commit15eaf1fbdc43a883efb9bfb8c5e1609aa5bdb342 authorBryan O'Sullivan <bos@serpentine.com> dateMon 8 Nov 2010, 13:56 (16 years ago) parent3b257df
3 files changed+36−36
Data/Text.hs+14−14 Data/Text/Lazy.hs+12−12 tests/Properties.hs+10−10
Data/Text.hs+14−14
@@ -150,8 +150,8 @@ module Data.Text
150150
151151 -- * Searching
152152 , filter
153+ , breakOnAll
153154 , find
154− , findBy
155155 , partitionBy
156156
157157 -- , findSubstring
@@ -1136,12 +1136,12 @@ chunksOf k = go
11361136-------------------------------------------------------------------------------
11371137-- ** Searching with a predicate
11381138
1139−-- | /O(n)/ The 'findBy' function takes a predicate and a 'Text', and
1140−-- returns the first element in matching the predicate, or 'Nothing'
1141−-- if there is no such element.
1142−findBy :: (Char -> Bool) -> Text -> Maybe Char
1143−findBy p t = S.findBy p (stream t)
1144−{-# INLINE findBy #-}
1139+-- | /O(n)/ The 'find' function takes a predicate and a 'Text', and
1140+-- returns the first element matching the predicate, or 'Nothing' if
1141+-- there is no such element.
1142+find :: (Char -> Bool) -> Text -> Maybe Char
1143+find p t = S.findBy p (stream t)
1144+{-# INLINE find #-}
11451145
11461146-- | /O(n)/ The 'partitionBy' function takes a predicate and a 'Text',
11471147-- and returns the pair of 'Text's with elements which do and do not
@@ -1175,7 +1175,7 @@ filter p t = unstream (S.filter p (stream t))
11751175-- > where (prefix, match) = breakOn needle haystack
11761176--
11771177-- If you need to break a string by a substring repeatedly (e.g. you
1178−-- want to break on every instance of a substring), use 'find'
1178+-- want to break on every instance of a substring), use 'breakOnAll'
11791179-- instead, as it has lower startup overhead.
11801180--
11811181-- In (unlikely) bad cases, this function's time complexity degrades
@@ -1219,16 +1219,16 @@ breakOnEnd pat src = (reverse b, reverse a)
12191219-- towards /O(n*m)/.
12201220--
12211221-- The @needle@ parameter may not be empty.
1222−find :: Text -- ^ @needle@ to search for
1223− -> Text -- ^ @haystack@ in which to search
1224− -> [(Text, Text)]
1225−find pat src@(Text arr off slen)
1226− | null pat = emptyError "find"
1222+breakOnAll :: Text -- ^ @needle@ to search for
1223+ -> Text -- ^ @haystack@ in which to search
1224+ -> [(Text, Text)]
1225+breakOnAll pat src@(Text arr off slen)
1226+ | null pat = emptyError "breakOnAll"
12271227 | otherwise = L.map step (indices pat src)
12281228 where
12291229 step x = (chunk 0 x, chunk x (slen-x))
12301230 chunk !n !l = textP arr (n+off) l
1231−{-# INLINE find #-}
1231+{-# INLINE breakOnAll #-}
12321232
12331233-------------------------------------------------------------------------------
12341234-- ** Indexing 'Text's
Data/Text/Lazy.hs+12−12
@@ -156,7 +156,7 @@ module Data.Text.Lazy
156156 -- * Searching
157157 , filter
158158 , find
159− , findBy
159+ , breakOnAll
160160 , partitionBy
161161
162162 -- , findSubstring
@@ -1010,9 +1010,9 @@ breakOnEnd pat src = let (a,b) = breakOn (reverse pat) (reverse src)
10101010--
10111011-- Examples:
10121012--
1013−-- > find "::" ""
1013+-- > breakOnAll "::" ""
10141014-- > ==> []
1015−-- > find "/" "a/b/c/"
1015+-- > breakOnAll "/" "a/b/c/"
10161016-- > ==> [("a", "/b/c/"), ("a/b", "/c/"), ("a/b/c", "/")]
10171017--
10181018-- This function is strict in its first argument, and lazy in its
@@ -1022,11 +1022,11 @@ breakOnEnd pat src = let (a,b) = breakOn (reverse pat) (reverse src)
10221022-- towards /O(n*m)/.
10231023--
10241024-- The @needle@ parameter may not be empty.
1025−find :: Text -- ^ @needle@ to search for
1026− -> Text -- ^ @haystack@ in which to search
1027− -> [(Text, Text)]
1028−find pat src
1029− | null pat = emptyError "find"
1025+breakOnAll :: Text -- ^ @needle@ to search for
1026+ -> Text -- ^ @haystack@ in which to search
1027+ -> [(Text, Text)]
1028+breakOnAll pat src
1029+ | null pat = emptyError "breakOnAll"
10301030 | otherwise = go 0 empty src (indices pat src)
10311031 where
10321032 go !n p s (x:xs) = let h :*: t = splitAtWord (x-n) s
@@ -1299,12 +1299,12 @@ filter :: (Char -> Bool) -> Text -> Text
12991299filter p t = unstream (S.filter p (stream t))
13001300{-# INLINE filter #-}
13011301
1302−-- | /O(n)/ The 'findBy' function takes a predicate and a 'Text', and
1302+-- | /O(n)/ The 'find' function takes a predicate and a 'Text', and
13031303-- returns the first element in matching the predicate, or 'Nothing'
13041304-- if there is no such element.
1305−findBy :: (Char -> Bool) -> Text -> Maybe Char
1306−findBy p t = S.findBy p (stream t)
1307−{-# INLINE findBy #-}
1305+find :: (Char -> Bool) -> Text -> Maybe Char
1306+find p t = S.findBy p (stream t)
1307+{-# INLINE find #-}
13081308
13091309-- | /O(n)/ The 'partitionBy' function takes a predicate and a 'Text',
13101310-- and returns the pair of 'Text's with elements which do and do not
tests/Properties.hs+10−10
@@ -511,17 +511,17 @@ t_tails = L.tails `eqP` (map unpackS . T.tails)
511511tl_tails = L.tails `eqP` (map unpackS . TL.tails)
512512t_findAppendId (NotEmpty s) = unsquare $ \ts ->
513513 let t = T.intercalate s ts
514− in all (==t) $ map (uncurry T.append) (T.find s t)
514+ in all (==t) $ map (uncurry T.append) (T.breakOnAll s t)
515515tl_findAppendId (NotEmpty s) = unsquare $ \ts ->
516516 let t = TL.intercalate s ts
517− in all (==t) $ map (uncurry TL.append) (TL.find s t)
518−t_findContains (NotEmpty s) = all (T.isPrefixOf s . snd) . T.find s .
517+ in all (==t) $ map (uncurry TL.append) (TL.breakOnAll s t)
518+t_findContains (NotEmpty s) = all (T.isPrefixOf s . snd) . T.breakOnAll s .
519519 T.intercalate s
520520tl_findContains (NotEmpty s) = all (TL.isPrefixOf s . snd) .
521− TL.find s . TL.intercalate s
521+ TL.breakOnAll s . TL.intercalate s
522522sl_filterCount c = (L.genericLength . L.filter (==c)) `eqP` SL.countChar c
523−t_findCount s = (L.length . T.find s) `eq` T.count s
524−tl_findCount s = (L.genericLength . TL.find s) `eq` TL.count s
523+t_findCount s = (L.length . T.breakOnAll s) `eq` T.count s
524+tl_findCount s = (L.genericLength . TL.breakOnAll s) `eq` TL.count s
525525
526526t_split_split s = (T.split s `eq` Slow.split s) . T.intercalate s
527527tl_split_split s = ((TL.split (TL.fromStrict s) . TL.fromStrict) `eq`
@@ -597,8 +597,8 @@ sf_filter q p = (L.filter p . L.filter q) `eqP`
597597t_filter p = L.filter p `eqP` (unpackS . T.filter p)
598598tl_filter p = L.filter p `eqP` (unpackS . TL.filter p)
599599sf_findBy q p = (L.find p . L.filter q) `eqP` (S.findBy p . S.filter q)
600−t_findBy p = L.find p `eqP` T.findBy p
601−tl_findBy p = L.find p `eqP` TL.findBy p
600+t_find p = L.find p `eqP` T.find p
601+tl_find p = L.find p `eqP` TL.find p
602602t_partition p = L.partition p `eqP` (unpack2 . T.partitionBy p)
603603tl_partition p = L.partition p `eqP` (unpack2 . TL.partitionBy p)
604604
@@ -1130,8 +1130,8 @@ tests = [
11301130 testProperty "t_filter" t_filter,
11311131 testProperty "tl_filter" tl_filter,
11321132 testProperty "sf_findBy" sf_findBy,
1133− testProperty "t_findBy" t_findBy,
1134− testProperty "tl_findBy" tl_findBy,
1133+ testProperty "t_find" t_find,
1134+ testProperty "tl_find" tl_find,
11351135 testProperty "t_partition" t_partition,
11361136 testProperty "tl_partition" tl_partition
11371137 ],