2 * encoding.h : interface for the encoding conversion functions needed for
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.
16 * See Copyright for the status of this software.
21 #ifndef __XML_CHAR_ENCODING_H__
22 #define __XML_CHAR_ENCODING_H__
24 #include <libxml/xmlversion.h>
26 #ifdef LIBXML_ICONV_ENABLED
36 * Predefined values for some standard encodings.
37 * Libxml don't do beforehand translation on UTF8, ISOLatinX.
38 * It also support UTF16 (LE and BE) by default.
40 * Anything else would have to be translated to UTF8 before being
41 * given to the parser itself. The BOM for UTF16 and the encoding
42 * declaration are looked at and a converter is looked for at that
43 * point. If not found the parser stops here as asked by the XML REC
44 * Converter can be registered by the user using xmlRegisterCharEncodingHandler
45 * but the current form doesn't allow stateful transcoding (a serious
46 * problem agreed !). If iconv has been found it will be used
47 * automatically and allow stateful transcoding, the simplest is then
48 * to be sure to enable icon and to provide iconv libs for the encoding
52 XML_CHAR_ENCODING_ERROR= -1, /* No char encoding detected */
53 XML_CHAR_ENCODING_NONE= 0, /* No char encoding detected */
54 XML_CHAR_ENCODING_UTF8= 1, /* UTF-8 */
55 XML_CHAR_ENCODING_UTF16LE= 2, /* UTF-16 little endian */
56 XML_CHAR_ENCODING_UTF16BE= 3, /* UTF-16 big endian */
57 XML_CHAR_ENCODING_UCS4LE= 4, /* UCS-4 little endian */
58 XML_CHAR_ENCODING_UCS4BE= 5, /* UCS-4 big endian */
59 XML_CHAR_ENCODING_EBCDIC= 6, /* EBCDIC uh! */
60 XML_CHAR_ENCODING_UCS4_2143=7, /* UCS-4 unusual ordering */
61 XML_CHAR_ENCODING_UCS4_3412=8, /* UCS-4 unusual ordering */
62 XML_CHAR_ENCODING_UCS2= 9, /* UCS-2 */
63 XML_CHAR_ENCODING_8859_1= 10,/* ISO-8859-1 ISO Latin 1 */
64 XML_CHAR_ENCODING_8859_2= 11,/* ISO-8859-2 ISO Latin 2 */
65 XML_CHAR_ENCODING_8859_3= 12,/* ISO-8859-3 */
66 XML_CHAR_ENCODING_8859_4= 13,/* ISO-8859-4 */
67 XML_CHAR_ENCODING_8859_5= 14,/* ISO-8859-5 */
68 XML_CHAR_ENCODING_8859_6= 15,/* ISO-8859-6 */
69 XML_CHAR_ENCODING_8859_7= 16,/* ISO-8859-7 */
70 XML_CHAR_ENCODING_8859_8= 17,/* ISO-8859-8 */
71 XML_CHAR_ENCODING_8859_9= 18,/* ISO-8859-9 */
72 XML_CHAR_ENCODING_2022_JP= 19,/* ISO-2022-JP */
73 XML_CHAR_ENCODING_SHIFT_JIS=20,/* Shift_JIS */
74 XML_CHAR_ENCODING_EUC_JP= 21,/* EUC-JP */
75 XML_CHAR_ENCODING_ASCII= 22 /* pure ASCII */
79 * xmlCharEncodingInputFunc:
80 * @out: a pointer to an array of bytes to store the UTF-8 result
81 * @outlen: the length of @out
82 * @in: a pointer to an array of chars in the original encoding
83 * @inlen: the length of @in
85 * Take a block of chars in the original encoding and try to convert
86 * it to an UTF-8 block of chars out.
88 * Returns the number of byte written, or -1 by lack of space, or -2
89 * if the transcoding failed.
90 * The value of @inlen after return is the number of octets consumed
91 * as the return value is positive, else unpredictiable.
92 * The value of @outlen after return is the number of octets consumed.
94 typedef int (* xmlCharEncodingInputFunc)(unsigned char *out, int *outlen,
95 const unsigned char *in, int *inlen);
99 * xmlCharEncodingOutputFunc:
100 * @out: a pointer to an array of bytes to store the result
101 * @outlen: the length of @out
102 * @in: a pointer to an array of UTF-8 chars
103 * @inlen: the length of @in
105 * Take a block of UTF-8 chars in and try to convert it to an other
107 * Note: a first call designed to produce heading info is called with
108 * in = NULL. If stateful this should also initialize the encoder state.
110 * Returns the number of byte written, or -1 by lack of space, or -2
111 * if the transcoding failed.
112 * The value of @inlen after return is the number of octets consumed
113 * as the return value is positive, else unpredictiable.
114 * The value of @outlen after return is the number of ocetes consumed.
116 typedef int (* xmlCharEncodingOutputFunc)(unsigned char *out, int *outlen,
117 const unsigned char *in, int *inlen);
121 * Block defining the handlers for non UTF-8 encodings.
122 * If iconv is supported, there is two extra fields.
125 typedef struct _xmlCharEncodingHandler xmlCharEncodingHandler;
126 typedef xmlCharEncodingHandler *xmlCharEncodingHandlerPtr;
127 struct _xmlCharEncodingHandler {
129 xmlCharEncodingInputFunc input;
130 xmlCharEncodingOutputFunc output;
131 #ifdef LIBXML_ICONV_ENABLED
134 #endif /* LIBXML_ICONV_ENABLED */
140 #include <libxml/tree.h>
146 * Interfaces for encoding handlers.
148 void xmlInitCharEncodingHandlers (void);
149 void xmlCleanupCharEncodingHandlers (void);
150 void xmlRegisterCharEncodingHandler (xmlCharEncodingHandlerPtr handler);
151 xmlCharEncodingHandlerPtr
152 xmlGetCharEncodingHandler (xmlCharEncoding enc);
153 xmlCharEncodingHandlerPtr
154 xmlFindCharEncodingHandler (const char *name);
155 xmlCharEncodingHandlerPtr
156 xmlNewCharEncodingHandler (const char *name,
157 xmlCharEncodingInputFunc input,
158 xmlCharEncodingOutputFunc output);
161 * Interfaces for encoding names and aliases.
163 int xmlAddEncodingAlias (const char *name,
165 int xmlDelEncodingAlias (const char *alias);
167 xmlGetEncodingAlias (const char *alias);
168 void xmlCleanupEncodingAliases (void);
170 xmlParseCharEncoding (const char *name);
172 xmlGetCharEncodingName (xmlCharEncoding enc);
175 * Interfaces directly used by the parsers.
178 xmlDetectCharEncoding (const unsigned char *in,
181 int xmlCharEncOutFunc (xmlCharEncodingHandler *handler,
185 int xmlCharEncInFunc (xmlCharEncodingHandler *handler,
188 int xmlCharEncFirstLine (xmlCharEncodingHandler *handler,
191 int xmlCharEncCloseFunc (xmlCharEncodingHandler *handler);
194 * Export a few useful functions
196 int UTF8Toisolat1 (unsigned char *out,
198 const unsigned char *in,
200 int isolat1ToUTF8 (unsigned char *out,
202 const unsigned char *in,
204 int xmlGetUTF8Char (const unsigned char *utf,
207 * exports additional "UTF-8 aware" string routines which are.
210 int xmlCheckUTF8 (const unsigned char *utf);
211 int xmlUTF8Strsize (const xmlChar *utf,
213 xmlChar * xmlUTF8Strndup (const xmlChar *utf,
215 xmlChar * xmlUTF8Strpos (const xmlChar *utf,
217 int xmlUTF8Strloc (const xmlChar *utf,
218 const xmlChar *utfchar);
219 xmlChar * xmlUTF8Strsub (const xmlChar *utf,
222 int xmlUTF8Strlen (const xmlChar *utf);
223 int xmlUTF8Size (const xmlChar *utf);
224 int xmlUTF8Charcmp (const xmlChar *utf1,
225 const xmlChar *utf2);
230 #endif /* __XML_CHAR_ENCODING_H__ */