encoding_index_singlebyte/
windows_1252.rs

1// AUTOGENERATED FROM index-windows-1252.txt, ORIGINAL COMMENT FOLLOWS:
2//
3// For details on index index-windows-1252.txt see the Encoding Standard
4// https://encoding.spec.whatwg.org/
5//
6// Identifier: e56d49d9176e9a412283cf29ac9bd613f5620462f2a080a84eceaf974cfa18b7
7// Date: 2018-01-06
8
9#[allow(dead_code)] const X: u16 = 0xffff;
10
11const FORWARD_TABLE: &[u16] = &[
12    8364, 129, 8218, 402, 8222, 8230, 8224, 8225, 710, 8240, 352, 8249, 338, 141, 381, 143, 144,
13    8216, 8217, 8220, 8221, 8226, 8211, 8212, 732, 8482, 353, 8250, 339, 157, 382, 376, 160, 161,
14    162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180,
15    181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199,
16    200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218,
17    219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237,
18    238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255,
19]; // 128 entries
20
21/// Returns the index code point for pointer `code` in this index.
22#[inline]
23pub fn forward(code: u8) -> u16 {
24    FORWARD_TABLE[(code - 0x80) as usize]
25}
26
27#[cfg(not(feature = "no-optimized-legacy-encoding"))]
28const BACKWARD_TABLE_LOWER: &[u8] = &[
29    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,
30    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,
31    136, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 152, 0, 0, 0, 0, 0, 0, 0,
32    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, 153, 0, 0,
33    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, 150, 151, 0,
34    0, 0, 145, 146, 130, 0, 147, 148, 132, 0, 134, 135, 149, 0, 0, 0, 133, 0, 0, 0, 0, 0, 0, 0, 0,
35    0, 137, 0, 0, 0, 0, 0, 0, 0, 0, 139, 155, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
36    131, 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,
37    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
38    0, 0, 0, 0, 140, 156, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 138, 154, 0, 0, 0, 0, 0, 0, 0, 0, 0,
39    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 159, 0, 0, 0, 0, 142, 158, 0, 129, 0, 0, 0, 0, 0, 0, 0,
40    0, 0, 0, 0, 141, 0, 143, 144, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 157, 0, 0, 160, 161, 162,
41    163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181,
42    182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200,
43    201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219,
44    220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238,
45    239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255,
46]; // 449 entries
47
48#[cfg(not(feature = "no-optimized-legacy-encoding"))]
49const BACKWARD_TABLE_UPPER: &[u16] = &[
50    0, 0, 321, 385, 0, 258, 192, 0, 0, 0, 0, 58, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
51    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,
52    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,
53    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,
54    0, 0, 0, 133, 0, 212, 0, 88,
55]; // 133 entries
56
57/// Returns the index pointer for code point `code` in this index.
58#[inline]
59#[cfg(not(feature = "no-optimized-legacy-encoding"))]
60pub fn backward(code: u32) -> u8 {
61    let offset = (code >> 6) as usize;
62    let offset = if offset < 133 {BACKWARD_TABLE_UPPER[offset] as usize} else {0};
63    BACKWARD_TABLE_LOWER[offset + ((code & 63) as usize)]
64}
65
66/// Returns the index pointer for code point `code` in this index.
67#[cfg(feature = "no-optimized-legacy-encoding")]
68pub fn backward(code: u32) -> u8 {
69    if code > 8482 || ((0x10003u32 >> (code >> 9)) & 1) == 0 { return 0; }
70    let code = code as u16;
71    for i in 0..0x80 {
72        if FORWARD_TABLE[i as usize] == code { return 0x80 + i; }
73    }
74    0
75}
76
77#[cfg(test)]
78encoding_index_tests::single_byte_tests! {
79}