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
28
29
pub fn sanitized(component: &str) -> String {
let mut buf = String::with_capacity(component.len());
for (i, c) in component.chars().enumerate() {
let is_lower = 'a' <= c && c <= 'z';
let is_upper = 'A' <= c && c <= 'Z';
let is_letter = is_upper || is_lower;
let is_number = '0' <= c && c <= '9';
let is_space = c == ' ';
let is_hyphen = c == '-';
let is_underscore = c == '_';
let is_period = c == '.' && i != 0;
let is_valid =
is_letter || is_number || is_space || is_hyphen || is_underscore || is_period;
if is_valid {
buf.push(c);
} else {
buf.push_str(&format!(",{},", c as u32));
}
}
buf
}