Blame include/libxml/encoding.h

Packit 423ecb
/*
Packit 423ecb
 * Summary: interface for the encoding conversion functions
Packit 423ecb
 * Description: interface for the encoding conversion functions needed for
Packit 423ecb
 *              XML basic encoding and iconv() support.
Packit 423ecb
 *
Packit 423ecb
 * Related specs are
Packit 423ecb
 * rfc2044        (UTF-8 and UTF-16) F. Yergeau Alis Technologies
Packit 423ecb
 * [ISO-10646]    UTF-8 and UTF-16 in Annexes
Packit 423ecb
 * [ISO-8859-1]   ISO Latin-1 characters codes.
Packit 423ecb
 * [UNICODE]      The Unicode Consortium, "The Unicode Standard --
Packit 423ecb
 *                Worldwide Character Encoding -- Version 1.0", Addison-
Packit 423ecb
 *                Wesley, Volume 1, 1991, Volume 2, 1992.  UTF-8 is
Packit 423ecb
 *                described in Unicode Technical Report #4.
Packit 423ecb
 * [US-ASCII]     Coded Character Set--7-bit American Standard Code for
Packit 423ecb
 *                Information Interchange, ANSI X3.4-1986.
Packit 423ecb
 *
Packit 423ecb
 * Copy: See Copyright for the status of this software.
Packit 423ecb
 *
Packit 423ecb
 * Author: Daniel Veillard
Packit 423ecb
 */
Packit 423ecb
Packit 423ecb
#ifndef __XML_CHAR_ENCODING_H__
Packit 423ecb
#define __XML_CHAR_ENCODING_H__
Packit 423ecb
Packit 423ecb
#include <libxml/xmlversion.h>
Packit 423ecb
Packit 423ecb
#ifdef LIBXML_ICONV_ENABLED
Packit 423ecb
#include <iconv.h>
Packit 423ecb
#endif
Packit 423ecb
#ifdef LIBXML_ICU_ENABLED
Packit 423ecb
#include <unicode/ucnv.h>
Packit 423ecb
#endif
Packit 423ecb
#ifdef __cplusplus
Packit 423ecb
extern "C" {
Packit 423ecb
#endif
Packit 423ecb
Packit 423ecb
/*
Packit 423ecb
 * xmlCharEncoding:
Packit 423ecb
 *
Packit 423ecb
 * Predefined values for some standard encodings.
Packit 423ecb
 * Libxml does not do beforehand translation on UTF8 and ISOLatinX.
Packit 423ecb
 * It also supports ASCII, ISO-8859-1, and UTF16 (LE and BE) by default.
Packit 423ecb
 *
Packit 423ecb
 * Anything else would have to be translated to UTF8 before being
Packit 423ecb
 * given to the parser itself. The BOM for UTF16 and the encoding
Packit 423ecb
 * declaration are looked at and a converter is looked for at that
Packit 423ecb
 * point. If not found the parser stops here as asked by the XML REC. A
Packit 423ecb
 * converter can be registered by the user using xmlRegisterCharEncodingHandler
Packit 423ecb
 * but the current form doesn't allow stateful transcoding (a serious
Packit 423ecb
 * problem agreed !). If iconv has been found it will be used
Packit 423ecb
 * automatically and allow stateful transcoding, the simplest is then
Packit 423ecb
 * to be sure to enable iconv and to provide iconv libs for the encoding
Packit 423ecb
 * support needed.
Packit 423ecb
 *
Packit 423ecb
 * Note that the generic "UTF-16" is not a predefined value.  Instead, only
Packit 423ecb
 * the specific UTF-16LE and UTF-16BE are present.
Packit 423ecb
 */
Packit 423ecb
typedef enum {
Packit 423ecb
    XML_CHAR_ENCODING_ERROR=   -1, /* No char encoding detected */
Packit 423ecb
    XML_CHAR_ENCODING_NONE=	0, /* No char encoding detected */
Packit 423ecb
    XML_CHAR_ENCODING_UTF8=	1, /* UTF-8 */
Packit 423ecb
    XML_CHAR_ENCODING_UTF16LE=	2, /* UTF-16 little endian */
Packit 423ecb
    XML_CHAR_ENCODING_UTF16BE=	3, /* UTF-16 big endian */
Packit 423ecb
    XML_CHAR_ENCODING_UCS4LE=	4, /* UCS-4 little endian */
Packit 423ecb
    XML_CHAR_ENCODING_UCS4BE=	5, /* UCS-4 big endian */
Packit 423ecb
    XML_CHAR_ENCODING_EBCDIC=	6, /* EBCDIC uh! */
Packit 423ecb
    XML_CHAR_ENCODING_UCS4_2143=7, /* UCS-4 unusual ordering */
Packit 423ecb
    XML_CHAR_ENCODING_UCS4_3412=8, /* UCS-4 unusual ordering */
Packit 423ecb
    XML_CHAR_ENCODING_UCS2=	9, /* UCS-2 */
Packit 423ecb
    XML_CHAR_ENCODING_8859_1=	10,/* ISO-8859-1 ISO Latin 1 */
Packit 423ecb
    XML_CHAR_ENCODING_8859_2=	11,/* ISO-8859-2 ISO Latin 2 */
Packit 423ecb
    XML_CHAR_ENCODING_8859_3=	12,/* ISO-8859-3 */
Packit 423ecb
    XML_CHAR_ENCODING_8859_4=	13,/* ISO-8859-4 */
Packit 423ecb
    XML_CHAR_ENCODING_8859_5=	14,/* ISO-8859-5 */
Packit 423ecb
    XML_CHAR_ENCODING_8859_6=	15,/* ISO-8859-6 */
Packit 423ecb
    XML_CHAR_ENCODING_8859_7=	16,/* ISO-8859-7 */
Packit 423ecb
    XML_CHAR_ENCODING_8859_8=	17,/* ISO-8859-8 */
Packit 423ecb
    XML_CHAR_ENCODING_8859_9=	18,/* ISO-8859-9 */
Packit 423ecb
    XML_CHAR_ENCODING_2022_JP=  19,/* ISO-2022-JP */
Packit 423ecb
    XML_CHAR_ENCODING_SHIFT_JIS=20,/* Shift_JIS */
Packit 423ecb
    XML_CHAR_ENCODING_EUC_JP=   21,/* EUC-JP */
Packit 423ecb
    XML_CHAR_ENCODING_ASCII=    22 /* pure ASCII */
Packit 423ecb
} xmlCharEncoding;
Packit 423ecb
Packit 423ecb
/**
Packit 423ecb
 * xmlCharEncodingInputFunc:
Packit 423ecb
 * @out:  a pointer to an array of bytes to store the UTF-8 result
Packit 423ecb
 * @outlen:  the length of @out
Packit 423ecb
 * @in:  a pointer to an array of chars in the original encoding
Packit 423ecb
 * @inlen:  the length of @in
Packit 423ecb
 *
Packit 423ecb
 * Take a block of chars in the original encoding and try to convert
Packit 423ecb
 * it to an UTF-8 block of chars out.
Packit 423ecb
 *
Packit 423ecb
 * Returns the number of bytes written, -1 if lack of space, or -2
Packit 423ecb
 *     if the transcoding failed.
Packit 423ecb
 * The value of @inlen after return is the number of octets consumed
Packit 423ecb
 *     if the return value is positive, else unpredictiable.
Packit 423ecb
 * The value of @outlen after return is the number of octets consumed.
Packit 423ecb
 */
Packit 423ecb
typedef int (* xmlCharEncodingInputFunc)(unsigned char *out, int *outlen,
Packit 423ecb
                                         const unsigned char *in, int *inlen);
Packit 423ecb
Packit 423ecb
Packit 423ecb
/**
Packit 423ecb
 * xmlCharEncodingOutputFunc:
Packit 423ecb
 * @out:  a pointer to an array of bytes to store the result
Packit 423ecb
 * @outlen:  the length of @out
Packit 423ecb
 * @in:  a pointer to an array of UTF-8 chars
Packit 423ecb
 * @inlen:  the length of @in
Packit 423ecb
 *
Packit 423ecb
 * Take a block of UTF-8 chars in and try to convert it to another
Packit 423ecb
 * encoding.
Packit 423ecb
 * Note: a first call designed to produce heading info is called with
Packit 423ecb
 * in = NULL. If stateful this should also initialize the encoder state.
Packit 423ecb
 *
Packit 423ecb
 * Returns the number of bytes written, -1 if lack of space, or -2
Packit 423ecb
 *     if the transcoding failed.
Packit 423ecb
 * The value of @inlen after return is the number of octets consumed
Packit 423ecb
 *     if the return value is positive, else unpredictiable.
Packit 423ecb
 * The value of @outlen after return is the number of octets produced.
Packit 423ecb
 */
Packit 423ecb
typedef int (* xmlCharEncodingOutputFunc)(unsigned char *out, int *outlen,
Packit 423ecb
                                          const unsigned char *in, int *inlen);
Packit 423ecb
Packit 423ecb
Packit 423ecb
/*
Packit 423ecb
 * Block defining the handlers for non UTF-8 encodings.
Packit 423ecb
 * If iconv is supported, there are two extra fields.
Packit 423ecb
 */
Packit 423ecb
#ifdef LIBXML_ICU_ENABLED
Packit 423ecb
struct _uconv_t {
Packit 423ecb
  UConverter *uconv; /* for conversion between an encoding and UTF-16 */
Packit 423ecb
  UConverter *utf8; /* for conversion between UTF-8 and UTF-16 */
Packit 423ecb
};
Packit 423ecb
typedef struct _uconv_t uconv_t;
Packit 423ecb
#endif
Packit 423ecb
Packit 423ecb
typedef struct _xmlCharEncodingHandler xmlCharEncodingHandler;
Packit 423ecb
typedef xmlCharEncodingHandler *xmlCharEncodingHandlerPtr;
Packit 423ecb
struct _xmlCharEncodingHandler {
Packit 423ecb
    char                       *name;
Packit 423ecb
    xmlCharEncodingInputFunc   input;
Packit 423ecb
    xmlCharEncodingOutputFunc  output;
Packit 423ecb
#ifdef LIBXML_ICONV_ENABLED
Packit 423ecb
    iconv_t                    iconv_in;
Packit 423ecb
    iconv_t                    iconv_out;
Packit 423ecb
#endif /* LIBXML_ICONV_ENABLED */
Packit 423ecb
#ifdef LIBXML_ICU_ENABLED
Packit 423ecb
    uconv_t                    *uconv_in;
Packit 423ecb
    uconv_t                    *uconv_out;
Packit 423ecb
#endif /* LIBXML_ICU_ENABLED */
Packit 423ecb
};
Packit 423ecb
Packit 423ecb
#ifdef __cplusplus
Packit 423ecb
}
Packit 423ecb
#endif
Packit 423ecb
#include <libxml/tree.h>
Packit 423ecb
#ifdef __cplusplus
Packit 423ecb
extern "C" {
Packit 423ecb
#endif
Packit 423ecb
Packit 423ecb
/*
Packit 423ecb
 * Interfaces for encoding handlers.
Packit 423ecb
 */
Packit 423ecb
XMLPUBFUN void XMLCALL
Packit 423ecb
	xmlInitCharEncodingHandlers	(void);
Packit 423ecb
XMLPUBFUN void XMLCALL
Packit 423ecb
	xmlCleanupCharEncodingHandlers	(void);
Packit 423ecb
XMLPUBFUN void XMLCALL
Packit 423ecb
	xmlRegisterCharEncodingHandler	(xmlCharEncodingHandlerPtr handler);
Packit 423ecb
XMLPUBFUN xmlCharEncodingHandlerPtr XMLCALL
Packit 423ecb
	xmlGetCharEncodingHandler	(xmlCharEncoding enc);
Packit 423ecb
XMLPUBFUN xmlCharEncodingHandlerPtr XMLCALL
Packit 423ecb
	xmlFindCharEncodingHandler	(const char *name);
Packit 423ecb
XMLPUBFUN xmlCharEncodingHandlerPtr XMLCALL
Packit 423ecb
	xmlNewCharEncodingHandler	(const char *name,
Packit 423ecb
					 xmlCharEncodingInputFunc input,
Packit 423ecb
					 xmlCharEncodingOutputFunc output);
Packit 423ecb
Packit 423ecb
/*
Packit 423ecb
 * Interfaces for encoding names and aliases.
Packit 423ecb
 */
Packit 423ecb
XMLPUBFUN int XMLCALL
Packit 423ecb
	xmlAddEncodingAlias		(const char *name,
Packit 423ecb
					 const char *alias);
Packit 423ecb
XMLPUBFUN int XMLCALL
Packit 423ecb
	xmlDelEncodingAlias		(const char *alias);
Packit 423ecb
XMLPUBFUN const char * XMLCALL
Packit 423ecb
	xmlGetEncodingAlias		(const char *alias);
Packit 423ecb
XMLPUBFUN void XMLCALL
Packit 423ecb
	xmlCleanupEncodingAliases	(void);
Packit 423ecb
XMLPUBFUN xmlCharEncoding XMLCALL
Packit 423ecb
	xmlParseCharEncoding		(const char *name);
Packit 423ecb
XMLPUBFUN const char * XMLCALL
Packit 423ecb
	xmlGetCharEncodingName		(xmlCharEncoding enc);
Packit 423ecb
Packit 423ecb
/*
Packit 423ecb
 * Interfaces directly used by the parsers.
Packit 423ecb
 */
Packit 423ecb
XMLPUBFUN xmlCharEncoding XMLCALL
Packit 423ecb
	xmlDetectCharEncoding		(const unsigned char *in,
Packit 423ecb
					 int len);
Packit 423ecb
Packit 423ecb
XMLPUBFUN int XMLCALL
Packit 423ecb
	xmlCharEncOutFunc		(xmlCharEncodingHandler *handler,
Packit 423ecb
					 xmlBufferPtr out,
Packit 423ecb
					 xmlBufferPtr in);
Packit 423ecb
Packit 423ecb
XMLPUBFUN int XMLCALL
Packit 423ecb
	xmlCharEncInFunc		(xmlCharEncodingHandler *handler,
Packit 423ecb
					 xmlBufferPtr out,
Packit 423ecb
					 xmlBufferPtr in);
Packit 423ecb
XMLPUBFUN int XMLCALL
Packit 423ecb
	xmlCharEncFirstLine		(xmlCharEncodingHandler *handler,
Packit 423ecb
					 xmlBufferPtr out,
Packit 423ecb
					 xmlBufferPtr in);
Packit 423ecb
XMLPUBFUN int XMLCALL
Packit 423ecb
	xmlCharEncCloseFunc		(xmlCharEncodingHandler *handler);
Packit 423ecb
Packit 423ecb
/*
Packit 423ecb
 * Export a few useful functions
Packit 423ecb
 */
Packit 423ecb
#ifdef LIBXML_OUTPUT_ENABLED
Packit 423ecb
XMLPUBFUN int XMLCALL
Packit 423ecb
	UTF8Toisolat1			(unsigned char *out,
Packit 423ecb
					 int *outlen,
Packit 423ecb
					 const unsigned char *in,
Packit 423ecb
					 int *inlen);
Packit 423ecb
#endif /* LIBXML_OUTPUT_ENABLED */
Packit 423ecb
XMLPUBFUN int XMLCALL
Packit 423ecb
	isolat1ToUTF8			(unsigned char *out,
Packit 423ecb
					 int *outlen,
Packit 423ecb
					 const unsigned char *in,
Packit 423ecb
					 int *inlen);
Packit 423ecb
#ifdef __cplusplus
Packit 423ecb
}
Packit 423ecb
#endif
Packit 423ecb
Packit 423ecb
#endif /* __XML_CHAR_ENCODING_H__ */