encoding_index_singlebyte/
iso_8859_6.rs

1// AUTOGENERATED FROM index-iso-8859-6.txt, ORIGINAL COMMENT FOLLOWS:
2//
3// For details on index index-iso-8859-6.txt see the Encoding Standard
4// https://encoding.spec.whatwg.org/
5//
6// Identifier: 85bb7b5c2dc75975afebe5743935ba4ed5a09c1e9e34e9bfb2ff80293f5d8bbc
7// Date: 2018-01-06
8
9#[allow(dead_code)] const X: u16 = 0xffff;
10
11const FORWARD_TABLE: &[u16] = &[
12    128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146,
13    147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, X, X, X, 164, X, X, X, X,
14    X, X, X, 1548, 173, X, X, X, X, X, X, X, X, X, X, X, X, X, 1563, X, X, X, 1567, X, 1569, 1570,
15    1571, 1572, 1573, 1574, 1575, 1576, 1577, 1578, 1579, 1580, 1581, 1582, 1583, 1584, 1585, 1586,
16    1587, 1588, 1589, 1590, 1591, 1592, 1593, 1594, X, X, X, X, X, 1600, 1601, 1602, 1603, 1604,
17    1605, 1606, 1607, 1608, 1609, 1610, 1611, 1612, 1613, 1614, 1615, 1616, 1617, 1618, X, X, X, X,
18    X, X, X, X, X, X, X, X, X,
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    224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242,
31    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203,
32    204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 0, 0, 0, 0, 0, 128,
33    129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147,
34    148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 0, 0, 0, 164, 0, 0, 0, 0, 0,
35    0, 0, 0, 173, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 172, 0, 0, 0, 0, 0, 0, 0,
36    0, 0, 0, 0, 0, 0, 0, 187, 0, 0, 0, 191,
37]; // 179 entries
38
39#[cfg(not(feature = "no-optimized-legacy-encoding"))]
40const BACKWARD_TABLE_UPPER: &[u16] = &[
41    0, 0, 0, 0, 95, 127, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
42    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 147, 63, 32,
43]; // 51 entries
44
45/// Returns the index pointer for code point `code` in this index.
46#[inline]
47#[cfg(not(feature = "no-optimized-legacy-encoding"))]
48pub fn backward(code: u32) -> u8 {
49    let offset = (code >> 5) as usize;
50    let offset = if offset < 51 {BACKWARD_TABLE_UPPER[offset] as usize} else {0};
51    BACKWARD_TABLE_LOWER[offset + ((code & 31) as usize)]
52}
53
54/// Returns the index pointer for code point `code` in this index.
55#[cfg(feature = "no-optimized-legacy-encoding")]
56pub fn backward(code: u32) -> u8 {
57    if code > 1618 || ((0x3000004u32 >> (code >> 6)) & 1) == 0 { return 0; }
58    let code = code as u16;
59    for i in 0..0x80 {
60        if FORWARD_TABLE[i as usize] == code { return 0x80 + i; }
61    }
62    0
63}
64
65#[cfg(test)]
66encoding_index_tests::single_byte_tests! {
67}