on master help sign in
Fix up splitWith.
39cfef6Bryan O'Sullivan
Data/Text.hs+5−7
@@ -755,13 +755,11 @@ split c = splitWith (==c)
755-- > splitWith (=='a') [] == []
755-- > splitWith (=='a') [] == []
756splitWith :: (Char -> Bool) -> Text -> [Text]
756splitWith :: (Char -> Bool) -> Text -> [Text]
757splitWith p = loop
757splitWith p = loop
758− where loop t@(Text arr off len)
758+ where loop s | null s = []
759− | null t = [empty]
760− | otherwise = text arr off n : rest
759+ | otherwise = if null s'
761− where n = findAIndexOrEnd p t
760+ then [s]
762− m = n + iter_ t n
761+ else l : loop (unsafeTail s')
763− rest | n >= len = []
762+ where (l, s') = break p s
764− | otherwise = loop (text arr (off+m) (len-m))
765{-# INLINE splitWith #-}
763{-# INLINE splitWith #-}
766
764
767-- ----------------------------------------------------------------------------
765-- ----------------------------------------------------------------------------
tests/Properties.hs+6−7
@@ -138,12 +138,11 @@ prop_split_i c = id `eq` (T.intercalate (T.singleton c) . T.split c)
138{-
138{-
139prop_splitWith p = splitWith p `eqP` (map unpack . T.splitWith p)
139prop_splitWith p = splitWith p `eqP` (map unpack . T.splitWith p)
140
140
141−splitWith _ [] = [""]
141+splitWith _ "" = []
142−splitWith p xs = h : splitWith p (whale t)
142+splitWith p s = if null s'
143+ then [s]
144+ else l : splitWith p (tail s')
143− where (h,t) = break p xs
145+ where (l, s') = break p s
144− whale (_:xs) = xs
145− whale xs = xs
146−-}
147
146
148prop_breakSubstring_isInfixOf s l
147prop_breakSubstring_isInfixOf s l
149 = T.isInfixOf s l ==
148 = T.isInfixOf s l ==
@@ -275,7 +274,7 @@ tests = [
275 ("prop_tails", mytest prop_tails),
274 ("prop_tails", mytest prop_tails),
276
275
277 ("prop_split_i", mytest prop_split_i),
276 ("prop_split_i", mytest prop_split_i),
278−--("prop_splitWith", mytest prop_splitWith),
277+ ("prop_splitWith", mytest prop_splitWith),
279 ("prop_breakSubstringC", mytest prop_breakSubstringC),
278 ("prop_breakSubstringC", mytest prop_breakSubstringC),
280 ("prop_breakSubstring_isInfixOf", mytest prop_breakSubstring_isInfixOf),
279 ("prop_breakSubstring_isInfixOf", mytest prop_breakSubstring_isInfixOf),
281
280