Open
Description
/// Trims this slice from the left.
fn trim_left_matches<F: Fn(T) -> bool>(&self, f: F) -> &[T] {
let mut res = self;
while res.len() > 0 && f(res[0]) {
res = res[1..];
}
res
}
/// Trims this slice from the right.
fn trim_right_matches<F: Fn(T) -> bool>(&self, f: F) -> &[T] {
let mut res = self;
while res.len() > 0 && f(res[res.len()-1]) {
res = res[..(res.len()-1)];
}
res
}
(and so on)
basically turns &["", "", "", "foo", ""]
into &["foo", ""]
, &["", "foo", "", "", ""]
into &["", "foo"]
, etc, depending on what you call.