Created
February 21, 2024 20:19
-
-
Save iitalics/dc6732982530e8ec782ff1856e2be6e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fn str_trim_ascii_whitespace(s: &str) -> &str { | |
let mut bs = s.as_bytes(); | |
while let Some((hd, tl)) = bs.split_first() { | |
if hd.is_ascii_whitespace() { | |
bs = tl; | |
} else { | |
break; | |
} | |
} | |
while let Some((tl, hd)) = bs.split_last() { | |
if tl.is_ascii_whitespace() { | |
bs = hd; | |
} else { | |
break; | |
} | |
} | |
match std::str::from_utf8(bs) { | |
Ok(s) => s, | |
Err(_) => unreachable!(), | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment