on master help sign in
Rename dropAfter to dropWhileEnd.
c6c7796Bryan O'Sullivan
Data/Text.hs+16−13
@@ -107,7 +107,7 @@ module Data.Text
107 , drop
107 , drop
108 , takeWhile
108 , takeWhile
109 , dropWhile
109 , dropWhile
110− , dropAfter
110+ , dropWhileEnd
111 , dropAround
111 , dropAround
112 , strip
112 , strip
113 , stripLeft
113 , stripLeft
@@ -762,29 +762,32 @@ dropWhile p t@(Text arr off len) = loop 0 0
762 unstream (S.dropWhile p (stream t)) = dropWhile p t
762 unstream (S.dropWhile p (stream t)) = dropWhile p t
763 #-}
763 #-}
764
764
765−-- | /O(n)/ 'dropAfter' @p@ @t@ returns the prefix remaining after
765+-- | /O(n)/ 'dropWhileEnd' @p@ @t@ returns the prefix remaining after
766-- dropping characters that fail the predicate @p@ from the end of
766-- dropping characters that fail the predicate @p@ from the end of
767−-- @t@. This function is subject to array fusion.
767+-- @t@. Subject to fusion.
768+-- Examples:
769+--
770+-- > dropWhileEnd (=='.') "foo..." == "foo"
768−dropAfter :: (Char -> Bool) -> Text -> Text
771+dropWhileEnd :: (Char -> Bool) -> Text -> Text
769−dropAfter p t@(Text arr off len) = loop (len-1) len
772+dropWhileEnd p t@(Text arr off len) = loop (len-1) len
770 where loop !i !l | l <= 0 = empty
773 where loop !i !l | l <= 0 = empty
771 | p c = loop (i+d) (l+d)
774 | p c = loop (i+d) (l+d)
772 | otherwise = Text arr off l
775 | otherwise = Text arr off l
773 where (c,d) = reverseIter t i
776 where (c,d) = reverseIter t i
774−{-# INLINE [1] dropAfter #-}
777+{-# INLINE [1] dropWhileEnd #-}
775
778
776{-# RULES
779{-# RULES
777−"TEXT dropAfter -> fused" [~1] forall p t.
780+"TEXT dropWhileEnd -> fused" [~1] forall p t.
778− dropAfter p t = S.reverse (S.dropWhile p (S.reverseStream t))
781+ dropWhileEnd p t = S.reverse (S.dropWhile p (S.reverseStream t))
779−"TEXT dropAfter -> unfused" [1] forall p t.
782+"TEXT dropWhileEnd -> unfused" [1] forall p t.
780− S.reverse (S.dropWhile p (S.reverseStream t)) = dropAfter p t
783+ S.reverse (S.dropWhile p (S.reverseStream t)) = dropWhileEnd p t
781 #-}
784 #-}
782
785
783-- | /O(n)/ 'dropAround' @p@ @t@ returns the substring remaining after
786-- | /O(n)/ 'dropAround' @p@ @t@ returns the substring remaining after
784-- dropping characters that fail the predicate @p@ from both the
787-- dropping characters that fail the predicate @p@ from both the
785-- beginning and end of @t@. Subject to fusion.
788-- beginning and end of @t@. Subject to fusion.
786dropAround :: (Char -> Bool) -> Text -> Text
789dropAround :: (Char -> Bool) -> Text -> Text
787−dropAround p = dropWhile p . dropAfter p
790+dropAround p = dropWhile p . dropWhileEnd p
788{-# INLINE [1] dropAround #-}
791{-# INLINE [1] dropAround #-}
789
792
790-- | /O(n)/ Remove leading white space from a string. Equivalent to:
793-- | /O(n)/ Remove leading white space from a string. Equivalent to:
@@ -796,9 +799,9 @@ stripLeft = dropWhile isSpace
796
799
797-- | /O(n)/ Remove trailing white space from a string. Equivalent to:
800-- | /O(n)/ Remove trailing white space from a string. Equivalent to:
798--
801--
799−-- > dropAfter isSpace
802+-- > dropWhileEnd isSpace
800stripRight :: Text -> Text
803stripRight :: Text -> Text
801−stripRight = dropAfter isSpace
804+stripRight = dropWhileEnd isSpace
802{-# INLINE [1] stripRight #-}
805{-# INLINE [1] stripRight #-}
803
806
804-- | /O(n)/ Remove leading and trailing white space from a string.
807-- | /O(n)/ Remove leading and trailing white space from a string.
tests/Properties.hs+6−6
@@ -277,11 +277,11 @@ prop_TL_takeWhile p = L.takeWhile p `eqP` (unpackS . TL.takeWhile p)
277prop_S_dropWhile p = L.dropWhile p `eqP` (unpackS . S.dropWhile p)
277prop_S_dropWhile p = L.dropWhile p `eqP` (unpackS . S.dropWhile p)
278prop_T_dropWhile p = L.dropWhile p `eqP` (unpackS . T.dropWhile p)
278prop_T_dropWhile p = L.dropWhile p `eqP` (unpackS . T.dropWhile p)
279prop_TL_dropWhile p = L.dropWhile p `eqP` (unpackS . S.dropWhile p)
279prop_TL_dropWhile p = L.dropWhile p `eqP` (unpackS . S.dropWhile p)
280−prop_S_dropAfter p = T.dropAfter p `eq` (S.reverse . S.dropWhile p . S.reverseStream)
280+prop_S_dropWhileEnd p = T.dropWhileEnd p `eq` (S.reverse . S.dropWhile p . S.reverseStream)
281−prop_T_dropAfter p = (T.reverse . T.dropWhile p . T.reverse) `eq` T.dropAfter p
281+prop_T_dropWhileEnd p = (T.reverse . T.dropWhile p . T.reverse) `eq` T.dropWhileEnd p
282−prop_T_dropAround p = (T.dropWhile p . T.dropAfter p) `eq` T.dropAround p
282+prop_T_dropAround p = (T.dropWhile p . T.dropWhileEnd p) `eq` T.dropAround p
283prop_T_stripLeft = T.dropWhile isSpace `eq` T.stripLeft
283prop_T_stripLeft = T.dropWhile isSpace `eq` T.stripLeft
284−prop_T_stripRight = T.dropAfter isSpace `eq` T.stripRight
284+prop_T_stripRight = T.dropWhileEnd isSpace `eq` T.stripRight
285prop_T_strip = T.dropAround isSpace `eq` T.strip
285prop_T_strip = T.dropAround isSpace `eq` T.strip
286prop_T_splitAt n = L.splitAt n `eqP` (unpack2 . T.splitAt n)
286prop_T_splitAt n = L.splitAt n `eqP` (unpack2 . T.splitAt n)
287prop_TL_splitAt n = L.splitAt n `eqP` (unpack2 . TL.splitAt (fromIntegral n))
287prop_TL_splitAt n = L.splitAt n `eqP` (unpack2 . TL.splitAt (fromIntegral n))
@@ -541,8 +541,8 @@ tests = [
541 ("prop_S_dropWhile", mytest prop_S_dropWhile),
541 ("prop_S_dropWhile", mytest prop_S_dropWhile),
542 ("prop_T_dropWhile", mytest prop_T_dropWhile),
542 ("prop_T_dropWhile", mytest prop_T_dropWhile),
543 ("prop_TL_dropWhile", mytest prop_TL_dropWhile),
543 ("prop_TL_dropWhile", mytest prop_TL_dropWhile),
544− ("prop_S_dropAfter", mytest prop_S_dropAfter),
544+ ("prop_S_dropWhileEnd", mytest prop_S_dropWhileEnd),
545− ("prop_T_dropAfter", mytest prop_T_dropAfter),
545+ ("prop_T_dropWhileEnd", mytest prop_T_dropWhileEnd),
546 ("prop_T_dropAround", mytest prop_T_dropAround),
546 ("prop_T_dropAround", mytest prop_T_dropAround),
547 ("prop_T_stripLeft", mytest prop_T_stripLeft),
547 ("prop_T_stripLeft", mytest prop_T_stripLeft),
548 ("prop_T_stripRight", mytest prop_T_stripRight),
548 ("prop_T_stripRight", mytest prop_T_stripRight),