encoding_index_singlebyte/
iso_8859_15.rs

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