Commit 47d358cd authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Simplify entity table a little

parent 3caf6353
...@@ -235,129 +235,128 @@ char *encode_URI_component( const char *psz_uri ) ...@@ -235,129 +235,128 @@ char *encode_URI_component( const char *psz_uri )
static const struct xml_entity_s static const struct xml_entity_s
{ {
char psz_entity[8]; char psz_entity[8];
uint8_t i_length;
char psz_char[4]; char psz_char[4];
} p_xml_entities[] = { } p_xml_entities[] = {
/* Important: this list has to be in alphabetical order (psz_entity-wise) */ /* Important: this list has to be in alphabetical order (psz_entity-wise) */
{ "AElig;", 6, "Æ" }, { "AElig;", "Æ" },
{ "Aacute;", 7, "Á" }, { "Aacute;", "Á" },
{ "Acirc;", 6, "Â" }, { "Acirc;", "Â" },
{ "Agrave;", 7, "À" }, { "Agrave;", "À" },
{ "Aring;", 6, "Å" }, { "Aring;", "Å" },
{ "Atilde;", 7, "Ã" }, { "Atilde;", "Ã" },
{ "Auml;", 5, "Ä" }, { "Auml;", "Ä" },
{ "Ccedil;", 7, "Ç" }, { "Ccedil;", "Ç" },
{ "Dagger;", 7, "‡" }, { "Dagger;", "‡" },
{ "ETH;", 4, "Ð" }, { "ETH;", "Ð" },
{ "Eacute;", 7, "É" }, { "Eacute;", "É" },
{ "Ecirc;", 6, "Ê" }, { "Ecirc;", "Ê" },
{ "Egrave;", 7, "È" }, { "Egrave;", "È" },
{ "Euml;", 5, "Ë" }, { "Euml;", "Ë" },
{ "Iacute;", 7, "Í" }, { "Iacute;", "Í" },
{ "Icirc;", 6, "Î" }, { "Icirc;", "Î" },
{ "Igrave;", 7, "Ì" }, { "Igrave;", "Ì" },
{ "Iuml;", 5, "Ï" }, { "Iuml;", "Ï" },
{ "Ntilde;", 7, "Ñ" }, { "Ntilde;", "Ñ" },
{ "OElig;", 6, "Œ" }, { "OElig;", "Œ" },
{ "Oacute;", 7, "Ó" }, { "Oacute;", "Ó" },
{ "Ocirc;", 6, "Ô" }, { "Ocirc;", "Ô" },
{ "Ograve;", 7, "Ò" }, { "Ograve;", "Ò" },
{ "Oslash;", 7, "Ø" }, { "Oslash;", "Ø" },
{ "Otilde;", 7, "Õ" }, { "Otilde;", "Õ" },
{ "Ouml;", 5, "Ö" }, { "Ouml;", "Ö" },
{ "Scaron;", 7, "Š" }, { "Scaron;", "Š" },
{ "THORN;", 6, "Þ" }, { "THORN;", "Þ" },
{ "Uacute;", 7, "Ú" }, { "Uacute;", "Ú" },
{ "Ucirc;", 6, "Û" }, { "Ucirc;", "Û" },
{ "Ugrave;", 7, "Ù" }, { "Ugrave;", "Ù" },
{ "Uuml;", 5, "Ü" }, { "Uuml;", "Ü" },
{ "Yacute;", 7, "Ý" }, { "Yacute;", "Ý" },
{ "Yuml;", 5, "Ÿ" }, { "Yuml;", "Ÿ" },
{ "aacute;", 7, "á" }, { "aacute;", "á" },
{ "acirc;", 6, "â" }, { "acirc;", "â" },
{ "acute;", 6, "´" }, { "acute;", "´" },
{ "aelig;", 6, "æ" }, { "aelig;", "æ" },
{ "agrave;", 7, "à" }, { "agrave;", "à" },
{ "aring;", 6, "å" }, { "aring;", "å" },
{ "atilde;", 7, "ã" }, { "atilde;", "ã" },
{ "auml;", 5, "ä" }, { "auml;", "ä" },
{ "bdquo;", 6, "„" }, { "bdquo;", "„" },
{ "brvbar;", 7, "¦" }, { "brvbar;", "¦" },
{ "ccedil;", 7, "ç" }, { "ccedil;", "ç" },
{ "cedil;", 6, "¸" }, { "cedil;", "¸" },
{ "cent;", 5, "¢" }, { "cent;", "¢" },
{ "circ;", 5, "ˆ" }, { "circ;", "ˆ" },
{ "copy;", 5, "©" }, { "copy;", "©" },
{ "curren;", 7, "¤" }, { "curren;", "¤" },
{ "dagger;", 7, "†" }, { "dagger;", "†" },
{ "deg;", 4, "°" }, { "deg;", "°" },
{ "divide;", 7, "÷" }, { "divide;", "÷" },
{ "eacute;", 7, "é" }, { "eacute;", "é" },
{ "ecirc;", 6, "ê" }, { "ecirc;", "ê" },
{ "egrave;", 7, "è" }, { "egrave;", "è" },
{ "eth;", 4, "ð" }, { "eth;", "ð" },
{ "euml;", 5, "ë" }, { "euml;", "ë" },
{ "euro;", 5, "€" }, { "euro;", "€" },
{ "frac12;", 7, "½" }, { "frac12;", "½" },
{ "frac14;", 7, "¼" }, { "frac14;", "¼" },
{ "frac34;", 7, "¾" }, { "frac34;", "¾" },
{ "hellip;", 7, "…" }, { "hellip;", "…" },
{ "iacute;", 7, "í" }, { "iacute;", "í" },
{ "icirc;", 6, "î" }, { "icirc;", "î" },
{ "iexcl;", 6, "¡" }, { "iexcl;", "¡" },
{ "igrave;", 7, "ì" }, { "igrave;", "ì" },
{ "iquest;", 7, "¿" }, { "iquest;", "¿" },
{ "iuml;", 5, "ï" }, { "iuml;", "ï" },
{ "laquo;", 6, "«" }, { "laquo;", "«" },
{ "ldquo;", 6, "“" }, { "ldquo;", "“" },
{ "lsaquo;", 7, "‹" }, { "lsaquo;", "‹" },
{ "lsquo;", 6, "‘" }, { "lsquo;", "‘" },
{ "macr;", 5, "¯" }, { "macr;", "¯" },
{ "mdash;", 6, "—" }, { "mdash;", "—" },
{ "micro;", 6, "µ" }, { "micro;", "µ" },
{ "middot;", 7, "·" }, { "middot;", "·" },
{ "nbsp;", 5, "\xc2\xa0" }, { "nbsp;", "\xc2\xa0" },
{ "ndash;", 6, "–" }, { "ndash;", "–" },
{ "not;", 4, "¬" }, { "not;", "¬" },
{ "ntilde;", 7, "ñ" }, { "ntilde;", "ñ" },
{ "oacute;", 7, "ó" }, { "oacute;", "ó" },
{ "ocirc;", 6, "ô" }, { "ocirc;", "ô" },
{ "oelig;", 6, "œ" }, { "oelig;", "œ" },
{ "ograve;", 7, "ò" }, { "ograve;", "ò" },
{ "ordf;", 5, "ª" }, { "ordf;", "ª" },
{ "ordm;", 5, "º" }, { "ordm;", "º" },
{ "oslash;", 7, "ø" }, { "oslash;", "ø" },
{ "otilde;", 7, "õ" }, { "otilde;", "õ" },
{ "ouml;", 5, "ö" }, { "ouml;", "ö" },
{ "para;", 5, "¶" }, { "para;", "¶" },
{ "permil;", 7, "‰" }, { "permil;", "‰" },
{ "plusmn;", 7, "±" }, { "plusmn;", "±" },
{ "pound;", 6, "£" }, { "pound;", "£" },
{ "raquo;", 6, "»" }, { "raquo;", "»" },
{ "rdquo;", 6, "”" }, { "rdquo;", "”" },
{ "reg;", 4, "®" }, { "reg;", "®" },
{ "rsaquo;", 7, "›" }, { "rsaquo;", "›" },
{ "rsquo;", 6, "’" }, { "rsquo;", "’" },
{ "sbquo;", 6, "‚" }, { "sbquo;", "‚" },
{ "scaron;", 7, "š" }, { "scaron;", "š" },
{ "sect;", 5, "§" }, { "sect;", "§" },
{ "shy;", 4, "­" }, { "shy;", "­" },
{ "sup1;", 5, "¹" }, { "sup1;", "¹" },
{ "sup2;", 5, "²" }, { "sup2;", "²" },
{ "sup3;", 5, "³" }, { "sup3;", "³" },
{ "szlig;", 6, "ß" }, { "szlig;", "ß" },
{ "thorn;", 6, "þ" }, { "thorn;", "þ" },
{ "tilde;", 6, "˜" }, { "tilde;", "˜" },
{ "times;", 6, "×" }, { "times;", "×" },
{ "trade;", 6, "™" }, { "trade;", "™" },
{ "uacute;", 7, "ú" }, { "uacute;", "ú" },
{ "ucirc;", 6, "û" }, { "ucirc;", "û" },
{ "ugrave;", 7, "ù" }, { "ugrave;", "ù" },
{ "uml;", 4, "¨" }, { "uml;", "¨" },
{ "uuml;", 5, "ü" }, { "uuml;", "ü" },
{ "yacute;", 7, "ý" }, { "yacute;", "ý" },
{ "yen;", 4, "¥" }, { "yen;", "¥" },
{ "yuml;", 5, "ÿ" }, { "yuml;", "ÿ" },
}; };
/** /**
...@@ -373,17 +372,17 @@ void resolve_xml_special_chars( char *psz_value ) ...@@ -373,17 +372,17 @@ void resolve_xml_special_chars( char *psz_value )
if( *psz_value == '&' ) if( *psz_value == '&' )
{ {
char *psz_value1 = psz_value + 1; char *psz_value1 = psz_value + 1;
#define TRY_CHAR( src, len, dst ) \ #define TRY_CHAR( src, dst ) \
if( !strncmp( psz_value1, src, len ) ) \ if( !strncmp( psz_value1, src";", strlen( src";" ) ) ) \
{ \ { \
*p_pos = dst; \ *p_pos = dst; \
psz_value += len + 1; \ psz_value += strlen( src ) + 2; \
} }
TRY_CHAR( "lt;", 3, '<' ) TRY_CHAR( "lt", '<' )
else TRY_CHAR( "amp;", 4, '&' ) else TRY_CHAR( "amp", '&' )
else TRY_CHAR( "apos;", 5, '\'' ) else TRY_CHAR( "apos", '\'' )
else TRY_CHAR( "gt;", 3, '>' ) else TRY_CHAR( "gt", '>' )
else TRY_CHAR( "quot;", 5, '"' ) else TRY_CHAR( "quot", '"' )
#undef TRY_CHAR #undef TRY_CHAR
else if( *psz_value1 == '#' ) else if( *psz_value1 == '#' )
{ {
...@@ -420,19 +419,20 @@ void resolve_xml_special_chars( char *psz_value ) ...@@ -420,19 +419,20 @@ void resolve_xml_special_chars( char *psz_value )
int cmp = -1; int cmp = -1;
while( step ) while( step )
{ {
size_t ilen = strlen( p_xml_entities[i].psz_entity );
step >>= 1; step >>= 1;
if( i >= i_entities ) if( i >= i_entities )
cmp = -1; cmp = -1;
else else
cmp = strncmp( psz_value1, /* Skip the & */ cmp = strncmp( psz_value1, /* Skip the & */
p_xml_entities[i].psz_entity, p_xml_entities[i].psz_entity,
p_xml_entities[i].i_length ); strlen( p_xml_entities[i].psz_entity ) );
if( cmp == 0 ) if( cmp == 0 )
{ {
size_t i_len = strlen( p_xml_entities[i].psz_char ); size_t olen = strlen( p_xml_entities[i].psz_char );
strncpy( p_pos, p_xml_entities[i].psz_char, i_len ); memcpy( p_pos, p_xml_entities[i].psz_char, olen );
p_pos += i_len - 1; p_pos += olen - 1;
psz_value += p_xml_entities[i].i_length+1; psz_value += ilen+1;
break; break;
} }
else if( cmp < 0 ) else if( cmp < 0 )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment