tools: add strip_ascii_whitespace for byte slices

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2020-07-15 11:53:19 +02:00
parent 3cfc56f5c2
commit cdf1da2872
1 changed files with 11 additions and 0 deletions

View File

@ -647,3 +647,14 @@ pub fn setup_safe_path_env() {
std::env::remove_var(name);
}
}
pub fn strip_ascii_whitespace(line: &[u8]) -> &[u8] {
let line = match line.iter().position(|&b| !b.is_ascii_whitespace()) {
Some(n) => &line[n..],
None => return &[],
};
match line.iter().rev().position(|&b| !b.is_ascii_whitespace()) {
Some(n) => &line[..(line.len() - n)],
None => &[],
}
}