diff options
author | Daniel Veillard <veillard@src.gnome.org> | 2000-06-28 23:40:59 +0000 |
---|---|---|
committer | Daniel Veillard <veillard@src.gnome.org> | 2000-06-28 23:40:59 +0000 |
commit | be803967dbecb5534c7c7fbc1a17157ba43366b5 (patch) | |
tree | a4bb29cb23f8facd1027cd259bc48b745f968bcf /entities.c | |
parent | c310d5648211aed9e61af8fc8e261295c4c7000f (diff) | |
download | android_external_libxml2-be803967dbecb5534c7c7fbc1a17157ba43366b5.tar.gz android_external_libxml2-be803967dbecb5534c7c7fbc1a17157ba43366b5.tar.bz2 android_external_libxml2-be803967dbecb5534c7c7fbc1a17157ba43366b5.zip |
- 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
Diffstat (limited to 'entities.c')
-rw-r--r-- | entities.c | 80 |
1 files changed, 80 insertions, 0 deletions
@@ -946,6 +946,86 @@ xmlEncodeEntitiesReentrant(xmlDocPtr doc, const xmlChar *input) { } /** + * 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: * * create and initialize an empty entities hash table. |