@@ -141,7 +141,9 @@ module Data.Text
141141 , breakOn
142142 , breakOnEnd
143143 , break
144+ , breakEnd
144145 , span
146+ , spanEnd
145147 , group
146148 , groupBy
147149 , inits
@@ -221,7 +223,7 @@ import qualified Data.Text.Internal.Fusion as S
221223import qualified Data.Text.Internal.Fusion.Common as S
222224import Data.Text.Encoding (decodeUtf8' , encodeUtf8 )
223225import Data.Text.Internal.Fusion (stream , reverseStream , unstream )
224- import Data.Text.Internal.Private (span_ )
226+ import Data.Text.Internal.Private (span_ , spanEnd_ )
225227import Data.Text.Internal (Text (.. ), empty , firstf , mul , safe , text )
226228import Data.Text.Show (singleton , unpack , unpackCString #)
227229import qualified Prelude as P
@@ -1333,6 +1335,15 @@ span p t = case span_ p t of
13331335 (# hd,tl # ) -> (hd,tl)
13341336{-# INLINE span #-}
13351337
1338+ -- | /O(n)/ Similar to 'span', but searches from the end of the
1339+ -- string.
1340+ --
1341+ -- >>> T.spanEnd (=='0') "AB000"
1342+ -- ("AB", "000")
1343+ spanEnd :: (Char -> Bool ) -> Text -> (Text , Text )
1344+ spanEnd p t = case spanEnd_ p t of (# hd, tl # ) -> (hd, tl)
1345+ {-# inline spanEnd #-}
1346+
13361347-- | /O(n)/ 'break' is like 'span', but the prefix returned is
13371348-- over elements that fail the predicate @p@.
13381349--
@@ -1342,6 +1353,15 @@ break :: (Char -> Bool) -> Text -> (Text, Text)
13421353break p = span (not . p)
13431354{-# INLINE break #-}
13441355
1356+ -- | /O(n)/ Similar to 'break', but searches from the end of the
1357+ -- string.
1358+ --
1359+ -- >>> T.breakEnd (=='0') "180cm"
1360+ -- ("180","cm")
1361+ breakEnd :: (Char -> Bool ) -> Text -> (Text , Text )
1362+ breakEnd p = spanEnd (not . p)
1363+ {-# inline breakEnd #-}
1364+
13451365-- | /O(n)/ Group characters in a string according to a predicate.
13461366groupBy :: (Char -> Char -> Bool ) -> Text -> [Text ]
13471367groupBy p = loop
0 commit comments