2 * Summary: interface for the encoding conversion functions
3 * Description: interface for the encoding conversion functions needed for
4 * XML basic encoding and iconv() support.
7 * rfc2044 (UTF-8 and UTF-16) F. Yergeau Alis Technologies
8 * [ISO-10646] UTF-8 and UTF-16 in Annexes
9 * [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 is
13 * described in Unicode Technical Report #4.
14 * [US-ASCII] Coded Character Set--7-bit American Standard Code for
15 * Information Interchange, ANSI X3.4-1986.
17 * Copy: See Copyright for the status of this software.
19 * Author: Daniel Veillard
20 * Portion Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
28 #ifndef XML_CHAR_ENCODING_H
29 #define XML_CHAR_ENCODING_H
31 //#include "libxml/Libxml2_xmlversion.h" // enable this when dependency on tree.h is removed
32 #include "libxml2_tree.h"
34 #ifdef LIBXML_ICONV_ENABLED
45 * Predefined values for some standard encodings.
46 * Libxml does not do beforehand translation on UTF8 and ISOLatinX.
47 * It also supports ASCII, ISO-8859-1, and UTF16 (LE and BE) by default.
49 * Anything else would have to be translated to UTF8 before being
50 * given to the parser itself. The BOM for UTF16 and the encoding
51 * declaration are looked at and a converter is looked for at that
52 * point. If not found the parser stops here as asked by the XML REC. A
53 * converter can be registered by the user using xmlRegisterCharEncodingHandler
54 * but the current form doesn't allow stateful transcoding (a serious
55 * problem agreed !). If iconv has been found it will be used
56 * automatically and allow stateful transcoding, the simplest is then
57 * to be sure to enable iconv and to provide iconv libs for the encoding
60 * Note that the generic "UTF-16" is not a predefined value. Instead, only
61 * the specific UTF-16LE and UTF-16BE are present.
64 XML_CHAR_ENCODING_ERROR= -1, /* No char encoding detected */
65 XML_CHAR_ENCODING_NONE= 0, /* No char encoding detected */
66 XML_CHAR_ENCODING_UTF8= 1, /* UTF-8 */
67 XML_CHAR_ENCODING_UTF16LE= 2, /* UTF-16 little endian */
68 XML_CHAR_ENCODING_UTF16BE= 3, /* UTF-16 big endian */
69 XML_CHAR_ENCODING_UCS4LE= 4, /* UCS-4 little endian */
70 XML_CHAR_ENCODING_UCS4BE= 5, /* UCS-4 big endian */
71 XML_CHAR_ENCODING_EBCDIC= 6, /* EBCDIC uh! */
72 XML_CHAR_ENCODING_UCS4_2143=7, /* UCS-4 unusual ordering */
73 XML_CHAR_ENCODING_UCS4_3412=8, /* UCS-4 unusual ordering */
74 XML_CHAR_ENCODING_UCS2= 9, /* UCS-2 */
75 XML_CHAR_ENCODING_8859_1= 10,/* ISO-8859-1 ISO Latin 1 */
76 XML_CHAR_ENCODING_8859_2= 11,/* ISO-8859-2 ISO Latin 2 */
77 XML_CHAR_ENCODING_8859_3= 12,/* ISO-8859-3 */
78 XML_CHAR_ENCODING_8859_4= 13,/* ISO-8859-4 */
79 XML_CHAR_ENCODING_8859_5= 14,/* ISO-8859-5 */
80 XML_CHAR_ENCODING_8859_6= 15,/* ISO-8859-6 */
81 XML_CHAR_ENCODING_8859_7= 16,/* ISO-8859-7 */
82 XML_CHAR_ENCODING_8859_8= 17,/* ISO-8859-8 */
83 XML_CHAR_ENCODING_8859_9= 18,/* ISO-8859-9 */
84 XML_CHAR_ENCODING_2022_JP= 19,/* ISO-2022-JP */
85 XML_CHAR_ENCODING_SHIFT_JIS=20,/* Shift_JIS */
86 XML_CHAR_ENCODING_EUC_JP= 21,/* EUC-JP */
87 XML_CHAR_ENCODING_ASCII= 22 /* pure ASCII */
91 * xmlCharEncodingInputFunc:
92 * @param out a pointer to an array of bytes to store the UTF-8 result
93 * @param outlen the length of out
94 * @param in a pointer to an array of chars in the original encoding
95 * @param inlen the length of in
97 * Take a block of chars in the original encoding and try to convert
98 * it to an UTF-8 block of chars out.
100 * Returns the number of bytes written, -1 if lack of space, or -2
101 * if the transcoding failed.
102 * The value of inlen after return is the number of octets consumed
103 * if the return value is positive, else unpredictiable.
104 * The value of outlen after return is the number of octets consumed.
106 typedef int (* xmlCharEncodingInputFunc)(unsigned char *out, int *outlen,
107 const unsigned char *in, int *inlen);
111 * xmlCharEncodingOutputFunc:
112 * @param out a pointer to an array of bytes to store the result
113 * @param outlen the length of out
114 * @param in a pointer to an array of UTF-8 chars
115 * @param inlen the length of in
117 * Take a block of UTF-8 chars in and try to convert it to another
119 * Note: a first call designed to produce heading info is called with
120 * in = NULL. If stateful this should also initialize the encoder state.
122 * Returns the number of bytes written, -1 if lack of space, or -2
123 * if the transcoding failed.
124 * The value of inlen after return is the number of octets consumed
125 * if the return value is positive, else unpredictiable.
126 * The value of outlen after return is the number of octets produced.
128 typedef int (* xmlCharEncodingOutputFunc)(unsigned char *out, int *outlen,
129 const unsigned char *in, int *inlen);
133 * Block defining the handlers for non UTF-8 encodings.
134 * If iconv is supported, there are two extra fields.
137 typedef struct _xmlCharEncodingHandler xmlCharEncodingHandler;
138 typedef xmlCharEncodingHandler *xmlCharEncodingHandlerPtr;
139 struct _xmlCharEncodingHandler {
141 xmlCharEncodingInputFunc input;
142 xmlCharEncodingOutputFunc output;
143 #ifdef LIBXML_ICONV_ENABLED
146 #endif /* LIBXML_ICONV_ENABLED */
157 * Interfaces for encoding handlers.
159 XMLPUBFUN void XMLCALL
160 xmlInitCharEncodingHandlers (void);
161 XMLPUBFUN void XMLCALL
162 xmlCleanupCharEncodingHandlers (void);
163 XMLPUBFUN void XMLCALL
164 xmlRegisterCharEncodingHandler (xmlCharEncodingHandlerPtr handler);
165 XMLPUBFUN xmlCharEncodingHandlerPtr XMLCALL
166 xmlGetCharEncodingHandler (xmlCharEncoding enc);
167 XMLPUBFUN xmlCharEncodingHandlerPtr XMLCALL
168 xmlFindCharEncodingHandler (const char *name);
169 XMLPUBFUN xmlCharEncodingHandlerPtr XMLCALL
170 xmlNewCharEncodingHandler (const char *name,
171 xmlCharEncodingInputFunc input,
172 xmlCharEncodingOutputFunc output);
175 * Interfaces for encoding names and aliases.
177 #ifndef XMLENGINE_EXCLUDE_UNUSED
178 XMLPUBFUN int XMLCALL xmlAddEncodingAlias(const char *name, const char *alias);
179 XMLPUBFUN int XMLCALL xmlDelEncodingAlias(const char *alias);
182 XMLPUBFUN const char * XMLCALL xmlGetEncodingAlias (const char *alias);
183 XMLPUBFUN void XMLCALL xmlCleanupEncodingAliases (void);
184 XMLPUBFUN xmlCharEncoding XMLCALL xmlParseCharEncoding (const char *name);
185 XMLPUBFUN const char * XMLCALL xmlGetCharEncodingName (xmlCharEncoding enc);
188 * Interfaces directly used by the parsers.
190 XMLPUBFUN xmlCharEncoding XMLCALL
191 xmlDetectCharEncoding (const unsigned char *in,
194 XMLPUBFUN int XMLCALL
195 xmlCharEncOutFunc (xmlCharEncodingHandler *handler,
199 XMLPUBFUN int XMLCALL
200 xmlCharEncInFunc (xmlCharEncodingHandler *handler,
203 XMLPUBFUN int XMLCALL
204 xmlCharEncFirstLine (xmlCharEncodingHandler *handler,
207 XMLPUBFUN int XMLCALL
208 xmlCharEncCloseFunc (xmlCharEncodingHandler *handler);
211 * Export a few useful functions
213 XMLPUBFUN int XMLCALL
214 UTF8Toisolat1 (unsigned char *out,
216 const unsigned char *in,
218 XMLPUBFUN int XMLCALL
219 isolat1ToUTF8 (unsigned char *out,
221 const unsigned char *in,
227 #endif /* XML_CHAR_ENCODING_H */