blob: 6a423359dab8920fd7d7fd0fc920b3c1324f0a99 [file] [log] [blame]
Daniel Veillard891e4041998-10-19 00:43:02 +00001/*
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 *
Daniel Veillard891e4041998-10-19 00:43:02 +000016 * See Copyright for the status of this software.
17 *
Daniel Veillard891e4041998-10-19 00:43:02 +000018 * Daniel.Veillard@w3.org
19 */
20
Daniel Veillard27d88741999-05-29 11:51:49 +000021#ifndef __XML_CHAR_ENCODING_H__
22#define __XML_CHAR_ENCODING_H__
Daniel Veillard891e4041998-10-19 00:43:02 +000023
24#ifdef __cplusplus
25extern "C" {
26#endif
27
Daniel Veillard14fff061999-06-22 21:49:07 +000028/**
29 * Predefined values for some standard encodings
30 */
Daniel Veillard27d88741999-05-29 11:51:49 +000031typedef enum {
32 XML_CHAR_ENCODING_ERROR= -1, /* No char encoding detected */
33 XML_CHAR_ENCODING_NONE= 0, /* No char encoding detected */
34 XML_CHAR_ENCODING_UTF8= 1, /* UTF-8 */
35 XML_CHAR_ENCODING_UTF16LE= 2, /* UTF-16 little endian */
36 XML_CHAR_ENCODING_UTF16BE= 3, /* UTF-16 big endian */
37 XML_CHAR_ENCODING_UCS4LE= 4, /* UCS-4 little endian */
38 XML_CHAR_ENCODING_UCS4BE= 5, /* UCS-4 big endian */
39 XML_CHAR_ENCODING_EBCDIC= 6, /* EBCDIC uh! */
40 XML_CHAR_ENCODING_UCS4_2143=7, /* UCS-4 unusual ordering */
41 XML_CHAR_ENCODING_UCS4_3412=8, /* UCS-4 unusual ordering */
42 XML_CHAR_ENCODING_UCS2= 9, /* UCS-2 */
43 XML_CHAR_ENCODING_8859_1= 10,/* ISO-8859-1 ISO Latin 1 */
44 XML_CHAR_ENCODING_8859_2= 11,/* ISO-8859-2 ISO Latin 2 */
45 XML_CHAR_ENCODING_8859_3= 12,/* ISO-8859-3 */
46 XML_CHAR_ENCODING_8859_4= 13,/* ISO-8859-4 */
47 XML_CHAR_ENCODING_8859_5= 14,/* ISO-8859-5 */
48 XML_CHAR_ENCODING_8859_6= 15,/* ISO-8859-6 */
49 XML_CHAR_ENCODING_8859_7= 16,/* ISO-8859-7 */
50 XML_CHAR_ENCODING_8859_8= 17,/* ISO-8859-8 */
51 XML_CHAR_ENCODING_8859_9= 18,/* ISO-8859-9 */
52 XML_CHAR_ENCODING_2022_JP= 19,/* ISO-2022-JP */
53 XML_CHAR_ENCODING_SHIFT_JIS=20,/* Shift_JIS */
Daniel Veillardb96e6431999-08-29 21:02:19 +000054 XML_CHAR_ENCODING_EUC_JP= 21 /* EUC-JP */
Daniel Veillard27d88741999-05-29 11:51:49 +000055} xmlCharEncoding;
56
Daniel Veillard14fff061999-06-22 21:49:07 +000057/**
58 * xmlCharEncodingInputFunc:
59 * @out: a pointer ot an array of bytes to store the UTF-8 result
60 * @outlen: the lenght of @out
61 * @in: a pointer ot an array of chars in the original encoding
62 * @inlen: the lenght of @in
63 *
64 * Take a block of chars in the original encoding and try to convert
65 * it to an UTF-8 block of chars out.
66 *
67 * Returns the number of byte written, or -1 by lack of space.
68 */
69typedef int (* xmlCharEncodingInputFunc)(unsigned char* out, int outlen,
70 unsigned char* in, int inlen);
71
72
73/**
74 * xmlCharEncodingInputFunc:
75 * @out: a pointer ot an array of bytes to store the result
76 * @outlen: the lenght of @out
77 * @in: a pointer ot an array of UTF-8 chars
78 * @inlen: the lenght of @in
79 *
80 * Take a block of UTF-8 chars in and try to convert it to an other
81 * encoding.
82 *
83 * Returns the number of byte written, or -1 by lack of space, or -2
84 * if the transcoding failed.
85 */
86typedef int (* xmlCharEncodingOutputFunc)(unsigned char* out, int outlen,
87 unsigned char* in, int inlen);
88
89/*
90 * Block defining the handlers for non UTF-8 encodings.
91 */
92
93typedef struct xmlCharEncodingHandler {
94 char *name;
95 xmlCharEncodingInputFunc input;
96 xmlCharEncodingOutputFunc output;
97} xmlCharEncodingHandler;
98typedef xmlCharEncodingHandler *xmlCharEncodingHandlerPtr;
99
Daniel Veillarda819dac1999-11-24 18:04:22 +0000100void xmlInitCharEncodingHandlers (void);
101void xmlCleanupCharEncodingHandlers (void);
102void xmlRegisterCharEncodingHandler (xmlCharEncodingHandlerPtr handler);
103xmlCharEncoding xmlDetectCharEncoding (const unsigned char* in);
104xmlCharEncoding xmlParseCharEncoding (const char* name);
Daniel Veillard14fff061999-06-22 21:49:07 +0000105xmlCharEncodingHandlerPtr xmlGetCharEncodingHandler(xmlCharEncoding enc);
106xmlCharEncodingHandlerPtr xmlFindCharEncodingHandler(const char *name);
107
Daniel Veillard27d88741999-05-29 11:51:49 +0000108
Daniel Veillard891e4041998-10-19 00:43:02 +0000109#ifdef __cplusplus
110}
111#endif
112
Daniel Veillard27d88741999-05-29 11:51:49 +0000113#endif /* __XML_CHAR_ENCODING_H__ */