[q-lang-cvs] q/src w3centities.h,NONE,1.1 qbase.c,1.25,1.26
Brought to you by:
agraef
From: Albert G. <ag...@us...> - 2008-01-16 08:28:18
|
Update of /cvsroot/q-lang/q/src In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv28296 Modified Files: qbase.c Added Files: w3centities.h Log Message: add xml entity character escapes, as suggested by Rob Hubbard and John Cowan Index: qbase.c =================================================================== RCS file: /cvsroot/q-lang/q/src/qbase.c,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** qbase.c 24 Sep 2007 12:20:59 -0000 1.25 --- qbase.c 16 Jan 2008 08:28:15 -0000 1.26 *************** *** 1019,1022 **** --- 1019,1051 ---- } + #include "w3centities.h" + + static int entcmp(const void *_x, const void *_y) + { + const char *x = (const char*)_x; + const Entity *y = (const Entity*)_y; + return strcmp(x, y->name); + } + + static inline long entity(const char *name) + { + Entity *x = bsearch(name, entities, sizeof(entities) / sizeof(Entity), + sizeof(Entity), entcmp); + return x?x->c:-1; + } + + static long parse_entity(char *s, char **t) + { + long c; + char *p = strchr(s, ';'); + if (!p) return -1; + *p = 0; + c = entity(s); + *p = ';'; + if (c < 0) return c; + *t = p+1; + return c; + } + static char * scanchar(char *t, char **s, char **p) *************** *** 1049,1052 **** --- 1078,1099 ---- *t++ = c; break; + case '&': { + char *r; + long c = parse_entity(*s, s); + if (c >= 0) { + #ifdef HAVE_UNICODE + if (c >= 0x110000) + c %= 0x110000; + u8encode(t, c); + t += strlen(t); + #else + *t++ = (char)c; + #endif + } else { + *p = *s-1; + *t++ = c; + } + break; + } case '(': { if ('0' <= **s && **s <= '9') { --- NEW FILE: w3centities.h --- /* generated from w3centities.ent Wed Jan 16 08:17:24 2008 */ typedef struct ENTITY { char *name; long c; } Entity; static Entity entities[] = { { "AElig", 0x000C6 }, { "Aacgr", 0x00386 }, { "Aacute", 0x000C1 }, { "Abreve", 0x00102 }, { "Acirc", 0x000C2 }, { "Acy", 0x00410 }, { "Afr", 0x1D504 }, { "Agr", 0x00391 }, { "Agrave", 0x000C0 }, { "Alpha", 0x00391 }, { "Amacr", 0x00100 }, { "And", 0x02A53 }, { "Aogon", 0x00104 }, { "Aopf", 0x1D538 }, [...2081 lines suppressed...] { "yicy", 0x00457 }, { "yopf", 0x1D56A }, { "yscr", 0x1D4CE }, { "yucy", 0x0044E }, { "yuml", 0x000FF }, { "zacute", 0x0017A }, { "zcaron", 0x0017E }, { "zcy", 0x00437 }, { "zdot", 0x0017C }, { "zeetrf", 0x02128 }, { "zeta", 0x003B6 }, { "zfr", 0x1D537 }, { "zgr", 0x003B6 }, { "zhcy", 0x00436 }, { "zigrarr", 0x021DD }, { "zopf", 0x1D56B }, { "zscr", 0x1D4CF }, { "zwj", 0x0200D }, { "zwnj", 0x0200C }, }; |