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
static FORWARD_TABLE: &'static [u16] = &[
128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142,
143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157,
158, 159, 160, 294, 728, 163, 164, 65535, 292, 167, 168, 304, 350, 286,
308, 173, 65535, 379, 176, 295, 178, 179, 180, 181, 293, 183, 184, 305,
351, 287, 309, 189, 65535, 380, 192, 193, 194, 65535, 196, 266, 264, 199,
200, 201, 202, 203, 204, 205, 206, 207, 65535, 209, 210, 211, 212, 288,
214, 215, 284, 217, 218, 219, 220, 364, 348, 223, 224, 225, 226, 65535,
228, 267, 265, 231, 232, 233, 234, 235, 236, 237, 238, 239, 65535, 241,
242, 243, 244, 289, 246, 247, 285, 249, 250, 251, 252, 365, 349, 729,
];
#[inline]
pub fn forward(code: u8) -> u16 {
FORWARD_TABLE[(code - 0x80) as usize]
}
static BACKWARD_TABLE_LOWER: &'static [u8] = &[
0, 0, 0, 0, 0, 0, 0, 0, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137,
138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152,
153, 154, 155, 156, 157, 158, 159, 160, 0, 0, 163, 164, 0, 0, 167, 168, 0,
0, 0, 0, 173, 0, 0, 176, 0, 178, 179, 180, 181, 0, 183, 184, 0, 0, 0, 0,
189, 0, 0, 192, 193, 194, 0, 196, 0, 0, 199, 200, 201, 202, 203, 204, 205,
206, 207, 0, 209, 210, 211, 212, 0, 214, 215, 0, 217, 218, 219, 220, 0, 0,
223, 224, 225, 226, 0, 228, 0, 0, 231, 232, 233, 234, 235, 236, 237, 238,
239, 0, 241, 242, 243, 244, 0, 246, 247, 0, 249, 250, 251, 252, 0, 0, 0,
198, 230, 197, 229, 0, 0, 0, 0, 0, 0, 0, 0, 216, 248, 171, 187, 213, 245,
0, 0, 166, 182, 161, 177, 169, 185, 0, 0, 172, 188, 0, 0, 0, 0, 0, 0, 222,
254, 170, 186, 0, 0, 0, 0, 221, 253, 0, 0, 0, 0, 0, 175, 191, 0, 0, 0, 162,
255, 0, 0, 0, 0, 0, 0,
];
static BACKWARD_TABLE_UPPER: &'static [u16] = &[
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 16, 24, 32, 40, 48, 56,
64, 72, 80, 88, 96, 104, 112, 120, 128, 0, 136, 0, 144, 152, 0, 160, 0, 0,
0, 0, 168, 0, 176, 0, 184, 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, 192,
];
#[inline]
pub fn backward(code: u32) -> u8 {
let offset = (code >> 3) as usize;
let offset = if offset < 92 {BACKWARD_TABLE_UPPER[offset] as usize} else {0};
BACKWARD_TABLE_LOWER[offset + ((code & 7) as usize)]
}
#[cfg(test)]
single_byte_tests!(
mod = iso_8859_3
);