Function konst::string::rsplit_once

source ·
pub const fn rsplit_once<'a, 'p, P>(
    this: &'a str,
    delim: P,
) -> Option<(&'a str, &'a str)>
where P: Pattern<'p>,
Expand description

A const-equivalent of the str::rsplit_once method.

This takes Pattern implementors as the delimiter.

§Example

use konst::string;

assert_eq!(string::rsplit_once("", "-"), None);
assert_eq!(string::rsplit_once("foo", "-"), None);
assert_eq!(string::rsplit_once("foo-", "-"), Some(("foo", "")));
assert_eq!(string::rsplit_once("-foo", "-"), Some(("","foo")));
assert_eq!(string::rsplit_once("foo-bar", "-"), Some(("foo", "bar")));
assert_eq!(string::rsplit_once("foo-bar-baz", "-"), Some(("foo-bar", "baz")));

assert_eq!(string::rsplit_once("foo,bar", ','), Some(("foo", "bar")));
assert_eq!(string::rsplit_once("foo,bar,baz", ','), Some(("foo,bar", "baz")));