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 | |
Daniel Veillard | 361d845 | 2000-04-03 19:48:13 +0000 | [diff] [blame^] | 24 | #include <libxml/xmlversion.h> |
Daniel Veillard | 891e404 | 1998-10-19 00:43:02 +0000 | [diff] [blame] | 25 | #ifdef __cplusplus |
| 26 | extern "C" { |
| 27 | #endif |
| 28 | |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 29 | /** |
| 30 | * Predefined values for some standard encodings |
| 31 | */ |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 32 | typedef enum { |
| 33 | XML_CHAR_ENCODING_ERROR= -1, /* No char encoding detected */ |
| 34 | XML_CHAR_ENCODING_NONE= 0, /* No char encoding detected */ |
| 35 | XML_CHAR_ENCODING_UTF8= 1, /* UTF-8 */ |
| 36 | XML_CHAR_ENCODING_UTF16LE= 2, /* UTF-16 little endian */ |
| 37 | XML_CHAR_ENCODING_UTF16BE= 3, /* UTF-16 big endian */ |
| 38 | XML_CHAR_ENCODING_UCS4LE= 4, /* UCS-4 little endian */ |
| 39 | XML_CHAR_ENCODING_UCS4BE= 5, /* UCS-4 big endian */ |
| 40 | XML_CHAR_ENCODING_EBCDIC= 6, /* EBCDIC uh! */ |
| 41 | XML_CHAR_ENCODING_UCS4_2143=7, /* UCS-4 unusual ordering */ |
| 42 | XML_CHAR_ENCODING_UCS4_3412=8, /* UCS-4 unusual ordering */ |
| 43 | XML_CHAR_ENCODING_UCS2= 9, /* UCS-2 */ |
| 44 | XML_CHAR_ENCODING_8859_1= 10,/* ISO-8859-1 ISO Latin 1 */ |
| 45 | XML_CHAR_ENCODING_8859_2= 11,/* ISO-8859-2 ISO Latin 2 */ |
| 46 | XML_CHAR_ENCODING_8859_3= 12,/* ISO-8859-3 */ |
| 47 | XML_CHAR_ENCODING_8859_4= 13,/* ISO-8859-4 */ |
| 48 | XML_CHAR_ENCODING_8859_5= 14,/* ISO-8859-5 */ |
| 49 | XML_CHAR_ENCODING_8859_6= 15,/* ISO-8859-6 */ |
| 50 | XML_CHAR_ENCODING_8859_7= 16,/* ISO-8859-7 */ |
| 51 | XML_CHAR_ENCODING_8859_8= 17,/* ISO-8859-8 */ |
| 52 | XML_CHAR_ENCODING_8859_9= 18,/* ISO-8859-9 */ |
| 53 | XML_CHAR_ENCODING_2022_JP= 19,/* ISO-2022-JP */ |
| 54 | XML_CHAR_ENCODING_SHIFT_JIS=20,/* Shift_JIS */ |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 55 | XML_CHAR_ENCODING_EUC_JP= 21 /* EUC-JP */ |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 56 | } xmlCharEncoding; |
| 57 | |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 58 | /** |
| 59 | * xmlCharEncodingInputFunc: |
| 60 | * @out: a pointer ot an array of bytes to store the UTF-8 result |
| 61 | * @outlen: the lenght of @out |
| 62 | * @in: a pointer ot an array of chars in the original encoding |
| 63 | * @inlen: the lenght of @in |
| 64 | * |
| 65 | * Take a block of chars in the original encoding and try to convert |
| 66 | * it to an UTF-8 block of chars out. |
| 67 | * |
| 68 | * Returns the number of byte written, or -1 by lack of space. |
| 69 | */ |
| 70 | typedef int (* xmlCharEncodingInputFunc)(unsigned char* out, int outlen, |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 71 | const unsigned char* in, int *inlen); |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 72 | |
| 73 | |
| 74 | /** |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 75 | * xmlCharEncodingOutputFunc: |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 76 | * @out: a pointer ot an array of bytes to store the result |
| 77 | * @outlen: the lenght of @out |
| 78 | * @in: a pointer ot an array of UTF-8 chars |
| 79 | * @inlen: the lenght of @in |
| 80 | * |
| 81 | * Take a block of UTF-8 chars in and try to convert it to an other |
| 82 | * encoding. |
| 83 | * |
| 84 | * Returns the number of byte written, or -1 by lack of space, or -2 |
| 85 | * if the transcoding failed. |
| 86 | */ |
| 87 | typedef int (* xmlCharEncodingOutputFunc)(unsigned char* out, int outlen, |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 88 | const unsigned char* in, int *inlen); |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 89 | |
| 90 | /* |
| 91 | * Block defining the handlers for non UTF-8 encodings. |
| 92 | */ |
| 93 | |
Daniel Veillard | 71b656e | 2000-01-05 14:46:17 +0000 | [diff] [blame] | 94 | typedef struct _xmlCharEncodingHandler xmlCharEncodingHandler; |
| 95 | typedef xmlCharEncodingHandler *xmlCharEncodingHandlerPtr; |
| 96 | struct _xmlCharEncodingHandler { |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 97 | char *name; |
| 98 | xmlCharEncodingInputFunc input; |
| 99 | xmlCharEncodingOutputFunc output; |
Daniel Veillard | 71b656e | 2000-01-05 14:46:17 +0000 | [diff] [blame] | 100 | }; |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 101 | |
Daniel Veillard | a819dac | 1999-11-24 18:04:22 +0000 | [diff] [blame] | 102 | void xmlInitCharEncodingHandlers (void); |
| 103 | void xmlCleanupCharEncodingHandlers (void); |
| 104 | void xmlRegisterCharEncodingHandler (xmlCharEncodingHandlerPtr handler); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 105 | xmlCharEncoding xmlDetectCharEncoding (const unsigned char* in, |
| 106 | int len); |
Daniel Veillard | a819dac | 1999-11-24 18:04:22 +0000 | [diff] [blame] | 107 | xmlCharEncoding xmlParseCharEncoding (const char* name); |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 108 | xmlCharEncodingHandlerPtr xmlGetCharEncodingHandler(xmlCharEncoding enc); |
| 109 | xmlCharEncodingHandlerPtr xmlFindCharEncodingHandler(const char *name); |
Daniel Veillard | cf46199 | 2000-03-14 18:30:20 +0000 | [diff] [blame] | 110 | int xmlCheckUTF8 (const unsigned char *utf); |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 111 | |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 112 | |
Daniel Veillard | 891e404 | 1998-10-19 00:43:02 +0000 | [diff] [blame] | 113 | #ifdef __cplusplus |
| 114 | } |
| 115 | #endif |
| 116 | |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 117 | #endif /* __XML_CHAR_ENCODING_H__ */ |