const DELIMITER_SIZES: [&str; 4] = ["Bigg", "bigg", "Big", "big"];
fn delimiter(base: &str) -> Option<char> {
Some(match base {
"parenleft" => '(',
"parenright" => ')',
"bracketleft" => '[',
"bracketright" => ']',
"braceleft" => '{',
"braceright" => '}',
"slash" => '/',
"backslash" => '\\',
"floorleft" => '\u{230A}',
"floorright" => '\u{230B}',
"ceilingleft" => '\u{2308}',
"ceilingright" => '\u{2309}',
"angbracketleft" => '\u{27E8}',
"angbracketright" => '\u{27E9}',
"radical" => '\u{221A}',
_ => return None,
})
}
fn operator(base: &str) -> Option<char> {
Some(match base {
"summation" => '\u{2211}',
"product" => '\u{220F}',
"coproduct" => '\u{2210}',
"integral" => '\u{222B}',
"contintegral" => '\u{222E}',
"union" => '\u{22C3}',
"intersection" => '\u{22C2}',
"unionmulti" => '\u{2A04}',
"unionsq" => '\u{2A06}',
"logicaland" => '\u{22C0}',
"logicalor" => '\u{22C1}',
"circledot" => '\u{2A00}',
"circleplus" => '\u{2A01}',
"circlemultiply" => '\u{2A02}',
_ => return None,
})
}
pub(crate) fn lookup(name: &str) -> Option<char> {
for size in DELIMITER_SIZES {
if let Some(c) = name.strip_suffix(size).and_then(delimiter) {
return Some(c);
}
}
for size in ["display", "text"] {
if let Some(c) = name.strip_suffix(size).and_then(operator) {
return Some(c);
}
}
Some(match name {
"angbracketleft" | "angbracketright" | "floorleft" | "floorright" | "ceilingleft"
| "ceilingright" => delimiter(name)?,
"vextendsingle" => '\u{2223}',
"vextenddouble" => '\u{2225}',
"radicalvertex" | "radicalbt" | "radicaltp" => '\u{221A}',
"arrowtp" => '\u{2191}',
"arrowbt" => '\u{2193}',
"prime" => '\u{2032}',
"breve" => '\u{02D8}',
"caron" => '\u{02C7}',
"circumflex" => '\u{02C6}',
"dotaccent" => '\u{02D9}',
"hungarumlaut" => '\u{02DD}',
"ogonek" => '\u{02DB}',
"ring" => '\u{02DA}',
"tilde" => '\u{02DC}',
"dotlessj" => '\u{0237}',
"dagger" => '\u{2020}',
"daggerdbl" => '\u{2021}',
"perthousand" => '\u{2030}',
"guilsinglleft" => '\u{2039}',
"guilsinglright" => '\u{203A}',
"Ifractur" => '\u{2111}',
"Rfractur" => '\u{211C}',
"coproduct" => '\u{2210}',
"unionmulti" => '\u{228E}',
"circledot" => '\u{2299}',
"latticetop" => '\u{22A4}',
"bardbl" => '\u{2016}',
"mapsto" => '\u{21A6}',
"owner" => '\u{220B}',
"negationslash" => '\u{0338}',
"nabla" => '\u{2207}',
"turnstileleft" => '\u{22A2}',
"turnstileright" => '\u{22A3}',
"follows" => '\u{227B}',
"precedes" => '\u{227A}',
"followsequal" => '\u{2AB0}',
"precedesequal" => '\u{2AAF}',
"lessmuch" => '\u{226A}',
"greatermuch" => '\u{226B}',
"equivasymptotic" => '\u{224D}',
"similarequal" => '\u{2243}',
"minusplus" => '\u{2213}',
"circleminus" => '\u{2296}',
"circledivide" => '\u{2298}',
"circlecopyrt" => '\u{25EF}',
"openbullet" => '\u{2218}',
"diamondmath" => '\u{22C4}',
"wreathproduct" => '\u{2240}',
"unionsq" => '\u{2294}',
"intersectionsq" => '\u{2293}',
"subsetsqequal" => '\u{2291}',
"supersetsqequal" => '\u{2292}',
"triangle" => '\u{25B3}',
"triangleinv" => '\u{25BD}',
"arrowboth" => '\u{2194}',
"arrowbothv" => '\u{2195}',
"arrowdblbothv" => '\u{21D5}',
"arrownortheast" => '\u{2197}',
"arrowsoutheast" => '\u{2198}',
"arrownorthwest" => '\u{2196}',
"arrowsouthwest" => '\u{2199}',
"star" => '\u{22C6}',
"triangleright" => '\u{25B7}',
"triangleleft" => '\u{25C1}',
"harpoonleftup" => '\u{21BC}',
"harpoonleftdown" => '\u{21BD}',
"harpoonrightup" => '\u{21C0}',
"harpoonrightdown" => '\u{21C1}',
"flat" => '\u{266D}',
"natural" => '\u{266E}',
"sharp" => '\u{266F}',
"slurbelow" => '\u{2323}',
"slurabove" => '\u{2322}',
"lscript" => '\u{2113}',
"weierstrass" => '\u{2118}',
"vector" => '\u{20D7}',
"tie" => '\u{2040}',
"trianglerightsld" => '\u{25B6}',
"triangleleftsld" => '\u{25C0}',
"squaresolid" => '\u{25A0}',
"square" => '\u{25A1}',
"lozenge" => '\u{25CA}',
_ => return None,
})
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn sizes_are_stripped() {
for (name, want) in [
("parenleftbig", '('),
("parenleftBig", '('),
("parenleftbigg", '('),
("parenrightBigg", ')'),
("bracketleftBig", '['),
("bracketrightbigg", ']'),
("braceleftbig", '{'),
("bracerightBigg", '}'),
("angbracketleftbig", '⟨'),
("angbracketrightBigg", '⟩'),
("floorleftbig", '⌊'),
("ceilingrightBig", '⌉'),
("slashbigg", '/'),
("backslashBig", '\\'),
("radicalbig", '√'),
("radicalBigg", '√'),
("summationtext", '∑'),
("summationdisplay", '∑'),
("producttext", '∏'),
("integraldisplay", '∫'),
("contintegraltext", '∮'),
("uniondisplay", '⋃'),
("intersectiontext", '⋂'),
("logicalanddisplay", '⋀'),
("circleplustext", '⨁'),
] {
assert_eq!(lookup(name), Some(want), "{name}");
}
for name in [
"big",
"Bigg",
"text",
"display",
"contextdisplay",
"hatwidebig",
] {
assert_eq!(lookup(name), None, "{name}");
}
}
#[test]
fn the_listed_names_resolve() {
for (name, want) in [
("vextendsingle", '∣'),
("vextenddouble", '∥'),
("bardbl", '‖'),
("mapsto", '↦'),
("angbracketleft", '⟨'),
("trianglerightsld", '▶'),
("triangleleftsld", '◀'),
] {
assert_eq!(lookup(name), Some(want), "{name}");
}
assert_eq!(lookup("nosuchglyphname"), None);
}
}