root/branches/dmdfe/entity.c

Revision 458, 24.6 kB (checked in by Gregor, 2 years ago)

MERGE: DMD 1.011

Line 
1 // Copyright (c) 1999-2006 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     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,<