@@ -3610,6 +3610,47 @@ impl str {
36103610 RSplitN ( self . splitn ( n, pat) . 0 )
36113611 }
36123612
3613+ /// Splits the string on the first occurrence of the specified delimiter and
3614+ /// returns prefix before delimiter and suffix after delimiter.
3615+ ///
3616+ /// # Examples
3617+ ///
3618+ /// ```
3619+ /// #![feature(str_split_once)]
3620+ ///
3621+ /// assert_eq!("cfg".split_once('='), None);
3622+ /// assert_eq!("cfg=foo".split_once('='), Some(("cfg", "foo")));
3623+ /// assert_eq!("cfg=foo=bar".split_once('='), Some(("cfg", "foo=bar")));
3624+ /// ```
3625+ #[ unstable( feature = "str_split_once" , reason = "newly added" , issue = "74773" ) ]
3626+ #[ inline]
3627+ pub fn split_once < ' a , P : Pattern < ' a > > ( & ' a self , delimiter : P ) -> Option < ( & ' a str , & ' a str ) > {
3628+ let ( start, end) = delimiter. into_searcher ( self ) . next_match ( ) ?;
3629+ Some ( ( & self [ ..start] , & self [ end..] ) )
3630+ }
3631+
3632+ /// Splits the string on the last occurrence of the specified delimiter and
3633+ /// returns prefix before delimiter and suffix after delimiter.
3634+ ///
3635+ /// # Examples
3636+ ///
3637+ /// ```
3638+ /// #![feature(str_split_once)]
3639+ ///
3640+ /// assert_eq!("cfg".rsplit_once('='), None);
3641+ /// assert_eq!("cfg=foo".rsplit_once('='), Some(("cfg", "foo")));
3642+ /// assert_eq!("cfg=foo=bar".rsplit_once('='), Some(("cfg=foo", "bar")));
3643+ /// ```
3644+ #[ unstable( feature = "str_split_once" , reason = "newly added" , issue = "74773" ) ]
3645+ #[ inline]
3646+ pub fn rsplit_once < ' a , P > ( & ' a self , delimiter : P ) -> Option < ( & ' a str , & ' a str ) >
3647+ where
3648+ P : Pattern < ' a , Searcher : ReverseSearcher < ' a > > ,
3649+ {
3650+ let ( start, end) = delimiter. into_searcher ( self ) . next_match_back ( ) ?;
3651+ Some ( ( & self [ ..start] , & self [ end..] ) )
3652+ }
3653+
36133654 /// An iterator over the disjoint matches of a pattern within the given string
36143655 /// slice.
36153656 ///
0 commit comments