uniaxe 0.1.1

A Rust crate to replace Unicode letters with Ascii equivalents
Documentation
// Uniaxe: A weapon for the war against unicode text

#[warn(clippy::all, clippy::pedantic)]
#[allow(clippy::too_many_lines)]
pub mod lookup;

use std::collections::HashMap;

/// This will actually carry out the replacement of unicode characters (this is the function you
/// probably want to use if you just want to use this crate)
///
/// # Example
/// ```
/// use uniaxe::uniaxe;
/// use uniaxe::lookup::generate_table;
///
/// let table = generate_table();
/// let text = uniaxe("๐™ก๐™ค๐™ค๐™  ๐™–๐™ฉ ๐™ข๐™š ๐™ž'๐™ข ๐™จ๐™ค ๐™ฆ๐™ช๐™ž๐™ง๐™ ๐™ฎ", &table);
/// println!("{}", text); // This will display "look at me i'm so quirky"
/// ```
///
/// This function will always return a string, so no need to handle any errors
pub fn uniaxe(text: &str, table: &HashMap<char, char>) -> String {
    // Function to destroy unicode text
    let mut result = String::new();
    for c in text.chars() {
        if lookup::TEMPLATE.contains(c) {
            result.push(c);
        } else if let Some(&equiv) = table.get(&c) {
            result.push(equiv);
        } else if c.is_ascii() {
            result.push(c);
        }
    }
    result
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn conversion() {
        let table = lookup::generate_table();
        assert_eq!(
            uniaxe("๐”ฅ๐”ข๐”ฉ๐”ฉ๐”ฌ ๐”ฑ๐”ฅ๐”ข๐”ฏ๐”ข ๐”ˆ๐”ซ๐”๐”ฌ๐”ถ ๐”—๐”ฅ๐”ฆ๐”ฐ ๐”Š๐”ฌ๐”—๐”ฅโ„‘๐”  ๐•ฟ๐–Š๐–๐–™ 123", &table),
            "hello there EnJoy This GoThIc Text 123"
        );
        assert_eq!(
            uniaxe("๐“ฒ๐“ณ๐“ด๐“ต๐“ถ๏ฝ†๏ฝ‡๏ฝˆ๏ฝ‰๏ฝŠ๏ฝ‹๏ฝŒ๏ฝ1234567890", &table),
            "ijklmfghijklm1234567890"
        );
        assert_eq!(
            uniaxe(
                "โ—โ–ฌโ–ฌโ–ฌโ–ฌ๐—Ÿ๐—ฎ๐˜€๐˜ ๐—ฟ๐—ฒ๐—บ๐—ถ๐—ป๐—ฑ๐—ฒ๐—ฟ,โ›”๏ธ ๐—ฌ๐—ผ๐˜‚๐—ฟ ๐—”๐—ป๐˜๐—ถ๐˜ƒ๐—ถ๐—ฟ๐˜‚๐˜€ ๐—ฒ๐˜…๐—ฝ๐—ถ๐—ฟ๐—ฒ๐˜€ ๐—ถ๐—ป ๐Ÿฎ๐Ÿฐ๐—ต๐—ฟ๐Ÿ’ฏโ—โ—---โ–ฌโ–ฌโ–ฌโ–ฌโ–ฌโ— #UdL04",
                &table
            ),
            "Last reminder, Your Antivirus expires in 24hr--- #UdL04"
        );
    }
    #[test]
    fn normal() {
        let table = lookup::generate_table();
        assert_eq!(
            uniaxe(
                "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
                &table
            ),
            "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
        );
    }
}