root/trunk/src/entity.c

Revision 428, 37.8 kB (checked in by walter, 2 years ago)

remove tabs, any trailing spaces

  • Property svn:eol-style set to native
Line 
1 // Copyright (c) 1999-2009 by Digital Mars
2 // All Rights Reserved
3 // written by Walter Bright
4 // http://www.digitalmars.com
5 // License for redistribution is by either the Artistic License
6 // in artistic.txt, or the GNU General Public License in gnu.txt.
7 // See the included readme.txt for details.
8
9
10 #include <string.h>
11
12 /*********************************************
13  * Convert from named entity to its encoding.
14  * For reference:
15  *      http://www.htmlhelp.com/reference/html40/entities/
16  *      http://www.w3.org/TR/1999/REC-html401-19991224/sgml/entities.html
17  */
18
19 struct NameId
20 {
21     const char *name;
22     unsigned short value;
23 };
24
25 #if IN_GCC
26 static NameId namesA[]={
27         "Aacgr",        0x0386,
28         "aacgr",        0x03AC,
29         "Aacute",       0x00C1,
30         "aacute",       0x00E1,
31         "Abreve",       0x0102,
32         "abreve",       0x0103,
33         "Acirc",        0x00C2,
34         "acirc",        0x00E2,
35         "acute",        0x00B4,
36         "Acy",          0x0410,
37         "acy",          0x0430,
38         "AElig",        0x00C6,
39         "aelig",        0x00E6,
40         "Agr",          0x0391,
41         "agr",          0x03B1,
42         "Agrave",       0x00C0,
43         "agrave",       0x00E0,
44         "aleph",        0x2135,
45         "alpha",        0x03B1,
46         "Amacr",        0x0100,
47         "amacr",        0x0101,
48         "amalg",        0x2210,
49         "amp",          0x0026,
50         "and",          0x2227,
51         "ang",          0x2220,
52         "ang90",        0x221F,
53         "angmsd",       0x2221,
54         "angsph",       0x2222,
55         "angst",        0x212B,
56         "Aogon",        0x0104,
57         "aogon",        0x0105,
58         "ap",           0x2248,
59         "ape",          0x224A,
60         "apos",         0x0027,
61         "Aring",        0x00C5,
62         "aring",        0x00E5,
63         "ast",          0x002A,
64         "asymp",        0x224D,
65         "Atilde",       0x00C3,
66         "atilde",       0x00E3,
67         "Auml",         0x00C4,
68         "auml",         0x00E4,
69         NULL,           0
70 };
71
72 static NameId namesB[]={
73         "barwed",       0x22BC,
74         "Barwed",       0x2306,
75         "bcong",        0x224C,
76         "Bcy",          0x0411,
77         "bcy",          0x0431,
78         "becaus",       0x2235,
79         "bepsi",        0x220D,
80         "bernou",       0x212C,
81         "beta",         0x03B2,
82         "beth",         0x2136,
83         "Bgr",          0x0392,
84         "bgr",          0x03B2,
85         "blank",        0x2423,
86         "blk12",        0x2592,
87         "blk14",        0x2591,
88         "blk34",        0x2593,
89         "block",        0x2588,
90         "bottom",       0x22A5,
91         "bowtie",       0x22C8,
92         "boxdl",        0x2510,
93         "boxDL",        0x2555,
94         "boxdL",        0x2556,
95         "boxDl",        0x2557,
96         "boxdr",        0x250C,
97         "boxDR",        0x2552,
98         "boxDr",        0x2553,
99         "boxdR",        0x2554,
100         "boxh",         0x2500,
101         "boxH",         0x2550,
102         "boxhd",        0x252C,
103         "boxhD",        0x2564,
104         "boxHD",        0x2565,
105         "boxHd",        0x2566,
106         "boxhu",        0x2534,
107         "boxhU",        0x2567,
108         "boxHU",        0x2568,
109         "boxHu",        0x2569,
110         "boxul",        0x2518,
111         "boxUL",        0x255B,
112         "boxUl",        0x255C,
113         "boxuL",        0x255D,
114         "boxur",        0x2514,
115         "boxUR",        0x2558,
116         "boxuR",        0x2559,
117         "boxUr",        0x255A,
118         "boxv",         0x2502,
119         "boxV",         0x2551,
120         "boxvh",        0x253C,
121         "boxvH",        0x256A,
122         "boxVH",        0x256B,
123         "boxVh",        0x256C,
124         "boxvl",        0x2524,
125         "boxvL",        0x2561,
126         "boxVL",        0x2562,
127         "boxVl",        0x2563,
128         "boxvr",        0x251C,
129         "boxvR",        0x255E,
130         "boxVR",        0x255F,
131         "boxVr",        0x2560,
132         "bprime",       0x2035,
133         "breve",        0x02D8,
134         "brvbar",       0x00A6,
135         "bsim",         0x223D,
136         "bsime",        0x22CD,
137         "bsol",         0x005C,
138         "bull",         0x2022,
139         "bump",         0x224E,
140         "bumpe",        0x224F,
141         NULL,           0
142 };
143
144 static NameId namesC[]={
145         "Cacute",       0x0106,
146         "cacute",       0x0107,
147         "cap",          0x2229,
148         "Cap",          0x22D2,
149         "caret",        0x2041,
150         "caron",        0x02C7,
151         "Ccaron",       0x010C,
152         "ccaron",       0x010D,
153         "Ccedil",       0x00C7,
154         "ccedil",       0x00E7,
155         "Ccirc",        0x0108,
156         "ccirc",        0x0109,
157         "Cdot",         0x010A,
158         "cdot",         0x010B,
159         "cedil",        0x00B8,
160         "cent",         0x00A2,
161         "CHcy",         0x0427,
162         "chcy",         0x0447,
163         "check",        0x2713,
164         "chi",          0x03C7,
165         "cir",          0x25CB,
166         "circ",         0x005E,
167         "cire",         0x2257,
168         "clubs",        0x2663,
169         "colon",        0x003A,
170         "colone",       0x2254,
171         "comma",        0x002C,
172         "commat",       0x0040,
173         "comp",         0x2201,
174         "compfn",       0x2218,
175         "cong",         0x2245,
176         "conint",       0x222E,
177         "coprod",       0x2210,
178         "copy",         0x00A9,
179         "copysr",       0x2117,
180         "cross",        0x2717,
181         "cuepr",        0x22DE,
182         "cuesc",        0x22DF,
183         "cularr",       0x21B6,
184         "cup",          0x222A,
185         "Cup",          0x22D3,
186         "cupre",        0x227C,
187         "curarr",       0x21B7,
188         "curren",       0x00A4,
189         "cuvee",        0x22CE,
190         "cuwed",        0x22CF,
191         NULL,           0
192 };
193
194 static NameId namesD[]={
195         "dagger",       0x2020,
196         "Dagger",       0x2021,
197         "daleth",       0x2138,
198         "darr",         0x2193,
199         "dArr",         0x21D3,
200         "darr2",        0x21CA,
201         "dash",         0x2010,
202         "dashv",        0x22A3,
203         "dblac",        0x02DD,
204         "Dcaron",       0x010E,
205         "dcaron",       0x010F,
206         "Dcy",          0x0414,
207         "dcy",          0x0434,
208         "deg",          0x00B0,
209         "Delta",        0x0394,
210         "delta",        0x03B4,
211         "Dgr",          0x0394,
212         "dgr",          0x03B4,
213         "dharl",        0x21C3,
214         "dharr",        0x21C2,
215         "diam",         0x22C4,
216         "diams",        0x2666,
217         "die",          0x00A8,
218         "divide",       0x00F7,
219         "divonx",       0x22C7,
220         "DJcy",         0x0402,
221         "djcy",         0x0452,
222         "dlarr",        0x2199,
223         "dlcorn",       0x231E,
224         "dlcrop",       0x230D,
225         "dollar",       0x0024,
226         "Dot",          0x00A8,
227         "dot",          0x02D9,
228         "DotDot",       0x20DC,
229         "drarr",        0x2198,
230         "drcorn",       0x231F,
231         "drcrop",       0x230C,
232         "DScy",         0x0405,
233         "dscy",         0x0455,
234         "Dstrok",       0x0110,
235         "dstrok",       0x0111,
236         "dtri",         0x25BF,
237         "dtrif",        0x25BE,
238         "DZcy",         0x040F,
239         "dzcy",         0x045F,
240         NULL,           0
241 };
242
243 static NameId namesE[]={
244         "Eacgr",        0x0388,
245         "eacgr",        0x03AD,
246         "Eacute",       0x00C9,
247         "eacute",       0x00E9,
248         "Ecaron",       0x011A,
249         "ecaron",       0x011B,
250         "ecir",         0x2256,
251         "Ecirc",        0x00CA,
252         "ecirc",        0x00EA,
253         "ecolon",       0x2255,
254         "Ecy",          0x042D,
255         "ecy",          0x044D,
256         "Edot",         0x0116,
257         "edot",         0x0117,
258         "eDot",         0x2251,
259         "EEacgr",       0x0389,
260         "eeacgr",       0x03AE,
261         "EEgr",         0x0397,
262         "eegr",         0x03B7,
263         "efDot",        0x2252,
264         "Egr",          0x0395,
265         "egr",          0x03B5,
266         "Egrave",       0x00C8,
267         "egrave",       0x00E8,
268         "egs",          0x22DD,
269         "ell",          0x2113,
270         "els",          0x22DC,
271         "Emacr",        0x0112,
272         "emacr",        0x0113,
273         "empty",        0x2205,
274         "emsp",         0x2003,
275         "emsp13",       0x2004,
276         "emsp14",       0x2005,
277         "ENG",          0x014A,
278         "eng",          0x014B,
279         "ensp",         0x2002,
280         "Eogon",        0x0118,
281         "eogon",        0x0119,
282         "epsi",         0x220A,
283         "epsis",        0x220A,
284         "epsiv",        0x03B5,
285         "equals",       0x003D,
286         "equiv",        0x2261,
287         "erDot",        0x2253,
288         "esdot",        0x2250,
289         "eta",          0x03B7,
290         "ETH",          0x00D0,
291         "eth",          0x00F0,
292         "Euml",         0x00CB,
293         "euml",         0x00EB,
294         "excl",         0x0021,
295         "exist",        0x2203,
296         NULL,           0
297 };
298
299 static NameId namesF[]={
300         "Fcy",          0x0424,
301         "fcy",          0x0444,
302         "female",       0x2640,
303         "ffilig",       0xFB03,
304         "fflig",        0xFB00,
305         "ffllig",       0xFB04,
306         "filig",        0xFB01,
307         "flat",         0x266D,
308         "fllig",        0xFB02,
309         "fnof",         0x0192,
310         "forall",       0x2200,
311         "fork",         0x22D4,
312         "frac12",       0x00BD,
313         "frac13",       0x2153,
314         "frac14",       0x00BC,
315         "frac15",       0x2155,
316         "frac16",       0x2159,
317         "frac18",       0x215B,
318         "frac23",       0x2154,
319         "frac25",       0x2156,
320         "frac34",       0x00BE,
321         "frac35",       0x2157,
322         "frac38",       0x215C,
323         "frac45",       0x2158,
324         "frac56",       0x215A,
325         "frac58",       0x215D,
326         "frac78",       0x215E,
327         "frown",        0x2322,
328         NULL,           0
329 };
330
331 static NameId namesG[]={
332         "gacute",       0x01F5,
333         "Gamma",        0x0393,
334         "gamma",        0x03B3,
335         "gammad",       0x03DC,
336         "gap",          0x2273,
337         "Gbreve",       0x011E,
338         "gbreve",       0x011F,
339         "Gcedil",       0x0122,
340         "Gcirc",        0x011C,
341         "gcirc",        0x011D,
342         "Gcy",          0x0413,
343         "gcy",          0x0433,
344         "Gdot",         0x0120,
345         "gdot",         0x0121,
346         "ge",           0x2265,
347         "gE",           0x2267,
348         "gel",          0x22DB,
349         "gEl",          0x22DB,
350         "ges",          0x2265,
351         "Gg",           0x22D9,
352         "Ggr",          0x0393,
353         "ggr",          0x03B3,
354         "gimel",        0x2137,
355         "GJcy",         0x0403,
356         "gjcy",         0x0453,
357         "gl",           0x2277,
358         "gnap",         0xE411,
359         "gne",          0x2269,
360         "gnE",          0x2269,
361         "gnsim",        0x22E7,
362         "grave",        0x0060,
363         "gsdot",        0x22D7,
364         "gsim",         0x2273,
365         "gt",           0x003E,
366         "Gt",           0x226B,
367         "gvnE",         0x2269,
368         NULL,           0
369 };
370
371 static NameId namesH[]={
372         "hairsp",       0x200A,
373         "half",         0x00BD,
374         "hamilt",       0x210B,
375         "HARDcy",       0x042A,
376         "hardcy",       0x044A,
377         "harr",         0x2194,
378         "hArr",         0x21D4,
379         "harrw",        0x21AD,
380         "Hcirc",        0x0124,
381         "hcirc",        0x0125,
382         "hearts",       0x2665,
383         "hellip",       0x2026,
384         "horbar",       0x2015,
385         "Hstrok",       0x0126,
386         "hstrok",       0x0127,
387         "hybull",       0x2043,
388         "hyphen",       0x002D,
389         NULL,           0
390 };
391
392 static NameId namesI[]={
393         "Iacgr",        0x038A,
394         "iacgr",        0x03AF,
395         "Iacute",       0x00CD,
396         "iacute",       0x00ED,
397         "Icirc",        0x00CE,
398         "icirc",        0x00EE,
399         "Icy",          0x0418,
400         "icy",          0x0438,
401         "idiagr",       0x0390,
402         "Idigr",        0x03AA,
403         "idigr",        0x03CA,
404         "Idot",         0x0130,
405         "IEcy",         0x0415,
406         "iecy",         0x0435,
407         "iexcl",        0x00A1,
408         "iff",          0x21D4,
409         "Igr",          0x0399,
410         "igr",          0x03B9,
411         "Igrave",       0x00CC,
412         "igrave",       0x00EC,
413         "IJlig",        0x0132,
414         "ijlig",        0x0133,
415         "Imacr",        0x012A,
416         "imacr",        0x012B,
417         "image",        0x2111,
418         "incare",       0x2105,
419         "infin",        0x221E,
420         "inodot",       0x0131,
421         "int",          0x222B,
422         "intcal",       0x22BA,
423         "IOcy",         0x0401,
424         "iocy",         0x0451,
425         "Iogon",        0x012E,
426         "iogon",        0x012F,
427         "iota",         0x03B9,
428         "iquest",       0x00BF,
429         "isin",         0x220A,
430         "Itilde",       0x0128,
431         "itilde",       0x0129,
432         "Iukcy",        0x0406,
433         "iukcy",        0x0456,
434         "Iuml",         0x00CF,
435         "iuml",         0x00EF,
436         NULL,           0
437 };
438
439 static NameId namesJ[]={
440         "Jcirc",        0x0134,
441         "jcirc",        0x0135,
442         "Jcy",          0x0419,
443         "jcy",          0x0439,
444         "Jsercy",       0x0408,
445         "jsercy",       0x0458,
446         "Jukcy",        0x0404,
447         "jukcy",        0x0454,
448         NULL,           0
449 };
450
451 static NameId namesK[]={
452         "kappa",        0x03BA,
453         "kappav",       0x03F0,
454         "Kcedil",       0x0136,
455         "kcedil",       0x0137,
456         "Kcy",          0x041A,
457         "kcy",          0x043A,
458         "Kgr",          0x039A,
459         "kgr",          0x03BA,
460         "kgreen",       0x0138,
461         "KHcy",         0x0425,
462         "khcy",         0x0445,
463         "KHgr",         0x03A7,
464         "khgr",         0x03C7,
465         "KJcy",         0x040C,
466         "kjcy",         0x045C,
467         NULL,           0
468 };
469
470 static NameId namesL[]={
471         "lAarr",        0x21DA,
472         "Lacute",       0x0139,
473         "lacute",       0x013A,
474         "lagran",       0x2112,
475         "Lambda",       0x039B,
476         "lambda",       0x03BB,
477         "lang",         0x3008,
478         "lap",          0x2272,
479         "laquo",        0x00AB,
480         "larr",         0x2190,
481         "Larr",         0x219E,
482         "lArr",         0x21D0,
483         "larr2",        0x21C7,
484         "larrhk",       0x21A9,
485         "larrlp",       0x21AB,
486         "larrtl",       0x21A2,
487         "Lcaron",       0x013D,
488         "lcaron",       0x013E,
489         "Lcedil",       0x013B,
490         "lcedil",       0x013C,
491         "lceil",        0x2308,
492         "lcub",         0x007B,
493         "Lcy",          0x041B,
494         "lcy",          0x043B,
495         "ldot",         0x22D6,
496         "ldquo",        0x201C,
497         "ldquor",       0x201E,
498         "le",           0x2264,
499         "lE",           0x2266,
500         "leg",          0x22DA,
501         "lEg",          0x22DA,
502         "les",          0x2264,
503         "lfloor",       0x230A,
504         "lg",           0x2276,
505         "Lgr",          0x039B,
506         "lgr",          0x03BB,
507         "lhard",        0x21BD,
508         "lharu",        0x21BC,
509         "lhblk",        0x2584,
510         "LJcy",         0x0409,
511         "ljcy",         0x0459,
512         "Ll",           0x22D8,
513         "Lmidot",       0x013F,
514         "lmidot",       0x0140,
515         "lnap",         0xE2A2,
516         "lne",          0x2268,
517         "lnE",          0x2268,
518         "lnsim",        0x22E6,
519         "lowast",       0x2217,
520         "lowbar",       0x005F,
521         "loz",          0x25CA,
522         "lozf",         0x2726,
523         "lpar",         0x0028,
524         "lrarr2",       0x21C6,
525         "lrhar2",       0x21CB,
526         "lsh",          0x21B0,
527         "lsim",         0x2272,
528         "lsqb",         0x005B,
529         "lsquo",        0x2018,
530         "lsquor",       0x201A,
531         "Lstrok",       0x0141,
532         "lstrok",       0x0142,
533         "lt",           0x003C,
534         "Lt",           0x226A,
535         "lthree",       0x22CB,
536         "ltimes",       0x22C9,
537         "ltri",         0x25C3,
538         "ltrie",        0x22B4,
539         "ltrif",        0x25C2,
540         "lvnE",         0x2268,
541         NULL,           0
542 };
543
544 static NameId namesM[]={
545         "macr",         0x00AF,
546         "male",         0x2642,
547         "malt",         0x2720,
548         "map",          0x21A6,
549         "marker",       0x25AE,
550         "Mcy",          0x041C,
551         "mcy",          0x043C,
552         "mdash",        0x2014,
553         "Mgr",          0x039C,
554         "mgr",          0x03BC,
555         "micro",        0x00B5,
556         "mid",          0x2223,
557         "middot",       0x00B7,
558         "minus",        0x2212,
559         "minusb",       0x229F,
560         "mldr",         0x2026,
561         "mnplus",       0x2213,
562         "models",       0x22A7,
563         "mu",           0x03BC,
564         "mumap",        0x22B8,
565         NULL,           0
566 };
567
568 static NameId namesN[]={
569         "nabla",        0x2207,
570         "Nacute",       0x0143,
571         "nacute",       0x0144,
572         "nap",          0x2249,
573         "napos",        0x0149,
574         "natur",        0x266E,
575 //      "nbsp",         0x00A0,
576         "nbsp",         32,    // make non-breaking space appear as space
577         "Ncaron",       0x0147,
578         "ncaron",       0x0148,
579         "Ncedil",       0x0145,
580         "ncedil",       0x0146,
581         "ncong",        0x2247,
582         "Ncy",          0x041D,
583         "ncy",          0x043D,
584         "ndash",        0x2013,
585         "ne",           0x2260,
586         "nearr",        0x2197,
587         "nequiv",       0x2262,
588         "nexist",       0x2204,
589         "nge",          0x2271,
590         "ngE",          0x2271,
591         "nges",         0x2271,
592         "Ngr",          0x039D,
593         "ngr",          0x03BD,
594         "ngt",          0x226F,
595         "nharr",        0x21AE,
596         "nhArr",        0x21CE,
597         "ni",           0x220D,
598         "NJcy",         0x040A,
599         "njcy",         0x045A,
600         "nlarr",        0x219A,
601         "nlArr",        0x21CD,
602         "nldr",         0x2025,
603         "nle",          0x2270,
604         "nlE",          0x2270,
605         "nles",         0x2270,
606         "nlt",          0x226E,
607         "nltri",        0x22EA,
608         "nltrie",       0x22EC,
609         "nmid",         0x2224,
610         "not",          0x00AC,
611         "notin",        0x2209,
612         "npar",         0x2226,
613         "npr",          0x2280,
614         "npre",         0x22E0,
615         "nrarr",        0x219B,
616         "nrArr",        0x21CF,
617         "nrtri",        0x22EB,
618         "nrtrie",       0x22ED,
619         "nsc",          0x2281,
620         "nsce",         0x22E1,
621         "nsim",         0x2241,
622         "nsime",        0x2244,
623         "nsmid",        0xE2AA,
624         "nspar",        0x2226,
625         "nsub",         0x2284,
626         "nsube",        0x2288,
627         "nsubE",        0x2288,
628         "nsup",         0x2285,
629         "nsupe",        0x2289,
630         "nsupE",        0x2289,
631         "Ntilde",       0x00D1,
632         "ntilde",       0x00F1,
633         "nu",           0x03BD,
634         "num",          0x0023,
635         "numero",       0x2116,
636         "numsp",        0x2007,
637         "nvdash",       0x22AC,
638         "nvDash",       0x22AD,
639         "nVdash",       0x22AE,
640         "nVDash",       0x22AF,
641         "nwarr",        0x2196,
642         NULL,           0
643 };
644
645 static NameId namesO[]={
646         "Oacgr",        0x038C,
647         "oacgr",        0x03CC,
648         "Oacute",       0x00D3,
649         "oacute",       0x00F3,
650         "oast",         0x229B,
651         "ocir",         0x229A,
652         "Ocirc",        0x00D4,
653         "ocirc",        0x00F4,
654         "Ocy",          0x041E,
655         "ocy",          0x043E,
656         "odash",        0x229D,
657         "Odblac",       0x0150,
658         "odblac",       0x0151,
659         "odot",         0x2299,
660         "OElig",        0x0152,
661         "oelig",        0x0153,
662         "ogon",         0x02DB,
663         "Ogr",          0x039F,
664         "ogr",          0x03BF,
665         "Ograve",       0x00D2,
666         "ograve",       0x00F2,
667         "OHacgr",       0x038F,
668         "ohacgr",       0x03CE,
669         "OHgr",         0x03A9,
670         "ohgr",         0x03C9,
671         "ohm",          0x2126,
672         "olarr",        0x21BA,
673         "Omacr",        0x014C,
674         "omacr",        0x014D,
675         "Omega",        0x03A9,
676         "omega",        0x03C9,
677         "ominus",       0x2296,
678         "oplus",        0x2295,
679         "or",           0x2228,
680         "orarr",        0x21BB,
681         "order",        0x2134,
682         "ordf",         0x00AA,
683         "ordm",         0x00BA,
684         "oS",           0x24C8,
685         "Oslash",       0x00D8,
686         "oslash",       0x00F8,
687         "osol",         0x2298,
688         "Otilde",       0x00D5,
689         "otilde",       0x00F5,
690         "otimes",       0x2297,
691         "Ouml",         0x00D6,
692         "ouml",         0x00F6,
693         NULL,           0
694 };
695
696 static NameId namesP[]={
697         "par",          0x2225,
698         "para",         0x00B6,
699         "part",         0x2202,
700         "Pcy",          0x041F,
701         "pcy",          0x043F,
702         "percnt",       0x0025,
703         "period",       0x002E,
704         "permil",       0x2030,
705         "perp",         0x22A5,
706         "Pgr",          0x03A0,
707         "pgr",          0x03C0,
708         "PHgr",         0x03A6,
709         "phgr",         0x03C6,
710         "Phi",          0x03A6,
711         "phis",         0x03C6,
712         "phiv",         0x03D5,
713         "phmmat",       0x2133,
714         "phone",        0x260E,
715         "Pi",           0x03A0,
716         "pi",           0x03C0,
717         "piv",          0x03D6,
718         "planck",       0x210F,
719         "plus",         0x002B,
720         "plusb",        0x229E,
721         "plusdo",       0x2214,
722         "plusmn",       0x00B1,
723         "pound",        0x00A3,
724         "pr",           0x227A,
725         "prap",         0x227E,
726         "pre",          0x227C,
727         "prime",        0x2032,
728         "Prime",        0x2033,
729         "prnap",        0x22E8,
730         "prnE",         0xE2B3,
731         "prnsim",       0x22E8,
732         "prod",         0x220F,
733         "prop",         0x221D,
734         "prsim",        0x227E,
735         "PSgr",         0x03A8,
736         "psgr",         0x03C8,
737         "Psi",          0x03A8,
738         "psi",          0x03C8,
739         "puncsp",       0x2008,
740         NULL,           0
741 };
742
743 static NameId namesQ[]={
744         "quest",        0x003F,
745         "quot",         0x0022,
746         NULL,           0
747 };
748
749 static NameId namesR[]={
750         "rAarr",        0x21DB,
751         "Racute",       0x0154,
752         "racute",       0x0155,
753         "radic",        0x221A,
754         "rang",         0x3009,
755         "raquo",        0x00BB,
756         "rarr",         0x2192,
757         "Rarr",         0x21A0,
758         "rArr",         0x21D2,
759         "rarr2",        0x21C9,
760         "rarrhk",       0x21AA,
761         "rarrlp",       0x21AC,
762         "rarrtl",       0x21A3,
763         "rarrw",        0x219D,
764         "Rcaron",       0x0158,
765         "rcaron",       0x0159,
766         "Rcedil",       0x0156,
767         "rcedil",       0x0157,
768         "rceil",        0x2309,
769         "rcub",         0x007D,
770         "Rcy",          0x0420,
771         "rcy",          0x0440,
772         "rdquo",        0x201D,
773         "rdquor",       0x201C,
774         "real",         0x211C,
775         "rect",         0x25AD,
776         "reg",          0x00AE,
777         "rfloor",       0x230B,
778         "Rgr",          0x03A1,
779         "rgr",          0x03C1,
780         "rhard",        0x21C1,
781         "rharu",        0x21C0,
782         "rho",          0x03C1,
783         "rhov",         0x03F1,
784         "ring",         0x02DA,
785         "rlarr2",       0x21C4,
786         "rlhar2",       0x21CC,
787         "rpar",         0x0029,
788         "rpargt",       0xE291,
789         "rsh",          0x21B1,
790         "rsqb",         0x005D,
791         "rsquo",        0x2019,
792         "rsquor",       0x2018,
793         "rthree",       0x22CC,
794         "rtimes",       0x22CA,
795         "rtri",         0x25B9,
796         "rtrie",        0x22B5,
797         "rtrif",        0x25B8,
798         "rx",           0x211E,
799         NULL,           0
800 };
801
802 static NameId namesS[]={
803         "Sacute",       0x015A,
804         "sacute",       0x015B,
805         "samalg",       0x2210,
806         "sbsol",        0xFE68,
807         "sc",           0x227B,
808         "scap",         0x227F,
809         "Scaron",       0x0160,
810         "scaron",       0x0161,
811         "sccue",        0x227D,
812         "sce",          0x227D,
813         "Scedil",       0x015E,
814         "scedil",       0x015F,
815         "Scirc",        0x015C,
816         "scirc",        0x015D,
817         "scnap",        0x22E9,
818         "scnE",         0xE2B5,
819         "scnsim",       0x22E9,
820         "scsim",        0x227F,
821         "Scy",          0x0421,
822         "scy",          0x0441,
823         "sdot",         0x22C5,
824         "sdotb",        0x22A1,
825         "sect",         0x00A7,
826         "semi",         0x003B,
827         "setmn",        0x2216,
828         "sext",         0x2736,
829         "sfgr",         0x03C2,
830         "sfrown",       0x2322,
831         "Sgr",          0x03A3,
832         "sgr",          0x03C3,
833         "sharp",        0x266F,
834         "SHCHcy",       0x0429,
835         "shchcy",       0x0449,
836         "SHcy",         0x0428,
837         "shcy",         0x0448,
838         "shy",          0x00AD,
839         "Sigma",        0x03A3,
840         "sigma",        0x03C3,
841         "sigmav",       0x03C2,
842         "sim",          0x223C,
843         "sime",         0x2243,
844         "smid",         0xE301,
845         "smile",        0x2323,
846         "SOFTcy",       0x042C,
847         "softcy",       0x044C,
848         "sol",          0x002F,
849         "spades",       0x2660,
850         "spar",         0x2225,
851         "sqcap",        0x2293,
852         "sqcup",        0x2294,
853         "sqsub",        0x228F,
854         "sqsube",       0x2291,
855         "sqsup",        0x2290,
856         "sqsupe",       0x2292,
857         "squ",          0x25A1,
858         "square",       0x25A1,
859         "squf",         0x25AA,
860         "ssetmn",       0x2216,
861         "ssmile",       0x2323,
862         "sstarf",       0x22C6,
863         "star",         0x22C6,
864         "starf",        0x2605,
865         "sub",          0x2282,
866         "Sub",          0x22D0,
867         "sube",         0x2286,
868         "subE",         0x2286,
869         "subne",        0x228A,
870         "subnE",        0x228A,
871         "sum",          0x2211,
872         "sung",         0x2669,
873         "sup",          0x2283,
874         "Sup",          0x22D1,
875         "sup1",         0x00B9,
876         "sup2",         0x00B2,
877         "sup3",         0x00B3,
878         "supe",         0x2287,
879         "supE",         0x2287,
880         "supne",        0x228B,
881         "supnE",        0x228B,
882         "szlig",        0x00DF,
883         NULL,           0
884 };
885
886 static NameId namesT[]={
887         "target",       0x2316,
888         "tau",          0x03C4,
889         "Tcaron",       0x0164,
890         "tcaron",       0x0165,
891         "Tcedil",       0x0162,
892         "tcedil",       0x0163,
893         "Tcy",          0x0422,
894         "tcy",          0x0442,
895         "tdot",         0x20DB,
896         "telrec",       0x2315,
897         "Tgr",          0x03A4,
898         "tgr",          0x03C4,
899         "there4",       0x2234,
900         "Theta",        0x0398,
901         "thetas",       0x03B8,
902         "thetav",       0x03D1,
903         "THgr",         0x0398,
904         "thgr",         0x03B8,
905         "thinsp",       0x2009,
906         "thkap",        0x2248,
907         "thksim",       0x223C,
908         "THORN",        0x00DE,
909         "thorn",        0x00FE,
910         "tilde",        0x02DC,
911         "times",        0x00D7,
912         "timesb",       0x22A0,
913         "top",          0x22A4,
914         "tprime",       0x2034,
915         "trade",        0x2122,
916         "trie",         0x225C,
917         "TScy",         0x0426,
918         "tscy",         0x0446,
919         "TSHcy",        0x040B,
920         "tshcy",        0x045B,
921         "Tstrok",       0x0166,
922         "tstrok",       0x0167,
923         "twixt",        0x226C,
924         NULL,           0
925 };
926
927 static NameId namesU[]={
928         "Uacgr",        0x038E,
929         "uacgr",        0x03CD,
930         "Uacute",       0x00DA,
931         "uacute",       0x00FA,
932         "uarr",         0x2191,
933         "uArr",         0x21D1,
934         "uarr2",        0x21C8,
935         "Ubrcy",        0x040E,
936         "ubrcy",        0x045E,
937         "Ubreve",       0x016C,
938         "ubreve",       0x016D,
939         "Ucirc",        0x00DB,
940         "ucirc",        0x00FB,
941         "Ucy",          0x0423,
942         "ucy",          0x0443,
943         "Udblac",       0x0170,
944         "udblac",       0x0171,
945         "udiagr",       0x03B0,
946         "Udigr",        0x03AB,
947         "udigr",        0x03CB,
948         "Ugr",          0x03A5,
949         "ugr",          0x03C5,
950         "Ugrave",       0x00D9,
951         "ugrave",       0x00F9,
952         "uharl",        0x21BF,
953         "uharr",        0x21BE,
954         "uhblk",        0x2580,
955         "ulcorn",       0x231C,
956         "ulcrop",       0x230F,
957         "Umacr",        0x016A,
958         "umacr",        0x016B,
959         "uml",          0x00A8,
960         "Uogon",        0x0172,
961         "uogon",        0x0173,
962         "uplus",        0x228E,
963         "upsi",         0x03C5,
964         "Upsi",         0x03D2,
965         "urcorn",       0x231D,
966         "urcrop",       0x230E,
967         "Uring",        0x016E,
968         "uring",        0x016F,
969         "Utilde",       0x0168,
970         "utilde",       0x0169,
971         "utri",         0x25B5,
972         "utrif",        0x25B4,
973         "Uuml",         0x00DC,
974         "uuml",         0x00FC,
975         NULL,           0
976 };
977
978 static NameId namesV[]={
979         "varr",         0x2195,
980         "vArr",         0x21D5,
981         "Vcy",          0x0412,
982         "vcy",          0x0432,
983         "vdash",        0x22A2,
984         "vDash",        0x22A8,
985         "Vdash",        0x22A9,
986         "veebar",       0x22BB,
987         "vellip",       0x22EE,
988         "verbar",       0x007C,
989         "Verbar",       0x2016,
990         "vltri",        0x22B2,
991         "vprime",       0x2032,
992         "vprop",        0x221D,
993         "vrtri",        0x22B3,
994         "vsubne",       0x228A,
995         "vsubnE",       0xE2B8,
996         "vsupne",       0x228B,
997         "vsupnE",       0x228B,
998         "Vvdash",       0x22AA,
999         NULL,           0
1000 };
1001
1002 static NameId namesW[]={
1003         "Wcirc",        0x0174,
1004         "wcirc",        0x0175,
1005         "wedgeq",       0x2259,
1006         "weierp",       0x2118,
1007         "wreath",       0x2240,
1008         NULL,           0
1009 };
1010
1011 static NameId namesX[]={
1012         "xcirc",        0x25CB,
1013         "xdtri",        0x25BD,
1014         "Xgr",          0x039E,
1015         "xgr",          0x03BE,
1016         "xharr",        0x2194,
1017         "xhArr",        0x2194,
1018         "Xi",           0x039E,
1019         "xi",           0x03BE,
1020         "xlArr",        0x21D0,
1021         "xrArr",        0x21D2,
1022         "xutri",        0x25B3,
1023         NULL,           0
1024 };
1025
1026 static NameId namesY[]={
1027         "Yacute",       0x00DD,
1028         "yacute",       0x00FD,
1029         "YAcy",         0x042F,
1030         "yacy",         0x044F,
1031         "Ycirc",        0x0176,
1032         "ycirc",        0x0177,
1033         "Ycy",          0x042B,
1034         "ycy",          0x044B,
1035         "yen",          0x00A5,
1036         "YIcy",         0x0407,
1037         "yicy",         0x0457,
1038         "YUcy",         0x042E,
1039         "yucy",         0x044E,
1040         "yuml",         0x00FF,
1041         "Yuml",         0x0178,
1042         NULL,           0
1043 };
1044
1045 static NameId namesZ[]={
1046         "Zacute",       0x0179,
1047         "zacute",       0x017A,
1048         "Zcaron",       0x017D,
1049         "zcaron",       0x017E,
1050         "Zcy",          0x0417,
1051         "zcy",          0x0437,
1052         "Zdot",         0x017B,
1053         "zdot",         0x017C,
1054         "zeta",         0x03B6,
1055         "Zgr",          0x0396,
1056         "zgr",          0x03B6,
1057         "ZHcy",         0x0416,
1058         "zhcy",         0x0436,
1059         NULL, 0
1060 };
1061
1062 // @todo@ order namesTable and names? by frequency
1063 static NameId* namesTable[] = {
1064         namesA, namesB, namesC, namesD, namesE, namesF, namesG, namesH, namesI,
1065         namesJ, namesK, namesL, namesM, namesN, namesO, namesP, namesQ, namesR,
1066         namesS, namesT, namesU, namesV, namesW, namesX, namesY, namesZ, NULL
1067 };
1068
1069 int HtmlNamedEntity(unsigned char *p, int length)
1070 {
1071     int tableIndex = tolower(*p) - 'a';
1072     if (tableIndex >= 0 && tableIndex < 26) {
1073         NameId* names = namesTable[tableIndex];
1074         int i;
1075
1076         for (i = 0; names[i].name; i++){
1077                 if (strncmp(names[i].name, (char *)p, length) == 0){
1078                         return names[i].value;
1079                 }
1080         }
1081     }
1082     error("unrecognized character entity \"%.*s\"", length, p);
1083     return -1;
1084 }
1085
1086 #else //TODO: Merge Walter's list with Thomas'
1087
1088 static NameId names[] =
1089 {
1090     // Entities
1091     "quot",     34,
1092     "amp",      38,
1093     "lt",       60,
1094     "gt",       62,
1095
1096     "OElig",    338,
1097     "oelig",    339,
1098     "Scaron",   352,
1099     "scaron",   353,
1100     "Yuml",     376,
1101     "circ",     710,
1102     "tilde",    732,
1103     "ensp",     8194,
1104     "emsp",     8195,
1105     "thinsp",   8201,
1106     "zwnj",     8204,
1107     "zwj",      8205,
1108     "lrm",      8206,
1109     "rlm",      8207,
1110     "ndash",    8211,
1111     "mdash",    8212,
1112     "lsquo",    8216,
1113     "rsquo",    8217,
1114     "sbquo",    8218,
1115     "ldquo",    8220,
1116     "rdquo",    8221,
1117     "bdquo",    8222,
1118     "dagger",   8224,
1119     "Dagger",   8225,
1120     "permil",   8240,
1121     "lsaquo",   8249,
1122     "rsaquo",   8250,
1123     "euro",     8364,
1124
1125     // Latin-1 (ISO-8859-1) Entities
1126     "nbsp",     160,
1127     "iexcl",    161,
1128     "cent",     162,
1129     "pound",    163,
1130     "curren",   164,
1131     "yen",      165,
1132     "brvbar",   166,
1133     "sect",     167,
1134     "uml",      168,
1135     "copy",     169,
1136     "ordf",     170,
1137     "laquo",    171,
1138     "not",      172,
1139     "shy",      173,
1140     "reg",      174,
1141     "macr",     175,
1142     "deg",      176,
1143     "plusmn",   177,
1144     "sup2",     178,
1145     "sup3",     179,
1146     "acute",    180,
1147     "micro",    181,
1148     "para",     182,
1149     "middot",   183,
1150     "cedil",    184,
1151     "sup1",     185,
1152     "ordm",     186,
1153     "raquo",    187,
1154     "frac14",   188,
1155     "frac12",   189,
1156     "frac34",   190,
1157     "iquest",   191,
1158     "Agrave",   192,
1159     "Aacute",   193,
1160     "Acirc",    194,
1161     "Atilde",   195,
1162     "Auml",     196,
1163     "Aring",    197,
1164     "AElig",    198,
1165     "Ccedil",   199,
1166     "Egrave",   200,
1167     "Eacute",   201,
1168     "Ecirc",    202,
1169     "Euml",     203,
1170     "Igrave",   204,
1171     "Iacute",   205,
1172     "Icirc",    206,
1173     "Iuml",     207,
1174     "ETH",      208,
1175     "Ntilde",   209,
1176     "Ograve",   210,
1177     "Oacute",   211,
1178     "Ocirc",    212,
1179     "Otilde",   213,
1180     "Ouml",     214,
1181     "times",    215,
1182     "Oslash",   216,
1183     "Ugrave",   217,
1184     "Uacute",   218,
1185     "Ucirc",    219,
1186     "Uuml",     220,
1187     "Yacute",   221,
1188     "THORN",    222,
1189     "szlig",    223,
1190     "agrave",   224,
1191     "aacute",   225,
1192     "acirc",    226,
1193     "atilde",   227,
1194     "auml",     228,
1195     "aring",    229,
1196     "aelig",    230,
1197     "ccedil",   231,
1198     "egrave",   232,
1199     "eacute",   233,
1200     "ecirc",    234,
1201     "euml",     235,
1202     "igrave",   236,
1203     "iacute",   237,
1204     "icirc",    238,
1205     "iuml",     239,
1206     "eth",      240,
1207     "ntilde",   241,
1208     "ograve",   242,
1209     "oacute",   243,
1210     "ocirc",    244,
1211     "otilde",   245,
1212     "ouml",     246,
1213     "divide",   247,
1214     "oslash",   248,
1215     "ugrave",   249,
1216     "uacute",   250,
1217     "ucirc",    251,
1218     "uuml",     252,
1219     "yacute",   253,
1220     "thorn",    254,
1221     "yuml",     255,
1222
1223         // Symbols and Greek letter entities
1224     "fnof",     402,
1225     "Alpha",    913,
1226     "Beta",     914,
1227     "Gamma",    915,
1228     "Delta",    916,
1229     "Epsilon",  917,
1230     "Zeta",     918,
1231     "Eta",      919,
1232     "Theta",    920,
1233     "Iota",     921,
1234     "Kappa",    922,
1235     "Lambda",   923,
1236     "Mu",       924,
1237     "Nu",       925,
1238     "Xi",       926,
1239     "Omicron",  927,
1240     "Pi",       928,
1241     "Rho",      929,
1242     "Sigma",    931,
1243     "Tau",      932,
1244     "Upsilon",  933,
1245     "Phi",      934,
1246     "Chi",      935,
1247     "Psi",      936,
1248     "Omega",    937,
1249     "alpha",    945,
1250     "beta",     946,
1251     "gamma",    947,
1252     "delta",    948,
1253     "epsilon",  949,
1254     "zeta",     950,
1255     "eta",      951,
1256     "theta",    952,
1257     "iota",     953,
1258     "kappa",    954,
1259     "lambda",   955,
1260     "mu",       956,
1261     "nu",       957,
1262     "xi",       958,
1263     "omicron",  959,
1264     "pi",       960,
1265     "rho",      961,
1266     "sigmaf",   962,
1267     "sigma",    963,
1268     "tau",      964,
1269     "upsilon",  965,
1270     "phi",      966,
1271     "chi",      967,
1272     "psi",      968,
1273     "omega",    969,
1274     "thetasym", 977,
1275     "upsih",    978,
1276     "piv",      982,
1277     "bull",     8226,
1278     "hellip",   8230,
1279     "prime",    8242,
1280     "Prime",    8243,
1281     "oline",    8254,
1282     "frasl",    8260,
1283     "weierp",   8472,
1284     "image",    8465,
1285     "real",     8476,
1286     "trade",    8482,
1287     "alefsym",  8501,
1288     "larr",     8592,
1289     "uarr",     8593,
1290     "rarr",     8594,
1291     "darr",     8595,
1292     "harr",     8596,
1293     "crarr",    8629,
1294     "lArr",     8656,
1295     "uArr",     8657,
1296     "rArr",     8658,
1297     "dArr",     8659,
1298     "hArr",     8660,
1299     "forall",   8704,
1300     "part",     8706,
1301     "exist",    8707,
1302     "empty",    8709,
1303     "nabla",    8711,
1304     "isin",     8712,
1305     "notin",    8713,
1306     "ni",       8715,
1307     "prod",     8719,
1308     "sum",      8721,
1309     "minus",    8722,
1310     "lowast",   8727,
1311     "radic",    8730,
1312     "prop",     8733,
1313     "infin",    8734,
1314     "ang",      8736,
1315     "and",      8743,
1316     "or",       8744,
1317     "cap",      8745,
1318     "cup",      8746,
1319     "int",      8747,
1320     "there4",   8756,
1321     "sim",      8764,
1322     "cong",     8773,
1323     "asymp",    8776,
1324     "ne",       8800,
1325     "equiv",    8801,
1326     "le",       8804,
1327     "ge",       8805,
1328     "sub",      8834,
1329     "sup",      8835,
1330     "nsub",     8836,
1331     "sube",     8838,
1332     "supe",     8839,
1333     "oplus",    8853,
1334     "otimes",   8855,
1335     "perp",     8869,
1336     "sdot",     8901,
1337     "lceil",    8968,
1338     "rceil",    8969,
1339     "lfloor",   8970,
1340     "rfloor",   8971,
1341     "lang",     9001,
1342     "rang",     9002,
1343     "loz",      9674,
1344     "spades",   9824,
1345     "clubs",    9827,
1346     "hearts",   9829,
1347     "diams",    9830,
1348 };
1349
1350 int HtmlNamedEntity(unsigned char *p, int length)
1351 {
1352     int i;
1353
1354     // BUG: this is a dumb, slow linear search
1355     for (i = 0; i < sizeof(names) / sizeof(names[0]); i++)
1356     {
1357         // Entries are case sensitive
1358         if (memcmp(names[i].name, (char *)p, length) == 0 &&
1359             !names[i].name[length])
1360             return names[i].value;
1361     }
1362     return -1;
1363 }
1364
1365 #endif
Note: See TracBrowser for help on using the browser.