Make shorthand list inspectable

This commit is contained in:
Laurenz 2023-01-29 20:43:36 +01:00
parent 9d715fd11c
commit 5f4f507ecf

View File

@ -424,35 +424,41 @@ node! {
} }
impl Shorthand { impl Shorthand {
/// A list of all shorthands.
pub const LIST: &[(&'static str, char)] = &[
("~", '\u{00A0}'),
("--", '\u{2013}'),
("---", '\u{2014}'),
("-?", '\u{00AD}'),
("...", '…'),
("*", ''),
("!=", '≠'),
("<<", '≪'),
("<<<", '⋘'),
(">>", '≫'),
(">>>", '⋙'),
("<=", '≤'),
(">=", '≥'),
("<-", '←'),
("->", '→'),
("=>", '⇒'),
("|->", '↦'),
("|=>", '⤇'),
("<->", '↔'),
("<=>", '⇔'),
(":=", '≔'),
("[|", '⟦'),
("|]", '⟧'),
("||", '‖'),
];
/// Get the shorthanded character. /// Get the shorthanded character.
pub fn get(&self) -> char { pub fn get(&self) -> char {
match self.0.text().as_str() { let text = self.0.text().as_str();
"~" => '\u{00A0}', Self::LIST
"--" => '\u{2013}', .iter()
"---" => '\u{2014}', .find(|&&(s, _)| s == text)
"-?" => '\u{00AD}', .map_or_else(char::default, |&(_, c)| c)
"..." => '…',
"*" => '',
"!=" => '≠',
"<<" => '≪',
"<<<" => '⋘',
">>" => '≫',
">>>" => '⋙',
"<=" => '≤',
">=" => '≥',
"<-" => '←',
"->" => '→',
"=>" => '⇒',
"|->" => '↦',
"|=>" => '⤇',
"<->" => '↔',
"<=>" => '⇔',
":=" => '≔',
"[|" => '⟦',
"|]" => '⟧',
"||" => '‖',
_ => char::default(),
}
} }
} }