2 // Copyright (c) 1999-2006 by Digital Mars
4 // written by Walter Bright
5 // http://www.digitalmars.com
6 // License for redistribution is by either the Artistic License
7 // in artistic.txt, or the GNU General Public License in gnu.txt.
8 // See the included readme.txt for details.
13 /*********************************************
14 * Convert from named entity to its encoding.
16 * http://www.htmlhelp.com/reference/html40/entities/
17 * http://www.w3.org/TR/1999/REC-html401-19991224/sgml/entities.html
27 static NameId namesA
[]={
73 static NameId namesB
[]={
145 static NameId namesC
[]={
195 static NameId namesD
[]={
244 static NameId namesE
[]={
300 static NameId namesF
[]={
332 static NameId namesG
[]={
372 static NameId namesH
[]={
393 static NameId namesI
[]={
440 static NameId namesJ
[]={
452 static NameId namesK
[]={
471 static NameId namesL
[]={
545 static NameId namesM
[]={
569 static NameId namesN
[]={
577 "nbsp", 32, // make non-breaking space appear as space
646 static NameId namesO
[]={
697 static NameId namesP
[]={
744 static NameId namesQ
[]={
750 static NameId namesR
[]={
803 static NameId namesS
[]={
887 static NameId namesT
[]={
928 static NameId namesU
[]={
979 static NameId namesV
[]={
1003 static NameId namesW
[]={
1012 static NameId namesX
[]={
1027 static NameId namesY
[]={
1046 static NameId namesZ
[]={
1063 // @todo@ order namesTable and names? by frequency
1064 static NameId
* namesTable
[] = {
1065 namesA
, namesB
, namesC
, namesD
, namesE
, namesF
, namesG
, namesH
, namesI
,
1066 namesJ
, namesK
, namesL
, namesM
, namesN
, namesO
, namesP
, namesQ
, namesR
,
1067 namesS
, namesT
, namesU
, namesV
, namesW
, namesX
, namesY
, namesZ
, NULL
1070 int HtmlNamedEntity(unsigned char *p
, int length
)
1072 int tableIndex
= tolower(*p
) - 'a';
1073 if (tableIndex
>= 0 && tableIndex
< 26) {
1074 NameId
* names
= namesTable
[tableIndex
];
1077 for (i
= 0; names
[i
].name
; i
++){
1078 if (strncmp(names
[i
].name
, (char *)p
, length
) == 0){
1079 return names
[i
].value
;
1083 error("unrecognized character entity \"%.*s\"", length
, p
);
1087 #else //TODO: Merge Walter's list with Thomas'
1089 static NameId names
[] =
1126 // Latin-1 (ISO-8859-1) Entities
1224 // Symbols and Greek letter entities
1351 int HtmlNamedEntity(unsigned char *p
, int length
)
1355 // BUG: this is a dumb, slow linear search
1356 for (i
= 0; i
< sizeof(names
) / sizeof(names
[0]); i
++)
1358 // Entries are case sensitive
1359 if (memcmp(names
[i
].name
, (char *)p
, length
) == 0 &&
1360 !names
[i
].name
[length
])
1361 return names
[i
].value
;