encoding_index_singlebyte/
ibm866.rs

1// AUTOGENERATED FROM index-ibm866.txt, ORIGINAL COMMENT FOLLOWS:
2//
3// For details on index index-ibm866.txt see the Encoding Standard
4// https://encoding.spec.whatwg.org/
5//
6// Identifier: db6fe14a559d1601a7667338d83704773d5708dbc641e1ad3c5e21405770f05e
7// Date: 2018-01-06
8
9#[allow(dead_code)] const X: u16 = 0xffff;
10
11const FORWARD_TABLE: &[u16] = &[
12    1040, 1041, 1042, 1043, 1044, 1045, 1046, 1047, 1048, 1049, 1050, 1051, 1052, 1053, 1054, 1055,
13    1056, 1057, 1058, 1059, 1060, 1061, 1062, 1063, 1064, 1065, 1066, 1067, 1068, 1069, 1070, 1071,
14    1072, 1073, 1074, 1075, 1076, 1077, 1078, 1079, 1080, 1081, 1082, 1083, 1084, 1085, 1086, 1087,
15    9617, 9618, 9619, 9474, 9508, 9569, 9570, 9558, 9557, 9571, 9553, 9559, 9565, 9564, 9563, 9488,
16    9492, 9524, 9516, 9500, 9472, 9532, 9566, 9567, 9562, 9556, 9577, 9574, 9568, 9552, 9580, 9575,
17    9576, 9572, 9573, 9561, 9560, 9554, 9555, 9579, 9578, 9496, 9484, 9608, 9604, 9612, 9616, 9600,
18    1088, 1089, 1090, 1091, 1092, 1093, 1094, 1095, 1096, 1097, 1098, 1099, 1100, 1101, 1102, 1103,
19    1025, 1105, 1028, 1108, 1031, 1111, 1038, 1118, 176, 8729, 183, 8730, 8470, 164, 9632, 160,
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    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,
32    224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 0, 241, 0, 0,
33    243, 0, 0, 245, 0, 0, 0, 0, 0, 0, 247, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
34    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 249, 251, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 252, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
37    0, 0, 255, 0, 0, 0, 253, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 248, 0, 0, 0, 0, 0, 0, 250, 0, 0, 0,
38    0, 0, 0, 0, 0, 196, 0, 179, 0, 0, 0, 0, 0, 0, 0, 0, 0, 218, 0, 0, 0, 191, 0, 0, 0, 192, 0, 0,
39    0, 217, 0, 0, 0, 195, 0, 0, 0, 0, 0, 0, 0, 180, 0, 0, 0, 0, 0, 0, 0, 194, 0, 0, 0, 0, 0, 0, 0,
40    193, 0, 0, 0, 0, 0, 0, 0, 197, 0, 0, 0, 223, 0, 0, 0, 220, 0, 0, 0, 219, 0, 0, 0, 221, 0, 0, 0,
41    222, 176, 177, 178, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 254, 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, 0, 0, 0, 205, 186, 213, 214, 201, 184, 183,
43    187, 212, 211, 200, 190, 189, 188, 198, 199, 204, 181, 182, 185, 209, 210, 203, 207, 208, 202,
44    216, 215, 206, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 240, 0, 0, 242, 0, 0,
45    244, 0, 0, 0, 0, 0, 0, 246, 0, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140,
46    141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
47    160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
48]; // 480 entries
49
50#[cfg(not(feature = "no-optimized-legacy-encoding"))]
51const BACKWARD_TABLE_UPPER: &[u16] = &[
52    0, 0, 177, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 416, 64, 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, 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, 145, 0, 0, 0, 103, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 241, 353, 305,
57]; // 151 entries
58
59/// Returns the index pointer for code point `code` in this index.
60#[inline]
61#[cfg(not(feature = "no-optimized-legacy-encoding"))]
62pub fn backward(code: u32) -> u8 {
63    let offset = (code >> 6) as usize;
64    let offset = if offset < 151 {BACKWARD_TABLE_UPPER[offset] as usize} else {0};
65    BACKWARD_TABLE_LOWER[offset + ((code & 63) as usize)]
66}
67
68/// Returns the index pointer for code point `code` in this index.
69#[cfg(feature = "no-optimized-legacy-encoding")]
70pub fn backward(code: u32) -> u8 {
71    if code > 9632 || ((0x70005u32 >> (code >> 9)) & 1) == 0 { return 0; }
72    let code = code as u16;
73    for i in 0..0x80 {
74        if FORWARD_TABLE[i as usize] == code { return 0x80 + i; }
75    }
76    0
77}
78
79#[cfg(test)]
80encoding_index_tests::single_byte_tests! {
81}