encoding_index_singlebyte/
windows_1256.rs

1// AUTOGENERATED FROM index-windows-1256.txt, ORIGINAL COMMENT FOLLOWS:
2//
3// For details on index index-windows-1256.txt see the Encoding Standard
4// https://encoding.spec.whatwg.org/
5//
6// Identifier: 161bdb381f16408e8bebcc8f5310c4190af0e359de8d9bbaa3628ce2f0875509
7// Date: 2018-01-06
8
9#[allow(dead_code)] const X: u16 = 0xffff;
10
11const FORWARD_TABLE: &[u16] = &[
12    8364, 1662, 8218, 402, 8222, 8230, 8224, 8225, 710, 8240, 1657, 8249, 338, 1670, 1688, 1672,
13    1711, 8216, 8217, 8220, 8221, 8226, 8211, 8212, 1705, 8482, 1681, 8250, 339, 8204, 8205, 1722,
14    160, 1548, 162, 163, 164, 165, 166, 167, 168, 169, 1726, 171, 172, 173, 174, 175, 176, 177,
15    178, 179, 180, 181, 182, 183, 184, 185, 1563, 187, 188, 189, 190, 1567, 1729, 1569, 1570, 1571,
16    1572, 1573, 1574, 1575, 1576, 1577, 1578, 1579, 1580, 1581, 1582, 1583, 1584, 1585, 1586, 1587,
17    1588, 1589, 1590, 215, 1591, 1592, 1593, 1594, 1600, 1601, 1602, 1603, 224, 1604, 226, 1605,
18    1606, 1607, 1608, 231, 232, 233, 234, 235, 1609, 1610, 238, 239, 1611, 1612, 1613, 1614, 244,
19    1615, 1616, 247, 1617, 249, 1618, 251, 252, 8206, 8207, 1746,
20]; // 128 entries
21
22/// Returns the index code point for pointer `code` in this index.
23#[inline]
24pub fn forward(code: u8) -> u16 {
25    FORWARD_TABLE[(code - 0x80) as usize]
26}
27
28#[cfg(not(feature = "no-optimized-legacy-encoding"))]
29const BACKWARD_TABLE_LOWER: &[u8] = &[
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    134, 135, 149, 0, 0, 0, 133, 0, 0, 0, 0, 0, 0, 0, 0, 0, 137, 0, 0, 0, 0, 0, 0, 0, 0, 139, 155,
32    0, 0, 0, 0, 0, 153, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
33    0, 0, 0, 0, 138, 0, 0, 0, 0, 129, 0, 160, 0, 162, 163, 164, 165, 166, 167, 168, 169, 0, 171,
34    172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 0, 187, 188, 189, 190, 0,
35    192, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
36    0, 157, 158, 253, 254, 0, 0, 0, 150, 151, 0, 0, 0, 145, 146, 130, 0, 147, 148, 132, 0, 224, 0,
37    226, 0, 0, 0, 0, 231, 232, 233, 234, 235, 0, 0, 238, 239, 0, 0, 0, 0, 244, 0, 0, 247, 0, 249,
38    0, 251, 252, 0, 0, 0, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206,
39    207, 208, 209, 210, 211, 212, 213, 214, 216, 217, 218, 219, 0, 0, 0, 0, 0, 0, 141, 0, 143, 0,
40    0, 0, 0, 0, 0, 0, 0, 154, 0, 0, 0, 0, 0, 0, 142, 0, 0, 0, 0, 0, 0, 0, 136, 0, 0, 0, 0, 0, 0, 0,
41    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 215, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
42    128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 140, 156, 0, 0, 0, 0, 0, 0, 0, 0,
43    0, 0, 0, 0, 152, 0, 0, 0, 0, 0, 144, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 159, 0, 0, 0, 170, 0, 220,
44    221, 222, 223, 225, 227, 228, 229, 230, 236, 237, 240, 241, 242, 243, 245, 246, 248, 250, 0, 0,
45    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 131, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
46    161, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 186, 0, 0, 0, 191,
47]; // 441 entries
48
49#[cfg(not(feature = "no-optimized-legacy-encoding"))]
50const BACKWARD_TABLE_UPPER: &[u16] = &[
51    0, 0, 0, 0, 0, 101, 277, 184, 0, 0, 315, 0, 389, 0, 0, 0, 0, 0, 0, 0, 0, 0, 268, 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, 409, 215, 370, 69, 242, 338, 132,
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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
55    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
56    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
57    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
58    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
59    0, 0, 0, 0, 0, 0, 0, 0, 0, 152, 32, 0, 0, 0, 301, 0, 0, 0, 62,
60]; // 266 entries
61
62/// Returns the index pointer for code point `code` in this index.
63#[inline]
64#[cfg(not(feature = "no-optimized-legacy-encoding"))]
65pub fn backward(code: u32) -> u8 {
66    let offset = (code >> 5) as usize;
67    let offset = if offset < 266 {BACKWARD_TABLE_UPPER[offset] as usize} else {0};
68    BACKWARD_TABLE_LOWER[offset + ((code & 31) as usize)]
69}
70
71/// Returns the index pointer for code point `code` in this index.
72#[cfg(feature = "no-optimized-legacy-encoding")]
73pub fn backward(code: u32) -> u8 {
74    if code > 8482 || ((0x1000bu32 >> (code >> 9)) & 1) == 0 { return 0; }
75    let code = code as u16;
76    for i in 0..0x80 {
77        if FORWARD_TABLE[i as usize] == code { return 0x80 + i; }
78    }
79    0
80}
81
82#[cfg(test)]
83encoding_index_tests::single_byte_tests! {
84}