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