Commit 36250394 authored by Michael R Sweet's avatar Michael R Sweet

Fixed entity number support (STR #8)

Fixed mxmlLoadString() bug with UTF-8 (STR #7)

Fixed entity lookup bug (STR #5)
parent c1931af5
CHANGES - 07/11/2004
CHANGES - 10/26/2004
--------------------
CHANGES IN Mini-XML 2.1
- Fixed entity number support (STR #8)
- Fixed mxmlLoadString() bug with UTF-8 (STR #7)
- Fixed entity lookup bug (STR #5)
- Added mxmlLoadFd() and mxmlSaveFd() functions.
- Fixed multi-word UTF-16 handling.
......
/*
* "$Id: mxml-entity.c,v 1.5 2004/06/01 20:19:34 mike Exp $"
* "$Id: mxml-entity.c,v 1.6 2004/10/26 21:04:32 mike Exp $"
*
* Character entity support code for Mini-XML, a small XML-like
* file parsing library.
......@@ -434,10 +434,14 @@ default_callback(const char *name) /* I - Entity name */
};
/*
* Do a binary search for the named entity...
*/
first = 0;
last = (int)(sizeof(entities) / sizeof(entities[0]) - 1);
while (last > first)
while ((last - first) > 1)
{
current = (first + last) / 2;
......@@ -449,15 +453,20 @@ default_callback(const char *name) /* I - Entity name */
first = current;
}
current = (first + last) / 2;
/*
* If we get here, there is a small chance that there is still
* a match; check first and last...
*/
if (!strcmp(name, entities[current].name))
return (entities[current].val);
if (!strcmp(name, entities[first].name))
return (entities[first].val);
else if (!strcmp(name, entities[last].name))
return (entities[last].val);
else
return (-1);
}
/*
* End of "$Id: mxml-entity.c,v 1.5 2004/06/01 20:19:34 mike Exp $".
* End of "$Id: mxml-entity.c,v 1.6 2004/10/26 21:04:32 mike Exp $".
*/
/*
* "$Id: mxml-file.c,v 1.34 2004/07/11 13:14:07 mike Exp $"
* "$Id: mxml-file.c,v 1.35 2004/10/26 21:04:32 mike Exp $"
*
* File loading code for Mini-XML, a small XML-like file parsing library.
*
......@@ -1168,12 +1168,12 @@ mxml_get_entity(mxml_node_t *parent, /* I - Parent node */
return (EOF);
}
if (entity[1] == '#')
if (entity[0] == '#')
{
if (entity[2] == 'x')
ch = strtol(entity + 3, NULL, 16);
if (entity[1] == 'x')
ch = strtol(entity + 2, NULL, 16);
else
ch = strtol(entity + 2, NULL, 10);
ch = strtol(entity + 1, NULL, 10);
}
else if ((ch = mxmlEntityGetValue(entity)) < 0)
mxml_error("Entity name \"%s;\" not supported under parent <%s>!",
......@@ -1838,7 +1838,7 @@ mxml_string_getc(void *p, /* I - Pointer to file */
s = (const char **)p;
if ((ch = *s[0] & 255) != 0 || *encoding == ENCODE_UTF16LE)
if ((ch = (*s)[0] & 255) != 0 || *encoding == ENCODE_UTF16LE)
{
/*
* Got character; convert UTF-8 to integer and return...
......@@ -1857,7 +1857,7 @@ mxml_string_getc(void *p, /* I - Pointer to file */
* UTF-16 big-endian BOM?
*/
if ((*s[0] & 255) != 0xff)
if (((*s)[0] & 255) != 0xff)
return (EOF);
*encoding = ENCODE_UTF16BE;
......@@ -1871,7 +1871,7 @@ mxml_string_getc(void *p, /* I - Pointer to file */
* UTF-16 little-endian BOM?
*/
if ((*s[0] & 255) != 0xfe)
if (((*s)[0] & 255) != 0xfe)
return (EOF);
*encoding = ENCODE_UTF16LE;
......@@ -1885,10 +1885,10 @@ mxml_string_getc(void *p, /* I - Pointer to file */
* Two-byte value...
*/
if ((*s[0] & 0xc0) != 0x80)
if (((*s)[0] & 0xc0) != 0x80)
return (EOF);
ch = ((ch & 0x1f) << 6) | (*s[0] & 0x3f);
ch = ((ch & 0x1f) << 6) | ((*s)[0] & 0x3f);
(*s)++;
......@@ -1900,11 +1900,11 @@ mxml_string_getc(void *p, /* I - Pointer to file */
* Three-byte value...
*/
if ((*s[0] & 0xc0) != 0x80 ||
(*s[1] & 0xc0) != 0x80)
if (((*s)[0] & 0xc0) != 0x80 ||
((*s)[1] & 0xc0) != 0x80)
return (EOF);
ch = ((((ch & 0x0f) << 6) | (*s[0] & 0x3f)) << 6) | (*s[1] & 0x3f);
ch = ((((ch & 0x0f) << 6) | ((*s)[0] & 0x3f)) << 6) | ((*s)[1] & 0x3f);
(*s) += 2;
......@@ -1916,13 +1916,13 @@ mxml_string_getc(void *p, /* I - Pointer to file */
* Four-byte value...
*/
if ((*s[0] & 0xc0) != 0x80 ||
(*s[1] & 0xc0) != 0x80 ||
(*s[2] & 0xc0) != 0x80)
if (((*s)[0] & 0xc0) != 0x80 ||
((*s)[1] & 0xc0) != 0x80 ||
((*s)[2] & 0xc0) != 0x80)
return (EOF);
ch = ((((((ch & 0x07) << 6) | (*s[0] & 0x3f)) << 6) |
(*s[1] & 0x3f)) << 6) | (*s[2] & 0x3f);
ch = ((((((ch & 0x07) << 6) | ((*s)[0] & 0x3f)) << 6) |
((*s)[1] & 0x3f)) << 6) | ((*s)[2] & 0x3f);
(*s) += 3;
......@@ -1936,7 +1936,7 @@ mxml_string_getc(void *p, /* I - Pointer to file */
* Read UTF-16 big-endian char...
*/
ch = (ch << 8) | (*s[0] & 255);
ch = (ch << 8) | ((*s)[0] & 255);
(*s) ++;
if (ch >= 0xd800 && ch <= 0xdbff)
......@@ -1948,10 +1948,10 @@ mxml_string_getc(void *p, /* I - Pointer to file */
int lch; /* Lower word */
if (!*s[0])
if (!(*s)[0])
return (EOF);
lch = ((*s[0] & 255) << 8) | (*s[1] & 255);
lch = (((*s)[0] & 255) << 8) | ((*s)[1] & 255);
(*s) += 2;
if (lch < 0xdc00 || lch >= 0xdfff)
......@@ -1967,7 +1967,7 @@ mxml_string_getc(void *p, /* I - Pointer to file */
* Read UTF-16 little-endian char...
*/
ch = ch | ((*s[0] & 255) << 8);
ch = ch | (((*s)[0] & 255) << 8);
if (!ch)
{
......@@ -1986,10 +1986,10 @@ mxml_string_getc(void *p, /* I - Pointer to file */
int lch; /* Lower word */
if (!*s[1])
if (!(*s)[1])
return (EOF);
lch = ((*s[1] & 255) << 8) | (*s[0] & 255);
lch = (((*s)[1] & 255) << 8) | ((*s)[0] & 255);
(*s) += 2;
if (lch < 0xdc00 || lch >= 0xdfff)
......@@ -2470,5 +2470,5 @@ mxml_write_ws(mxml_node_t *node, /* I - Current node */
/*
* End of "$Id: mxml-file.c,v 1.34 2004/07/11 13:14:07 mike Exp $".
* End of "$Id: mxml-file.c,v 1.35 2004/10/26 21:04:32 mike Exp $".
*/
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