First commit

This commit is contained in:
Maurus Decimus
2021-10-03 16:45:16 +00:00
commit c5ed27bb12
14 changed files with 2912 additions and 0 deletions
+2
View File
@@ -0,0 +1,2 @@
/target
/test
Generated
+7
View File
@@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "stalwart"
version = "0.1.0"
+8
View File
@@ -0,0 +1,8 @@
[package]
name = "stalwart"
version = "0.1.0"
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
+329
View File
@@ -0,0 +1,329 @@
use super::{Decoder, DecoderResult};
pub struct Base64Decoder {
chunk: Base64Chunk,
count: u8,
}
#[repr(C)]
union Base64Chunk {
val: u32,
bytes: [u8; std::mem::size_of::<u32>()],
}
impl Base64Decoder {
pub fn new() -> Base64Decoder {
Base64Decoder {
chunk: Base64Chunk { val: 0 },
count: 0,
}
}
}
impl Decoder for Base64Decoder {
fn ingest(&mut self, ch: u8) -> DecoderResult {
if ch != b'=' {
let val = unsafe {
BASE64_MAP
.get_unchecked(self.count as usize)
.get_unchecked(ch as usize)
};
if *val >= 0x01ffffff {
return DecoderResult::Error;
}
self.count = (self.count + 1) & 3;
if self.count == 1 {
self.chunk.val = *val;
} else {
self.chunk.val = unsafe { self.chunk.val } | *val;
if self.count == 0 {
return DecoderResult::ByteArray(unsafe {
&self.chunk.bytes.get_unchecked(0..3)
});
}
}
} else {
match self.count {
1 | 2 => {
self.count = 0;
return DecoderResult::Byte(unsafe { *self.chunk.bytes.get_unchecked(0) });
}
3 => {
self.count = 0;
return DecoderResult::ByteArray(unsafe {
&self.chunk.bytes.get_unchecked(0..2)
});
}
0 => (),
_ => {
return DecoderResult::Error;
}
}
}
DecoderResult::NeedData
}
}
#[cfg(test)]
mod tests {
use super::Base64Decoder;
use crate::decoders::{Decoder, DecoderResult};
#[test]
fn decode_success() {
let inputs = [
("VGVzdA==".as_bytes(), "Test".as_bytes()),
("WWU=".as_bytes(), "Ye".as_bytes()),
("QQ==".as_bytes(), "A".as_bytes()),
("cm8=".as_bytes(), "ro".as_bytes()),
(
"QXJlIHlvdSBhIFNoaW1hbm8gb3IgQ2FtcGFnbm9sbyBwZXJzb24/".as_bytes(),
"Are you a Shimano or Campagnolo person?".as_bytes(),
),
(
"PCFET0NUWVBFIGh0bWw+CjxodG1sPgo8Ym9keT4KPC9ib2R5Pgo8L2h0bWw+Cg==".as_bytes(),
"<!DOCTYPE html>\n<html>\n<body>\n</body>\n</html>\n".as_bytes(),
),
("w6HDqcOtw7PDug==".as_bytes(), "áéíóú".as_bytes()),
];
for input in inputs {
let mut decoder = Base64Decoder::new();
let mut output = Vec::new();
for ch in input.0 {
match decoder.ingest(*ch) {
DecoderResult::Byte(v) => {
output.push(v);
}
DecoderResult::ByteArray(v) => {
output.extend_from_slice(v);
}
DecoderResult::NeedData => (),
DecoderResult::Error => {
panic!(
"Failed to decode Base64: {}",
std::str::from_utf8(&input.0).unwrap()
);
}
}
}
//println!("'{}'", std::str::from_utf8(&output).unwrap());
assert_eq!(output, input.1);
}
}
#[test]
fn decode_invalid() {
let inputs = [
"====".as_bytes(),
"w6HDq!cOtw7PDug=".as_bytes(),
"w6 HD".as_bytes(),
"cmáé".as_bytes(),
"áé".as_bytes(),
];
for input in inputs {
let mut decoder = Base64Decoder::new();
let mut failed = false;
let mut is_empty = true;
for ch in input {
match decoder.ingest(*ch) {
DecoderResult::Byte(_) => {
is_empty = false;
}
DecoderResult::ByteArray(_) => {
is_empty = false;
}
DecoderResult::NeedData => (),
DecoderResult::Error => {
failed = true;
break;
}
}
}
assert!(
failed || is_empty,
"Test failed on '{}'",
std::str::from_utf8(input).unwrap()
);
}
}
}
/*
* Table adapted from Nick Galbreath's "High performance base64 encoder / decoder"
*
* Copyright 2005, 2006, 2007 Nick Galbreath -- nickg [at] modp [dot] com
* All rights reserved.
*
* http://code.google.com/p/stringencoders/
*
* Released under bsd license.
*
*/
static BASE64_MAP: &'static [&[u32]] = &[
&[
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x000000f8, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x000000fc, 0x000000d0,
0x000000d4, 0x000000d8, 0x000000dc, 0x000000e0, 0x000000e4, 0x000000e8, 0x000000ec,
0x000000f0, 0x000000f4, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x00000000, 0x00000004, 0x00000008, 0x0000000c, 0x00000010,
0x00000014, 0x00000018, 0x0000001c, 0x00000020, 0x00000024, 0x00000028, 0x0000002c,
0x00000030, 0x00000034, 0x00000038, 0x0000003c, 0x00000040, 0x00000044, 0x00000048,
0x0000004c, 0x00000050, 0x00000054, 0x00000058, 0x0000005c, 0x00000060, 0x00000064,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x00000068,
0x0000006c, 0x00000070, 0x00000074, 0x00000078, 0x0000007c, 0x00000080, 0x00000084,
0x00000088, 0x0000008c, 0x00000090, 0x00000094, 0x00000098, 0x0000009c, 0x000000a0,
0x000000a4, 0x000000a8, 0x000000ac, 0x000000b0, 0x000000b4, 0x000000b8, 0x000000bc,
0x000000c0, 0x000000c4, 0x000000c8, 0x000000cc, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
],
&[
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x0000e003, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x0000f003, 0x00004003,
0x00005003, 0x00006003, 0x00007003, 0x00008003, 0x00009003, 0x0000a003, 0x0000b003,
0x0000c003, 0x0000d003, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x00000000, 0x00001000, 0x00002000, 0x00003000, 0x00004000,
0x00005000, 0x00006000, 0x00007000, 0x00008000, 0x00009000, 0x0000a000, 0x0000b000,
0x0000c000, 0x0000d000, 0x0000e000, 0x0000f000, 0x00000001, 0x00001001, 0x00002001,
0x00003001, 0x00004001, 0x00005001, 0x00006001, 0x00007001, 0x00008001, 0x00009001,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x0000a001,
0x0000b001, 0x0000c001, 0x0000d001, 0x0000e001, 0x0000f001, 0x00000002, 0x00001002,
0x00002002, 0x00003002, 0x00004002, 0x00005002, 0x00006002, 0x00007002, 0x00008002,
0x00009002, 0x0000a002, 0x0000b002, 0x0000c002, 0x0000d002, 0x0000e002, 0x0000f002,
0x00000003, 0x00001003, 0x00002003, 0x00003003, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
],
&[
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x00800f00, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x00c00f00, 0x00000d00,
0x00400d00, 0x00800d00, 0x00c00d00, 0x00000e00, 0x00400e00, 0x00800e00, 0x00c00e00,
0x00000f00, 0x00400f00, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x00000000, 0x00400000, 0x00800000, 0x00c00000, 0x00000100,
0x00400100, 0x00800100, 0x00c00100, 0x00000200, 0x00400200, 0x00800200, 0x00c00200,
0x00000300, 0x00400300, 0x00800300, 0x00c00300, 0x00000400, 0x00400400, 0x00800400,
0x00c00400, 0x00000500, 0x00400500, 0x00800500, 0x00c00500, 0x00000600, 0x00400600,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x00800600,
0x00c00600, 0x00000700, 0x00400700, 0x00800700, 0x00c00700, 0x00000800, 0x00400800,
0x00800800, 0x00c00800, 0x00000900, 0x00400900, 0x00800900, 0x00c00900, 0x00000a00,
0x00400a00, 0x00800a00, 0x00c00a00, 0x00000b00, 0x00400b00, 0x00800b00, 0x00c00b00,
0x00000c00, 0x00400c00, 0x00800c00, 0x00c00c00, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
],
&[
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x003e0000, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x003f0000, 0x00340000,
0x00350000, 0x00360000, 0x00370000, 0x00380000, 0x00390000, 0x003a0000, 0x003b0000,
0x003c0000, 0x003d0000, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x00000000, 0x00010000, 0x00020000, 0x00030000, 0x00040000,
0x00050000, 0x00060000, 0x00070000, 0x00080000, 0x00090000, 0x000a0000, 0x000b0000,
0x000c0000, 0x000d0000, 0x000e0000, 0x000f0000, 0x00100000, 0x00110000, 0x00120000,
0x00130000, 0x00140000, 0x00150000, 0x00160000, 0x00170000, 0x00180000, 0x00190000,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x001a0000,
0x001b0000, 0x001c0000, 0x001d0000, 0x001e0000, 0x001f0000, 0x00200000, 0x00210000,
0x00220000, 0x00230000, 0x00240000, 0x00250000, 0x00260000, 0x00270000, 0x00280000,
0x00290000, 0x002a0000, 0x002b0000, 0x002c0000, 0x002d0000, 0x002e0000, 0x002f0000,
0x00300000, 0x00310000, 0x00320000, 0x00330000, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
],
];
File diff suppressed because it is too large Load Diff
+491
View File
@@ -0,0 +1,491 @@
use super::CharsetDecoder;
pub struct SingleByteDecoder {
table: &'static [char],
result: String,
}
impl CharsetDecoder for SingleByteDecoder {
fn ingest(&mut self, ch: u8) -> () {
self.result
.push(unsafe { *self.table.get_unchecked(ch as usize) });
}
fn to_string(&self) -> Option<&str> {
if self.result.len() > 0 {
Some(&self.result)
} else {
None
}
}
}
impl SingleByteDecoder {
pub fn new(table: &'static [char], capacity: usize) -> SingleByteDecoder {
SingleByteDecoder {
result: String::with_capacity(capacity),
table: table,
}
}
pub const ISO_8859_1: &'static [char] = &[
'\u{0}', '\u{1}', '\u{2}', '\u{3}', '\u{4}', '\u{5}', '\u{6}', '\u{7}', '\u{8}', '\u{9}',
'\u{a}', '\u{b}', '\u{c}', '\u{d}', '\u{e}', '\u{f}', '\u{10}', '\u{11}', '\u{12}',
'\u{13}', '\u{14}', '\u{15}', '\u{16}', '\u{17}', '\u{18}', '\u{19}', '\u{1a}', '\u{1b}',
'\u{1c}', '\u{1d}', '\u{1e}', '\u{1f}', '\u{20}', '\u{21}', '\u{22}', '\u{23}', '\u{24}',
'\u{25}', '\u{26}', '\u{27}', '\u{28}', '\u{29}', '\u{2a}', '\u{2b}', '\u{2c}', '\u{2d}',
'\u{2e}', '\u{2f}', '\u{30}', '\u{31}', '\u{32}', '\u{33}', '\u{34}', '\u{35}', '\u{36}',
'\u{37}', '\u{38}', '\u{39}', '\u{3a}', '\u{3b}', '\u{3c}', '\u{3d}', '\u{3e}', '\u{3f}',
'\u{40}', '\u{41}', '\u{42}', '\u{43}', '\u{44}', '\u{45}', '\u{46}', '\u{47}', '\u{48}',
'\u{49}', '\u{4a}', '\u{4b}', '\u{4c}', '\u{4d}', '\u{4e}', '\u{4f}', '\u{50}', '\u{51}',
'\u{52}', '\u{53}', '\u{54}', '\u{55}', '\u{56}', '\u{57}', '\u{58}', '\u{59}', '\u{5a}',
'\u{5b}', '\u{5c}', '\u{5d}', '\u{5e}', '\u{5f}', '\u{60}', '\u{61}', '\u{62}', '\u{63}',
'\u{64}', '\u{65}', '\u{66}', '\u{67}', '\u{68}', '\u{69}', '\u{6a}', '\u{6b}', '\u{6c}',
'\u{6d}', '\u{6e}', '\u{6f}', '\u{70}', '\u{71}', '\u{72}', '\u{73}', '\u{74}', '\u{75}',
'\u{76}', '\u{77}', '\u{78}', '\u{79}', '\u{7a}', '\u{7b}', '\u{7c}', '\u{7d}', '\u{7e}',
'\u{7f}', '\u{80}', '\u{81}', '\u{82}', '\u{83}', '\u{84}', '\u{85}', '\u{86}', '\u{87}',
'\u{88}', '\u{89}', '\u{8a}', '\u{8b}', '\u{8c}', '\u{8d}', '\u{8e}', '\u{8f}', '\u{90}',
'\u{91}', '\u{92}', '\u{93}', '\u{94}', '\u{95}', '\u{96}', '\u{97}', '\u{98}', '\u{99}',
'\u{9a}', '\u{9b}', '\u{9c}', '\u{9d}', '\u{9e}', '\u{9f}', '\u{a0}', '\u{a1}', '\u{a2}',
'\u{a3}', '\u{a4}', '\u{a5}', '\u{a6}', '\u{a7}', '\u{a8}', '\u{a9}', '\u{aa}', '\u{ab}',
'\u{ac}', '\u{ad}', '\u{ae}', '\u{af}', '\u{b0}', '\u{b1}', '\u{b2}', '\u{b3}', '\u{b4}',
'\u{b5}', '\u{b6}', '\u{b7}', '\u{b8}', '\u{b9}', '\u{ba}', '\u{bb}', '\u{bc}', '\u{bd}',
'\u{be}', '\u{bf}', '\u{c0}', '\u{c1}', '\u{c2}', '\u{c3}', '\u{c4}', '\u{c5}', '\u{c6}',
'\u{c7}', '\u{c8}', '\u{c9}', '\u{ca}', '\u{cb}', '\u{cc}', '\u{cd}', '\u{ce}', '\u{cf}',
'\u{d0}', '\u{d1}', '\u{d2}', '\u{d3}', '\u{d4}', '\u{d5}', '\u{d6}', '\u{d7}', '\u{d8}',
'\u{d9}', '\u{da}', '\u{db}', '\u{dc}', '\u{dd}', '\u{de}', '\u{df}', '\u{e0}', '\u{e1}',
'\u{e2}', '\u{e3}', '\u{e4}', '\u{e5}', '\u{e6}', '\u{e7}', '\u{e8}', '\u{e9}', '\u{ea}',
'\u{eb}', '\u{ec}', '\u{ed}', '\u{ee}', '\u{ef}', '\u{f0}', '\u{f1}', '\u{f2}', '\u{f3}',
'\u{f4}', '\u{f5}', '\u{f6}', '\u{f7}', '\u{f8}', '\u{f9}', '\u{fa}', '\u{fb}', '\u{fc}',
'\u{fd}', '\u{fe}', '\u{ff}',
];
pub const ISO_8859_2: &'static [char] = &[
'\u{0}', '\u{1}', '\u{2}', '\u{3}', '\u{4}', '\u{5}', '\u{6}', '\u{7}', '\u{8}', '\u{9}',
'\u{a}', '\u{b}', '\u{c}', '\u{d}', '\u{e}', '\u{f}', '\u{10}', '\u{11}', '\u{12}',
'\u{13}', '\u{14}', '\u{15}', '\u{16}', '\u{17}', '\u{18}', '\u{19}', '\u{1a}', '\u{1b}',
'\u{1c}', '\u{1d}', '\u{1e}', '\u{1f}', '\u{20}', '\u{21}', '\u{22}', '\u{23}', '\u{24}',
'\u{25}', '\u{26}', '\u{27}', '\u{28}', '\u{29}', '\u{2a}', '\u{2b}', '\u{2c}', '\u{2d}',
'\u{2e}', '\u{2f}', '\u{30}', '\u{31}', '\u{32}', '\u{33}', '\u{34}', '\u{35}', '\u{36}',
'\u{37}', '\u{38}', '\u{39}', '\u{3a}', '\u{3b}', '\u{3c}', '\u{3d}', '\u{3e}', '\u{3f}',
'\u{40}', '\u{41}', '\u{42}', '\u{43}', '\u{44}', '\u{45}', '\u{46}', '\u{47}', '\u{48}',
'\u{49}', '\u{4a}', '\u{4b}', '\u{4c}', '\u{4d}', '\u{4e}', '\u{4f}', '\u{50}', '\u{51}',
'\u{52}', '\u{53}', '\u{54}', '\u{55}', '\u{56}', '\u{57}', '\u{58}', '\u{59}', '\u{5a}',
'\u{5b}', '\u{5c}', '\u{5d}', '\u{5e}', '\u{5f}', '\u{60}', '\u{61}', '\u{62}', '\u{63}',
'\u{64}', '\u{65}', '\u{66}', '\u{67}', '\u{68}', '\u{69}', '\u{6a}', '\u{6b}', '\u{6c}',
'\u{6d}', '\u{6e}', '\u{6f}', '\u{70}', '\u{71}', '\u{72}', '\u{73}', '\u{74}', '\u{75}',
'\u{76}', '\u{77}', '\u{78}', '\u{79}', '\u{7a}', '\u{7b}', '\u{7c}', '\u{7d}', '\u{7e}',
'\u{7f}', '\u{80}', '\u{81}', '\u{82}', '\u{83}', '\u{84}', '\u{85}', '\u{86}', '\u{87}',
'\u{88}', '\u{89}', '\u{8a}', '\u{8b}', '\u{8c}', '\u{8d}', '\u{8e}', '\u{8f}', '\u{90}',
'\u{91}', '\u{92}', '\u{93}', '\u{94}', '\u{95}', '\u{96}', '\u{97}', '\u{98}', '\u{99}',
'\u{9a}', '\u{9b}', '\u{9c}', '\u{9d}', '\u{9e}', '\u{9f}', '\u{a0}', '\u{104}', '\u{2d8}',
'\u{141}', '\u{a4}', '\u{13d}', '\u{15a}', '\u{a7}', '\u{a8}', '\u{160}', '\u{15e}',
'\u{164}', '\u{179}', '\u{ad}', '\u{17d}', '\u{17b}', '\u{b0}', '\u{105}', '\u{2db}',
'\u{142}', '\u{b4}', '\u{13e}', '\u{15b}', '\u{2c7}', '\u{b8}', '\u{161}', '\u{15f}',
'\u{165}', '\u{17a}', '\u{2dd}', '\u{17e}', '\u{17c}', '\u{154}', '\u{c1}', '\u{c2}',
'\u{102}', '\u{c4}', '\u{139}', '\u{106}', '\u{c7}', '\u{10c}', '\u{c9}', '\u{118}',
'\u{cb}', '\u{11a}', '\u{cd}', '\u{ce}', '\u{10e}', '\u{110}', '\u{143}', '\u{147}',
'\u{d3}', '\u{d4}', '\u{150}', '\u{d6}', '\u{d7}', '\u{158}', '\u{16e}', '\u{da}',
'\u{170}', '\u{dc}', '\u{dd}', '\u{162}', '\u{df}', '\u{155}', '\u{e1}', '\u{e2}',
'\u{103}', '\u{e4}', '\u{13a}', '\u{107}', '\u{e7}', '\u{10d}', '\u{e9}', '\u{119}',
'\u{eb}', '\u{11b}', '\u{ed}', '\u{ee}', '\u{10f}', '\u{111}', '\u{144}', '\u{148}',
'\u{f3}', '\u{f4}', '\u{151}', '\u{f6}', '\u{f7}', '\u{159}', '\u{16f}', '\u{fa}',
'\u{171}', '\u{fc}', '\u{fd}', '\u{163}', '\u{2d9}',
];
pub const ISO_8859_3: &'static [char] = &[
'\u{0}', '\u{1}', '\u{2}', '\u{3}', '\u{4}', '\u{5}', '\u{6}', '\u{7}', '\u{8}', '\u{9}',
'\u{a}', '\u{b}', '\u{c}', '\u{d}', '\u{e}', '\u{f}', '\u{10}', '\u{11}', '\u{12}',
'\u{13}', '\u{14}', '\u{15}', '\u{16}', '\u{17}', '\u{18}', '\u{19}', '\u{1a}', '\u{1b}',
'\u{1c}', '\u{1d}', '\u{1e}', '\u{1f}', '\u{20}', '\u{21}', '\u{22}', '\u{23}', '\u{24}',
'\u{25}', '\u{26}', '\u{27}', '\u{28}', '\u{29}', '\u{2a}', '\u{2b}', '\u{2c}', '\u{2d}',
'\u{2e}', '\u{2f}', '\u{30}', '\u{31}', '\u{32}', '\u{33}', '\u{34}', '\u{35}', '\u{36}',
'\u{37}', '\u{38}', '\u{39}', '\u{3a}', '\u{3b}', '\u{3c}', '\u{3d}', '\u{3e}', '\u{3f}',
'\u{40}', '\u{41}', '\u{42}', '\u{43}', '\u{44}', '\u{45}', '\u{46}', '\u{47}', '\u{48}',
'\u{49}', '\u{4a}', '\u{4b}', '\u{4c}', '\u{4d}', '\u{4e}', '\u{4f}', '\u{50}', '\u{51}',
'\u{52}', '\u{53}', '\u{54}', '\u{55}', '\u{56}', '\u{57}', '\u{58}', '\u{59}', '\u{5a}',
'\u{5b}', '\u{5c}', '\u{5d}', '\u{5e}', '\u{5f}', '\u{60}', '\u{61}', '\u{62}', '\u{63}',
'\u{64}', '\u{65}', '\u{66}', '\u{67}', '\u{68}', '\u{69}', '\u{6a}', '\u{6b}', '\u{6c}',
'\u{6d}', '\u{6e}', '\u{6f}', '\u{70}', '\u{71}', '\u{72}', '\u{73}', '\u{74}', '\u{75}',
'\u{76}', '\u{77}', '\u{78}', '\u{79}', '\u{7a}', '\u{7b}', '\u{7c}', '\u{7d}', '\u{7e}',
'\u{7f}', '\u{80}', '\u{81}', '\u{82}', '\u{83}', '\u{84}', '\u{85}', '\u{86}', '\u{87}',
'\u{88}', '\u{89}', '\u{8a}', '\u{8b}', '\u{8c}', '\u{8d}', '\u{8e}', '\u{8f}', '\u{90}',
'\u{91}', '\u{92}', '\u{93}', '\u{94}', '\u{95}', '\u{96}', '\u{97}', '\u{98}', '\u{99}',
'\u{9a}', '\u{9b}', '\u{9c}', '\u{9d}', '\u{9e}', '\u{9f}', '\u{a0}', '\u{126}', '\u{2d8}',
'\u{a3}', '\u{a4}', '\u{fffd}', '\u{124}', '\u{a7}', '\u{a8}', '\u{130}', '\u{15e}',
'\u{11e}', '\u{134}', '\u{ad}', '\u{fffd}', '\u{17b}', '\u{b0}', '\u{127}', '\u{b2}',
'\u{b3}', '\u{b4}', '\u{b5}', '\u{125}', '\u{b7}', '\u{b8}', '\u{131}', '\u{15f}',
'\u{11f}', '\u{135}', '\u{bd}', '\u{fffd}', '\u{17c}', '\u{c0}', '\u{c1}', '\u{c2}',
'\u{fffd}', '\u{c4}', '\u{10a}', '\u{108}', '\u{c7}', '\u{c8}', '\u{c9}', '\u{ca}',
'\u{cb}', '\u{cc}', '\u{cd}', '\u{ce}', '\u{cf}', '\u{fffd}', '\u{d1}', '\u{d2}', '\u{d3}',
'\u{d4}', '\u{120}', '\u{d6}', '\u{d7}', '\u{11c}', '\u{d9}', '\u{da}', '\u{db}', '\u{dc}',
'\u{16c}', '\u{15c}', '\u{df}', '\u{e0}', '\u{e1}', '\u{e2}', '\u{fffd}', '\u{e4}',
'\u{10b}', '\u{109}', '\u{e7}', '\u{e8}', '\u{e9}', '\u{ea}', '\u{eb}', '\u{ec}', '\u{ed}',
'\u{ee}', '\u{ef}', '\u{fffd}', '\u{f1}', '\u{f2}', '\u{f3}', '\u{f4}', '\u{121}',
'\u{f6}', '\u{f7}', '\u{11d}', '\u{f9}', '\u{fa}', '\u{fb}', '\u{fc}', '\u{16d}',
'\u{15d}', '\u{2d9}',
];
pub const ISO_8859_4: &'static [char] = &[
'\u{0}', '\u{1}', '\u{2}', '\u{3}', '\u{4}', '\u{5}', '\u{6}', '\u{7}', '\u{8}', '\u{9}',
'\u{a}', '\u{b}', '\u{c}', '\u{d}', '\u{e}', '\u{f}', '\u{10}', '\u{11}', '\u{12}',
'\u{13}', '\u{14}', '\u{15}', '\u{16}', '\u{17}', '\u{18}', '\u{19}', '\u{1a}', '\u{1b}',
'\u{1c}', '\u{1d}', '\u{1e}', '\u{1f}', '\u{20}', '\u{21}', '\u{22}', '\u{23}', '\u{24}',
'\u{25}', '\u{26}', '\u{27}', '\u{28}', '\u{29}', '\u{2a}', '\u{2b}', '\u{2c}', '\u{2d}',
'\u{2e}', '\u{2f}', '\u{30}', '\u{31}', '\u{32}', '\u{33}', '\u{34}', '\u{35}', '\u{36}',
'\u{37}', '\u{38}', '\u{39}', '\u{3a}', '\u{3b}', '\u{3c}', '\u{3d}', '\u{3e}', '\u{3f}',
'\u{40}', '\u{41}', '\u{42}', '\u{43}', '\u{44}', '\u{45}', '\u{46}', '\u{47}', '\u{48}',
'\u{49}', '\u{4a}', '\u{4b}', '\u{4c}', '\u{4d}', '\u{4e}', '\u{4f}', '\u{50}', '\u{51}',
'\u{52}', '\u{53}', '\u{54}', '\u{55}', '\u{56}', '\u{57}', '\u{58}', '\u{59}', '\u{5a}',
'\u{5b}', '\u{5c}', '\u{5d}', '\u{5e}', '\u{5f}', '\u{60}', '\u{61}', '\u{62}', '\u{63}',
'\u{64}', '\u{65}', '\u{66}', '\u{67}', '\u{68}', '\u{69}', '\u{6a}', '\u{6b}', '\u{6c}',
'\u{6d}', '\u{6e}', '\u{6f}', '\u{70}', '\u{71}', '\u{72}', '\u{73}', '\u{74}', '\u{75}',
'\u{76}', '\u{77}', '\u{78}', '\u{79}', '\u{7a}', '\u{7b}', '\u{7c}', '\u{7d}', '\u{7e}',
'\u{7f}', '\u{80}', '\u{81}', '\u{82}', '\u{83}', '\u{84}', '\u{85}', '\u{86}', '\u{87}',
'\u{88}', '\u{89}', '\u{8a}', '\u{8b}', '\u{8c}', '\u{8d}', '\u{8e}', '\u{8f}', '\u{90}',
'\u{91}', '\u{92}', '\u{93}', '\u{94}', '\u{95}', '\u{96}', '\u{97}', '\u{98}', '\u{99}',
'\u{9a}', '\u{9b}', '\u{9c}', '\u{9d}', '\u{9e}', '\u{9f}', '\u{a0}', '\u{104}', '\u{138}',
'\u{156}', '\u{a4}', '\u{128}', '\u{13b}', '\u{a7}', '\u{a8}', '\u{160}', '\u{112}',
'\u{122}', '\u{166}', '\u{ad}', '\u{17d}', '\u{af}', '\u{b0}', '\u{105}', '\u{2db}',
'\u{157}', '\u{b4}', '\u{129}', '\u{13c}', '\u{2c7}', '\u{b8}', '\u{161}', '\u{113}',
'\u{123}', '\u{167}', '\u{14a}', '\u{17e}', '\u{14b}', '\u{100}', '\u{c1}', '\u{c2}',
'\u{c3}', '\u{c4}', '\u{c5}', '\u{c6}', '\u{12e}', '\u{10c}', '\u{c9}', '\u{118}',
'\u{cb}', '\u{116}', '\u{cd}', '\u{ce}', '\u{12a}', '\u{110}', '\u{145}', '\u{14c}',
'\u{136}', '\u{d4}', '\u{d5}', '\u{d6}', '\u{d7}', '\u{d8}', '\u{172}', '\u{da}', '\u{db}',
'\u{dc}', '\u{168}', '\u{16a}', '\u{df}', '\u{101}', '\u{e1}', '\u{e2}', '\u{e3}',
'\u{e4}', '\u{e5}', '\u{e6}', '\u{12f}', '\u{10d}', '\u{e9}', '\u{119}', '\u{eb}',
'\u{117}', '\u{ed}', '\u{ee}', '\u{12b}', '\u{111}', '\u{146}', '\u{14d}', '\u{137}',
'\u{f4}', '\u{f5}', '\u{f6}', '\u{f7}', '\u{f8}', '\u{173}', '\u{fa}', '\u{fb}', '\u{fc}',
'\u{169}', '\u{16b}', '\u{2d9}',
];
pub const ISO_8859_5: &'static [char] = &[
'\u{0}', '\u{1}', '\u{2}', '\u{3}', '\u{4}', '\u{5}', '\u{6}', '\u{7}', '\u{8}', '\u{9}',
'\u{a}', '\u{b}', '\u{c}', '\u{d}', '\u{e}', '\u{f}', '\u{10}', '\u{11}', '\u{12}',
'\u{13}', '\u{14}', '\u{15}', '\u{16}', '\u{17}', '\u{18}', '\u{19}', '\u{1a}', '\u{1b}',
'\u{1c}', '\u{1d}', '\u{1e}', '\u{1f}', '\u{20}', '\u{21}', '\u{22}', '\u{23}', '\u{24}',
'\u{25}', '\u{26}', '\u{27}', '\u{28}', '\u{29}', '\u{2a}', '\u{2b}', '\u{2c}', '\u{2d}',
'\u{2e}', '\u{2f}', '\u{30}', '\u{31}', '\u{32}', '\u{33}', '\u{34}', '\u{35}', '\u{36}',
'\u{37}', '\u{38}', '\u{39}', '\u{3a}', '\u{3b}', '\u{3c}', '\u{3d}', '\u{3e}', '\u{3f}',
'\u{40}', '\u{41}', '\u{42}', '\u{43}', '\u{44}', '\u{45}', '\u{46}', '\u{47}', '\u{48}',
'\u{49}', '\u{4a}', '\u{4b}', '\u{4c}', '\u{4d}', '\u{4e}', '\u{4f}', '\u{50}', '\u{51}',
'\u{52}', '\u{53}', '\u{54}', '\u{55}', '\u{56}', '\u{57}', '\u{58}', '\u{59}', '\u{5a}',
'\u{5b}', '\u{5c}', '\u{5d}', '\u{5e}', '\u{5f}', '\u{60}', '\u{61}', '\u{62}', '\u{63}',
'\u{64}', '\u{65}', '\u{66}', '\u{67}', '\u{68}', '\u{69}', '\u{6a}', '\u{6b}', '\u{6c}',
'\u{6d}', '\u{6e}', '\u{6f}', '\u{70}', '\u{71}', '\u{72}', '\u{73}', '\u{74}', '\u{75}',
'\u{76}', '\u{77}', '\u{78}', '\u{79}', '\u{7a}', '\u{7b}', '\u{7c}', '\u{7d}', '\u{7e}',
'\u{7f}', '\u{80}', '\u{81}', '\u{82}', '\u{83}', '\u{84}', '\u{85}', '\u{86}', '\u{87}',
'\u{88}', '\u{89}', '\u{8a}', '\u{8b}', '\u{8c}', '\u{8d}', '\u{8e}', '\u{8f}', '\u{90}',
'\u{91}', '\u{92}', '\u{93}', '\u{94}', '\u{95}', '\u{96}', '\u{97}', '\u{98}', '\u{99}',
'\u{9a}', '\u{9b}', '\u{9c}', '\u{9d}', '\u{9e}', '\u{9f}', '\u{a0}', '\u{401}', '\u{402}',
'\u{403}', '\u{404}', '\u{405}', '\u{406}', '\u{407}', '\u{408}', '\u{409}', '\u{40a}',
'\u{40b}', '\u{40c}', '\u{ad}', '\u{40e}', '\u{40f}', '\u{410}', '\u{411}', '\u{412}',
'\u{413}', '\u{414}', '\u{415}', '\u{416}', '\u{417}', '\u{418}', '\u{419}', '\u{41a}',
'\u{41b}', '\u{41c}', '\u{41d}', '\u{41e}', '\u{41f}', '\u{420}', '\u{421}', '\u{422}',
'\u{423}', '\u{424}', '\u{425}', '\u{426}', '\u{427}', '\u{428}', '\u{429}', '\u{42a}',
'\u{42b}', '\u{42c}', '\u{42d}', '\u{42e}', '\u{42f}', '\u{430}', '\u{431}', '\u{432}',
'\u{433}', '\u{434}', '\u{435}', '\u{436}', '\u{437}', '\u{438}', '\u{439}', '\u{43a}',
'\u{43b}', '\u{43c}', '\u{43d}', '\u{43e}', '\u{43f}', '\u{440}', '\u{441}', '\u{442}',
'\u{443}', '\u{444}', '\u{445}', '\u{446}', '\u{447}', '\u{448}', '\u{449}', '\u{44a}',
'\u{44b}', '\u{44c}', '\u{44d}', '\u{44e}', '\u{44f}', '\u{2116}', '\u{451}', '\u{452}',
'\u{453}', '\u{454}', '\u{455}', '\u{456}', '\u{457}', '\u{458}', '\u{459}', '\u{45a}',
'\u{45b}', '\u{45c}', '\u{a7}', '\u{45e}', '\u{45f}',
];
pub const ISO_8859_6: &'static [char] = &[
'\u{0}', '\u{1}', '\u{2}', '\u{3}', '\u{4}', '\u{5}', '\u{6}', '\u{7}', '\u{8}', '\u{9}',
'\u{a}', '\u{b}', '\u{c}', '\u{d}', '\u{e}', '\u{f}', '\u{10}', '\u{11}', '\u{12}',
'\u{13}', '\u{14}', '\u{15}', '\u{16}', '\u{17}', '\u{18}', '\u{19}', '\u{1a}', '\u{1b}',
'\u{1c}', '\u{1d}', '\u{1e}', '\u{1f}', '\u{20}', '\u{21}', '\u{22}', '\u{23}', '\u{24}',
'\u{25}', '\u{26}', '\u{27}', '\u{28}', '\u{29}', '\u{2a}', '\u{2b}', '\u{2c}', '\u{2d}',
'\u{2e}', '\u{2f}', '\u{30}', '\u{31}', '\u{32}', '\u{33}', '\u{34}', '\u{35}', '\u{36}',
'\u{37}', '\u{38}', '\u{39}', '\u{3a}', '\u{3b}', '\u{3c}', '\u{3d}', '\u{3e}', '\u{3f}',
'\u{40}', '\u{41}', '\u{42}', '\u{43}', '\u{44}', '\u{45}', '\u{46}', '\u{47}', '\u{48}',
'\u{49}', '\u{4a}', '\u{4b}', '\u{4c}', '\u{4d}', '\u{4e}', '\u{4f}', '\u{50}', '\u{51}',
'\u{52}', '\u{53}', '\u{54}', '\u{55}', '\u{56}', '\u{57}', '\u{58}', '\u{59}', '\u{5a}',
'\u{5b}', '\u{5c}', '\u{5d}', '\u{5e}', '\u{5f}', '\u{60}', '\u{61}', '\u{62}', '\u{63}',
'\u{64}', '\u{65}', '\u{66}', '\u{67}', '\u{68}', '\u{69}', '\u{6a}', '\u{6b}', '\u{6c}',
'\u{6d}', '\u{6e}', '\u{6f}', '\u{70}', '\u{71}', '\u{72}', '\u{73}', '\u{74}', '\u{75}',
'\u{76}', '\u{77}', '\u{78}', '\u{79}', '\u{7a}', '\u{7b}', '\u{7c}', '\u{7d}', '\u{7e}',
'\u{7f}', '\u{80}', '\u{81}', '\u{82}', '\u{83}', '\u{84}', '\u{85}', '\u{86}', '\u{87}',
'\u{88}', '\u{89}', '\u{8a}', '\u{8b}', '\u{8c}', '\u{8d}', '\u{8e}', '\u{8f}', '\u{90}',
'\u{91}', '\u{92}', '\u{93}', '\u{94}', '\u{95}', '\u{96}', '\u{97}', '\u{98}', '\u{99}',
'\u{9a}', '\u{9b}', '\u{9c}', '\u{9d}', '\u{9e}', '\u{9f}', '\u{a0}', '\u{fffd}',
'\u{fffd}', '\u{fffd}', '\u{a4}', '\u{fffd}', '\u{fffd}', '\u{fffd}', '\u{fffd}',
'\u{fffd}', '\u{fffd}', '\u{fffd}', '\u{60c}', '\u{ad}', '\u{fffd}', '\u{fffd}',
'\u{fffd}', '\u{fffd}', '\u{fffd}', '\u{fffd}', '\u{fffd}', '\u{fffd}', '\u{fffd}',
'\u{fffd}', '\u{fffd}', '\u{fffd}', '\u{fffd}', '\u{61b}', '\u{fffd}', '\u{fffd}',
'\u{fffd}', '\u{61f}', '\u{fffd}', '\u{621}', '\u{622}', '\u{623}', '\u{624}', '\u{625}',
'\u{626}', '\u{627}', '\u{628}', '\u{629}', '\u{62a}', '\u{62b}', '\u{62c}', '\u{62d}',
'\u{62e}', '\u{62f}', '\u{630}', '\u{631}', '\u{632}', '\u{633}', '\u{634}', '\u{635}',
'\u{636}', '\u{637}', '\u{638}', '\u{639}', '\u{63a}', '\u{fffd}', '\u{fffd}', '\u{fffd}',
'\u{fffd}', '\u{fffd}', '\u{640}', '\u{641}', '\u{642}', '\u{643}', '\u{644}', '\u{645}',
'\u{646}', '\u{647}', '\u{648}', '\u{649}', '\u{64a}', '\u{64b}', '\u{64c}', '\u{64d}',
'\u{64e}', '\u{64f}', '\u{650}', '\u{651}', '\u{652}', '\u{fffd}', '\u{fffd}', '\u{fffd}',
'\u{fffd}', '\u{fffd}', '\u{fffd}', '\u{fffd}', '\u{fffd}', '\u{fffd}', '\u{fffd}',
'\u{fffd}', '\u{fffd}', '\u{fffd}',
];
pub const ISO_8859_7: &'static [char] = &[
'\u{0}', '\u{1}', '\u{2}', '\u{3}', '\u{4}', '\u{5}', '\u{6}', '\u{7}', '\u{8}', '\u{9}',
'\u{a}', '\u{b}', '\u{c}', '\u{d}', '\u{e}', '\u{f}', '\u{10}', '\u{11}', '\u{12}',
'\u{13}', '\u{14}', '\u{15}', '\u{16}', '\u{17}', '\u{18}', '\u{19}', '\u{1a}', '\u{1b}',
'\u{1c}', '\u{1d}', '\u{1e}', '\u{1f}', '\u{20}', '\u{21}', '\u{22}', '\u{23}', '\u{24}',
'\u{25}', '\u{26}', '\u{27}', '\u{28}', '\u{29}', '\u{2a}', '\u{2b}', '\u{2c}', '\u{2d}',
'\u{2e}', '\u{2f}', '\u{30}', '\u{31}', '\u{32}', '\u{33}', '\u{34}', '\u{35}', '\u{36}',
'\u{37}', '\u{38}', '\u{39}', '\u{3a}', '\u{3b}', '\u{3c}', '\u{3d}', '\u{3e}', '\u{3f}',
'\u{40}', '\u{41}', '\u{42}', '\u{43}', '\u{44}', '\u{45}', '\u{46}', '\u{47}', '\u{48}',
'\u{49}', '\u{4a}', '\u{4b}', '\u{4c}', '\u{4d}', '\u{4e}', '\u{4f}', '\u{50}', '\u{51}',
'\u{52}', '\u{53}', '\u{54}', '\u{55}', '\u{56}', '\u{57}', '\u{58}', '\u{59}', '\u{5a}',
'\u{5b}', '\u{5c}', '\u{5d}', '\u{5e}', '\u{5f}', '\u{60}', '\u{61}', '\u{62}', '\u{63}',
'\u{64}', '\u{65}', '\u{66}', '\u{67}', '\u{68}', '\u{69}', '\u{6a}', '\u{6b}', '\u{6c}',
'\u{6d}', '\u{6e}', '\u{6f}', '\u{70}', '\u{71}', '\u{72}', '\u{73}', '\u{74}', '\u{75}',
'\u{76}', '\u{77}', '\u{78}', '\u{79}', '\u{7a}', '\u{7b}', '\u{7c}', '\u{7d}', '\u{7e}',
'\u{7f}', '\u{80}', '\u{81}', '\u{82}', '\u{83}', '\u{84}', '\u{85}', '\u{86}', '\u{87}',
'\u{88}', '\u{89}', '\u{8a}', '\u{8b}', '\u{8c}', '\u{8d}', '\u{8e}', '\u{8f}', '\u{90}',
'\u{91}', '\u{92}', '\u{93}', '\u{94}', '\u{95}', '\u{96}', '\u{97}', '\u{98}', '\u{99}',
'\u{9a}', '\u{9b}', '\u{9c}', '\u{9d}', '\u{9e}', '\u{9f}', '\u{a0}', '\u{2018}',
'\u{2019}', '\u{a3}', '\u{fffd}', '\u{fffd}', '\u{a6}', '\u{a7}', '\u{a8}', '\u{a9}',
'\u{fffd}', '\u{ab}', '\u{ac}', '\u{ad}', '\u{fffd}', '\u{2015}', '\u{b0}', '\u{b1}',
'\u{b2}', '\u{b3}', '\u{384}', '\u{385}', '\u{386}', '\u{b7}', '\u{388}', '\u{389}',
'\u{38a}', '\u{bb}', '\u{38c}', '\u{bd}', '\u{38e}', '\u{38f}', '\u{390}', '\u{391}',
'\u{392}', '\u{393}', '\u{394}', '\u{395}', '\u{396}', '\u{397}', '\u{398}', '\u{399}',
'\u{39a}', '\u{39b}', '\u{39c}', '\u{39d}', '\u{39e}', '\u{39f}', '\u{3a0}', '\u{3a1}',
'\u{fffd}', '\u{3a3}', '\u{3a4}', '\u{3a5}', '\u{3a6}', '\u{3a7}', '\u{3a8}', '\u{3a9}',
'\u{3aa}', '\u{3ab}', '\u{3ac}', '\u{3ad}', '\u{3ae}', '\u{3af}', '\u{3b0}', '\u{3b1}',
'\u{3b2}', '\u{3b3}', '\u{3b4}', '\u{3b5}', '\u{3b6}', '\u{3b7}', '\u{3b8}', '\u{3b9}',
'\u{3ba}', '\u{3bb}', '\u{3bc}', '\u{3bd}', '\u{3be}', '\u{3bf}', '\u{3c0}', '\u{3c1}',
'\u{3c2}', '\u{3c3}', '\u{3c4}', '\u{3c5}', '\u{3c6}', '\u{3c7}', '\u{3c8}', '\u{3c9}',
'\u{3ca}', '\u{3cb}', '\u{3cc}', '\u{3cd}', '\u{3ce}', '\u{fffd}',
];
pub const ISO_8859_8: &'static [char] = &[
'\u{0}', '\u{1}', '\u{2}', '\u{3}', '\u{4}', '\u{5}', '\u{6}', '\u{7}', '\u{8}', '\u{9}',
'\u{a}', '\u{b}', '\u{c}', '\u{d}', '\u{e}', '\u{f}', '\u{10}', '\u{11}', '\u{12}',
'\u{13}', '\u{14}', '\u{15}', '\u{16}', '\u{17}', '\u{18}', '\u{19}', '\u{1a}', '\u{1b}',
'\u{1c}', '\u{1d}', '\u{1e}', '\u{1f}', '\u{20}', '\u{21}', '\u{22}', '\u{23}', '\u{24}',
'\u{25}', '\u{26}', '\u{27}', '\u{28}', '\u{29}', '\u{2a}', '\u{2b}', '\u{2c}', '\u{2d}',
'\u{2e}', '\u{2f}', '\u{30}', '\u{31}', '\u{32}', '\u{33}', '\u{34}', '\u{35}', '\u{36}',
'\u{37}', '\u{38}', '\u{39}', '\u{3a}', '\u{3b}', '\u{3c}', '\u{3d}', '\u{3e}', '\u{3f}',
'\u{40}', '\u{41}', '\u{42}', '\u{43}', '\u{44}', '\u{45}', '\u{46}', '\u{47}', '\u{48}',
'\u{49}', '\u{4a}', '\u{4b}', '\u{4c}', '\u{4d}', '\u{4e}', '\u{4f}', '\u{50}', '\u{51}',
'\u{52}', '\u{53}', '\u{54}', '\u{55}', '\u{56}', '\u{57}', '\u{58}', '\u{59}', '\u{5a}',
'\u{5b}', '\u{5c}', '\u{5d}', '\u{5e}', '\u{5f}', '\u{60}', '\u{61}', '\u{62}', '\u{63}',
'\u{64}', '\u{65}', '\u{66}', '\u{67}', '\u{68}', '\u{69}', '\u{6a}', '\u{6b}', '\u{6c}',
'\u{6d}', '\u{6e}', '\u{6f}', '\u{70}', '\u{71}', '\u{72}', '\u{73}', '\u{74}', '\u{75}',
'\u{76}', '\u{77}', '\u{78}', '\u{79}', '\u{7a}', '\u{7b}', '\u{7c}', '\u{7d}', '\u{7e}',
'\u{7f}', '\u{80}', '\u{81}', '\u{82}', '\u{83}', '\u{84}', '\u{85}', '\u{86}', '\u{87}',
'\u{88}', '\u{89}', '\u{8a}', '\u{8b}', '\u{8c}', '\u{8d}', '\u{8e}', '\u{8f}', '\u{90}',
'\u{91}', '\u{92}', '\u{93}', '\u{94}', '\u{95}', '\u{96}', '\u{97}', '\u{98}', '\u{99}',
'\u{9a}', '\u{9b}', '\u{9c}', '\u{9d}', '\u{9e}', '\u{9f}', '\u{a0}', '\u{fffd}', '\u{a2}',
'\u{a3}', '\u{a4}', '\u{a5}', '\u{a6}', '\u{a7}', '\u{a8}', '\u{a9}', '\u{d7}', '\u{ab}',
'\u{ac}', '\u{ad}', '\u{ae}', '\u{af}', '\u{b0}', '\u{b1}', '\u{b2}', '\u{b3}', '\u{b4}',
'\u{b5}', '\u{b6}', '\u{b7}', '\u{b8}', '\u{b9}', '\u{f7}', '\u{bb}', '\u{bc}', '\u{bd}',
'\u{be}', '\u{fffd}', '\u{fffd}', '\u{fffd}', '\u{fffd}', '\u{fffd}', '\u{fffd}',
'\u{fffd}', '\u{fffd}', '\u{fffd}', '\u{fffd}', '\u{fffd}', '\u{fffd}', '\u{fffd}',
'\u{fffd}', '\u{fffd}', '\u{fffd}', '\u{fffd}', '\u{fffd}', '\u{fffd}', '\u{fffd}',
'\u{fffd}', '\u{fffd}', '\u{fffd}', '\u{fffd}', '\u{fffd}', '\u{fffd}', '\u{fffd}',
'\u{fffd}', '\u{fffd}', '\u{fffd}', '\u{fffd}', '\u{fffd}', '\u{2017}', '\u{5d0}',
'\u{5d1}', '\u{5d2}', '\u{5d3}', '\u{5d4}', '\u{5d5}', '\u{5d6}', '\u{5d7}', '\u{5d8}',
'\u{5d9}', '\u{5da}', '\u{5db}', '\u{5dc}', '\u{5dd}', '\u{5de}', '\u{5df}', '\u{5e0}',
'\u{5e1}', '\u{5e2}', '\u{5e3}', '\u{5e4}', '\u{5e5}', '\u{5e6}', '\u{5e7}', '\u{5e8}',
'\u{5e9}', '\u{5ea}', '\u{fffd}', '\u{fffd}', '\u{200e}', '\u{200f}', '\u{fffd}',
];
pub const ISO_8859_9: &'static [char] = &[
'\u{0}', '\u{1}', '\u{2}', '\u{3}', '\u{4}', '\u{5}', '\u{6}', '\u{7}', '\u{8}', '\u{9}',
'\u{a}', '\u{b}', '\u{c}', '\u{d}', '\u{e}', '\u{f}', '\u{10}', '\u{11}', '\u{12}',
'\u{13}', '\u{14}', '\u{15}', '\u{16}', '\u{17}', '\u{18}', '\u{19}', '\u{1a}', '\u{1b}',
'\u{1c}', '\u{1d}', '\u{1e}', '\u{1f}', '\u{20}', '\u{21}', '\u{22}', '\u{23}', '\u{24}',
'\u{25}', '\u{26}', '\u{27}', '\u{28}', '\u{29}', '\u{2a}', '\u{2b}', '\u{2c}', '\u{2d}',
'\u{2e}', '\u{2f}', '\u{30}', '\u{31}', '\u{32}', '\u{33}', '\u{34}', '\u{35}', '\u{36}',
'\u{37}', '\u{38}', '\u{39}', '\u{3a}', '\u{3b}', '\u{3c}', '\u{3d}', '\u{3e}', '\u{3f}',
'\u{40}', '\u{41}', '\u{42}', '\u{43}', '\u{44}', '\u{45}', '\u{46}', '\u{47}', '\u{48}',
'\u{49}', '\u{4a}', '\u{4b}', '\u{4c}', '\u{4d}', '\u{4e}', '\u{4f}', '\u{50}', '\u{51}',
'\u{52}', '\u{53}', '\u{54}', '\u{55}', '\u{56}', '\u{57}', '\u{58}', '\u{59}', '\u{5a}',
'\u{5b}', '\u{5c}', '\u{5d}', '\u{5e}', '\u{5f}', '\u{60}', '\u{61}', '\u{62}', '\u{63}',
'\u{64}', '\u{65}', '\u{66}', '\u{67}', '\u{68}', '\u{69}', '\u{6a}', '\u{6b}', '\u{6c}',
'\u{6d}', '\u{6e}', '\u{6f}', '\u{70}', '\u{71}', '\u{72}', '\u{73}', '\u{74}', '\u{75}',
'\u{76}', '\u{77}', '\u{78}', '\u{79}', '\u{7a}', '\u{7b}', '\u{7c}', '\u{7d}', '\u{7e}',
'\u{7f}', '\u{80}', '\u{81}', '\u{82}', '\u{83}', '\u{84}', '\u{85}', '\u{86}', '\u{87}',
'\u{88}', '\u{89}', '\u{8a}', '\u{8b}', '\u{8c}', '\u{8d}', '\u{8e}', '\u{8f}', '\u{90}',
'\u{91}', '\u{92}', '\u{93}', '\u{94}', '\u{95}', '\u{96}', '\u{97}', '\u{98}', '\u{99}',
'\u{9a}', '\u{9b}', '\u{9c}', '\u{9d}', '\u{9e}', '\u{9f}', '\u{a0}', '\u{a1}', '\u{a2}',
'\u{a3}', '\u{a4}', '\u{a5}', '\u{a6}', '\u{a7}', '\u{a8}', '\u{a9}', '\u{aa}', '\u{ab}',
'\u{ac}', '\u{ad}', '\u{ae}', '\u{af}', '\u{b0}', '\u{b1}', '\u{b2}', '\u{b3}', '\u{b4}',
'\u{b5}', '\u{b6}', '\u{b7}', '\u{b8}', '\u{b9}', '\u{ba}', '\u{bb}', '\u{bc}', '\u{bd}',
'\u{be}', '\u{bf}', '\u{c0}', '\u{c1}', '\u{c2}', '\u{c3}', '\u{c4}', '\u{c5}', '\u{c6}',
'\u{c7}', '\u{c8}', '\u{c9}', '\u{ca}', '\u{cb}', '\u{cc}', '\u{cd}', '\u{ce}', '\u{cf}',
'\u{11e}', '\u{d1}', '\u{d2}', '\u{d3}', '\u{d4}', '\u{d5}', '\u{d6}', '\u{d7}', '\u{d8}',
'\u{d9}', '\u{da}', '\u{db}', '\u{dc}', '\u{130}', '\u{15e}', '\u{df}', '\u{e0}', '\u{e1}',
'\u{e2}', '\u{e3}', '\u{e4}', '\u{e5}', '\u{e6}', '\u{e7}', '\u{e8}', '\u{e9}', '\u{ea}',
'\u{eb}', '\u{ec}', '\u{ed}', '\u{ee}', '\u{ef}', '\u{11f}', '\u{f1}', '\u{f2}', '\u{f3}',
'\u{f4}', '\u{f5}', '\u{f6}', '\u{f7}', '\u{f8}', '\u{f9}', '\u{fa}', '\u{fb}', '\u{fc}',
'\u{131}', '\u{15f}', '\u{ff}',
];
pub const ISO_8859_10: &'static [char] = &[
'\u{0}', '\u{1}', '\u{2}', '\u{3}', '\u{4}', '\u{5}', '\u{6}', '\u{7}', '\u{8}', '\u{9}',
'\u{a}', '\u{b}', '\u{c}', '\u{d}', '\u{e}', '\u{f}', '\u{10}', '\u{11}', '\u{12}',
'\u{13}', '\u{14}', '\u{15}', '\u{16}', '\u{17}', '\u{18}', '\u{19}', '\u{1a}', '\u{1b}',
'\u{1c}', '\u{1d}', '\u{1e}', '\u{1f}', '\u{20}', '\u{21}', '\u{22}', '\u{23}', '\u{24}',
'\u{25}', '\u{26}', '\u{27}', '\u{28}', '\u{29}', '\u{2a}', '\u{2b}', '\u{2c}', '\u{2d}',
'\u{2e}', '\u{2f}', '\u{30}', '\u{31}', '\u{32}', '\u{33}', '\u{34}', '\u{35}', '\u{36}',
'\u{37}', '\u{38}', '\u{39}', '\u{3a}', '\u{3b}', '\u{3c}', '\u{3d}', '\u{3e}', '\u{3f}',
'\u{40}', '\u{41}', '\u{42}', '\u{43}', '\u{44}', '\u{45}', '\u{46}', '\u{47}', '\u{48}',
'\u{49}', '\u{4a}', '\u{4b}', '\u{4c}', '\u{4d}', '\u{4e}', '\u{4f}', '\u{50}', '\u{51}',
'\u{52}', '\u{53}', '\u{54}', '\u{55}', '\u{56}', '\u{57}', '\u{58}', '\u{59}', '\u{5a}',
'\u{5b}', '\u{5c}', '\u{5d}', '\u{5e}', '\u{5f}', '\u{60}', '\u{61}', '\u{62}', '\u{63}',
'\u{64}', '\u{65}', '\u{66}', '\u{67}', '\u{68}', '\u{69}', '\u{6a}', '\u{6b}', '\u{6c}',
'\u{6d}', '\u{6e}', '\u{6f}', '\u{70}', '\u{71}', '\u{72}', '\u{73}', '\u{74}', '\u{75}',
'\u{76}', '\u{77}', '\u{78}', '\u{79}', '\u{7a}', '\u{7b}', '\u{7c}', '\u{7d}', '\u{7e}',
'\u{7f}', '\u{80}', '\u{81}', '\u{82}', '\u{83}', '\u{84}', '\u{85}', '\u{86}', '\u{87}',
'\u{88}', '\u{89}', '\u{8a}', '\u{8b}', '\u{8c}', '\u{8d}', '\u{8e}', '\u{8f}', '\u{90}',
'\u{91}', '\u{92}', '\u{93}', '\u{94}', '\u{95}', '\u{96}', '\u{97}', '\u{98}', '\u{99}',
'\u{9a}', '\u{9b}', '\u{9c}', '\u{9d}', '\u{9e}', '\u{9f}', '\u{a0}', '\u{104}', '\u{112}',
'\u{122}', '\u{12a}', '\u{128}', '\u{136}', '\u{a7}', '\u{13b}', '\u{110}', '\u{160}',
'\u{166}', '\u{17d}', '\u{ad}', '\u{16a}', '\u{14a}', '\u{b0}', '\u{105}', '\u{113}',
'\u{123}', '\u{12b}', '\u{129}', '\u{137}', '\u{b7}', '\u{13c}', '\u{111}', '\u{161}',
'\u{167}', '\u{17e}', '\u{2015}', '\u{16b}', '\u{14b}', '\u{100}', '\u{c1}', '\u{c2}',
'\u{c3}', '\u{c4}', '\u{c5}', '\u{c6}', '\u{12e}', '\u{10c}', '\u{c9}', '\u{118}',
'\u{cb}', '\u{116}', '\u{cd}', '\u{ce}', '\u{cf}', '\u{d0}', '\u{145}', '\u{14c}',
'\u{d3}', '\u{d4}', '\u{d5}', '\u{d6}', '\u{168}', '\u{d8}', '\u{172}', '\u{da}', '\u{db}',
'\u{dc}', '\u{dd}', '\u{de}', '\u{df}', '\u{101}', '\u{e1}', '\u{e2}', '\u{e3}', '\u{e4}',
'\u{e5}', '\u{e6}', '\u{12f}', '\u{10d}', '\u{e9}', '\u{119}', '\u{eb}', '\u{117}',
'\u{ed}', '\u{ee}', '\u{ef}', '\u{f0}', '\u{146}', '\u{14d}', '\u{f3}', '\u{f4}', '\u{f5}',
'\u{f6}', '\u{169}', '\u{f8}', '\u{173}', '\u{fa}', '\u{fb}', '\u{fc}', '\u{fd}', '\u{fe}',
'\u{138}',
];
pub const ISO_8859_13: &'static [char] = &[
'\u{0}', '\u{1}', '\u{2}', '\u{3}', '\u{4}', '\u{5}', '\u{6}', '\u{7}', '\u{8}', '\u{9}',
'\u{a}', '\u{b}', '\u{c}', '\u{d}', '\u{e}', '\u{f}', '\u{10}', '\u{11}', '\u{12}',
'\u{13}', '\u{14}', '\u{15}', '\u{16}', '\u{17}', '\u{18}', '\u{19}', '\u{1a}', '\u{1b}',
'\u{1c}', '\u{1d}', '\u{1e}', '\u{1f}', '\u{20}', '\u{21}', '\u{22}', '\u{23}', '\u{24}',
'\u{25}', '\u{26}', '\u{27}', '\u{28}', '\u{29}', '\u{2a}', '\u{2b}', '\u{2c}', '\u{2d}',
'\u{2e}', '\u{2f}', '\u{30}', '\u{31}', '\u{32}', '\u{33}', '\u{34}', '\u{35}', '\u{36}',
'\u{37}', '\u{38}', '\u{39}', '\u{3a}', '\u{3b}', '\u{3c}', '\u{3d}', '\u{3e}', '\u{3f}',
'\u{40}', '\u{41}', '\u{42}', '\u{43}', '\u{44}', '\u{45}', '\u{46}', '\u{47}', '\u{48}',
'\u{49}', '\u{4a}', '\u{4b}', '\u{4c}', '\u{4d}', '\u{4e}', '\u{4f}', '\u{50}', '\u{51}',
'\u{52}', '\u{53}', '\u{54}', '\u{55}', '\u{56}', '\u{57}', '\u{58}', '\u{59}', '\u{5a}',
'\u{5b}', '\u{5c}', '\u{5d}', '\u{5e}', '\u{5f}', '\u{60}', '\u{61}', '\u{62}', '\u{63}',
'\u{64}', '\u{65}', '\u{66}', '\u{67}', '\u{68}', '\u{69}', '\u{6a}', '\u{6b}', '\u{6c}',
'\u{6d}', '\u{6e}', '\u{6f}', '\u{70}', '\u{71}', '\u{72}', '\u{73}', '\u{74}', '\u{75}',
'\u{76}', '\u{77}', '\u{78}', '\u{79}', '\u{7a}', '\u{7b}', '\u{7c}', '\u{7d}', '\u{7e}',
'\u{7f}', '\u{80}', '\u{81}', '\u{82}', '\u{83}', '\u{84}', '\u{85}', '\u{86}', '\u{87}',
'\u{88}', '\u{89}', '\u{8a}', '\u{8b}', '\u{8c}', '\u{8d}', '\u{8e}', '\u{8f}', '\u{90}',
'\u{91}', '\u{92}', '\u{93}', '\u{94}', '\u{95}', '\u{96}', '\u{97}', '\u{98}', '\u{99}',
'\u{9a}', '\u{9b}', '\u{9c}', '\u{9d}', '\u{9e}', '\u{9f}', '\u{a0}', '\u{201d}', '\u{a2}',
'\u{a3}', '\u{a4}', '\u{201e}', '\u{a6}', '\u{a7}', '\u{d8}', '\u{a9}', '\u{156}',
'\u{ab}', '\u{ac}', '\u{ad}', '\u{ae}', '\u{c6}', '\u{b0}', '\u{b1}', '\u{b2}', '\u{b3}',
'\u{201c}', '\u{b5}', '\u{b6}', '\u{b7}', '\u{f8}', '\u{b9}', '\u{157}', '\u{bb}',
'\u{bc}', '\u{bd}', '\u{be}', '\u{e6}', '\u{104}', '\u{12e}', '\u{100}', '\u{106}',
'\u{c4}', '\u{c5}', '\u{118}', '\u{112}', '\u{10c}', '\u{c9}', '\u{179}', '\u{116}',
'\u{122}', '\u{136}', '\u{12a}', '\u{13b}', '\u{160}', '\u{143}', '\u{145}', '\u{d3}',
'\u{14c}', '\u{d5}', '\u{d6}', '\u{d7}', '\u{172}', '\u{141}', '\u{15a}', '\u{16a}',
'\u{dc}', '\u{17b}', '\u{17d}', '\u{df}', '\u{105}', '\u{12f}', '\u{101}', '\u{107}',
'\u{e4}', '\u{e5}', '\u{119}', '\u{113}', '\u{10d}', '\u{e9}', '\u{17a}', '\u{117}',
'\u{123}', '\u{137}', '\u{12b}', '\u{13c}', '\u{161}', '\u{144}', '\u{146}', '\u{f3}',
'\u{14d}', '\u{f5}', '\u{f6}', '\u{f7}', '\u{173}', '\u{142}', '\u{15b}', '\u{16b}',
'\u{fc}', '\u{17c}', '\u{17e}', '\u{2019}',
];
pub const ISO_8859_14: &'static [char] = &[
'\u{0}', '\u{1}', '\u{2}', '\u{3}', '\u{4}', '\u{5}', '\u{6}', '\u{7}', '\u{8}', '\u{9}',
'\u{a}', '\u{b}', '\u{c}', '\u{d}', '\u{e}', '\u{f}', '\u{10}', '\u{11}', '\u{12}',
'\u{13}', '\u{14}', '\u{15}', '\u{16}', '\u{17}', '\u{18}', '\u{19}', '\u{1a}', '\u{1b}',
'\u{1c}', '\u{1d}', '\u{1e}', '\u{1f}', '\u{20}', '\u{21}', '\u{22}', '\u{23}', '\u{24}',
'\u{25}', '\u{26}', '\u{27}', '\u{28}', '\u{29}', '\u{2a}', '\u{2b}', '\u{2c}', '\u{2d}',
'\u{2e}', '\u{2f}', '\u{30}', '\u{31}', '\u{32}', '\u{33}', '\u{34}', '\u{35}', '\u{36}',
'\u{37}', '\u{38}', '\u{39}', '\u{3a}', '\u{3b}', '\u{3c}', '\u{3d}', '\u{3e}', '\u{3f}',
'\u{40}', '\u{41}', '\u{42}', '\u{43}', '\u{44}', '\u{45}', '\u{46}', '\u{47}', '\u{48}',
'\u{49}', '\u{4a}', '\u{4b}', '\u{4c}', '\u{4d}', '\u{4e}', '\u{4f}', '\u{50}', '\u{51}',
'\u{52}', '\u{53}', '\u{54}', '\u{55}', '\u{56}', '\u{57}', '\u{58}', '\u{59}', '\u{5a}',
'\u{5b}', '\u{5c}', '\u{5d}', '\u{5e}', '\u{5f}', '\u{60}', '\u{61}', '\u{62}', '\u{63}',
'\u{64}', '\u{65}', '\u{66}', '\u{67}', '\u{68}', '\u{69}', '\u{6a}', '\u{6b}', '\u{6c}',
'\u{6d}', '\u{6e}', '\u{6f}', '\u{70}', '\u{71}', '\u{72}', '\u{73}', '\u{74}', '\u{75}',
'\u{76}', '\u{77}', '\u{78}', '\u{79}', '\u{7a}', '\u{7b}', '\u{7c}', '\u{7d}', '\u{7e}',
'\u{7f}', '\u{80}', '\u{81}', '\u{82}', '\u{83}', '\u{84}', '\u{85}', '\u{86}', '\u{87}',
'\u{88}', '\u{89}', '\u{8a}', '\u{8b}', '\u{8c}', '\u{8d}', '\u{8e}', '\u{8f}', '\u{90}',
'\u{91}', '\u{92}', '\u{93}', '\u{94}', '\u{95}', '\u{96}', '\u{97}', '\u{98}', '\u{99}',
'\u{9a}', '\u{9b}', '\u{9c}', '\u{9d}', '\u{9e}', '\u{9f}', '\u{a0}', '\u{1e02}',
'\u{1e03}', '\u{a3}', '\u{10a}', '\u{10b}', '\u{1e0a}', '\u{a7}', '\u{1e80}', '\u{a9}',
'\u{1e82}', '\u{1e0b}', '\u{1ef2}', '\u{ad}', '\u{ae}', '\u{178}', '\u{1e1e}', '\u{1e1f}',
'\u{120}', '\u{121}', '\u{1e40}', '\u{1e41}', '\u{b6}', '\u{1e56}', '\u{1e81}', '\u{1e57}',
'\u{1e83}', '\u{1e60}', '\u{1ef3}', '\u{1e84}', '\u{1e85}', '\u{1e61}', '\u{c0}', '\u{c1}',
'\u{c2}', '\u{c3}', '\u{c4}', '\u{c5}', '\u{c6}', '\u{c7}', '\u{c8}', '\u{c9}', '\u{ca}',
'\u{cb}', '\u{cc}', '\u{cd}', '\u{ce}', '\u{cf}', '\u{174}', '\u{d1}', '\u{d2}', '\u{d3}',
'\u{d4}', '\u{d5}', '\u{d6}', '\u{1e6a}', '\u{d8}', '\u{d9}', '\u{da}', '\u{db}', '\u{dc}',
'\u{dd}', '\u{176}', '\u{df}', '\u{e0}', '\u{e1}', '\u{e2}', '\u{e3}', '\u{e4}', '\u{e5}',
'\u{e6}', '\u{e7}', '\u{e8}', '\u{e9}', '\u{ea}', '\u{eb}', '\u{ec}', '\u{ed}', '\u{ee}',
'\u{ef}', '\u{175}', '\u{f1}', '\u{f2}', '\u{f3}', '\u{f4}', '\u{f5}', '\u{f6}',
'\u{1e6b}', '\u{f8}', '\u{f9}', '\u{fa}', '\u{fb}', '\u{fc}', '\u{fd}', '\u{177}',
'\u{ff}',
];
pub const ISO_8859_15: &'static [char] = &[
'\u{0}', '\u{1}', '\u{2}', '\u{3}', '\u{4}', '\u{5}', '\u{6}', '\u{7}', '\u{8}', '\u{9}',
'\u{a}', '\u{b}', '\u{c}', '\u{d}', '\u{e}', '\u{f}', '\u{10}', '\u{11}', '\u{12}',
'\u{13}', '\u{14}', '\u{15}', '\u{16}', '\u{17}', '\u{18}', '\u{19}', '\u{1a}', '\u{1b}',
'\u{1c}', '\u{1d}', '\u{1e}', '\u{1f}', '\u{20}', '\u{21}', '\u{22}', '\u{23}', '\u{24}',
'\u{25}', '\u{26}', '\u{27}', '\u{28}', '\u{29}', '\u{2a}', '\u{2b}', '\u{2c}', '\u{2d}',
'\u{2e}', '\u{2f}', '\u{30}', '\u{31}', '\u{32}', '\u{33}', '\u{34}', '\u{35}', '\u{36}',
'\u{37}', '\u{38}', '\u{39}', '\u{3a}', '\u{3b}', '\u{3c}', '\u{3d}', '\u{3e}', '\u{3f}',
'\u{40}', '\u{41}', '\u{42}', '\u{43}', '\u{44}', '\u{45}', '\u{46}', '\u{47}', '\u{48}',
'\u{49}', '\u{4a}', '\u{4b}', '\u{4c}', '\u{4d}', '\u{4e}', '\u{4f}', '\u{50}', '\u{51}',
'\u{52}', '\u{53}', '\u{54}', '\u{55}', '\u{56}', '\u{57}', '\u{58}', '\u{59}', '\u{5a}',
'\u{5b}', '\u{5c}', '\u{5d}', '\u{5e}', '\u{5f}', '\u{60}', '\u{61}', '\u{62}', '\u{63}',
'\u{64}', '\u{65}', '\u{66}', '\u{67}', '\u{68}', '\u{69}', '\u{6a}', '\u{6b}', '\u{6c}',
'\u{6d}', '\u{6e}', '\u{6f}', '\u{70}', '\u{71}', '\u{72}', '\u{73}', '\u{74}', '\u{75}',
'\u{76}', '\u{77}', '\u{78}', '\u{79}', '\u{7a}', '\u{7b}', '\u{7c}', '\u{7d}', '\u{7e}',
'\u{7f}', '\u{80}', '\u{81}', '\u{82}', '\u{83}', '\u{84}', '\u{85}', '\u{86}', '\u{87}',
'\u{88}', '\u{89}', '\u{8a}', '\u{8b}', '\u{8c}', '\u{8d}', '\u{8e}', '\u{8f}', '\u{90}',
'\u{91}', '\u{92}', '\u{93}', '\u{94}', '\u{95}', '\u{96}', '\u{97}', '\u{98}', '\u{99}',
'\u{9a}', '\u{9b}', '\u{9c}', '\u{9d}', '\u{9e}', '\u{9f}', '\u{a0}', '\u{a1}', '\u{a2}',
'\u{a3}', '\u{20ac}', '\u{a5}', '\u{160}', '\u{a7}', '\u{161}', '\u{a9}', '\u{aa}',
'\u{ab}', '\u{ac}', '\u{ad}', '\u{ae}', '\u{af}', '\u{b0}', '\u{b1}', '\u{b2}', '\u{b3}',
'\u{17d}', '\u{b5}', '\u{b6}', '\u{b7}', '\u{17e}', '\u{b9}', '\u{ba}', '\u{bb}',
'\u{152}', '\u{153}', '\u{178}', '\u{bf}', '\u{c0}', '\u{c1}', '\u{c2}', '\u{c3}',
'\u{c4}', '\u{c5}', '\u{c6}', '\u{c7}', '\u{c8}', '\u{c9}', '\u{ca}', '\u{cb}', '\u{cc}',
'\u{cd}', '\u{ce}', '\u{cf}', '\u{d0}', '\u{d1}', '\u{d2}', '\u{d3}', '\u{d4}', '\u{d5}',
'\u{d6}', '\u{d7}', '\u{d8}', '\u{d9}', '\u{da}', '\u{db}', '\u{dc}', '\u{dd}', '\u{de}',
'\u{df}', '\u{e0}', '\u{e1}', '\u{e2}', '\u{e3}', '\u{e4}', '\u{e5}', '\u{e6}', '\u{e7}',
'\u{e8}', '\u{e9}', '\u{ea}', '\u{eb}', '\u{ec}', '\u{ed}', '\u{ee}', '\u{ef}', '\u{f0}',
'\u{f1}', '\u{f2}', '\u{f3}', '\u{f4}', '\u{f5}', '\u{f6}', '\u{f7}', '\u{f8}', '\u{f9}',
'\u{fa}', '\u{fb}', '\u{fc}', '\u{fd}', '\u{fe}', '\u{ff}',
];
pub const ISO_8859_16: &'static [char] = &[
'\u{0}', '\u{1}', '\u{2}', '\u{3}', '\u{4}', '\u{5}', '\u{6}', '\u{7}', '\u{8}', '\u{9}',
'\u{a}', '\u{b}', '\u{c}', '\u{d}', '\u{e}', '\u{f}', '\u{10}', '\u{11}', '\u{12}',
'\u{13}', '\u{14}', '\u{15}', '\u{16}', '\u{17}', '\u{18}', '\u{19}', '\u{1a}', '\u{1b}',
'\u{1c}', '\u{1d}', '\u{1e}', '\u{1f}', '\u{20}', '\u{21}', '\u{22}', '\u{23}', '\u{24}',
'\u{25}', '\u{26}', '\u{27}', '\u{28}', '\u{29}', '\u{2a}', '\u{2b}', '\u{2c}', '\u{2d}',
'\u{2e}', '\u{2f}', '\u{30}', '\u{31}', '\u{32}', '\u{33}', '\u{34}', '\u{35}', '\u{36}',
'\u{37}', '\u{38}', '\u{39}', '\u{3a}', '\u{3b}', '\u{3c}', '\u{3d}', '\u{3e}', '\u{3f}',
'\u{40}', '\u{41}', '\u{42}', '\u{43}', '\u{44}', '\u{45}', '\u{46}', '\u{47}', '\u{48}',
'\u{49}', '\u{4a}', '\u{4b}', '\u{4c}', '\u{4d}', '\u{4e}', '\u{4f}', '\u{50}', '\u{51}',
'\u{52}', '\u{53}', '\u{54}', '\u{55}', '\u{56}', '\u{57}', '\u{58}', '\u{59}', '\u{5a}',
'\u{5b}', '\u{5c}', '\u{5d}', '\u{5e}', '\u{5f}', '\u{60}', '\u{61}', '\u{62}', '\u{63}',
'\u{64}', '\u{65}', '\u{66}', '\u{67}', '\u{68}', '\u{69}', '\u{6a}', '\u{6b}', '\u{6c}',
'\u{6d}', '\u{6e}', '\u{6f}', '\u{70}', '\u{71}', '\u{72}', '\u{73}', '\u{74}', '\u{75}',
'\u{76}', '\u{77}', '\u{78}', '\u{79}', '\u{7a}', '\u{7b}', '\u{7c}', '\u{7d}', '\u{7e}',
'\u{7f}', '\u{80}', '\u{81}', '\u{82}', '\u{83}', '\u{84}', '\u{85}', '\u{86}', '\u{87}',
'\u{88}', '\u{89}', '\u{8a}', '\u{8b}', '\u{8c}', '\u{8d}', '\u{8e}', '\u{8f}', '\u{90}',
'\u{91}', '\u{92}', '\u{93}', '\u{94}', '\u{95}', '\u{96}', '\u{97}', '\u{98}', '\u{99}',
'\u{9a}', '\u{9b}', '\u{9c}', '\u{9d}', '\u{9e}', '\u{9f}', '\u{a0}', '\u{104}', '\u{105}',
'\u{141}', '\u{20ac}', '\u{ab}', '\u{160}', '\u{a7}', '\u{161}', '\u{a9}', '\u{218}',
'\u{201e}', '\u{179}', '\u{ad}', '\u{17a}', '\u{17b}', '\u{b0}', '\u{b1}', '\u{10c}',
'\u{142}', '\u{17d}', '\u{201d}', '\u{b6}', '\u{b7}', '\u{17e}', '\u{10d}', '\u{219}',
'\u{bb}', '\u{152}', '\u{153}', '\u{178}', '\u{17c}', '\u{c0}', '\u{c1}', '\u{c2}',
'\u{102}', '\u{c4}', '\u{106}', '\u{c6}', '\u{c7}', '\u{c8}', '\u{c9}', '\u{ca}', '\u{cb}',
'\u{cc}', '\u{cd}', '\u{ce}', '\u{cf}', '\u{110}', '\u{143}', '\u{d2}', '\u{d3}', '\u{d4}',
'\u{150}', '\u{d6}', '\u{15a}', '\u{170}', '\u{d9}', '\u{da}', '\u{db}', '\u{dc}',
'\u{118}', '\u{21a}', '\u{df}', '\u{e0}', '\u{e1}', '\u{e2}', '\u{103}', '\u{e4}',
'\u{107}', '\u{e6}', '\u{e7}', '\u{e8}', '\u{e9}', '\u{ea}', '\u{eb}', '\u{ec}', '\u{ed}',
'\u{ee}', '\u{ef}', '\u{111}', '\u{144}', '\u{f2}', '\u{f3}', '\u{f4}', '\u{151}',
'\u{f6}', '\u{15b}', '\u{171}', '\u{f9}', '\u{fa}', '\u{fb}', '\u{fc}', '\u{119}',
'\u{21b}', '\u{ff}',
];
}
+14
View File
@@ -0,0 +1,14 @@
pub mod quoted_printable;
pub mod base64;
pub mod charsets;
pub enum DecoderResult<'x> {
Byte(u8),
ByteArray(&'x [u8]),
NeedData,
Error
}
pub trait Decoder {
fn ingest(&mut self, ch: u8) -> DecoderResult;
}
+182
View File
@@ -0,0 +1,182 @@
use super::{Decoder, DecoderResult};
enum QuotedPrintableState {
None,
Eq,
Hex1,
}
pub struct QuotedPrintableDecoder {
state: QuotedPrintableState,
hex_1: i8,
}
impl QuotedPrintableDecoder {
pub fn new() -> QuotedPrintableDecoder {
QuotedPrintableDecoder {
state: QuotedPrintableState::None,
hex_1: 0,
}
}
}
impl Decoder for QuotedPrintableDecoder {
fn ingest(&mut self, ch: u8) -> DecoderResult {
match ch {
b'=' => {
// =
if let QuotedPrintableState::None = self.state {
self.state = QuotedPrintableState::Eq;
} else {
return DecoderResult::Error;
}
}
b'\n' => {
// \n
match self.state {
QuotedPrintableState::Eq => {
self.state = QuotedPrintableState::None;
}
QuotedPrintableState::Hex1 => {
return DecoderResult::Error;
}
QuotedPrintableState::None => {
return DecoderResult::Byte(b'\n');
}
}
}
b'\r' | b'\t' => (), // \r
b' '..=b'~' => match self.state {
QuotedPrintableState::None => {
return DecoderResult::Byte(ch);
}
QuotedPrintableState::Eq => {
self.hex_1 = unsafe { *HEX_MAP.get_unchecked(ch as usize) };
if self.hex_1 == -1 {
return DecoderResult::Error;
} else {
self.state = QuotedPrintableState::Hex1;
}
}
QuotedPrintableState::Hex1 => {
let hex2 = unsafe { *HEX_MAP.get_unchecked(ch as usize) };
self.state = QuotedPrintableState::None;
if hex2 == -1 {
return DecoderResult::Error;
} else {
return DecoderResult::Byte(((self.hex_1 as u8) << 4) | hex2 as u8);
}
}
},
_ => {
if let QuotedPrintableState::None = self.state {
return DecoderResult::Byte(b'!');
} else {
return DecoderResult::Error;
}
}
}
DecoderResult::NeedData
}
}
#[cfg(test)]
mod tests {
use crate::decoders::{quoted_printable::QuotedPrintableDecoder, Decoder, DecoderResult};
#[test]
fn decode_success() {
let input = [
b"J'interdis aux marchands de vanter trop leurs marchandises. ".to_vec(),
b"Car ils se font=\nvite p=C3=A9dagogues et t'enseignent comme but ce ".to_vec(),
b"qui n'est par essence qu=\n'un moyen, et te trompant ainsi sur la route ".to_vec(),
b"=C3=A0 suivre les voil=C3=\n=A0 bient=C3=B4t qui te d=C3=A9gradent, car ".to_vec(),
b"si leur musique est vulgaire il=\ns te fabriquent pour te la vendre une ".to_vec(),
b"=C3=A2me vulgaire.\n=E2=80=94=E2=80=89Antoine de Saint-Exup=C3=A9ry, ".to_vec(),
b"Citadelle (1948)".to_vec(),
]
.concat();
let mut decoder = QuotedPrintableDecoder::new();
let mut result = Vec::new();
for ch in input {
match decoder.ingest(ch) {
DecoderResult::Byte(val) => {
result.push(val);
}
DecoderResult::NeedData => (),
_ => {
assert!(false, "Error decoding.");
}
}
}
assert_eq!(
std::str::from_utf8(&result[..]).unwrap(),
concat!(
"J'interdis aux marchands de vanter trop leurs marchandises. ",
"Car ils se fontvite pédagogues et t'enseignent comme but ce qui ",
"n'est par essence qu'un moyen, et te trompant ainsi sur la route ",
"à suivre les voilà bientôt qui te dégradent, car si leur musique ",
"est vulgaire ils te fabriquent pour te la vendre une âme vulgaire.\n",
"— Antoine de Saint-Exupéry, Citadelle (1948)"
)
);
}
#[test]
fn decode_invalid() {
let inputs = [
b"=2=123".to_vec(),
b"= 20".to_vec(),
b"=====".to_vec(),
b"=20=20=XX".to_vec(),
b"=AX".to_vec(),
b"=\n=\n==".to_vec(),
b"=\r=1z".to_vec(),
b"=|".to_vec(),
];
for input in inputs {
let mut failed = false;
let mut decoder = QuotedPrintableDecoder::new();
for ch in &input {
match decoder.ingest(*ch) {
DecoderResult::Byte(_) | DecoderResult::NeedData => (),
DecoderResult::ByteArray(_) => {
assert!(false, "Error decoding.");
}
DecoderResult::Error => {
failed = true;
break;
}
}
}
assert_eq!(failed, true, "{}", std::str::from_utf8(&input[..]).unwrap());
}
}
}
/*
* Adapted from Daniel Lemire's source:
* https://github.com/lemire/Code-used-on-Daniel-Lemire-s-blog/blob/master/2019/04/17/hexparse.cpp
*
*/
static HEX_MAP: &'static [i8] = &[
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 10,
11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
];
+223
View File
@@ -0,0 +1,223 @@
use std::{
borrow::{BorrowMut, Cow},
error::Error
};
/*
"Date:" date-time CRLF
"From:" mailbox-list CRLF
"Sender:" mailbox CRLF
"Reply-To:" address-list CRLF
"To:" address-list CRLF
"Cc:" address-list CRLF
"Bcc:" [address-list / CFWS] CRLF
"Message-ID:" msg-id CRLF
"In-Reply-To:" 1*msg-id CRLF
"References:" 1*msg-id CRLF
"Subject:" unstructured CRLF
"Comments:" unstructured CRLF
"Keywords:" phrase *("," phrase) CRLF
"Resent-Date:" date-time CRLF
"Resent-From:" mailbox-list CRLF
"Resent-Sender:" mailbox CRLF
"Resent-To:" address-list CRLF
"Resent-Cc:" address-list CRLF
"Resent-Bcc:" [address-list / CFWS] CRLF
"Resent-Message-ID:" msg-id CRLF
"Return-Path:" path CRLF
"Received:" *received-token ";" date-time CRLF
Content-Type: multipart/mixed; boundary=gc0p4Jq0M2Yt08j34c0p
Content-transfer-encoding: base64
"Content-ID" ":" msg-id
*/
mod parsers;
mod decoders;
/*struct Message<'x> {
headers: Vec<Header<'x>>,
}*/
use crate::parsers::message_stream::MessageStream;
use crate::parsers::header::Header;
static HEX_TO_VAL: &'static [i8] = &[
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8,
9, -1, -1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1];
fn main() {
let mut mail = concat!(
"Subject: This is a test email\n",
"Content-Type: multipart/alternative; boundary=foobar\n",
"Date: Sun, 02 Oct 2016 07:06:22 -0700 (PDT)\n",
"\n",
"--foobar\n",
"Content-Type: text/plain; charset=utf-8\n",
"Content-Transfer-Encoding: quoted-printable\n",
"\n",
"This is the plaintext version, in utf-8. Proof by Euro: =E2=82=AC\n",
"--foobar\n",
"Content-Type: text/html\n",
"Content-Transfer-Encoding: base64\n",
"\n",
"PGh0bWw+PGJvZHk+VGhpcyBpcyB0aGUgPGI+SFRNTDwvYj4gdmVyc2lvbiwgaW4g \n",
"dXMtYXNjaWkuIFByb29mIGJ5IEV1cm86ICZldXJvOzwvYm9keT48L2h0bWw+Cg== \n",
"--foobar--\n",
"After the final boundary stuff gets ignored.\n"
)
.to_string();
//let mut parser = MessageStream::new(unsafe { mail.as_bytes_mut() });
//let hdr = Header::parse(&mut parser);
let val = (HEX_TO_VAL['3' as usize] << 4) as u8 | HEX_TO_VAL['f' as usize] as u8;
println!("{}", val);
/*static HASH_VALUES: &'static [i8] =
&[38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
38, 38, 38, 38, 38, 38, 38, 38, 0, 0,
10, 0, 0, 5, 5, 0, 38, 5, 38, 15,
38, 25, 38, 38, 0, 15, 10, 38, 38, 38,
38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
38, 38, 38, 38, 38, 38];
for item in HASH_VALUES.into_iter().enumerate() {
let (i, x): (usize, &i8) = item;
if *x != 38 {
println!("{} => {},", i, x);
}
}*/
//let part1 = std::str::from_utf8(parser.get_slice(0, 10)).unwrap();
//let part2 = std::str::from_utf8(parser.get_slice(11, 20)).unwrap();
//println!("{}-{}", part1, part2 );
}
/*
pub fn qp_decode<'x>(stream: &'x mut MessageStream, is_header: bool) -> Option<&'x [u8]> {
let mut state: QuotedPrintableState = QuotedPrintableState::None;
let mut hex_1: i8 = 0;
let output_start = stream.begin_write();
while let Some(ch) = stream.next() {
match ch {
b'=' => { // =
if let QuotedPrintableState::None = state {
state = QuotedPrintableState::Eq;
} else {
break;
}
},
b'\n' if !is_header => { // \n
match state {
QuotedPrintableState::Eq => {
state = QuotedPrintableState::None;
},
QuotedPrintableState::Hex1 => {
break;
},
QuotedPrintableState::None => {
stream.write(b'\n');
}
}
},
b'\n' if is_header => {
break;
},
b'\r' | b'\t' => (), // \r
b'_' if is_header => {
match state {
QuotedPrintableState::None => {
stream.write(b' ');
},
_ => {
break;
}
}
},
b' '..=b'~' => {
match state {
QuotedPrintableState::None => {
stream.write(ch);
},
QuotedPrintableState::Eq => {
hex_1 = unsafe{*HEX_TO_VAL.get_unchecked(ch as usize)};
if hex_1 == -1 {
break;
} else {
state = QuotedPrintableState::Hex1;
}
},
QuotedPrintableState::Hex1 => {
let hex2 = unsafe{*HEX_TO_VAL.get_unchecked(ch as usize)};
state = QuotedPrintableState::None;
if hex2 == -1 {
break;
} else {
stream.write(((hex_1 as u8) << 4) | hex2 as u8);
}
}
}
},
_ => {
if let QuotedPrintableState::None = state {
stream.write(b'!');
} else {
break;
}
}
}
}
let output_end = stream.get_write_pos();
if output_end > output_start {
return stream.get_bytes(output_start, output_end);
} else {
return None;
}
}
*/
+15
View File
@@ -0,0 +1,15 @@
pub type EmailAddress<'x> = &'x str;
pub type InvalidAddress<'x> = &'x str;
pub struct NamedAddress<'x> {
name: &'x str,
email: EmailAddress<'x>,
}
pub enum Address<'x> {
EmailAddress(EmailAddress<'x>),
NamedAddress(NamedAddress<'x>),
InvalidAddress(InvalidAddress<'x>),
}
pub type AddressList<'x> = Vec<Address<'x>>;
+144
View File
@@ -0,0 +1,144 @@
use crate::parsers::message_stream::MessageStream;
use crate::parsers::address::*;
pub enum Header<'x> {
Sender(Address<'x>),
From(Address<'x>),
To(AddressList<'x>),
Cc(AddressList<'x>),
Bcc(AddressList<'x>),
Subject(&'x str),
Other((&'x str, &'x str)),
}
/*
List-Help
List-Unsubscribe
List-Subscribe
List-Post
List-Owner
List-Archive
*/
pub enum EncodingType {
QuotedPrintable,
Base64,
Bit7,
Bit8
}
pub struct NonAsciiText<'x> {
encoding: EncodingType,
charset: &'x [u8],
data: &'x [u8]
}
impl<'x> Header<'x> {
pub fn parse(s: &'x mut MessageStream) -> Option<Header<'x>> {
let mut ch_hash_1: u8 = 0;
let mut ch_hash_2: u8 = 0;
let mut start_pos: isize = -1;
let mut end_pos: isize = -1;
let hash_ch = |x: u8| -> u32 {
match x {
98 | 99 | 101 | 102 | 105 | 114 => 0,
103 | 104 | 107 => 5,
100 | 116 => 10,
109 | 115 => 15,
111 => 25,
_ => 38
}
};
while let Some(ch) = (*s).get_lower_char() {
match ch {
10 => return None,
13 | 9 | 32 => (), // CR TAB SPACE
58 if start_pos != -1 => { // :
let field_len: u32 = (end_pos - start_pos + 1) as u32;
if field_len >= 2 && field_len <= 25 {
let hash = field_len + hash_ch(ch_hash_2) + hash_ch(ch_hash_1);
if hash >= 2 && hash <= 37 {
let field = (*s).get_bytes(start_pos as usize, (end_pos + 1) as usize).unwrap();
match hash - 2 {
0 if field == b"cc" => {
},
1 if field == b"bcc" => {
},
7 if field == b"resent-cc" => {
},
8 if field == b"resent-bcc" => {
},
9 if field == b"resent-date" => {
},
10 if field == b"content-type" => {
},
11 if field == b"resent-sender" => {
},
12 if field == b"date" => {
},
14 if field == b"return-path" => {
},
16 if field == b"received" => {
},
17 if field == b"from" => {
},
18 if field == b"content-id" => {
},
19 if field == b"sender" => {
},
21 if field == b"comments" => {
},
23 if field == b"references" => {
},
24 if field == b"resent-from" => {
},
25 if field == b"resent-message-id" => {
},
26 if field == b"keywords" => {
},
28 if field == b"content-transfer-encoding" => {
},
30 if field == b"subject" => {
println!("Subject!");
},
31 if field == b"reply-to" => {
},
32 if field == b"resent-to" => {
},
33 if field == b"message-id" => {
},
34 if field == b"in-reply-to" => {
},
35 if field == b"to" => {
},
_ => ()
}
}
}
},
_ => {
if start_pos != -1 {
end_pos = (*s).get_read_pos();
ch_hash_2 = ch;
} else {
start_pos = (*s).get_read_pos();
end_pos = start_pos;
ch_hash_1 = ch;
}
}
}
}
None
}
}
+92
View File
@@ -0,0 +1,92 @@
use std::borrow::Cow;
pub struct MessageStream<'x> {
data: &'x mut [u8],
read_pos: isize,
write_pos: usize
}
impl<'x> MessageStream<'x> {
pub fn new(data: &mut [u8]) -> MessageStream {
MessageStream {
data: data,
read_pos: -1,
write_pos: 0
}
}
pub fn get_bytes(&self, from: usize, to: usize) -> Option<&[u8]> {
self.data.get(from..to)
}
pub fn get_str_lossy(&'x self, from: usize, to: usize) -> Option<Cow<'x, str>> {
match self.data.get(from..to) {
Some(bytes) => Some(String::from_utf8_lossy(bytes)),
None => None,
}
}
pub fn get_str(&'x self, from: usize, to: usize) -> Option<&str> {
match self.data.get(from..to) {
Some(bytes) => Some(unsafe { std::str::from_utf8_unchecked(bytes) }),
None => None,
}
}
pub fn begin_write(&mut self) -> usize {
if self.read_pos > 0 {
self.write_pos = self.read_pos as usize;
}
self.write_pos
}
pub fn write(&mut self, ch: u8) -> () {
self.data[self.write_pos] = ch;
self.write_pos = self.write_pos + 1;
}
pub fn write_slice(&mut self, chars: &[u8]) -> () {
self.data[self.write_pos..(self.write_pos+chars.len())].copy_from_slice(chars);
self.write_pos = self.write_pos + chars.len();
}
#[inline(always)]
pub fn get_read_pos(&self) -> isize {
self.read_pos
}
pub fn get_write_pos(&self) -> usize {
self.write_pos
}
#[inline(always)]
pub fn get_lower_char(&mut self) -> Option<u8> {
self.read_pos = self.read_pos + 1;
match self.data.get_mut(self.read_pos as usize) {
Some(ch) => {
if *ch >= 65 && *ch <= 90 {
*ch = *ch + 32;
}
Some(*ch)
},
None => None
}
}
pub fn rewind(&mut self, read_pos: usize) -> () {
self.read_pos = self.read_pos - std::cmp::min(self.read_pos, read_pos as isize);
}
}
impl<'x> Iterator for MessageStream<'x> {
type Item = u8;
#[inline(always)]
fn next(&mut self) -> Option<u8> {
self.read_pos = self.read_pos + 1;
match self.data.get(self.read_pos as usize) {
Some(ch) => Some(*ch),
None => None
}
}
}
+5
View File
@@ -0,0 +1,5 @@
pub mod address;
pub mod header;
pub mod message_stream;
pub mod rfc2047;
+118
View File
@@ -0,0 +1,118 @@
use crate::parsers::message_stream::MessageStream;
enum Rfc2047State {
Charset,
Language,
Encoding,
Data
}
enum Rfc2047Encoding {
Invalid,
Base64,
QuotedPrintable
}
pub fn try_decode<'x>(stream: &'x mut MessageStream) -> Option<&'x str> {
let mut charset: [u8; 10] = [0; 10];
let mut state = Rfc2047State::Charset;
let mut encoding = Rfc2047Encoding::Invalid;
let mut pos: usize = 0;
for mut ch in stream.by_ref() {
match state {
Rfc2047State::Charset => {
match ch {
65..=90 => { // A-Z
ch = ch + 32; // To uppercase
},
97..=122 | 45 | 95 => (), // a-z - _
63 => { // ?
if pos > 0 {
println!("Charset: {}", unsafe { std::str::from_utf8_unchecked(&charset[0..pos]) });
state = Rfc2047State::Encoding;
continue;
} else {
return None;
}
},
42 => { // *
state = Rfc2047State::Language;
continue;
},
_ => {
//stream.rewind(1);
return None;
}
}
// Add to charset array
match charset.get_mut(pos) {
Some(val) => {
*val = ch;
},
None => {return None;}
}
pos = pos + 1;
},
Rfc2047State::Language => { // Ignore language
match ch {
65..=90 | 97..=122 | 45 | 95 => (),
63 => { // ?
if pos > 0 {
println!("Charset: {}", unsafe { std::str::from_utf8_unchecked(&charset[0..pos]) });
state = Rfc2047State::Encoding;
continue;
} else {
return None;
}
},
_ => {
return None;
}
}
},
Rfc2047State::Encoding => {
match ch {
113 | 81 => { // q Q
if let Rfc2047Encoding::Invalid = encoding {
encoding = Rfc2047Encoding::QuotedPrintable;
} else {
return None;
}
},
98 | 66 => { // b B
if let Rfc2047Encoding::Invalid = encoding {
encoding = Rfc2047Encoding::Base64;
} else {
return None;
}
},
63 => { // ?
if let Rfc2047Encoding::Invalid = encoding {
return None;
}
state = Rfc2047State::Data;
},
_ => {
return None;
}
}
},
Rfc2047State::Data => {
match ch {
63 => { // ?
},
13 | 9 | 32 => (), // CR TAB SPACE
10 => { // LF
return None;
},
_ => ()
}
}
}
}
None
}