Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-22 10:41:48

0001 /*
0002  * Summary: interface for the encoding conversion functions
0003  * Description: interface for the encoding conversion functions needed for
0004  *              XML basic encoding and iconv() support.
0005  *
0006  * Related specs are
0007  * rfc2044        (UTF-8 and UTF-16) F. Yergeau Alis Technologies
0008  * [ISO-10646]    UTF-8 and UTF-16 in Annexes
0009  * [ISO-8859-1]   ISO Latin-1 characters codes.
0010  * [UNICODE]      The Unicode Consortium, "The Unicode Standard --
0011  *                Worldwide Character Encoding -- Version 1.0", Addison-
0012  *                Wesley, Volume 1, 1991, Volume 2, 1992.  UTF-8 is
0013  *                described in Unicode Technical Report #4.
0014  * [US-ASCII]     Coded Character Set--7-bit American Standard Code for
0015  *                Information Interchange, ANSI X3.4-1986.
0016  *
0017  * Copy: See Copyright for the status of this software.
0018  *
0019  * Author: Daniel Veillard
0020  */
0021 
0022 #ifndef __XML_CHAR_ENCODING_H__
0023 #define __XML_CHAR_ENCODING_H__
0024 
0025 #include <libxml/xmlversion.h>
0026 
0027 #ifdef LIBXML_ICONV_ENABLED
0028 #include <iconv.h>
0029 #endif
0030 
0031 #ifdef __cplusplus
0032 extern "C" {
0033 #endif
0034 
0035 typedef enum {
0036     XML_ENC_ERR_SUCCESS     =  0,
0037     XML_ENC_ERR_SPACE       = -1,
0038     XML_ENC_ERR_INPUT       = -2,
0039     XML_ENC_ERR_PARTIAL     = -3,
0040     XML_ENC_ERR_INTERNAL    = -4,
0041     XML_ENC_ERR_MEMORY      = -5
0042 } xmlCharEncError;
0043 
0044 /*
0045  * xmlCharEncoding:
0046  *
0047  * Predefined values for some standard encodings.
0048  * Libxml does not do beforehand translation on UTF8 and ISOLatinX.
0049  * It also supports ASCII, ISO-8859-1, and UTF16 (LE and BE) by default.
0050  *
0051  * Anything else would have to be translated to UTF8 before being
0052  * given to the parser itself. The BOM for UTF16 and the encoding
0053  * declaration are looked at and a converter is looked for at that
0054  * point. If not found the parser stops here as asked by the XML REC. A
0055  * converter can be registered by the user using xmlRegisterCharEncodingHandler
0056  * but the current form doesn't allow stateful transcoding (a serious
0057  * problem agreed !). If iconv has been found it will be used
0058  * automatically and allow stateful transcoding, the simplest is then
0059  * to be sure to enable iconv and to provide iconv libs for the encoding
0060  * support needed.
0061  *
0062  * Note that the generic "UTF-16" is not a predefined value.  Instead, only
0063  * the specific UTF-16LE and UTF-16BE are present.
0064  */
0065 typedef enum {
0066     XML_CHAR_ENCODING_ERROR=   -1, /* No char encoding detected */
0067     XML_CHAR_ENCODING_NONE= 0, /* No char encoding detected */
0068     XML_CHAR_ENCODING_UTF8= 1, /* UTF-8 */
0069     XML_CHAR_ENCODING_UTF16LE=  2, /* UTF-16 little endian */
0070     XML_CHAR_ENCODING_UTF16BE=  3, /* UTF-16 big endian */
0071     XML_CHAR_ENCODING_UCS4LE=   4, /* UCS-4 little endian */
0072     XML_CHAR_ENCODING_UCS4BE=   5, /* UCS-4 big endian */
0073     XML_CHAR_ENCODING_EBCDIC=   6, /* EBCDIC uh! */
0074     XML_CHAR_ENCODING_UCS4_2143=7, /* UCS-4 unusual ordering */
0075     XML_CHAR_ENCODING_UCS4_3412=8, /* UCS-4 unusual ordering */
0076     XML_CHAR_ENCODING_UCS2= 9, /* UCS-2 */
0077     XML_CHAR_ENCODING_8859_1=   10,/* ISO-8859-1 ISO Latin 1 */
0078     XML_CHAR_ENCODING_8859_2=   11,/* ISO-8859-2 ISO Latin 2 */
0079     XML_CHAR_ENCODING_8859_3=   12,/* ISO-8859-3 */
0080     XML_CHAR_ENCODING_8859_4=   13,/* ISO-8859-4 */
0081     XML_CHAR_ENCODING_8859_5=   14,/* ISO-8859-5 */
0082     XML_CHAR_ENCODING_8859_6=   15,/* ISO-8859-6 */
0083     XML_CHAR_ENCODING_8859_7=   16,/* ISO-8859-7 */
0084     XML_CHAR_ENCODING_8859_8=   17,/* ISO-8859-8 */
0085     XML_CHAR_ENCODING_8859_9=   18,/* ISO-8859-9 */
0086     XML_CHAR_ENCODING_2022_JP=  19,/* ISO-2022-JP */
0087     XML_CHAR_ENCODING_SHIFT_JIS=20,/* Shift_JIS */
0088     XML_CHAR_ENCODING_EUC_JP=   21,/* EUC-JP */
0089     XML_CHAR_ENCODING_ASCII=    22 /* pure ASCII */
0090 } xmlCharEncoding;
0091 
0092 /**
0093  * xmlCharEncodingInputFunc:
0094  * @out:  a pointer to an array of bytes to store the UTF-8 result
0095  * @outlen:  the length of @out
0096  * @in:  a pointer to an array of chars in the original encoding
0097  * @inlen:  the length of @in
0098  *
0099  * Take a block of chars in the original encoding and try to convert
0100  * it to an UTF-8 block of chars out.
0101  *
0102  * Returns the number of bytes written, -1 if lack of space, or -2
0103  *     if the transcoding failed.
0104  * The value of @inlen after return is the number of octets consumed
0105  *     if the return value is positive, else unpredictiable.
0106  * The value of @outlen after return is the number of octets consumed.
0107  */
0108 typedef int (* xmlCharEncodingInputFunc)(unsigned char *out, int *outlen,
0109                                          const unsigned char *in, int *inlen);
0110 
0111 
0112 /**
0113  * xmlCharEncodingOutputFunc:
0114  * @out:  a pointer to an array of bytes to store the result
0115  * @outlen:  the length of @out
0116  * @in:  a pointer to an array of UTF-8 chars
0117  * @inlen:  the length of @in
0118  *
0119  * Take a block of UTF-8 chars in and try to convert it to another
0120  * encoding.
0121  * Note: a first call designed to produce heading info is called with
0122  * in = NULL. If stateful this should also initialize the encoder state.
0123  *
0124  * Returns the number of bytes written, -1 if lack of space, or -2
0125  *     if the transcoding failed.
0126  * The value of @inlen after return is the number of octets consumed
0127  *     if the return value is positive, else unpredictiable.
0128  * The value of @outlen after return is the number of octets produced.
0129  */
0130 typedef int (* xmlCharEncodingOutputFunc)(unsigned char *out, int *outlen,
0131                                           const unsigned char *in, int *inlen);
0132 
0133 
0134 /*
0135  * Block defining the handlers for non UTF-8 encodings.
0136  * If iconv is supported, there are two extra fields.
0137  */
0138 typedef struct _xmlCharEncodingHandler xmlCharEncodingHandler;
0139 typedef xmlCharEncodingHandler *xmlCharEncodingHandlerPtr;
0140 struct _xmlCharEncodingHandler {
0141     char                       *name;
0142     xmlCharEncodingInputFunc   input;
0143     xmlCharEncodingOutputFunc  output;
0144 #ifdef LIBXML_ICONV_ENABLED
0145     iconv_t                    iconv_in;
0146     iconv_t                    iconv_out;
0147 #endif /* LIBXML_ICONV_ENABLED */
0148 #ifdef LIBXML_ICU_ENABLED
0149     struct _uconv_t            *uconv_in;
0150     struct _uconv_t            *uconv_out;
0151 #endif /* LIBXML_ICU_ENABLED */
0152 };
0153 
0154 /*
0155  * Interfaces for encoding handlers.
0156  */
0157 XML_DEPRECATED
0158 XMLPUBFUN void
0159     xmlInitCharEncodingHandlers (void);
0160 XML_DEPRECATED
0161 XMLPUBFUN void
0162     xmlCleanupCharEncodingHandlers  (void);
0163 XMLPUBFUN void
0164     xmlRegisterCharEncodingHandler  (xmlCharEncodingHandlerPtr handler);
0165 XMLPUBFUN int
0166     xmlLookupCharEncodingHandler    (xmlCharEncoding enc,
0167                      xmlCharEncodingHandlerPtr *out);
0168 XMLPUBFUN int
0169     xmlOpenCharEncodingHandler  (const char *name,
0170                      int output,
0171                      xmlCharEncodingHandlerPtr *out);
0172 XMLPUBFUN xmlCharEncodingHandlerPtr
0173     xmlGetCharEncodingHandler   (xmlCharEncoding enc);
0174 XMLPUBFUN xmlCharEncodingHandlerPtr
0175     xmlFindCharEncodingHandler  (const char *name);
0176 XMLPUBFUN xmlCharEncodingHandlerPtr
0177     xmlNewCharEncodingHandler   (const char *name,
0178                      xmlCharEncodingInputFunc input,
0179                      xmlCharEncodingOutputFunc output);
0180 
0181 /*
0182  * Interfaces for encoding names and aliases.
0183  */
0184 XMLPUBFUN int
0185     xmlAddEncodingAlias     (const char *name,
0186                      const char *alias);
0187 XMLPUBFUN int
0188     xmlDelEncodingAlias     (const char *alias);
0189 XMLPUBFUN const char *
0190     xmlGetEncodingAlias     (const char *alias);
0191 XMLPUBFUN void
0192     xmlCleanupEncodingAliases   (void);
0193 XMLPUBFUN xmlCharEncoding
0194     xmlParseCharEncoding        (const char *name);
0195 XMLPUBFUN const char *
0196     xmlGetCharEncodingName      (xmlCharEncoding enc);
0197 
0198 /*
0199  * Interfaces directly used by the parsers.
0200  */
0201 XMLPUBFUN xmlCharEncoding
0202     xmlDetectCharEncoding       (const unsigned char *in,
0203                      int len);
0204 
0205 /** DOC_DISABLE */
0206 struct _xmlBuffer;
0207 /** DOC_ENABLE */
0208 XMLPUBFUN int
0209     xmlCharEncOutFunc       (xmlCharEncodingHandler *handler,
0210                      struct _xmlBuffer *out,
0211                      struct _xmlBuffer *in);
0212 
0213 XMLPUBFUN int
0214     xmlCharEncInFunc        (xmlCharEncodingHandler *handler,
0215                      struct _xmlBuffer *out,
0216                      struct _xmlBuffer *in);
0217 XML_DEPRECATED
0218 XMLPUBFUN int
0219     xmlCharEncFirstLine     (xmlCharEncodingHandler *handler,
0220                      struct _xmlBuffer *out,
0221                      struct _xmlBuffer *in);
0222 XMLPUBFUN int
0223     xmlCharEncCloseFunc     (xmlCharEncodingHandler *handler);
0224 
0225 /*
0226  * Export a few useful functions
0227  */
0228 #ifdef LIBXML_OUTPUT_ENABLED
0229 XMLPUBFUN int
0230     UTF8Toisolat1           (unsigned char *out,
0231                      int *outlen,
0232                      const unsigned char *in,
0233                      int *inlen);
0234 #endif /* LIBXML_OUTPUT_ENABLED */
0235 XMLPUBFUN int
0236     isolat1ToUTF8           (unsigned char *out,
0237                      int *outlen,
0238                      const unsigned char *in,
0239                      int *inlen);
0240 #ifdef __cplusplus
0241 }
0242 #endif
0243 
0244 #endif /* __XML_CHAR_ENCODING_H__ */