codekingpro/portable-devtools
116k
1/*2 * Summary: interface for the encoding conversion functions3 * Description: interface for the encoding conversion functions needed for4 * XML basic encoding and iconv() support.5 *6 * Related specs are7 * rfc2044 (UTF-8 and UTF-16) F. Yergeau Alis Technologies8 * [ISO-10646] UTF-8 and UTF-16 in Annexes9 * [ISO-8859-1] ISO Latin-1 characters codes.10 * [UNICODE] The Unicode Consortium, "The Unicode Standard --11 * Worldwide Character Encoding -- Version 1.0", Addison-12 * Wesley, Volume 1, 1991, Volume 2, 1992. UTF-8 is13 * described in Unicode Technical Report #4.14 * [US-ASCII] Coded Character Set--7-bit American Standard Code for15 * Information Interchange, ANSI X3.4-1986.16 *17 * Copy: See Copyright for the status of this software.18 *19 * Author: Daniel Veillard20 */21 22#ifndef __XML_CHAR_ENCODING_H__23#define __XML_CHAR_ENCODING_H__24 25#include <libxml/xmlversion.h>26 27#ifdef LIBXML_ICONV_ENABLED28#include <iconv.h>29#endif30 31#ifdef __cplusplus32extern "C" {33#endif34 35/*36 * xmlCharEncoding:37 *38 * Predefined values for some standard encodings.39 * Libxml does not do beforehand translation on UTF8 and ISOLatinX.40 * It also supports ASCII, ISO-8859-1, and UTF16 (LE and BE) by default.41 *42 * Anything else would have to be translated to UTF8 before being43 * given to the parser itself. The BOM for UTF16 and the encoding44 * declaration are looked at and a converter is looked for at that45 * point. If not found the parser stops here as asked by the XML REC. A46 * converter can be registered by the user using xmlRegisterCharEncodingHandler47 * but the current form doesn't allow stateful transcoding (a serious48 * problem agreed !). If iconv has been found it will be used49 * automatically and allow stateful transcoding, the simplest is then50 * to be sure to enable iconv and to provide iconv libs for the encoding51 * support needed.52 *53 * Note that the generic "UTF-16" is not a predefined value. Instead, only54 * the specific UTF-16LE and UTF-16BE are present.55 */56typedef enum {57 XML_CHAR_ENCODING_ERROR= -1, /* No char encoding detected */58 XML_CHAR_ENCODING_NONE= 0, /* No char encoding detected */59 XML_CHAR_ENCODING_UTF8= 1, /* UTF-8 */60 XML_CHAR_ENCODING_UTF16LE= 2, /* UTF-16 little endian */61 XML_CHAR_ENCODING_UTF16BE= 3, /* UTF-16 big endian */62 XML_CHAR_ENCODING_UCS4LE= 4, /* UCS-4 little endian */63 XML_CHAR_ENCODING_UCS4BE= 5, /* UCS-4 big endian */64 XML_CHAR_ENCODING_EBCDIC= 6, /* EBCDIC uh! */65 XML_CHAR_ENCODING_UCS4_2143=7, /* UCS-4 unusual ordering */66 XML_CHAR_ENCODING_UCS4_3412=8, /* UCS-4 unusual ordering */67 XML_CHAR_ENCODING_UCS2= 9, /* UCS-2 */68 XML_CHAR_ENCODING_8859_1= 10,/* ISO-8859-1 ISO Latin 1 */69 XML_CHAR_ENCODING_8859_2= 11,/* ISO-8859-2 ISO Latin 2 */70 XML_CHAR_ENCODING_8859_3= 12,/* ISO-8859-3 */71 XML_CHAR_ENCODING_8859_4= 13,/* ISO-8859-4 */72 XML_CHAR_ENCODING_8859_5= 14,/* ISO-8859-5 */73 XML_CHAR_ENCODING_8859_6= 15,/* ISO-8859-6 */74 XML_CHAR_ENCODING_8859_7= 16,/* ISO-8859-7 */75 XML_CHAR_ENCODING_8859_8= 17,/* ISO-8859-8 */76 XML_CHAR_ENCODING_8859_9= 18,/* ISO-8859-9 */77 XML_CHAR_ENCODING_2022_JP= 19,/* ISO-2022-JP */78 XML_CHAR_ENCODING_SHIFT_JIS=20,/* Shift_JIS */79 XML_CHAR_ENCODING_EUC_JP= 21,/* EUC-JP */80 XML_CHAR_ENCODING_ASCII= 22 /* pure ASCII */81} xmlCharEncoding;82 83/**84 * xmlCharEncodingInputFunc:85 * @out: a pointer to an array of bytes to store the UTF-8 result86 * @outlen: the length of @out87 * @in: a pointer to an array of chars in the original encoding88 * @inlen: the length of @in89 *90 * Take a block of chars in the original encoding and try to convert91 * it to an UTF-8 block of chars out.92 *93 * Returns the number of bytes written, -1 if lack of space, or -294 * if the transcoding failed.95 * The value of @inlen after return is the number of octets consumed96 * if the return value is positive, else unpredictiable.97 * The value of @outlen after return is the number of octets consumed.98 */99typedef int (* xmlCharEncodingInputFunc)(unsigned char *out, int *outlen,100 const unsigned char *in, int *inlen);101 102 103/**104 * xmlCharEncodingOutputFunc:105 * @out: a pointer to an array of bytes to store the result106 * @outlen: the length of @out107 * @in: a pointer to an array of UTF-8 chars108 * @inlen: the length of @in109 *110 * Take a block of UTF-8 chars in and try to convert it to another111 * encoding.112 * Note: a first call designed to produce heading info is called with113 * in = NULL. If stateful this should also initialize the encoder state.114 *115 * Returns the number of bytes written, -1 if lack of space, or -2116 * if the transcoding failed.117 * The value of @inlen after return is the number of octets consumed118 * if the return value is positive, else unpredictiable.119 * The value of @outlen after return is the number of octets produced.120 */121typedef int (* xmlCharEncodingOutputFunc)(unsigned char *out, int *outlen,122 const unsigned char *in, int *inlen);123 124 125/*126 * Block defining the handlers for non UTF-8 encodings.127 * If iconv is supported, there are two extra fields.128 */129typedef struct _xmlCharEncodingHandler xmlCharEncodingHandler;130typedef xmlCharEncodingHandler *xmlCharEncodingHandlerPtr;131struct _xmlCharEncodingHandler {132 char *name;133 xmlCharEncodingInputFunc input;134 xmlCharEncodingOutputFunc output;135#ifdef LIBXML_ICONV_ENABLED136 iconv_t iconv_in;137 iconv_t iconv_out;138#endif /* LIBXML_ICONV_ENABLED */139#ifdef LIBXML_ICU_ENABLED140 struct _uconv_t *uconv_in;141 struct _uconv_t *uconv_out;142#endif /* LIBXML_ICU_ENABLED */143};144 145#ifdef __cplusplus146}147#endif148#include <libxml/tree.h>149#ifdef __cplusplus150extern "C" {151#endif152 153/*154 * Interfaces for encoding handlers.155 */156XML_DEPRECATED157XMLPUBFUN void158 xmlInitCharEncodingHandlers (void);159XML_DEPRECATED160XMLPUBFUN void161 xmlCleanupCharEncodingHandlers (void);162XMLPUBFUN void163 xmlRegisterCharEncodingHandler (xmlCharEncodingHandlerPtr handler);164XMLPUBFUN xmlCharEncodingHandlerPtr165 xmlGetCharEncodingHandler (xmlCharEncoding enc);166XMLPUBFUN xmlCharEncodingHandlerPtr167 xmlFindCharEncodingHandler (const char *name);168XMLPUBFUN xmlCharEncodingHandlerPtr169 xmlNewCharEncodingHandler (const char *name,170 xmlCharEncodingInputFunc input,171 xmlCharEncodingOutputFunc output);172 173/*174 * Interfaces for encoding names and aliases.175 */176XMLPUBFUN int177 xmlAddEncodingAlias (const char *name,178 const char *alias);179XMLPUBFUN int180 xmlDelEncodingAlias (const char *alias);181XMLPUBFUN const char *182 xmlGetEncodingAlias (const char *alias);183XMLPUBFUN void184 xmlCleanupEncodingAliases (void);185XMLPUBFUN xmlCharEncoding186 xmlParseCharEncoding (const char *name);187XMLPUBFUN const char *188 xmlGetCharEncodingName (xmlCharEncoding enc);189 190/*191 * Interfaces directly used by the parsers.192 */193XMLPUBFUN xmlCharEncoding194 xmlDetectCharEncoding (const unsigned char *in,195 int len);196 197XMLPUBFUN int198 xmlCharEncOutFunc (xmlCharEncodingHandler *handler,199 xmlBufferPtr out,200 xmlBufferPtr in);201 202XMLPUBFUN int203 xmlCharEncInFunc (xmlCharEncodingHandler *handler,204 xmlBufferPtr out,205 xmlBufferPtr in);206XML_DEPRECATED207XMLPUBFUN int208 xmlCharEncFirstLine (xmlCharEncodingHandler *handler,209 xmlBufferPtr out,210 xmlBufferPtr in);211XMLPUBFUN int212 xmlCharEncCloseFunc (xmlCharEncodingHandler *handler);213 214/*215 * Export a few useful functions216 */217#ifdef LIBXML_OUTPUT_ENABLED218XMLPUBFUN int219 UTF8Toisolat1 (unsigned char *out,220 int *outlen,221 const unsigned char *in,222 int *inlen);223#endif /* LIBXML_OUTPUT_ENABLED */224XMLPUBFUN int225 isolat1ToUTF8 (unsigned char *out,226 int *outlen,227 const unsigned char *in,228 int *inlen);229#ifdef __cplusplus230}231#endif232 233#endif /* __XML_CHAR_ENCODING_H__ */234 