mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-01-12 09:17:37 +03:00
encoding: Deprecate xmlCharEncodingHandler members
This commit is contained in:
parent
b34dc1e4a3
commit
3b4a84e4b7
@ -29,7 +29,6 @@ void testXmlwriterFilename(const char *uri);
|
||||
void testXmlwriterMemory(void);
|
||||
void testXmlwriterDoc(void);
|
||||
void testXmlwriterTree(void);
|
||||
xmlChar *ConvertInput(const char *in, const char *encoding);
|
||||
|
||||
int
|
||||
main(void)
|
||||
@ -68,7 +67,6 @@ testXmlwriterFilename(const char *uri)
|
||||
{
|
||||
int rc;
|
||||
xmlTextWriterPtr writer;
|
||||
xmlChar *tmp;
|
||||
|
||||
/* Create a new XmlWriter for uri, with no compression. */
|
||||
writer = xmlNewTextWriterFilename(uri, 0);
|
||||
@ -96,19 +94,12 @@ testXmlwriterFilename(const char *uri)
|
||||
return;
|
||||
}
|
||||
|
||||
/* Write a comment as child of EXAMPLE.
|
||||
* Please observe, that the input to the xmlTextWriter functions
|
||||
* HAS to be in UTF-8, even if the output XML is encoded
|
||||
* in iso-8859-1 */
|
||||
tmp = ConvertInput("This is a comment with special chars: <\xE4\xF6\xFC>",
|
||||
MY_ENCODING);
|
||||
rc = xmlTextWriterWriteComment(writer, tmp);
|
||||
rc = xmlTextWriterWriteComment(writer, BAD_CAST "This is a comment");
|
||||
if (rc < 0) {
|
||||
printf
|
||||
("testXmlwriterFilename: Error at xmlTextWriterWriteComment\n");
|
||||
return;
|
||||
}
|
||||
if (tmp != NULL) xmlFree(tmp);
|
||||
|
||||
/* Start an element named "ORDER" as child of EXAMPLE. */
|
||||
rc = xmlTextWriterStartElement(writer, BAD_CAST "ORDER");
|
||||
@ -137,16 +128,12 @@ testXmlwriterFilename(const char *uri)
|
||||
}
|
||||
|
||||
/* Write a comment as child of ORDER */
|
||||
tmp = ConvertInput("<\xE4\xF6\xFC>", MY_ENCODING);
|
||||
rc = xmlTextWriterWriteFormatComment(writer,
|
||||
"This is another comment with special chars: %s",
|
||||
tmp);
|
||||
rc = xmlTextWriterWriteComment(writer, BAD_CAST "This is another comment");
|
||||
if (rc < 0) {
|
||||
printf
|
||||
("testXmlwriterFilename: Error at xmlTextWriterWriteFormatComment\n");
|
||||
return;
|
||||
}
|
||||
if (tmp != NULL) xmlFree(tmp);
|
||||
|
||||
/* Start an element named "HEADER" as child of ORDER. */
|
||||
rc = xmlTextWriterStartElement(writer, BAD_CAST "HEADER");
|
||||
@ -175,24 +162,22 @@ testXmlwriterFilename(const char *uri)
|
||||
}
|
||||
|
||||
/* Write an element named "NAME_1" as child of HEADER. */
|
||||
tmp = ConvertInput("M\xFCller", MY_ENCODING);
|
||||
rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_1", tmp);
|
||||
rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_1",
|
||||
BAD_CAST "Mueller");
|
||||
if (rc < 0) {
|
||||
printf
|
||||
("testXmlwriterFilename: Error at xmlTextWriterWriteElement\n");
|
||||
return;
|
||||
}
|
||||
if (tmp != NULL) xmlFree(tmp);
|
||||
|
||||
/* Write an element named "NAME_2" as child of HEADER. */
|
||||
tmp = ConvertInput("J\xF6rg", MY_ENCODING);
|
||||
rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_2", tmp);
|
||||
rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_2",
|
||||
BAD_CAST "Joerg");
|
||||
if (rc < 0) {
|
||||
printf
|
||||
("testXmlwriterFilename: Error at xmlTextWriterWriteElement\n");
|
||||
return;
|
||||
}
|
||||
if (tmp != NULL) xmlFree(tmp);
|
||||
|
||||
/* Close the element named HEADER. */
|
||||
rc = xmlTextWriterEndElement(writer);
|
||||
@ -337,7 +322,6 @@ testXmlwriterMemory(void)
|
||||
int rc;
|
||||
xmlTextWriterPtr writer;
|
||||
xmlBufferPtr buf;
|
||||
xmlChar *tmp;
|
||||
|
||||
/* Create a new XML buffer, to which the XML document will be
|
||||
* written */
|
||||
@ -374,19 +358,13 @@ testXmlwriterMemory(void)
|
||||
return;
|
||||
}
|
||||
|
||||
/* Write a comment as child of EXAMPLE.
|
||||
* Please observe, that the input to the xmlTextWriter functions
|
||||
* HAS to be in UTF-8, even if the output XML is encoded
|
||||
* in iso-8859-1 */
|
||||
tmp = ConvertInput("This is a comment with special chars: <\xE4\xF6\xFC>",
|
||||
MY_ENCODING);
|
||||
rc = xmlTextWriterWriteComment(writer, tmp);
|
||||
/* Write a comment as child of EXAMPLE. */
|
||||
rc = xmlTextWriterWriteComment(writer, BAD_CAST "This is a comment");
|
||||
if (rc < 0) {
|
||||
printf
|
||||
("testXmlwriterMemory: Error at xmlTextWriterWriteComment\n");
|
||||
return;
|
||||
}
|
||||
if (tmp != NULL) xmlFree(tmp);
|
||||
|
||||
/* Start an element named "ORDER" as child of EXAMPLE. */
|
||||
rc = xmlTextWriterStartElement(writer, BAD_CAST "ORDER");
|
||||
@ -415,16 +393,12 @@ testXmlwriterMemory(void)
|
||||
}
|
||||
|
||||
/* Write a comment as child of ORDER */
|
||||
tmp = ConvertInput("<\xE4\xF6\xFC>", MY_ENCODING);
|
||||
rc = xmlTextWriterWriteFormatComment(writer,
|
||||
"This is another comment with special chars: %s",
|
||||
tmp);
|
||||
rc = xmlTextWriterWriteComment(writer, BAD_CAST "This is another comment");
|
||||
if (rc < 0) {
|
||||
printf
|
||||
("testXmlwriterMemory: Error at xmlTextWriterWriteFormatComment\n");
|
||||
return;
|
||||
}
|
||||
if (tmp != NULL) xmlFree(tmp);
|
||||
|
||||
/* Start an element named "HEADER" as child of ORDER. */
|
||||
rc = xmlTextWriterStartElement(writer, BAD_CAST "HEADER");
|
||||
@ -453,25 +427,23 @@ testXmlwriterMemory(void)
|
||||
}
|
||||
|
||||
/* Write an element named "NAME_1" as child of HEADER. */
|
||||
tmp = ConvertInput("M\xFCller", MY_ENCODING);
|
||||
rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_1", tmp);
|
||||
rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_1",
|
||||
BAD_CAST "Mueller");
|
||||
if (rc < 0) {
|
||||
printf
|
||||
("testXmlwriterMemory: Error at xmlTextWriterWriteElement\n");
|
||||
return;
|
||||
}
|
||||
if (tmp != NULL) xmlFree(tmp);
|
||||
|
||||
/* Write an element named "NAME_2" as child of HEADER. */
|
||||
tmp = ConvertInput("J\xF6rg", MY_ENCODING);
|
||||
rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_2", tmp);
|
||||
rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_2",
|
||||
BAD_CAST "Joerg");
|
||||
|
||||
if (rc < 0) {
|
||||
printf
|
||||
("testXmlwriterMemory: Error at xmlTextWriterWriteElement\n");
|
||||
return;
|
||||
}
|
||||
if (tmp != NULL) xmlFree(tmp);
|
||||
|
||||
/* Close the element named HEADER. */
|
||||
rc = xmlTextWriterEndElement(writer);
|
||||
@ -611,7 +583,6 @@ testXmlwriterDoc(void)
|
||||
{
|
||||
int rc;
|
||||
xmlTextWriterPtr writer;
|
||||
xmlChar *tmp;
|
||||
xmlDocPtr doc;
|
||||
|
||||
|
||||
@ -639,18 +610,12 @@ testXmlwriterDoc(void)
|
||||
return;
|
||||
}
|
||||
|
||||
/* Write a comment as child of EXAMPLE.
|
||||
* Please observe, that the input to the xmlTextWriter functions
|
||||
* HAS to be in UTF-8, even if the output XML is encoded
|
||||
* in iso-8859-1 */
|
||||
tmp = ConvertInput("This is a comment with special chars: <\xE4\xF6\xFC>",
|
||||
MY_ENCODING);
|
||||
rc = xmlTextWriterWriteComment(writer, tmp);
|
||||
/* Write a comment as child of EXAMPLE. */
|
||||
rc = xmlTextWriterWriteComment(writer, BAD_CAST "This is a comment");
|
||||
if (rc < 0) {
|
||||
printf("testXmlwriterDoc: Error at xmlTextWriterWriteComment\n");
|
||||
return;
|
||||
}
|
||||
if (tmp != NULL) xmlFree(tmp);
|
||||
|
||||
/* Start an element named "ORDER" as child of EXAMPLE. */
|
||||
rc = xmlTextWriterStartElement(writer, BAD_CAST "ORDER");
|
||||
@ -676,16 +641,12 @@ testXmlwriterDoc(void)
|
||||
}
|
||||
|
||||
/* Write a comment as child of ORDER */
|
||||
tmp = ConvertInput("<\xE4\xF6\xFC>", MY_ENCODING);
|
||||
rc = xmlTextWriterWriteFormatComment(writer,
|
||||
"This is another comment with special chars: %s",
|
||||
tmp);
|
||||
rc = xmlTextWriterWriteComment(writer, BAD_CAST "This is another comment");
|
||||
if (rc < 0) {
|
||||
printf
|
||||
("testXmlwriterDoc: Error at xmlTextWriterWriteFormatComment\n");
|
||||
return;
|
||||
}
|
||||
if (tmp != NULL) xmlFree(tmp);
|
||||
|
||||
/* Start an element named "HEADER" as child of ORDER. */
|
||||
rc = xmlTextWriterStartElement(writer, BAD_CAST "HEADER");
|
||||
@ -713,22 +674,20 @@ testXmlwriterDoc(void)
|
||||
}
|
||||
|
||||
/* Write an element named "NAME_1" as child of HEADER. */
|
||||
tmp = ConvertInput("M\xFCller", MY_ENCODING);
|
||||
rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_1", tmp);
|
||||
rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_1",
|
||||
BAD_CAST "Mueller");
|
||||
if (rc < 0) {
|
||||
printf("testXmlwriterDoc: Error at xmlTextWriterWriteElement\n");
|
||||
return;
|
||||
}
|
||||
if (tmp != NULL) xmlFree(tmp);
|
||||
|
||||
/* Write an element named "NAME_2" as child of HEADER. */
|
||||
tmp = ConvertInput("J\xF6rg", MY_ENCODING);
|
||||
rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_2", tmp);
|
||||
rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_2",
|
||||
BAD_CAST "Joerg");
|
||||
if (rc < 0) {
|
||||
printf("testXmlwriterDoc: Error at xmlTextWriterWriteElement\n");
|
||||
return;
|
||||
}
|
||||
if (tmp != NULL) xmlFree(tmp);
|
||||
|
||||
/* Close the element named HEADER. */
|
||||
rc = xmlTextWriterEndElement(writer);
|
||||
@ -863,7 +822,6 @@ testXmlwriterTree(void)
|
||||
xmlTextWriterPtr writer;
|
||||
xmlDocPtr doc;
|
||||
xmlNodePtr node;
|
||||
xmlChar *tmp;
|
||||
|
||||
/* Create a new XML DOM tree, to which the XML document will be
|
||||
* written */
|
||||
@ -901,18 +859,12 @@ testXmlwriterTree(void)
|
||||
return;
|
||||
}
|
||||
|
||||
/* Write a comment as child of EXAMPLE.
|
||||
* Please observe, that the input to the xmlTextWriter functions
|
||||
* HAS to be in UTF-8, even if the output XML is encoded
|
||||
* in iso-8859-1 */
|
||||
tmp = ConvertInput("This is a comment with special chars: <\xE4\xF6\xFC>",
|
||||
MY_ENCODING);
|
||||
rc = xmlTextWriterWriteComment(writer, tmp);
|
||||
/* Write a comment as child of EXAMPLE. */
|
||||
rc = xmlTextWriterWriteComment(writer, BAD_CAST "This is a comment");
|
||||
if (rc < 0) {
|
||||
printf("testXmlwriterTree: Error at xmlTextWriterWriteComment\n");
|
||||
return;
|
||||
}
|
||||
if (tmp != NULL) xmlFree(tmp);
|
||||
|
||||
/* Start an element named "ORDER" as child of EXAMPLE. */
|
||||
rc = xmlTextWriterStartElement(writer, BAD_CAST "ORDER");
|
||||
@ -940,16 +892,12 @@ testXmlwriterTree(void)
|
||||
}
|
||||
|
||||
/* Write a comment as child of ORDER */
|
||||
tmp = ConvertInput("<\xE4\xF6\xFC>", MY_ENCODING);
|
||||
rc = xmlTextWriterWriteFormatComment(writer,
|
||||
"This is another comment with special chars: %s",
|
||||
tmp);
|
||||
rc = xmlTextWriterWriteComment(writer, BAD_CAST "This is another comment");
|
||||
if (rc < 0) {
|
||||
printf
|
||||
("testXmlwriterTree: Error at xmlTextWriterWriteFormatComment\n");
|
||||
return;
|
||||
}
|
||||
if (tmp != NULL) xmlFree(tmp);
|
||||
|
||||
/* Start an element named "HEADER" as child of ORDER. */
|
||||
rc = xmlTextWriterStartElement(writer, BAD_CAST "HEADER");
|
||||
@ -977,22 +925,20 @@ testXmlwriterTree(void)
|
||||
}
|
||||
|
||||
/* Write an element named "NAME_1" as child of HEADER. */
|
||||
tmp = ConvertInput("M\xFCller", MY_ENCODING);
|
||||
rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_1", tmp);
|
||||
rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_1",
|
||||
BAD_CAST "Mueller");
|
||||
if (rc < 0) {
|
||||
printf("testXmlwriterTree: Error at xmlTextWriterWriteElement\n");
|
||||
return;
|
||||
}
|
||||
if (tmp != NULL) xmlFree(tmp);
|
||||
|
||||
/* Write an element named "NAME_2" as child of HEADER. */
|
||||
tmp = ConvertInput("J\xF6rg", MY_ENCODING);
|
||||
rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_2", tmp);
|
||||
rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_2",
|
||||
BAD_CAST "Joerg");
|
||||
if (rc < 0) {
|
||||
printf("testXmlwriterTree: Error at xmlTextWriterWriteElement\n");
|
||||
return;
|
||||
}
|
||||
if (tmp != NULL) xmlFree(tmp);
|
||||
|
||||
/* Close the element named HEADER. */
|
||||
rc = xmlTextWriterEndElement(writer);
|
||||
@ -1114,65 +1060,6 @@ testXmlwriterTree(void)
|
||||
xmlFreeDoc(doc);
|
||||
}
|
||||
|
||||
/**
|
||||
* ConvertInput:
|
||||
* @in: string in a given encoding
|
||||
* @encoding: the encoding used
|
||||
*
|
||||
* Converts @in into UTF-8 for processing with libxml2 APIs
|
||||
*
|
||||
* Returns the converted UTF-8 string, or NULL in case of error.
|
||||
*/
|
||||
xmlChar *
|
||||
ConvertInput(const char *in, const char *encoding)
|
||||
{
|
||||
xmlChar *out;
|
||||
int ret;
|
||||
int size;
|
||||
int out_size;
|
||||
int temp;
|
||||
xmlCharEncodingHandlerPtr handler;
|
||||
|
||||
if (in == 0)
|
||||
return 0;
|
||||
|
||||
handler = xmlFindCharEncodingHandler(encoding);
|
||||
|
||||
if (!handler) {
|
||||
printf("ConvertInput: no encoding handler found for '%s'\n",
|
||||
encoding ? encoding : "");
|
||||
return 0;
|
||||
}
|
||||
|
||||
size = (int) strlen(in) + 1;
|
||||
out_size = size * 2 - 1;
|
||||
out = (unsigned char *) xmlMalloc((size_t) out_size);
|
||||
|
||||
if (out != 0) {
|
||||
temp = size - 1;
|
||||
ret = handler->input(out, &out_size, (const xmlChar *) in, &temp);
|
||||
if ((ret < 0) || (temp - size + 1)) {
|
||||
if (ret < 0) {
|
||||
printf("ConvertInput: conversion wasn't successful.\n");
|
||||
} else {
|
||||
printf
|
||||
("ConvertInput: conversion wasn't successful. converted: %i octets.\n",
|
||||
temp);
|
||||
}
|
||||
|
||||
xmlFree(out);
|
||||
out = 0;
|
||||
} else {
|
||||
out = (unsigned char *) xmlRealloc(out, out_size + 1);
|
||||
out[out_size] = 0; /*null terminating out */
|
||||
}
|
||||
} else {
|
||||
printf("ConvertInput: no mem\n");
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
#else
|
||||
int main(void) {
|
||||
fprintf(stderr, "Writer or output support not compiled in\n");
|
||||
|
@ -139,15 +139,15 @@ typedef struct _xmlCharEncodingHandler xmlCharEncodingHandler;
|
||||
typedef xmlCharEncodingHandler *xmlCharEncodingHandlerPtr;
|
||||
struct _xmlCharEncodingHandler {
|
||||
char *name;
|
||||
xmlCharEncodingInputFunc input;
|
||||
xmlCharEncodingOutputFunc output;
|
||||
xmlCharEncodingInputFunc input XML_DEPRECATED_MEMBER;
|
||||
xmlCharEncodingOutputFunc output XML_DEPRECATED_MEMBER;
|
||||
#ifdef LIBXML_ICONV_ENABLED
|
||||
iconv_t iconv_in;
|
||||
iconv_t iconv_out;
|
||||
iconv_t iconv_in XML_DEPRECATED_MEMBER;
|
||||
iconv_t iconv_out XML_DEPRECATED_MEMBER;
|
||||
#endif /* LIBXML_ICONV_ENABLED */
|
||||
#ifdef LIBXML_ICU_ENABLED
|
||||
struct _uconv_t *uconv_in;
|
||||
struct _uconv_t *uconv_out;
|
||||
struct _uconv_t *uconv_in XML_DEPRECATED_MEMBER;
|
||||
struct _uconv_t *uconv_out XML_DEPRECATED_MEMBER;
|
||||
#endif /* LIBXML_ICU_ENABLED */
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user