Function rfind_skip

Source
pub const fn rfind_skip<'a>(this: &'a str, needle: &str) -> Option<&'a str>
Expand description

Truncates this to before the last instance of needle.

Return None if no instance of needle is found.

Return Some(this) if needle is empty.

§Motivation

This function exists because calling rfind + str_up_to when the "rust_1_64" feature is disabled is slower than it could be, since the slice has to be traversed twice.

§Example

use konst::string;

{
    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);
}
{
    const EMPTY_NEEDLE: Option<&str> = string::rfind_skip("foo bar baz", "");
    assert_eq!(EMPTY_NEEDLE, Some("foo bar baz"));
}