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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
const PATH_CHARS: [u8; 256] = [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, b'!', 0, 0, b'$', b'%', b'&', b'\'',
b'(', b')', b'*', b'+', b',', b'-', b'.', b'/', b'0', b'1',
b'2', b'3', b'4', b'5', b'6', b'7', b'8', b'9', b':', b';',
1, b'=', 1, 0, b'@', b'A', b'B', b'C', b'D', b'E',
b'F', b'G', b'H', b'I', b'J', b'K', b'L', b'M', b'N', b'O',
b'P', b'Q', b'R', b'S', b'T', b'U', b'V', b'W', b'X', b'Y',
b'Z', 0, 0, 0, 0, b'_', 0, b'a', b'b', b'c',
b'd', b'e', b'f', b'g', b'h', b'i', b'j', b'k', b'l', b'm',
b'n', b'o', b'p', b'q', b'r', b's', b't', b'u', b'v', b'w',
b'x', b'y', b'z', 0, 0, 0, b'~', 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0
];
#[inline(always)]
pub fn is_pchar(c: u8) -> bool {
PATH_CHARS[c as usize] == c
}
#[inline(always)]
pub fn is_pchar_or_rchar(c: u8) -> bool {
PATH_CHARS[c as usize] != 0
}
const REG_CHARS: [u8; 256] = [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, b'!', 0, 0, b'$', 0, b'&', b'\'',
b'(', b')', b'*', b'+', b',', b'-', b'.', 0, b'0', b'1',
b'2', b'3', b'4', b'5', b'6', b'7', b'8', b'9', 0, b';',
0, b'=', 0, 0, 0, b'A', b'B', b'C', b'D', b'E',
b'F', b'G', b'H', b'I', b'J', b'K', b'L', b'M', b'N', b'O',
b'P', b'Q', b'R', b'S', b'T', b'U', b'V', b'W', b'X', b'Y',
b'Z', 0, 0, 0, 0, b'_', 0, b'a', b'b', b'c',
b'd', b'e', b'f', b'g', b'h', b'i', b'j', b'k', b'l', b'm',
b'n', b'o', b'p', b'q', b'r', b's', b't', b'u', b'v', b'w',
b'x', b'y', b'z', 0, 0, 0, b'~', 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0
];
#[inline(always)]
pub fn is_reg_name_char(c: u8) -> bool {
REG_CHARS[c as usize] != 0
}
#[cfg(test)]
mod tests {
fn test_char_table(table: &[u8]) {
for (i, &v) in table.iter().enumerate() {
if v != 0 && v != 1 {
assert_eq!(i, v as usize);
}
}
}
#[test]
fn check_tables() {
test_char_table(&super::PATH_CHARS[..]);
test_char_table(&super::REG_CHARS[..]);
}
}