encoding_index_singlebyte/
iso_8859_7.rs

1// AUTOGENERATED FROM index-iso-8859-7.txt, ORIGINAL COMMENT FOLLOWS:
2//
3// For details on index index-iso-8859-7.txt see the Encoding Standard
4// https://encoding.spec.whatwg.org/
5//
6// Identifier: f53d8aeba36314ef950eef02ffcf11dff540638ce27dfe7a86b6ccc6875afb24
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, 8216, 8217, 163, 8364,
14    8367, 166, 167, 168, 169, 890, 171, 172, 173, X, 8213, 176, 177, 178, 179, 900, 901, 902, 183,
15    904, 905, 906, 187, 908, 189, 910, 911, 912, 913, 914, 915, 916, 917, 918, 919, 920, 921, 922,
16    923, 924, 925, 926, 927, 928, 929, X, 931, 932, 933, 934, 935, 936, 937, 938, 939, 940, 941,
17    942, 943, 944, 945, 946, 947, 948, 949, 950, 951, 952, 953, 954, 955, 956, 957, 958, 959, 960,
18    961, 962, 963, 964, 965, 966, 967, 968, 969, 970, 971, 972, 973, 974, 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    0, 0, 0, 0, 0, 0, 0, 0, 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    128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146,
32    147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 0, 0, 163, 0, 0, 166,
33    167, 168, 169, 0, 171, 172, 173, 0, 0, 176, 177, 178, 179, 0, 0, 0, 183, 0, 0, 0, 187, 0, 189,
34    0, 0, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 0, 0, 0, 0, 0,
35    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
36    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 170, 0, 0, 0, 0, 0, 0, 0, 0, 0,
37    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 175, 0, 0, 161, 162, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
38    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
39    164, 0, 0, 165, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 180, 181, 182, 0, 184, 185,
40    186, 0, 188, 0, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205,
41    206, 207, 208, 209, 0, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224,
42    225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
43]; // 352 entries
44
45#[cfg(not(feature = "no-optimized-legacy-encoding"))]
46const BACKWARD_TABLE_UPPER: &[u16] = &[
47    0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 143, 288, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
48    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
49    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
50    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
51    0, 0, 0, 202, 0, 228,
52]; // 131 entries
53
54/// Returns the index pointer for code point `code` in this index.
55#[inline]
56#[cfg(not(feature = "no-optimized-legacy-encoding"))]
57pub fn backward(code: u32) -> u8 {
58    let offset = (code >> 6) as usize;
59    let offset = if offset < 131 {BACKWARD_TABLE_UPPER[offset] as usize} else {0};
60    BACKWARD_TABLE_LOWER[offset + ((code & 63) as usize)]
61}
62
63/// Returns the index pointer for code point `code` in this index.
64#[cfg(feature = "no-optimized-legacy-encoding")]
65pub fn backward(code: u32) -> u8 {
66    if code > 8367 || ((0x10003u32 >> (code >> 9)) & 1) == 0 { return 0; }
67    let code = code as u16;
68    for i in 0..0x80 {
69        if FORWARD_TABLE[i as usize] == code { return 0x80 + i; }
70    }
71    0
72}
73
74#[cfg(test)]
75encoding_index_tests::single_byte_tests! {
76}