use crate::prelude::*;
impl FilePath<'_> {
#[expect(clippy::missing_panics_doc, reason = "Can't happen.")]
pub fn pop(&mut self) -> Result<bool, SetPathError> {
match self.0.memrchr(b'/').expect("???") {
0 => Err(CantBeEmpty)?,
x => unsafe {self.0.truncate_unchecked(x)}
}
Ok(true)
}
pub fn pop_if_empty(&mut self) -> Result<bool, SetPathError> {
Ok(match self.as_str().as_bytes() {
[ b'/'] => Err(CantBeEmpty)?,
[x @ .., b'/'] => {
unsafe {
self.0.truncate_unchecked(x.len())
}
true
},
_ => false
})
}
pub fn remove(&mut self, index: isize) -> Result<bool, SetPathError> {
Ok(match self.get_str(index) {
Some(temp) => {
let mut range = self.as_str().my_substr_range(temp);
range.start -= 1;
if range.len() == self.len() {
Err(CantBeEmpty)?;
}
self.0.replace_range(range, "");
true
},
None => false
})
}
}