Daniel Veillard | 891e404 | 1998-10-19 00:43:02 +0000 | [diff] [blame] | 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 | * |
Daniel Veillard | 891e404 | 1998-10-19 00:43:02 +0000 | [diff] [blame] | 16 | * See Copyright for the status of this software. |
| 17 | * |
Daniel Veillard | 891e404 | 1998-10-19 00:43:02 +0000 | [diff] [blame] | 18 | * Daniel.Veillard@w3.org |
| 19 | */ |
| 20 | |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 21 | #ifndef __XML_CHAR_ENCODING_H__ |
| 22 | #define __XML_CHAR_ENCODING_H__ |
Daniel Veillard | 891e404 | 1998-10-19 00:43:02 +0000 | [diff] [blame] | 23 | |
| 24 | #ifdef __cplusplus |
| 25 | extern "C" { |
| 26 | #endif |
| 27 | |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 28 | /** |
| 29 | * Predefined values for some standard encodings |
| 30 | */ |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 31 | typedef 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 Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 54 | XML_CHAR_ENCODING_EUC_JP= 21 /* EUC-JP */ |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 55 | } xmlCharEncoding; |
| 56 | |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 57 | /** |
| 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 | */ |
| 69 | typedef 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 | */ |
| 86 | typedef 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 | |
| 93 | typedef struct xmlCharEncodingHandler { |
| 94 | char *name; |
| 95 | xmlCharEncodingInputFunc input; |
| 96 | xmlCharEncodingOutputFunc output; |
| 97 | } xmlCharEncodingHandler; |
| 98 | typedef xmlCharEncodingHandler *xmlCharEncodingHandlerPtr; |
| 99 | |
Daniel Veillard | a819dac | 1999-11-24 18:04:22 +0000 | [diff] [blame] | 100 | void xmlInitCharEncodingHandlers (void); |
| 101 | void xmlCleanupCharEncodingHandlers (void); |
| 102 | void xmlRegisterCharEncodingHandler (xmlCharEncodingHandlerPtr handler); |
| 103 | xmlCharEncoding xmlDetectCharEncoding (const unsigned char* in); |
| 104 | xmlCharEncoding xmlParseCharEncoding (const char* name); |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 105 | xmlCharEncodingHandlerPtr xmlGetCharEncodingHandler(xmlCharEncoding enc); |
| 106 | xmlCharEncodingHandlerPtr xmlFindCharEncodingHandler(const char *name); |
| 107 | |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 108 | |
Daniel Veillard | 891e404 | 1998-10-19 00:43:02 +0000 | [diff] [blame] | 109 | #ifdef __cplusplus |
| 110 | } |
| 111 | #endif |
| 112 | |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 113 | #endif /* __XML_CHAR_ENCODING_H__ */ |