Skip to main content

strip_optional_word_prefix

Function strip_optional_word_prefix 

Source
pub fn strip_optional_word_prefix<'a>(input: &'a str, word: &str) -> &'a str
Expand description

Strip an optional leading word (case-insensitive) that is separated from the rest by whitespace, returning the trimmed remainder, or input unchanged when the prefix is absent or not word-boundary separated.

Canonical home for shell/file operand prefixes such as on/from.

assert_eq!(strip_optional_word_prefix("on src/main.rs", "on"), "src/main.rs");
assert_eq!(strip_optional_word_prefix("From here", "from"), "here");
// No whitespace boundary: left untouched.
assert_eq!(strip_optional_word_prefix("onto x", "on"), "onto x");