on master help sign in
Rename dropAfter to dropWhileEnd.

--HG-- extra : convert_revision : 4fbcdb4fa040cf05269f248cf235210cf88df967

commitc6c779674637bef83d0565b913a7d3d3abf6ca5a authorBryan O'Sullivan <bos@serpentine.com> dateFri 14 Aug 2009, 04:35 (17 years ago) parent9e46d20
2 files changed+22−19
Data/Text.hs+16−13 tests/Properties.hs+6−6
Data/Text.hs+16−13
@@ -107,7 +107,7 @@ module Data.Text
107107 , drop
108108 , takeWhile
109109 , dropWhile
110− , dropAfter
110+ , dropWhileEnd
111111 , dropAround
112112 , strip
113113 , stripLeft
@@ -762,29 +762,32 @@ dropWhile p t@(Text arr off len) = loop 0 0
762762 unstream (S.dropWhile p (stream t)) = dropWhile p t
763763 #-}
764764
765−-- | /O(n)/ 'dropAfter' @p@ @t@ returns the prefix remaining after
765+-- | /O(n)/ 'dropWhileEnd' @p@ @t@ returns the prefix remaining after
766766-- dropping characters that fail the predicate @p@ from the end of
767−-- @t@. This function is subject to array fusion.
768−dropAfter :: (Char -> Bool) -> Text -> Text
769−dropAfter p t@(Text arr off len) = loop (len-1) len
767+-- @t@. Subject to fusion.
768+-- Examples:
769+--
770+-- > dropWhileEnd (=='.') "foo..." == "foo"
771+dropWhileEnd :: (Char -> Bool) -> Text -> Text
772+dropWhileEnd p t@(Text arr off len) = loop (len-1) len
770773 where loop !i !l | l <= 0 = empty
771774 | p c = loop (i+d) (l+d)
772775 | otherwise = Text arr off l
773776 where (c,d) = reverseIter t i
774−{-# INLINE [1] dropAfter #-}
777+{-# INLINE [1] dropWhileEnd #-}
775778
776779{-# RULES
777−"TEXT dropAfter -> fused" [~1] forall p t.
778− dropAfter p t = S.reverse (S.dropWhile p (S.reverseStream t))
779−"TEXT dropAfter -> unfused" [1] forall p t.
780− S.reverse (S.dropWhile p (S.reverseStream t)) = dropAfter p t
780+"TEXT dropWhileEnd -> fused" [~1] forall p t.
781+ dropWhileEnd p t = S.reverse (S.dropWhile p (S.reverseStream t))
782+"TEXT dropWhileEnd -> unfused" [1] forall p t.
783+ S.reverse (S.dropWhile p (S.reverseStream t)) = dropWhileEnd p t
781784 #-}
782785
783786-- | /O(n)/ 'dropAround' @p@ @t@ returns the substring remaining after
784787-- dropping characters that fail the predicate @p@ from both the
785788-- beginning and end of @t@. Subject to fusion.
786789dropAround :: (Char -> Bool) -> Text -> Text
787−dropAround p = dropWhile p . dropAfter p
790+dropAround p = dropWhile p . dropWhileEnd p
788791{-# INLINE [1] dropAround #-}
789792
790793-- | /O(n)/ Remove leading white space from a string. Equivalent to:
@@ -796,9 +799,9 @@ stripLeft = dropWhile isSpace
796799
797800-- | /O(n)/ Remove trailing white space from a string. Equivalent to:
798801--
799−-- > dropAfter isSpace
802+-- > dropWhileEnd isSpace
800803stripRight :: Text -> Text
801−stripRight = dropAfter isSpace
804+stripRight = dropWhileEnd isSpace
802805{-# INLINE [1] stripRight #-}
803806
804807-- | /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)
277277prop_S_dropWhile p = L.dropWhile p `eqP` (unpackS . S.dropWhile p)
278278prop_T_dropWhile p = L.dropWhile p `eqP` (unpackS . T.dropWhile p)
279279prop_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)
281−prop_T_dropAfter p = (T.reverse . T.dropWhile p . T.reverse) `eq` T.dropAfter p
282−prop_T_dropAround p = (T.dropWhile p . T.dropAfter p) `eq` T.dropAround p
280+prop_S_dropWhileEnd p = T.dropWhileEnd p `eq` (S.reverse . S.dropWhile p . S.reverseStream)
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.dropWhileEnd p) `eq` T.dropAround p
283283prop_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
285285prop_T_strip = T.dropAround isSpace `eq` T.strip
286286prop_T_splitAt n = L.splitAt n `eqP` (unpack2 . T.splitAt n)
287287prop_TL_splitAt n = L.splitAt n `eqP` (unpack2 . TL.splitAt (fromIntegral n))
@@ -541,8 +541,8 @@ tests = [
541541 ("prop_S_dropWhile", mytest prop_S_dropWhile),
542542 ("prop_T_dropWhile", mytest prop_T_dropWhile),
543543 ("prop_TL_dropWhile", mytest prop_TL_dropWhile),
544− ("prop_S_dropAfter", mytest prop_S_dropAfter),
545− ("prop_T_dropAfter", mytest prop_T_dropAfter),
544+ ("prop_S_dropWhileEnd", mytest prop_S_dropWhileEnd),
545+ ("prop_T_dropWhileEnd", mytest prop_T_dropWhileEnd),
546546 ("prop_T_dropAround", mytest prop_T_dropAround),
547547 ("prop_T_stripLeft", mytest prop_T_stripLeft),
548548 ("prop_T_stripRight", mytest prop_T_stripRight),