1
0
Fork 0
forked from wry/wry

autocommit 2022-03-23 16:23:28 CET

This commit is contained in:
Julian Orth 2022-03-23 16:23:28 +01:00
parent d7f298ab5f
commit a9a4fc04b7
13 changed files with 91 additions and 70 deletions

View file

@ -21,6 +21,7 @@ pub mod smallmap;
pub mod stack;
pub mod syncqueue;
pub mod tri;
pub mod trim;
pub mod vasprintf;
pub mod vec_ext;
pub mod vecstorage;

33
src/utils/trim.rs Normal file
View file

@ -0,0 +1,33 @@
pub trait AsciiTrim {
fn trim(&self) -> &[u8];
fn trim_start(&self) -> &[u8];
fn trim_end(&self) -> &[u8];
}
impl AsciiTrim for [u8] {
fn trim(&self) -> &[u8] {
self.trim_start().trim_end()
}
fn trim_start(&self) -> &[u8] {
let mut s = self;
while let Some((b, r)) = s.split_first() {
if !matches!(*b, b' ' | b'\t' | b'\n') {
break;
}
s = r;
}
s
}
fn trim_end(&self) -> &[u8] {
let mut s = self;
while let Some((b, r)) = s.split_last() {
if !matches!(*b, b' ' | b'\t' | b'\n') {
break;
}
s = r;
}
s
}
}