mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-07-29 11:41:22 +03:00
- Large resync between W3C and Gnome tree
- configure.in: 2.1.0 prerelease - example/Makefile.am example/gjobread.c tree.h: work on libxml1 libxml2 convergence. - nanoftp, nanohttp.c: fixed stalled connections probs - HTMLtree.c SAX.c : support for attribute without values in HTML for andersca - valid.c: Fixed most validation + namespace problems - HTMLparser.c: start document callback for andersca - debugXML.c xpath.c: lots of XPath fixups from Picdar Technology - parser.h, SAX.c: serious speed improvement for large CDATA blocks - encoding.[ch] xmlIO.[ch]: Improved seriously saving to different encoding - config.h.in parser.c xmllint.c: added xmlCheckVersion() and the LIBXML_TEST_VERSION macro Daniel
This commit is contained in:
80
entities.c
80
entities.c
@ -945,6 +945,86 @@ xmlEncodeEntitiesReentrant(xmlDocPtr doc, const xmlChar *input) {
|
||||
return(buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlEncodeSpecialChars:
|
||||
* @doc: the document containing the string
|
||||
* @input: A string to convert to XML.
|
||||
*
|
||||
* Do a global encoding of a string, replacing the predefined entities
|
||||
* this routine is reentrant, and result must be deallocated.
|
||||
*
|
||||
* Returns A newly allocated string with the substitution done.
|
||||
*/
|
||||
xmlChar *
|
||||
xmlEncodeSpecialChars(xmlDocPtr doc, const xmlChar *input) {
|
||||
const xmlChar *cur = input;
|
||||
xmlChar *buffer = NULL;
|
||||
xmlChar *out = NULL;
|
||||
int buffer_size = 0;
|
||||
int html = 0;
|
||||
|
||||
if (input == NULL) return(NULL);
|
||||
if (doc != NULL)
|
||||
html = (doc->type == XML_HTML_DOCUMENT_NODE);
|
||||
|
||||
/*
|
||||
* allocate an translation buffer.
|
||||
*/
|
||||
buffer_size = 1000;
|
||||
buffer = (xmlChar *) xmlMalloc(buffer_size * sizeof(xmlChar));
|
||||
if (buffer == NULL) {
|
||||
perror("malloc failed");
|
||||
return(NULL);
|
||||
}
|
||||
out = buffer;
|
||||
|
||||
while (*cur != '\0') {
|
||||
if (out - buffer > buffer_size - 10) {
|
||||
int index = out - buffer;
|
||||
|
||||
growBufferReentrant();
|
||||
out = &buffer[index];
|
||||
}
|
||||
|
||||
/*
|
||||
* By default one have to encode at least '<', '>', '"' and '&' !
|
||||
*/
|
||||
if (*cur == '<') {
|
||||
*out++ = '&';
|
||||
*out++ = 'l';
|
||||
*out++ = 't';
|
||||
*out++ = ';';
|
||||
} else if (*cur == '>') {
|
||||
*out++ = '&';
|
||||
*out++ = 'g';
|
||||
*out++ = 't';
|
||||
*out++ = ';';
|
||||
} else if (*cur == '&') {
|
||||
*out++ = '&';
|
||||
*out++ = 'a';
|
||||
*out++ = 'm';
|
||||
*out++ = 'p';
|
||||
*out++ = ';';
|
||||
} else if (*cur == '"') {
|
||||
*out++ = '&';
|
||||
*out++ = 'q';
|
||||
*out++ = 'u';
|
||||
*out++ = 'o';
|
||||
*out++ = 't';
|
||||
*out++ = ';';
|
||||
} else {
|
||||
/*
|
||||
* Works because on UTF-8, all extended sequences cannot
|
||||
* result in bytes in the ASCII range.
|
||||
*/
|
||||
*out++ = *cur;
|
||||
}
|
||||
cur++;
|
||||
}
|
||||
*out++ = 0;
|
||||
return(buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlCreateEntitiesTable:
|
||||
*
|
||||
|
Reference in New Issue
Block a user