on master help sign in
Rename splitWith to splitBy.

--HG-- extra : convert_revision : 441c5090f245482704b30958a01f241c93b77e20

commit3ebc7fa435df02bd845c8cc27298152ba567532c authorBryan O'Sullivan <bos@serpentine.com> dateTue 6 Oct 2009, 20:31 (17 years ago) parente0ef874
4 files changed+38−38
Data/Text.hs+11−11 Data/Text/Lazy.hs+14−14 tests/Properties.hs+12−12 tests/SlowFunctions.hs+1−1
Data/Text.hs+11−11
@@ -126,7 +126,7 @@ module Data.Text
126126 , split
127127 , splitTimes
128128 , splitTimesEnd
129− , splitWith
129+ , splitBy
130130 , chunksOf
131131
132132 -- ** Breaking into lines and words
@@ -914,14 +914,14 @@ tails t | null t = [empty]
914914-- and
915915--
916916-- > intercalate s . split s == id
917−-- > split (singleton c) == splitWith (==c)
917+-- > split (singleton c) == splitBy (==c)
918918--
919919-- In (unlikely) bad cases, this function's time complexity
920920-- degenerates towards /O(n*m)/.
921921split :: Text -> Text -> [Text]
922922split pat@(Text _ _ l) src@(Text arr off len)
923923 | l <= 0 = emptyError "split"
924− | isSingleton pat = splitWith (== unsafeHead pat) src
924+ | isSingleton pat = splitBy (== unsafeHead pat) src
925925 | otherwise = go 0 (indices pat src)
926926 where
927927 go !s (x:xs) = textP arr (s+off) (x-s) : go (x+l) xs
@@ -929,8 +929,8 @@ split pat@(Text _ _ l) src@(Text arr off len)
929929{-# INLINE [1] split #-}
930930
931931{-# RULES
932−"TEXT split/singleton -> splitWith/==" [~1] forall c t.
933− split (singleton c) t = splitWith (==c) t
932+"TEXT split/singleton -> splitBy/==" [~1] forall c t.
933+ split (singleton c) t = splitBy (==c) t
934934 #-}
935935
936936-- | /O(m+n)/ Break a 'Text' into pieces at most @k@ times,
@@ -990,15 +990,15 @@ splitTimesEnd k pat src =
990990-- resulting components do not contain the separators. Two adjacent
991991-- separators result in an empty component in the output. eg.
992992--
993−-- > splitWith (=='a') "aabbaca" == ["","","bb","c",""]
994−-- > splitWith (=='a') "" == [""]
995−splitWith :: (Char -> Bool) -> Text -> [Text]
996−splitWith _ t@(Text _off _arr 0) = [t]
997−splitWith p t = loop t
993+-- > splitBy (=='a') "aabbaca" == ["","","bb","c",""]
994+-- > splitBy (=='a') "" == [""]
995+splitBy :: (Char -> Bool) -> Text -> [Text]
996+splitBy _ t@(Text _off _arr 0) = [t]
997+splitBy p t = loop t
998998 where loop s | null s' = [l]
999999 | otherwise = l : loop (unsafeTail s')
10001000 where (l, s') = break p s
1001−{-# INLINE splitWith #-}
1001+{-# INLINE splitBy #-}
10021002
10031003-- | /O(n)/ Splits a 'Text' into components of length @k@. The last
10041004-- element may be shorter than the other chunks, depending on the
Data/Text/Lazy.hs+14−14
@@ -130,7 +130,7 @@ module Data.Text.Lazy
130130 , split
131131 , splitTimes
132132 , splitTimesEnd
133− , splitWith
133+ , splitBy
134134 , chunksOf
135135 -- , breakSubstring
136136
@@ -881,13 +881,13 @@ tails ts@(Chunk t ts')
881881-- and
882882--
883883-- > intercalate s . split s == id
884−-- > split (singleton c) == splitWith (==c)
884+-- > split (singleton c) == splitBy (==c)
885885split :: Text -- ^ Text to split on
886886 -> Text -- ^ Input text
887887 -> [Text]
888888split pat src0
889889 | l == 0 = emptyError "split"
890− | l == 1 = splitWith (== (head pat)) src0
890+ | l == 1 = splitBy (== (head pat)) src0
891891 | otherwise = go src0
892892 where
893893 l = length pat
@@ -900,8 +900,8 @@ split pat src0
900900{-# INLINE [1] split #-}
901901
902902{-# RULES
903−"LAZY TEXT split/singleton -> splitWith/==" [~1] forall c t.
904− split (singleton c) t = splitWith (==c) t
903+"LAZY TEXT split/singleton -> splitBy/==" [~1] forall c t.
904+ split (singleton c) t = splitBy (==c) t
905905 #-}
906906
907907-- | /O(m)*O(n)/ Break a 'Text' into pieces at most @k@ times,
@@ -960,16 +960,16 @@ splitTimesEnd k pat src =
960960-- resulting components do not contain the separators. Two adjacent
961961-- separators result in an empty component in the output. eg.
962962--
963−-- > splitWith (=='a') "aabbaca" == ["","","bb","c",""]
964−-- > splitWith (=='a') [] == [""]
965−splitWith :: (Char -> Bool) -> Text -> [Text]
966−splitWith _ Empty = [Empty]
967−splitWith p (Chunk t0 ts0) = comb [] (T.splitWith p t0) ts0
963+-- > splitBy (=='a') "aabbaca" == ["","","bb","c",""]
964+-- > splitBy (=='a') [] == [""]
965+splitBy :: (Char -> Bool) -> Text -> [Text]
966+splitBy _ Empty = [Empty]
967+splitBy p (Chunk t0 ts0) = comb [] (T.splitBy p t0) ts0
968968 where comb acc (s:[]) Empty = revChunks (s:acc) : []
969− comb acc (s:[]) (Chunk t ts) = comb (s:acc) (T.splitWith p t) ts
969+ comb acc (s:[]) (Chunk t ts) = comb (s:acc) (T.splitBy p t) ts
970970 comb acc (s:ss) ts = revChunks (s:acc) : comb [] ss ts
971− comb _ [] _ = impossibleError "splitWith"
972−{-# INLINE splitWith #-}
971+ comb _ [] _ = impossibleError "splitBy"
972+{-# INLINE splitBy #-}
973973
974974-- | /O(n)/ Splits a 'Text' into components of length @k@. The last
975975-- element may be shorter than the other chunks, depending on the
@@ -996,7 +996,7 @@ lines t = let (l,t') = break ((==) '\n') t
996996-- | /O(n)/ Breaks a 'Text' up into a list of words, delimited by 'Char's
997997-- representing white space.
998998words :: Text -> [Text]
999−words = L.filter (not . null) . splitWith isSpace
999+words = L.filter (not . null) . splitBy isSpace
10001000{-# INLINE words #-}
10011001
10021002-- | /O(n)/ Joins lines, after appending a terminating newline to
tests/Properties.hs+12−12
@@ -422,14 +422,14 @@ tl_splitTimesEnd_i k (NotEmpty t) = id `eq` (TL.intercalate t . TL.splitTimesEnd
422422t_splitTimesEnd_split (NotEmpty t) = T.splitTimesEnd maxBound t `eq` T.split t
423423tl_splitTimesEnd_split (NotEmpty t) = TL.splitTimesEnd maxBound t `eq` TL.split t
424424
425−t_splitWith p = splitWith p `eqP` (map unpackS . T.splitWith p)
426−t_splitWith_count c = (L.length . T.splitWith (==c)) `eq` ((1+) . T.count (T.singleton c))
427−t_splitWith_split c = T.splitWith (==c) `eq` T.split (T.singleton c)
428−tl_splitWith p = splitWith p `eqP` (map unpackS . TL.splitWith p)
429−
430−splitWith :: (a -> Bool) -> [a] -> [[a]]
431−splitWith _ [] = [[]]
432−splitWith p xs = loop xs
425+t_splitBy p = splitBy p `eqP` (map unpackS . T.splitBy p)
426+t_splitBy_count c = (L.length . T.splitBy (==c)) `eq` ((1+) . T.count (T.singleton c))
427+t_splitBy_split c = T.splitBy (==c) `eq` T.split (T.singleton c)
428+tl_splitBy p = splitBy p `eqP` (map unpackS . TL.splitBy p)
429+
430+splitBy :: (a -> Bool) -> [a] -> [[a]]
431+splitBy _ [] = [[]]
432+splitBy p xs = loop xs
433433 where loop s | null s' = [l]
434434 | otherwise = l : loop (tail s')
435435 where (l, s') = break p s
@@ -807,10 +807,10 @@ tests = [
807807 testProperty "t_splitTimesEnd_split" t_splitTimesEnd_split,
808808 testProperty "tl_splitTimesEnd_split" tl_splitTimesEnd_split,
809809 testProperty "tl_split_i" tl_split_i,
810− testProperty "t_splitWith" t_splitWith,
811− testProperty "t_splitWith_count" t_splitWith_count,
812− testProperty "t_splitWith_split" t_splitWith_split,
813− testProperty "tl_splitWith" tl_splitWith,
810+ testProperty "t_splitBy" t_splitBy,
811+ testProperty "t_splitBy_count" t_splitBy_count,
812+ testProperty "t_splitBy_split" t_splitBy_split,
813+ testProperty "tl_splitBy" tl_splitBy,
814814 testProperty "t_chunksOf_same_lengths" t_chunksOf_same_lengths,
815815 testProperty "t_chunksOf_length" t_chunksOf_length,
816816 testProperty "tl_chunksOf" tl_chunksOf
tests/SlowFunctions.hs+1−1
@@ -28,7 +28,7 @@ split :: Text -- ^ Text to split on
2828 -> [Text]
2929split pat src0
3030 | T.null pat = error "split: empty"
31− | l == 1 = T.splitWith (== (unsafeHead pat)) src0
31+ | l == 1 = T.splitBy (== (unsafeHead pat)) src0
3232 | otherwise = go src0
3333 where
3434 l = T.length pat