Annotation of XML/encoding.h, revision 1.22

1.1       daniel      1: /*
                      2:  * encoding.h : interface for the encoding conversion functions needed for
                      3:  *              XML
                      4:  *
                      5:  * Related specs: 
                      6:  * rfc2044        (UTF-8 and UTF-16) F. Yergeau Alis Technologies
                      7:  * [ISO-10646]    UTF-8 and UTF-16 in Annexes
                      8:  * [ISO-8859-1]   ISO Latin-1 characters codes.
                      9:  * [UNICODE]      The Unicode Consortium, "The Unicode Standard --
                     10:  *                Worldwide Character Encoding -- Version 1.0", Addison-
                     11:  *                Wesley, Volume 1, 1991, Volume 2, 1992.  UTF-8 is
                     12:  *                described in Unicode Technical Report #4.
                     13:  * [US-ASCII]     Coded Character Set--7-bit American Standard Code for
                     14:  *                Information Interchange, ANSI X3.4-1986.
                     15:  *
                     16:  * See Copyright for the status of this software.
                     17:  *
                     18:  * Daniel.Veillard@w3.org
                     19:  */
                     20: 
1.6       daniel     21: #ifndef __XML_CHAR_ENCODING_H__
                     22: #define __XML_CHAR_ENCODING_H__
1.1       daniel     23: 
1.15      daniel     24: #include <libxml/xmlversion.h>
1.16      daniel     25: #ifdef LIBXML_ICONV_ENABLED
                     26: #include <iconv.h>
                     27: #endif
1.17      daniel     28: #include <libxml/tree.h>
1.16      daniel     29: 
1.1       daniel     30: #ifdef __cplusplus
                     31: extern "C" {
                     32: #endif
                     33: 
1.8       daniel     34: /**
                     35:  * Predefined values for some standard encodings
1.16      daniel     36:  * Libxml don't do beforehand translation on UTF8, ISOLatinX
                     37:  * It also support UTF16 (LE and BE) by default.
                     38:  *
                     39:  * Anything else would have to be translated to UTF8 before being
                     40:  * given to the parser itself. The BOM for UTF16 and the encoding
                     41:  * declaration are looked at and a converter is looked for at that
                     42:  * point. If not found the parser stops here as asked by the XML REC
                     43:  * Converter can be registered by the user using xmlRegisterCharEncodingHandler
                     44:  * but the currentl form doesn't allow stateful transcoding (a serious
                     45:  * problem agreed !). If iconv has been found it will be used
                     46:  * automatically and allow stateful transcoding, the simplest is then
                     47:  * to be sure to enable icon and to provide iconv libs for the encoding
                     48:  * support needed.
1.8       daniel     49:  */
1.6       daniel     50: typedef enum {
                     51:     XML_CHAR_ENCODING_ERROR=   -1, /* No char encoding detected */
                     52:     XML_CHAR_ENCODING_NONE=    0, /* No char encoding detected */
                     53:     XML_CHAR_ENCODING_UTF8=    1, /* UTF-8 */
                     54:     XML_CHAR_ENCODING_UTF16LE= 2, /* UTF-16 little endian */
                     55:     XML_CHAR_ENCODING_UTF16BE= 3, /* UTF-16 big endian */
                     56:     XML_CHAR_ENCODING_UCS4LE=  4, /* UCS-4 little endian */
                     57:     XML_CHAR_ENCODING_UCS4BE=  5, /* UCS-4 big endian */
                     58:     XML_CHAR_ENCODING_EBCDIC=  6, /* EBCDIC uh! */
                     59:     XML_CHAR_ENCODING_UCS4_2143=7, /* UCS-4 unusual ordering */
                     60:     XML_CHAR_ENCODING_UCS4_3412=8, /* UCS-4 unusual ordering */
                     61:     XML_CHAR_ENCODING_UCS2=    9, /* UCS-2 */
                     62:     XML_CHAR_ENCODING_8859_1=  10,/* ISO-8859-1 ISO Latin 1 */
                     63:     XML_CHAR_ENCODING_8859_2=  11,/* ISO-8859-2 ISO Latin 2 */
                     64:     XML_CHAR_ENCODING_8859_3=  12,/* ISO-8859-3 */
                     65:     XML_CHAR_ENCODING_8859_4=  13,/* ISO-8859-4 */
                     66:     XML_CHAR_ENCODING_8859_5=  14,/* ISO-8859-5 */
                     67:     XML_CHAR_ENCODING_8859_6=  15,/* ISO-8859-6 */
                     68:     XML_CHAR_ENCODING_8859_7=  16,/* ISO-8859-7 */
                     69:     XML_CHAR_ENCODING_8859_8=  17,/* ISO-8859-8 */
                     70:     XML_CHAR_ENCODING_8859_9=  18,/* ISO-8859-9 */
                     71:     XML_CHAR_ENCODING_2022_JP=  19,/* ISO-2022-JP */
                     72:     XML_CHAR_ENCODING_SHIFT_JIS=20,/* Shift_JIS */
1.21      veillard   73:     XML_CHAR_ENCODING_EUC_JP=   21,/* EUC-JP */
                     74:     XML_CHAR_ENCODING_ASCII=    22 /* pure ASCII */
1.6       daniel     75: } xmlCharEncoding;
                     76: 
1.8       daniel     77: /**
                     78:  * xmlCharEncodingInputFunc:
                     79:  * @out:  a pointer ot an array of bytes to store the UTF-8 result
                     80:  * @outlen:  the lenght of @out
                     81:  * @in:  a pointer ot an array of chars in the original encoding
                     82:  * @inlen:  the lenght of @in
                     83:  *
                     84:  * Take a block of chars in the original encoding and try to convert
                     85:  * it to an UTF-8 block of chars out.
                     86:  *
1.17      daniel     87:  * Returns the number of byte written, or -1 by lack of space, or -2
                     88:  *     if the transcoding failed.
1.18      daniel     89:  * The value of @inlen after return is the number of octets consumed
                     90:  *     as the return value is positive, else unpredictiable.
                     91:  * The value of @outlen after return is the number of ocetes consumed.
1.8       daniel     92:  */
1.18      daniel     93: typedef int (* xmlCharEncodingInputFunc)(unsigned char* out, int *outlen,
1.14      daniel     94:                                          const unsigned char* in, int *inlen);
1.8       daniel     95: 
                     96: 
                     97: /**
1.14      daniel     98:  * xmlCharEncodingOutputFunc:
1.8       daniel     99:  * @out:  a pointer ot an array of bytes to store the result
                    100:  * @outlen:  the lenght of @out
                    101:  * @in:  a pointer ot an array of UTF-8 chars
                    102:  * @inlen:  the lenght of @in
                    103:  *
                    104:  * Take a block of UTF-8 chars in and try to convert it to an other
                    105:  * encoding.
1.19      daniel    106:  * Note: a first call designed to produce heading info is called with
                    107:  * in = NULL. If stateful this should also initialize the encoder state
1.8       daniel    108:  *
                    109:  * Returns the number of byte written, or -1 by lack of space, or -2
                    110:  *     if the transcoding failed.
1.18      daniel    111:  * The value of @inlen after return is the number of octets consumed
                    112:  *     as the return value is positive, else unpredictiable.
                    113:  * The value of @outlen after return is the number of ocetes consumed.
1.8       daniel    114:  */
1.18      daniel    115: typedef int (* xmlCharEncodingOutputFunc)(unsigned char* out, int *outlen,
1.14      daniel    116:                                           const unsigned char* in, int *inlen);
1.8       daniel    117: 
1.16      daniel    118: 
1.8       daniel    119: /*
                    120:  * Block defining the handlers for non UTF-8 encodings.
1.16      daniel    121:  * If iconv is supported, there is two extra fields 
1.8       daniel    122:  */
                    123: 
1.11      daniel    124: typedef struct _xmlCharEncodingHandler xmlCharEncodingHandler;
                    125: typedef xmlCharEncodingHandler *xmlCharEncodingHandlerPtr;
                    126: struct _xmlCharEncodingHandler {
1.8       daniel    127:     char                       *name;
                    128:     xmlCharEncodingInputFunc   input;
1.16      daniel    129:     xmlCharEncodingOutputFunc  output;
                    130: #ifdef LIBXML_ICONV_ENABLED
                    131:     iconv_t                    iconv_in;
                    132:     iconv_t                    iconv_out;
                    133: #endif /* LIBXML_ICONV_ENABLED */
1.11      daniel    134: };
1.8       daniel    135: 
1.22    ! veillard  136: /*
        !           137:  * Interfaces for encoding handlers
        !           138:  */
1.10      daniel    139: void   xmlInitCharEncodingHandlers     (void);
                    140: void   xmlCleanupCharEncodingHandlers  (void);
                    141: void   xmlRegisterCharEncodingHandler  (xmlCharEncodingHandlerPtr handler);
1.22    ! veillard  142: xmlCharEncodingHandlerPtr
        !           143:        xmlGetCharEncodingHandler       (xmlCharEncoding enc);
        !           144: xmlCharEncodingHandlerPtr
        !           145:        xmlFindCharEncodingHandler      (const char *name);
        !           146: 
        !           147: 
        !           148: /*
        !           149:  * Interfaces for encoding names and aliases
        !           150:  */
        !           151: int    xmlAddEncodingAlias             (const char *name,
        !           152:                                         const char *alias);
        !           153: int    xmlDelEncodingAlias             (const char *alias);
        !           154: const char *
        !           155:        xmlGetEncodingAlias             (const char *alias);
        !           156: void   xmlCleanupEncodingAliases       (void);
        !           157: xmlCharEncoding
        !           158:        xmlParseCharEncoding            (const char* name);
        !           159: const char*
        !           160:        xmlGetCharEncodingName          (xmlCharEncoding enc);
        !           161: 
        !           162: /*
        !           163:  * Interfaces directly used by the parsers.
        !           164:  */
        !           165: xmlCharEncoding
        !           166:        xmlDetectCharEncoding           (const unsigned char* in,
1.14      daniel    167:                                         int len);
1.22    ! veillard  168: 
1.12      daniel    169: int    xmlCheckUTF8                    (const unsigned char *utf);
1.8       daniel    170: 
1.16      daniel    171: int    xmlCharEncOutFunc               (xmlCharEncodingHandler *handler,
1.17      daniel    172:                                         xmlBufferPtr out,
                    173:                                         xmlBufferPtr in);
1.16      daniel    174: 
                    175: int    xmlCharEncInFunc                (xmlCharEncodingHandler *handler,
1.20      daniel    176:                                         xmlBufferPtr out,
                    177:                                         xmlBufferPtr in);
                    178: int    xmlCharEncFirstLine             (xmlCharEncodingHandler *handler,
1.17      daniel    179:                                         xmlBufferPtr out,
                    180:                                         xmlBufferPtr in);
1.16      daniel    181: int    xmlCharEncCloseFunc             (xmlCharEncodingHandler *handler);
1.6       daniel    182: 
1.1       daniel    183: #ifdef __cplusplus
                    184: }
                    185: #endif
                    186: 
1.6       daniel    187: #endif /* __XML_CHAR_ENCODING_H__ */

Webmaster