Skip to main content

hermes_parser/
html_entities.rs

1// Copyright (c) Meta Platforms, Inc. and affiliates.
2//
3// This source code is licensed under the MIT license found in the
4// LICENSE file in the root directory of this source tree.
5//
6// GENERATED by gen_html_entities.py from include/hermes/Parser/HTMLEntities.def.
7// DO NOT EDIT BY HAND.
8//
9//! XHTML named-entity table for the JSX lexer. Port of the
10//! `initializeHTMLEntities` map in `lib/Parser/JSLexer.cpp`, but
11//! emitted sorted by name so `&name;` lookup is a binary search.
12
13/// The XHTML named entities, sorted by name. Each entry maps an entity
14/// name (the bytes between `&` and `;`) to its Unicode code point.
15pub static HTML_ENTITIES: [(&[u8], u32); 253] = [
16    (b"AElig", 0x00c6),
17    (b"Aacute", 0x00c1),
18    (b"Acirc", 0x00c2),
19    (b"Agrave", 0x00c0),
20    (b"Alpha", 0x0391),
21    (b"Aring", 0x00c5),
22    (b"Atilde", 0x00c3),
23    (b"Auml", 0x00c4),
24    (b"Beta", 0x0392),
25    (b"Ccedil", 0x00c7),
26    (b"Chi", 0x03a7),
27    (b"Dagger", 0x2021),
28    (b"Delta", 0x0394),
29    (b"ETH", 0x00d0),
30    (b"Eacute", 0x00c9),
31    (b"Ecirc", 0x00ca),
32    (b"Egrave", 0x00c8),
33    (b"Epsilon", 0x0395),
34    (b"Eta", 0x0397),
35    (b"Euml", 0x00cb),
36    (b"Gamma", 0x0393),
37    (b"Iacute", 0x00cd),
38    (b"Icirc", 0x00ce),
39    (b"Igrave", 0x00cc),
40    (b"Iota", 0x0399),
41    (b"Iuml", 0x00cf),
42    (b"Kappa", 0x039a),
43    (b"Lambda", 0x039b),
44    (b"Mu", 0x039c),
45    (b"Ntilde", 0x00d1),
46    (b"Nu", 0x039d),
47    (b"OElig", 0x0152),
48    (b"Oacute", 0x00d3),
49    (b"Ocirc", 0x00d4),
50    (b"Ograve", 0x00d2),
51    (b"Omega", 0x03a9),
52    (b"Omicron", 0x039f),
53    (b"Oslash", 0x00d8),
54    (b"Otilde", 0x00d5),
55    (b"Ouml", 0x00d6),
56    (b"Phi", 0x03a6),
57    (b"Pi", 0x03a0),
58    (b"Prime", 0x2033),
59    (b"Psi", 0x03a8),
60    (b"Rho", 0x03a1),
61    (b"Scaron", 0x0160),
62    (b"Sigma", 0x03a3),
63    (b"THORN", 0x00de),
64    (b"Tau", 0x03a4),
65    (b"Theta", 0x0398),
66    (b"Uacute", 0x00da),
67    (b"Ucirc", 0x00db),
68    (b"Ugrave", 0x00d9),
69    (b"Upsilon", 0x03a5),
70    (b"Uuml", 0x00dc),
71    (b"Xi", 0x039e),
72    (b"Yacute", 0x00dd),
73    (b"Yuml", 0x0178),
74    (b"Zeta", 0x0396),
75    (b"aacute", 0x00e1),
76    (b"acirc", 0x00e2),
77    (b"acute", 0x00b4),
78    (b"aelig", 0x00e6),
79    (b"agrave", 0x00e0),
80    (b"alefsym", 0x2135),
81    (b"alpha", 0x03b1),
82    (b"amp", 0x0026),
83    (b"and", 0x2227),
84    (b"ang", 0x2220),
85    (b"apos", 0x0027),
86    (b"aring", 0x00e5),
87    (b"asymp", 0x2248),
88    (b"atilde", 0x00e3),
89    (b"auml", 0x00e4),
90    (b"bdquo", 0x201e),
91    (b"beta", 0x03b2),
92    (b"brvbar", 0x00a6),
93    (b"bull", 0x2022),
94    (b"cap", 0x2229),
95    (b"ccedil", 0x00e7),
96    (b"cedil", 0x00b8),
97    (b"cent", 0x00a2),
98    (b"chi", 0x03c7),
99    (b"circ", 0x02c6),
100    (b"clubs", 0x2663),
101    (b"cong", 0x2245),
102    (b"copy", 0x00a9),
103    (b"crarr", 0x21b5),
104    (b"cup", 0x222a),
105    (b"curren", 0x00a4),
106    (b"dArr", 0x21d3),
107    (b"dagger", 0x2020),
108    (b"darr", 0x2193),
109    (b"deg", 0x00b0),
110    (b"delta", 0x03b4),
111    (b"diams", 0x2666),
112    (b"divide", 0x00f7),
113    (b"eacute", 0x00e9),
114    (b"ecirc", 0x00ea),
115    (b"egrave", 0x00e8),
116    (b"empty", 0x2205),
117    (b"emsp", 0x2003),
118    (b"ensp", 0x2002),
119    (b"epsilon", 0x03b5),
120    (b"equiv", 0x2261),
121    (b"eta", 0x03b7),
122    (b"eth", 0x00f0),
123    (b"euml", 0x00eb),
124    (b"euro", 0x20ac),
125    (b"exist", 0x2203),
126    (b"fnof", 0x0192),
127    (b"forall", 0x2200),
128    (b"frac12", 0x00bd),
129    (b"frac14", 0x00bc),
130    (b"frac34", 0x00be),
131    (b"frasl", 0x2044),
132    (b"gamma", 0x03b3),
133    (b"ge", 0x2265),
134    (b"gt", 0x003e),
135    (b"hArr", 0x21d4),
136    (b"harr", 0x2194),
137    (b"hearts", 0x2665),
138    (b"hellip", 0x2026),
139    (b"iacute", 0x00ed),
140    (b"icirc", 0x00ee),
141    (b"iexcl", 0x00a1),
142    (b"igrave", 0x00ec),
143    (b"image", 0x2111),
144    (b"infin", 0x221e),
145    (b"int", 0x222b),
146    (b"iota", 0x03b9),
147    (b"iquest", 0x00bf),
148    (b"isin", 0x2208),
149    (b"iuml", 0x00ef),
150    (b"kappa", 0x03ba),
151    (b"lArr", 0x21d0),
152    (b"lambda", 0x03bb),
153    (b"lang", 0x2329),
154    (b"laquo", 0x00ab),
155    (b"larr", 0x2190),
156    (b"lceil", 0x2308),
157    (b"ldquo", 0x201c),
158    (b"le", 0x2264),
159    (b"lfloor", 0x230a),
160    (b"lowast", 0x2217),
161    (b"loz", 0x25ca),
162    (b"lrm", 0x200e),
163    (b"lsaquo", 0x2039),
164    (b"lsquo", 0x2018),
165    (b"lt", 0x003c),
166    (b"macr", 0x00af),
167    (b"mdash", 0x2014),
168    (b"micro", 0x00b5),
169    (b"middot", 0x00b7),
170    (b"minus", 0x2212),
171    (b"mu", 0x03bc),
172    (b"nabla", 0x2207),
173    (b"nbsp", 0x00a0),
174    (b"ndash", 0x2013),
175    (b"ne", 0x2260),
176    (b"ni", 0x220b),
177    (b"not", 0x00ac),
178    (b"notin", 0x2209),
179    (b"nsub", 0x2284),
180    (b"ntilde", 0x00f1),
181    (b"nu", 0x03bd),
182    (b"oacute", 0x00f3),
183    (b"ocirc", 0x00f4),
184    (b"oelig", 0x0153),
185    (b"ograve", 0x00f2),
186    (b"oline", 0x203e),
187    (b"omega", 0x03c9),
188    (b"omicron", 0x03bf),
189    (b"oplus", 0x2295),
190    (b"or", 0x2228),
191    (b"ordf", 0x00aa),
192    (b"ordm", 0x00ba),
193    (b"oslash", 0x00f8),
194    (b"otilde", 0x00f5),
195    (b"otimes", 0x2297),
196    (b"ouml", 0x00f6),
197    (b"para", 0x00b6),
198    (b"part", 0x2202),
199    (b"permil", 0x2030),
200    (b"perp", 0x22a5),
201    (b"phi", 0x03c6),
202    (b"pi", 0x03c0),
203    (b"piv", 0x03d6),
204    (b"plusmn", 0x00b1),
205    (b"pound", 0x00a3),
206    (b"prime", 0x2032),
207    (b"prod", 0x220f),
208    (b"prop", 0x221d),
209    (b"psi", 0x03c8),
210    (b"quot", 0x0022),
211    (b"rArr", 0x21d2),
212    (b"radic", 0x221a),
213    (b"rang", 0x232a),
214    (b"raquo", 0x00bb),
215    (b"rarr", 0x2192),
216    (b"rceil", 0x2309),
217    (b"rdquo", 0x201d),
218    (b"real", 0x211c),
219    (b"reg", 0x00ae),
220    (b"rfloor", 0x230b),
221    (b"rho", 0x03c1),
222    (b"rlm", 0x200f),
223    (b"rsaquo", 0x203a),
224    (b"rsquo", 0x2019),
225    (b"sbquo", 0x201a),
226    (b"scaron", 0x0161),
227    (b"sdot", 0x22c5),
228    (b"sect", 0x00a7),
229    (b"shy", 0x00ad),
230    (b"sigma", 0x03c3),
231    (b"sigmaf", 0x03c2),
232    (b"sim", 0x223c),
233    (b"spades", 0x2660),
234    (b"sub", 0x2282),
235    (b"sube", 0x2286),
236    (b"sum", 0x2211),
237    (b"sup", 0x2283),
238    (b"sup1", 0x00b9),
239    (b"sup2", 0x00b2),
240    (b"sup3", 0x00b3),
241    (b"supe", 0x2287),
242    (b"szlig", 0x00df),
243    (b"tau", 0x03c4),
244    (b"there4", 0x2234),
245    (b"theta", 0x03b8),
246    (b"thetasym", 0x03d1),
247    (b"thinsp", 0x2009),
248    (b"thorn", 0x00fe),
249    (b"tilde", 0x02dc),
250    (b"times", 0x00d7),
251    (b"trade", 0x2122),
252    (b"uArr", 0x21d1),
253    (b"uacute", 0x00fa),
254    (b"uarr", 0x2191),
255    (b"ucirc", 0x00fb),
256    (b"ugrave", 0x00f9),
257    (b"uml", 0x00a8),
258    (b"upsih", 0x03d2),
259    (b"upsilon", 0x03c5),
260    (b"uuml", 0x00fc),
261    (b"weierp", 0x2118),
262    (b"xi", 0x03be),
263    (b"yacute", 0x00fd),
264    (b"yen", 0x00a5),
265    (b"yuml", 0x00ff),
266    (b"zeta", 0x03b6),
267    (b"zwj", 0x200d),
268    (b"zwnj", 0x200c),
269];
270
271/// Look up an XHTML named entity by name (the bytes between `&`
272/// and `;`). Returns its code point, or `None` if unknown.
273pub fn lookup(name: &[u8]) -> Option<u32> {
274    HTML_ENTITIES
275        .binary_search_by(|(n, _)| (*n).cmp(name))
276        .ok()
277        .map(|i| HTML_ENTITIES[i].1)
278}
279
280#[cfg(test)]
281mod tests {
282    use super::*;
283
284    #[test]
285    fn known_entities() {
286        assert_eq!(lookup(b"amp"), Some(0x26));
287        assert_eq!(lookup(b"lt"), Some(0x3c));
288        assert_eq!(lookup(b"nope"), None);
289    }
290
291    #[test]
292    fn table_is_sorted_and_full() {
293        assert_eq!(HTML_ENTITIES.len(), 253);
294        for w in HTML_ENTITIES.windows(2) {
295            assert!(w[0].0 < w[1].0, "table not sorted by name");
296        }
297    }
298}