Fix reading of UTF-16 characters from files.

pull/193/head
Michael R Sweet 11 years ago
parent b6c73fe01c
commit ace5aa8686
  1. 3
      CHANGES
  2. 77
      mxml-file.c

@ -3,11 +3,12 @@ CHANGES - 2013-11-11
CHANGES IN Mini-XML 2.8
- Now call docsetutil using xcrun on OS X.
- Now call docsetutil using xcrun on OS X (Bug #458)
- mxmldoc did not escape special HTML characters inside @code foo@
comments.
- Fixed a memory leak in mxmlElementDeleteAttr (Bug #452)
- Added MXML_MAJOR/MINOR_VERSION definitions to mxml.h (Bug $461)
- Fixed a bug reading UTF-16 characters from a file (Bug #454)
CHANGES IN Mini-XML 2.7

@ -3,7 +3,7 @@
*
* File loading code for Mini-XML, a small XML-like file parsing library.
*
* Copyright 2003-2011 by Michael R Sweet.
* Copyright 2003-2013 by Michael R Sweet.
*
* These coded instructions, statements, and computer programs are the
* property of Michael R Sweet and are protected by Federal copyright
@ -12,41 +12,6 @@
* missing or damaged, see the license at:
*
* http://www.minixml.org/
*
* Contents:
*
* mxmlLoadFd() - Load a file descriptor into an XML node tree.
* mxmlLoadFile() - Load a file into an XML node tree.
* mxmlLoadString() - Load a string into an XML node tree.
* mxmlSaveAllocString() - Save an XML tree to an allocated string.
* mxmlSaveFd() - Save an XML tree to a file descriptor.
* mxmlSaveFile() - Save an XML tree to a file.
* mxmlSaveString() - Save an XML node tree to a string.
* mxmlSAXLoadFd() - Load a file descriptor into an XML node tree
* using a SAX callback.
* mxmlSAXLoadFile() - Load a file into an XML node tree
* using a SAX callback.
* mxmlSAXLoadString() - Load a string into an XML node tree
* using a SAX callback.
* mxmlSetCustomHandlers() - Set the handling functions for custom data.
* mxmlSetErrorCallback() - Set the error message callback.
* mxmlSetWrapMargin() - Set the wrap margin when saving XML data.
* mxml_add_char() - Add a character to a buffer, expanding as needed.
* mxml_fd_getc() - Read a character from a file descriptor.
* mxml_fd_putc() - Write a character to a file descriptor.
* mxml_fd_read() - Read a buffer of data from a file descriptor.
* mxml_fd_write() - Write a buffer of data to a file descriptor.
* mxml_file_getc() - Get a character from a file.
* mxml_file_putc() - Write a character to a file.
* mxml_get_entity() - Get the character corresponding to an entity...
* mxml_load_data() - Load data into an XML node tree.
* mxml_parse_element() - Parse an element for any attributes...
* mxml_string_getc() - Get a character from a string.
* mxml_string_putc() - Write a character to a string.
* mxml_write_name() - Write a name string.
* mxml_write_node() - Save an XML node to a file.
* mxml_write_string() - Write a string, escaping & and < as needed.
* mxml_write_ws() - Do whitespace callback...
*/
/*
@ -128,7 +93,7 @@ static int mxml_write_node(mxml_node_t *node, void *p,
_mxml_global_t *global);
static int mxml_write_string(const char *s, void *p,
_mxml_putc_cb_t putc_cb);
static int mxml_write_ws(mxml_node_t *node, void *p,
static int mxml_write_ws(mxml_node_t *node, void *p,
mxml_save_cb_t cb, int ws,
int col, _mxml_putc_cb_t putc_cb);
@ -567,7 +532,7 @@ mxmlSAXLoadString(
*
* The save function accepts a node pointer and must return a malloc'd
* string on success and NULL on error.
*
*
*/
void
@ -756,7 +721,7 @@ mxml_fd_getc(void *p, /* I - File descriptor buffer */
return (EOF);
ch = *(buf->current)++;
if (ch != 0xff)
return (EOF);
@ -775,7 +740,7 @@ mxml_fd_getc(void *p, /* I - File descriptor buffer */
return (EOF);
ch = *(buf->current)++;
if (ch != 0xfe)
return (EOF);
@ -1287,7 +1252,8 @@ mxml_file_getc(void *p, /* I - Pointer to file */
* Multi-word UTF-16 char...
*/
int lch = (getc(fp) << 8) | getc(fp);
int lch = getc(fp);
lch = (lch << 8) | getc(fp);
if (lch < 0xdc00 || lch >= 0xdfff)
return (EOF);
@ -1315,7 +1281,8 @@ mxml_file_getc(void *p, /* I - Pointer to file */
* Multi-word UTF-16 char...
*/
int lch = getc(fp) | (getc(fp) << 8);
int lch = getc(fp);
lch |= (getc(fp) << 8);
if (lch < 0xdc00 || lch >= 0xdfff)
return (EOF);
@ -1516,7 +1483,7 @@ mxml_load_data(
default : /* Ignore... */
node = NULL;
break;
}
}
if (*bufptr)
{
@ -1659,9 +1626,9 @@ mxml_load_data(
* There can only be one root element!
*/
mxml_error("<%s> cannot be a second root node after <%s>",
mxml_error("<%s> cannot be a second root node after <%s>",
buffer, first->value.element.name);
goto error;
goto error;
}
if ((node = mxmlNewElement(parent, buffer)) == NULL)
@ -1727,9 +1694,9 @@ mxml_load_data(
* There can only be one root element!
*/
mxml_error("<%s> cannot be a second root node after <%s>",
mxml_error("<%s> cannot be a second root node after <%s>",
buffer, first->value.element.name);
goto error;
goto error;
}
if ((node = mxmlNewElement(parent, buffer)) == NULL)
@ -1794,9 +1761,9 @@ mxml_load_data(
* There can only be one root element!
*/
mxml_error("<%s> cannot be a second root node after <%s>",
mxml_error("<%s> cannot be a second root node after <%s>",
buffer, first->value.element.name);
goto error;
goto error;
}
if ((node = mxmlNewElement(parent, buffer)) == NULL)
@ -1880,9 +1847,9 @@ mxml_load_data(
* There can only be one root element!
*/
mxml_error("<%s> cannot be a second root node after <%s>",
mxml_error("<%s> cannot be a second root node after <%s>",
buffer, first->value.element.name);
goto error;
goto error;
}
if ((node = mxmlNewElement(parent, buffer)) == NULL)
@ -1972,9 +1939,9 @@ mxml_load_data(
* There can only be one root element!
*/
mxml_error("<%s> cannot be a second root node after <%s>",
mxml_error("<%s> cannot be a second root node after <%s>",
buffer, first->value.element.name);
goto error;
goto error;
}
if ((node = mxmlNewElement(parent, buffer)) == NULL)
@ -2284,7 +2251,7 @@ mxml_parse_element(
if (ch == '&')
if ((ch = mxml_get_entity(node, p, encoding, getc_cb)) == EOF)
goto error;
if (mxml_add_char(ch, &ptr, &value, &valsize))
goto error;
}
@ -2308,7 +2275,7 @@ mxml_parse_element(
if (ch == '&')
if ((ch = mxml_get_entity(node, p, encoding, getc_cb)) == EOF)
goto error;
if (mxml_add_char(ch, &ptr, &value, &valsize))
goto error;
}

Loading…
Cancel
Save