macro_rules! trim_ascii {
($s: expr) => { ... };
}
Expand description
Trims ASCII whitespace from both ends of a string.
ASCII whitespace characters are space (0x20), tab (0x09), newline (0x0A), vertical tab (0x0B), form feed (0x0C), and carriage return (0x0D).
This macro is const-fn compatible.
ยงExamples
const TRIMMED: &str = const_str::trim_ascii!(" hello world ");
assert_eq!(TRIMMED, "hello world");
const MIXED: &str = const_str::trim_ascii!("\t\n hello\tworld\n \r");
assert_eq!(MIXED, "hello\tworld");
const EMPTY: &str = const_str::trim_ascii!(" ");
assert_eq!(EMPTY, "");
// Works in const functions too
const fn process_string(s: &str) -> &str {
const_str::trim_ascii!(s)
}
assert_eq!(process_string(" test "), "test");