penmanship 0.1.0

A Unicode character lookup library for converting text patterns to Unicode characters
Documentation
//! Punctuation and typography character mappings.

use phf::phf_map;

/// Punctuation and typography mappings.
///
/// Includes ellipsis, dashes, quotes, guillemets, inverted punctuation,
/// and other typographical symbols.
pub static PUNCTUATION: phf::Map<&'static str, (&'static str, &'static str)> = phf_map! {
    // Basic punctuation
    ".." => ("\u{2025}", "two dot leader"),                                 //    "twodot" => ("\u{2025}", "two dot leader"),                             //    "..." => ("\u{2026}", "horizontal ellipsis"),                           //    "ellipsis" => ("\u{2026}", "horizontal ellipsis"),                      //    "en" => ("\u{2013}", "en dash"),                                        //    "em" => ("\u{2014}", "em dash"),                                        //    "--" => ("\u{2014}", "em dash"),                                        //
    // Quotes
    "\"l" => ("\u{201C}", "left double quotation mark"),                    // "
    "\"r" => ("\u{201D}", "right double quotation mark"),                   // "
    "'l" => ("\u{2018}", "left single quotation mark"),                     // '
    "'r" => ("\u{2019}", "right single quotation mark"),                    // '
    "<<" => ("\u{00AB}", "left-pointing double angle quotation mark"),      // «
    ">>" => ("\u{00BB}", "right-pointing double angle quotation mark"),     // »

    // Inverted punctuation
    "!i" => ("\u{00A1}", "inverted exclamation mark"),                      // ¡
    "?i" => ("\u{00BF}", "inverted question mark"),                         // ¿
    "+!?" => ("\u{203D}", "interrobang"),                                   //    "+!?i" => ("\u{2E18}", "inverted interrobang"),                         //    "!?" => ("\u{2049}", "exclamation question mark"),                      //    "!!" => ("\u{203C}", "double exclamation mark"),                        //    "??" => ("\u{2047}", "double question mark"),                           //};

#[cfg(test)]
mod tests {
    use super::*;

    /// Test basic punctuation lookups.
    #[test]
    fn test_basic_punctuation() {
        assert_eq!(PUNCTUATION.get(".."), Some(&("\u{2025}", "two dot leader")));
        assert_eq!(
            PUNCTUATION.get("twodot"),
            Some(&("\u{2025}", "two dot leader"))
        );
        assert_eq!(
            PUNCTUATION.get("..."),
            Some(&("\u{2026}", "horizontal ellipsis"))
        );
        assert_eq!(
            PUNCTUATION.get("ellipsis"),
            Some(&("\u{2026}", "horizontal ellipsis"))
        );
        assert_eq!(PUNCTUATION.get("em"), Some(&("\u{2014}", "em dash")));
        assert_eq!(PUNCTUATION.get("--"), Some(&("\u{2014}", "em dash")));
    }

    /// Test quote lookups.
    #[test]
    fn test_quotes() {
        assert_eq!(
            PUNCTUATION.get("\"l"),
            Some(&("\u{201C}", "left double quotation mark"))
        );
        assert_eq!(
            PUNCTUATION.get("\"r"),
            Some(&("\u{201D}", "right double quotation mark"))
        );
        assert_eq!(
            PUNCTUATION.get("'l"),
            Some(&("\u{2018}", "left single quotation mark"))
        );
        assert_eq!(
            PUNCTUATION.get("'r"),
            Some(&("\u{2019}", "right single quotation mark"))
        );
        assert_eq!(
            PUNCTUATION.get("<<"),
            Some(&("\u{00AB}", "left-pointing double angle quotation mark"))
        );
    }

    /// Test inverted punctuation.
    #[test]
    fn test_inverted_punctuation() {
        assert_eq!(
            PUNCTUATION.get("!i"),
            Some(&("\u{00A1}", "inverted exclamation mark"))
        );
        assert_eq!(
            PUNCTUATION.get("?i"),
            Some(&("\u{00BF}", "inverted question mark"))
        );
        assert_eq!(PUNCTUATION.get("+!?"), Some(&("\u{203D}", "interrobang")));
    }
}