1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-10-21 14:53:44 +03:00

revamped the encoding support, added iconv support, so now libxml if

* encoding.[ch], xmlIO.[ch], parser.c, configure.in : revamped
  the encoding support, added iconv support, so now libxml if
  compiled with iconv automatically support japanese encodings
  among others. Work based on initial patch from Yuan-Chen Cheng
  I may have broken binary compat in the encoding handler
  registration scheme, but that was so utterly broken I don't
  expect anybody to have used this feature until now.
* parserInternals.h: fixup on the CHAR range macro
* xml-error.h, parser.c: catch URL/URI errors using the uri.c
  code.
* tree.[ch]: added xmlBufferGrow(), was needed for iconv
* uri.c: added xmlParseURI() I can't believe I forgot to
  implement this one in 2.0 !!!
* SAX.c: moved doc->encoding update in the endDocument() call.
* TODO: updated.

  Iconv rules :-)

Daniel
This commit is contained in:
Daniel Veillard
2000-05-03 14:20:55 +00:00
parent 06047432eb
commit 496a1cf592
18 changed files with 1163 additions and 487 deletions

View File

@@ -22,12 +22,30 @@
#define __XML_CHAR_ENCODING_H__
#include <libxml/xmlversion.h>
#ifdef LIBXML_ICONV_ENABLED
#include <iconv.h>
#endif
#include <libxml/tree.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* Predefined values for some standard encodings
* Libxml don't do beforehand translation on UTF8, ISOLatinX
* It also support UTF16 (LE and BE) by default.
*
* Anything else would have to be translated to UTF8 before being
* given to the parser itself. The BOM for UTF16 and the encoding
* declaration are looked at and a converter is looked for at that
* point. If not found the parser stops here as asked by the XML REC
* Converter can be registered by the user using xmlRegisterCharEncodingHandler
* but the currentl form doesn't allow stateful transcoding (a serious
* problem agreed !). If iconv has been found it will be used
* automatically and allow stateful transcoding, the simplest is then
* to be sure to enable icon and to provide iconv libs for the encoding
* support needed.
*/
typedef enum {
XML_CHAR_ENCODING_ERROR= -1, /* No char encoding detected */
@@ -65,9 +83,13 @@ typedef enum {
* Take a block of chars in the original encoding and try to convert
* it to an UTF-8 block of chars out.
*
* Returns the number of byte written, or -1 by lack of space.
* Returns the number of byte written, or -1 by lack of space, or -2
* if the transcoding failed.
* The value of @inlen after return is the number of octets consumed
* as the return value is positive, else unpredictiable.
* The value of @outlen after return is the number of ocetes consumed.
*/
typedef int (* xmlCharEncodingInputFunc)(unsigned char* out, int outlen,
typedef int (* xmlCharEncodingInputFunc)(unsigned char* out, int *outlen,
const unsigned char* in, int *inlen);
@@ -83,12 +105,17 @@ typedef int (* xmlCharEncodingInputFunc)(unsigned char* out, int outlen,
*
* Returns the number of byte written, or -1 by lack of space, or -2
* if the transcoding failed.
* The value of @inlen after return is the number of octets consumed
* as the return value is positive, else unpredictiable.
* The value of @outlen after return is the number of ocetes consumed.
*/
typedef int (* xmlCharEncodingOutputFunc)(unsigned char* out, int outlen,
typedef int (* xmlCharEncodingOutputFunc)(unsigned char* out, int *outlen,
const unsigned char* in, int *inlen);
/*
* Block defining the handlers for non UTF-8 encodings.
* If iconv is supported, there is two extra fields
*/
typedef struct _xmlCharEncodingHandler xmlCharEncodingHandler;
@@ -96,7 +123,11 @@ typedef xmlCharEncodingHandler *xmlCharEncodingHandlerPtr;
struct _xmlCharEncodingHandler {
char *name;
xmlCharEncodingInputFunc input;
xmlCharEncodingOutputFunc output;
xmlCharEncodingOutputFunc output;
#ifdef LIBXML_ICONV_ENABLED
iconv_t iconv_in;
iconv_t iconv_out;
#endif /* LIBXML_ICONV_ENABLED */
};
void xmlInitCharEncodingHandlers (void);
@@ -109,6 +140,14 @@ xmlCharEncodingHandlerPtr xmlGetCharEncodingHandler(xmlCharEncoding enc);
xmlCharEncodingHandlerPtr xmlFindCharEncodingHandler(const char *name);
int xmlCheckUTF8 (const unsigned char *utf);
int xmlCharEncOutFunc (xmlCharEncodingHandler *handler,
xmlBufferPtr out,
xmlBufferPtr in);
int xmlCharEncInFunc (xmlCharEncodingHandler *handler,
xmlBufferPtr out,
xmlBufferPtr in);
int xmlCharEncCloseFunc (xmlCharEncodingHandler *handler);
#ifdef __cplusplus
}