1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#[must_use]
pub fn sanitized(component: &str) -> String {
let mut buf = String::with_capacity(component.len());
for (i, c) in component.chars().enumerate() {
let is_alnum = c.is_ascii_alphanumeric();
let is_space = c == ' ';
let is_hyphen = c == '-';
let is_underscore = c == '_';
let is_period = c == '.' && i != 0; let is_valid = is_alnum || is_space || is_hyphen || is_underscore || is_period;
if is_valid {
buf.push(c);
} else {
use std::fmt::Write;
let _ = write!(&mut buf, ",{},", c as u32);
}
}
buf
}