fast2s 0.3.1

A fast Traditional Chinese to Simplified Chinese conversion library. Built with FST, faster than most of other libraries.
Documentation
use hashbrown::{HashMap, HashSet};

use crate::{hashmap, hashset};
use lazy_static::lazy_static;

type Word = [char; 2];

static MAP_DATA: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/map.bin"));

lazy_static! {
    /// state machine for the translation
    static ref MAP: HashMap<char, char> = {
        let data: Vec<(char, char)> = bincode::deserialize(MAP_DATA).unwrap();
        data.into_iter().collect()
    };

    // thanks https://github.com/bosondata/simplet2s-rs/blob/master/src/lib.rs#L8 for this special logic
    // Traditional Chinese -> Not convert case
    static ref T2S_EXCLUDE: HashMap<char, HashSet<Word>> = {
        hashmap!{
            '' => hashset!{['','']},
            '' => hashset!{['', ''], ['',''], ['','']},
            '' => hashset!{['','']},
            '' => hashset!{['',''], ['','']},
            '' => hashset!{['','']},
            '' => hashset!{['','']},
            '' => hashset!{['','']},
            '' => hashset!{['','']},
            '' => hashset!{['',''], ['', ''], ['', '']}
        }
    };
    // Traditional Chinese -> Special convert cases ( only convert in certain case )
    static ref T2S_SPECIAL_CONVERT_TYPE: HashMap<char, HashMap<Word, char>> = {
        hashmap!{
            // not convert these chars if not in special cases
            '' => hashmap!{['',''] => '', ['',''] => ''},
            '' => hashmap!{['',''] => ''},
            '' => hashmap!{['',''] => ''},
            // convert these chars use naive mapping if not in special cases
            '' => hashmap!{['',''] => ''},
            '' => hashmap!{['',''] => ''},
            '' => hashmap!{['',''] => '', ['',''] => '', ['',''] => ''},
            '' => hashmap!{['',''] => '', ['',''] => ''},
        }
    };
}

#[inline(always)]
pub fn special_convert(prev: char, cur: char, next: char) -> char {
    let w1 = [prev, cur];
    let w2 = [cur, next];
    if let Some(inner_set) = T2S_EXCLUDE.get(&cur) {
        if inner_set.contains(&w1) || inner_set.contains(&w2) {
            return cur;
        }
    } else if let Some(inner_map) = T2S_SPECIAL_CONVERT_TYPE.get(&cur) {
        if let Some(c) = inner_map.get(&w1) {
            return *c;
        }
        if let Some(c) = inner_map.get(&w2) {
            return *c;
        }
    }
    *MAP.get(&cur).unwrap_or(&cur)
}