Function konst::string::rfind_skip

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

Truncates this to before the last instance of needle.

Returns None if no instance of needle is found.

Returns Some(this) if needle is empty.

This takes Pattern implementors as the needle.

§Example

use konst::string;

{
    const FOUND: Option<&str> = string::rfind_skip("foo bar _ bar baz", '_');
    assert_eq!(FOUND, Some("foo bar "));
}

{
    const FOUND: Option<&str> = string::rfind_skip("foo bar _ bar baz", "bar");
    assert_eq!(FOUND, Some("foo bar _ "));
}
{
    const NOT_FOUND: Option<&str> = string::rfind_skip("foo bar baz", "qux");
    assert_eq!(NOT_FOUND, None);
}