@@ -3427,6 +3427,47 @@ impl str {
34273427 RSplitN ( self . splitn ( n, pat) . 0 )
34283428 }
34293429
3430+ /// Splits the string on the first occurrence of the specified delimiter and
3431+ /// returns prefix before delimiter and suffix after delimiter.
3432+ ///
3433+ /// # Examples
3434+ ///
3435+ /// ```
3436+ /// #![feature(str_split_once)]
3437+ ///
3438+ /// assert_eq!("cfg".split_once('='), None);
3439+ /// assert_eq!("cfg=foo".split_once('='), Some(("cfg", "foo")));
3440+ /// assert_eq!("cfg=foo=bar".split_once('='), Some(("cfg", "foo=bar")));
3441+ /// ```
3442+ #[ unstable( feature = "str_split_once" , reason = "newly added" , issue = "74773" ) ]
3443+ #[ inline]
3444+ pub fn split_once < ' a , P : Pattern < ' a > > ( & ' a self , delimiter : P ) -> Option < ( & ' a str , & ' a str ) > {
3445+ let ( start, end) = delimiter. into_searcher ( self ) . next_match ( ) ?;
3446+ Some ( ( & self [ ..start] , & self [ end..] ) )
3447+ }
3448+
3449+ /// Splits the string on the last occurrence of the specified delimiter and
3450+ /// returns prefix before delimiter and suffix after delimiter.
3451+ ///
3452+ /// # Examples
3453+ ///
3454+ /// ```
3455+ /// #![feature(str_split_once)]
3456+ ///
3457+ /// assert_eq!("cfg".rsplit_once('='), None);
3458+ /// assert_eq!("cfg=foo".rsplit_once('='), Some(("cfg", "foo")));
3459+ /// assert_eq!("cfg=foo=bar".rsplit_once('='), Some(("cfg=foo", "bar")));
3460+ /// ```
3461+ #[ unstable( feature = "str_split_once" , reason = "newly added" , issue = "74773" ) ]
3462+ #[ inline]
3463+ pub fn rsplit_once < ' a , P > ( & ' a self , delimiter : P ) -> Option < ( & ' a str , & ' a str ) >
3464+ where
3465+ P : Pattern < ' a , Searcher : ReverseSearcher < ' a > > ,
3466+ {
3467+ let ( start, end) = delimiter. into_searcher ( self ) . next_match_back ( ) ?;
3468+ Some ( ( & self [ ..start] , & self [ end..] ) )
3469+ }
3470+
34303471 /// An iterator over the disjoint matches of a pattern within the given string
34313472 /// slice.
34323473 ///
0 commit comments