mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-24 08:11:04 +00:00
16 lines
444 B
Rust
16 lines
444 B
Rust
pub trait BytesExt {
|
|
fn kebab_cased(&self) -> bool;
|
|
fn split_by_seq(&self, sep: &[u8]) -> Option<(&[u8], &[u8])>;
|
|
}
|
|
|
|
impl BytesExt for [u8] {
|
|
fn kebab_cased(&self) -> bool {
|
|
self.iter().all(|&b| matches!(b, b'0'..=b'9' | b'a'..=b'z' | b'-'))
|
|
}
|
|
|
|
fn split_by_seq(&self, sep: &[u8]) -> Option<(&[u8], &[u8])> {
|
|
let idx = memchr::memmem::find(self, sep)?;
|
|
let (left, right) = self.split_at(idx);
|
|
Some((left, &right[sep.len()..]))
|
|
}
|
|
}
|