encoding.h.svn-base
上传用户:szjkjd
上传日期:2022-06-27
资源大小:8968k
文件大小:8k
源码类别:

浏览器

开发平台:

Visual C++

  1. /*
  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.
  5.  *
  6.  * Related specs are
  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.
  16.  *
  17.  * Copy: See Copyright for the status of this software.
  18.  *
  19.  * Author: Daniel Veillard
  20.  */
  21. #ifndef __XML_CHAR_ENCODING_H__
  22. #define __XML_CHAR_ENCODING_H__
  23. #include <libxml/xmlversion.h>
  24. #ifdef LIBXML_ICONV_ENABLED
  25. #include "iconv.h"
  26. #endif
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. /*
  31.  * xmlCharEncoding:
  32.  *
  33.  * Predefined values for some standard encodings.
  34.  * Libxml does not do beforehand translation on UTF8 and ISOLatinX.
  35.  * It also supports ASCII, ISO-8859-1, and UTF16 (LE and BE) by default.
  36.  *
  37.  * Anything else would have to be translated to UTF8 before being
  38.  * given to the parser itself. The BOM for UTF16 and the encoding
  39.  * declaration are looked at and a converter is looked for at that
  40.  * point. If not found the parser stops here as asked by the XML REC. A
  41.  * converter can be registered by the user using xmlRegisterCharEncodingHandler
  42.  * but the current form doesn't allow stateful transcoding (a serious
  43.  * problem agreed !). If iconv has been found it will be used
  44.  * automatically and allow stateful transcoding, the simplest is then
  45.  * to be sure to enable iconv and to provide iconv libs for the encoding
  46.  * support needed.
  47.  *
  48.  * Note that the generic "UTF-16" is not a predefined value.  Instead, only
  49.  * the specific UTF-16LE and UTF-16BE are present.
  50.  */
  51. typedef enum {
  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 */
  76. } xmlCharEncoding;
  77. /**
  78.  * xmlCharEncodingInputFunc:
  79.  * @out:  a pointer to an array of bytes to store the UTF-8 result
  80.  * @outlen:  the length of @out
  81.  * @in:  a pointer to an array of chars in the original encoding
  82.  * @inlen:  the length of @in
  83.  *
  84.  * Take a block of chars in the original encoding and try to convert
  85.  * it to an UTF-8 block of chars out.
  86.  *
  87.  * Returns the number of bytes written, -1 if lack of space, or -2
  88.  *     if the transcoding failed.
  89.  * The value of @inlen after return is the number of octets consumed
  90.  *     if the return value is positive, else unpredictiable.
  91.  * The value of @outlen after return is the number of octets consumed.
  92.  */
  93. typedef int (* xmlCharEncodingInputFunc)(unsigned char *out, int *outlen,
  94.                                          const unsigned char *in, int *inlen);
  95. /**
  96.  * xmlCharEncodingOutputFunc:
  97.  * @out:  a pointer to an array of bytes to store the result
  98.  * @outlen:  the length of @out
  99.  * @in:  a pointer to an array of UTF-8 chars
  100.  * @inlen:  the length of @in
  101.  *
  102.  * Take a block of UTF-8 chars in and try to convert it to another
  103.  * encoding.
  104.  * Note: a first call designed to produce heading info is called with
  105.  * in = NULL. If stateful this should also initialize the encoder state.
  106.  *
  107.  * Returns the number of bytes written, -1 if lack of space, or -2
  108.  *     if the transcoding failed.
  109.  * The value of @inlen after return is the number of octets consumed
  110.  *     if the return value is positive, else unpredictiable.
  111.  * The value of @outlen after return is the number of octets produced.
  112.  */
  113. typedef int (* xmlCharEncodingOutputFunc)(unsigned char *out, int *outlen,
  114.                                           const unsigned char *in, int *inlen);
  115. /*
  116.  * Block defining the handlers for non UTF-8 encodings.
  117.  * If iconv is supported, there are two extra fields.
  118.  */
  119. typedef struct _xmlCharEncodingHandler xmlCharEncodingHandler;
  120. typedef xmlCharEncodingHandler *xmlCharEncodingHandlerPtr;
  121. struct _xmlCharEncodingHandler {
  122.     char                       *name;
  123.     xmlCharEncodingInputFunc   input;
  124.     xmlCharEncodingOutputFunc  output;
  125. #ifdef LIBXML_ICONV_ENABLED
  126.     iconv_t                    iconv_in;
  127.     iconv_t                    iconv_out;
  128. #endif /* LIBXML_ICONV_ENABLED */
  129. };
  130. #ifdef __cplusplus
  131. }
  132. #endif
  133. #include <libxml/tree.h>
  134. #ifdef __cplusplus
  135. extern "C" {
  136. #endif
  137. /*
  138.  * Interfaces for encoding handlers.
  139.  */
  140. XMLPUBFUN void XMLCALL
  141. xmlInitCharEncodingHandlers (void);
  142. XMLPUBFUN void XMLCALL
  143. xmlCleanupCharEncodingHandlers (void);
  144. XMLPUBFUN void XMLCALL
  145. xmlRegisterCharEncodingHandler (xmlCharEncodingHandlerPtr handler);
  146. XMLPUBFUN xmlCharEncodingHandlerPtr XMLCALL
  147. xmlGetCharEncodingHandler (xmlCharEncoding enc);
  148. XMLPUBFUN xmlCharEncodingHandlerPtr XMLCALL
  149. xmlFindCharEncodingHandler (const char *name);
  150. XMLPUBFUN xmlCharEncodingHandlerPtr XMLCALL
  151. xmlNewCharEncodingHandler (const char *name, 
  152.                             xmlCharEncodingInputFunc input,
  153.                             xmlCharEncodingOutputFunc output);
  154. /*
  155.  * Interfaces for encoding names and aliases.
  156.  */
  157. XMLPUBFUN int XMLCALL
  158. xmlAddEncodingAlias (const char *name,
  159.  const char *alias);
  160. XMLPUBFUN int XMLCALL
  161. xmlDelEncodingAlias (const char *alias);
  162. XMLPUBFUN const char * XMLCALL
  163. xmlGetEncodingAlias (const char *alias);
  164. XMLPUBFUN void XMLCALL
  165. xmlCleanupEncodingAliases (void);
  166. XMLPUBFUN xmlCharEncoding XMLCALL
  167. xmlParseCharEncoding (const char *name);
  168. XMLPUBFUN const char * XMLCALL
  169. xmlGetCharEncodingName (xmlCharEncoding enc);
  170. /*
  171.  * Interfaces directly used by the parsers.
  172.  */
  173. XMLPUBFUN xmlCharEncoding XMLCALL
  174. xmlDetectCharEncoding (const unsigned char *in,
  175.  int len);
  176. XMLPUBFUN int XMLCALL
  177. xmlCharEncOutFunc (xmlCharEncodingHandler *handler,
  178.  xmlBufferPtr out,
  179.  xmlBufferPtr in);
  180. XMLPUBFUN int XMLCALL
  181. xmlCharEncInFunc (xmlCharEncodingHandler *handler,
  182.  xmlBufferPtr out,
  183.  xmlBufferPtr in);
  184. XMLPUBFUN int XMLCALL
  185. xmlCharEncFirstLine (xmlCharEncodingHandler *handler,
  186.  xmlBufferPtr out,
  187.  xmlBufferPtr in);
  188. XMLPUBFUN int XMLCALL
  189. xmlCharEncCloseFunc (xmlCharEncodingHandler *handler);
  190. /*
  191.  * Export a few useful functions
  192.  */
  193. #ifdef LIBXML_OUTPUT_ENABLED
  194. XMLPUBFUN int XMLCALL
  195. UTF8Toisolat1 (unsigned char *out,
  196.  int *outlen,
  197.  const unsigned char *in,
  198.  int *inlen);
  199. #endif /* LIBXML_OUTPUT_ENABLED */
  200. XMLPUBFUN int XMLCALL
  201. isolat1ToUTF8 (unsigned char *out,
  202.  int *outlen,
  203.  const unsigned char *in,
  204.  int *inlen);
  205. #ifdef __cplusplus
  206. }
  207. #endif
  208. #endif /* __XML_CHAR_ENCODING_H__ */