encoding.inc 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. {$IFDEF POINTER}
  22. xmlCharEncodingHandlerPtr = ^xmlCharEncodingHandler;
  23. {$ENDIF}
  24. (*
  25. * xmlCharEncoding:
  26. *
  27. * Predefined values for some standard encodings.
  28. * Libxml does not do beforehand translation on UTF8 and ISOLatinX.
  29. * It also supports ASCII, ISO-8859-1, and UTF16 (LE and BE) by default.
  30. *
  31. * Anything else would have to be translated to UTF8 before being
  32. * given to the parser itself. The BOM for UTF16 and the encoding
  33. * declaration are looked at and a converter is looked for at that
  34. * point. If not found the parser stops here as asked by the XML REC. A
  35. * converter can be registered by the user using xmlRegisterCharEncodingHandler
  36. * but the current form doesn't allow stateful transcoding (a serious
  37. * problem agreed !). If iconv has been found it will be used
  38. * automatically and allow stateful transcoding, the simplest is then
  39. * to be sure to enable iconv and to provide iconv libs for the encoding
  40. * support needed.
  41. *
  42. * Note that the generic "UTF-16" is not a predefined value. Instead, only
  43. * the specific UTF-16LE and UTF-16BE are present.
  44. *)
  45. {$IFDEF TYPE}
  46. xmlCharEncoding = (
  47. XML_CHAR_ENCODING_ERROR= -1, (* No char encoding detected *)
  48. XML_CHAR_ENCODING_NONE= 0, (* No char encoding detected *)
  49. XML_CHAR_ENCODING_UTF8= 1, (* UTF-8 *)
  50. XML_CHAR_ENCODING_UTF16LE= 2, (* UTF-16 little endian *)
  51. XML_CHAR_ENCODING_UTF16BE= 3, (* UTF-16 big endian *)
  52. XML_CHAR_ENCODING_UCS4LE= 4, (* UCS-4 little endian *)
  53. XML_CHAR_ENCODING_UCS4BE= 5, (* UCS-4 big endian *)
  54. XML_CHAR_ENCODING_EBCDIC= 6, (* EBCDIC uh! *)
  55. XML_CHAR_ENCODING_UCS4_2143=7, (* UCS-4 unusual ordering *)
  56. XML_CHAR_ENCODING_UCS4_3412=8, (* UCS-4 unusual ordering *)
  57. XML_CHAR_ENCODING_UCS2= 9, (* UCS-2 *)
  58. XML_CHAR_ENCODING_8859_1= 10,(* ISO-8859-1 ISO Latin 1 *)
  59. XML_CHAR_ENCODING_8859_2= 11,(* ISO-8859-2 ISO Latin 2 *)
  60. XML_CHAR_ENCODING_8859_3= 12,(* ISO-8859-3 *)
  61. XML_CHAR_ENCODING_8859_4= 13,(* ISO-8859-4 *)
  62. XML_CHAR_ENCODING_8859_5= 14,(* ISO-8859-5 *)
  63. XML_CHAR_ENCODING_8859_6= 15,(* ISO-8859-6 *)
  64. XML_CHAR_ENCODING_8859_7= 16,(* ISO-8859-7 *)
  65. XML_CHAR_ENCODING_8859_8= 17,(* ISO-8859-8 *)
  66. XML_CHAR_ENCODING_8859_9= 18,(* ISO-8859-9 *)
  67. XML_CHAR_ENCODING_2022_JP= 19,(* ISO-2022-JP *)
  68. XML_CHAR_ENCODING_SHIFT_JIS=20,(* Shift_JIS *)
  69. XML_CHAR_ENCODING_EUC_JP= 21,(* EUC-JP *)
  70. XML_CHAR_ENCODING_ASCII= 22 (* pure ASCII *)
  71. );
  72. (**
  73. * xmlCharEncodingInputFunc:
  74. * @out: a pointer to an array of bytes to store the UTF-8 result
  75. * @outlen: the length of @out
  76. * @in: a pointer to an array of chars in the original encoding
  77. * @inlen: the length of @in
  78. *
  79. * Take a block of chars in the original encoding and try to convert
  80. * it to an UTF-8 block of chars out.
  81. *
  82. * Returns the number of bytes written, -1 if lack of space, or -2
  83. * if the transcoding failed.
  84. * The value of @inlen after return is the number of octets consumed
  85. * if the return value is positive, else unpredictiable.
  86. * The value of @outlen after return is the number of octets consumed.
  87. *)
  88. xmlCharEncodingInputFunc = function(_out: pchar; outlen: pcint; _in: pchar; inlen: pcint): cint; cdecl;
  89. (**
  90. * xmlCharEncodingOutputFunc:
  91. * @out: a pointer to an array of bytes to store the result
  92. * @outlen: the length of @out
  93. * @in: a pointer to an array of UTF-8 chars
  94. * @inlen: the length of @in
  95. *
  96. * Take a block of UTF-8 chars in and try to convert it to another
  97. * encoding.
  98. * Note: a first call designed to produce heading info is called with
  99. * in = NULL. If stateful this should also initialize the encoder state.
  100. *
  101. * Returns the number of bytes written, -1 if lack of space, or -2
  102. * if the transcoding failed.
  103. * The value of @inlen after return is the number of octets consumed
  104. * if the return value is positive, else unpredictiable.
  105. * The value of @outlen after return is the number of octets produced.
  106. *)
  107. xmlCharEncodingOutputFunc = function(_out: pchar; outlen: pcint; _in: pchar; inlen: pcint): cint; cdecl;
  108. (*
  109. * Block defining the handlers for non UTF-8 encodings.
  110. * If iconv is supported, there are two extra fields.
  111. *)
  112. xmlCharEncodingHandler = record
  113. name : pchar;
  114. input : xmlCharEncodingInputFunc;
  115. output : xmlCharEncodingOutputFunc;
  116. {$IFDEF LIBXML_ICONV_ENABLED}
  117. iconv_in : iconv_t;
  118. iconv_out : iconv_t;
  119. {$ENDIF} (* LIBXML_ICONV_ENABLED *)
  120. end;
  121. {$ENDIF}
  122. {$IFDEF FUNCTION}
  123. (*
  124. * Interfaces for encoding handlers.
  125. *)
  126. procedure xmlInitCharEncodingHandlers; EXTDECL; external xml2lib;
  127. procedure xmlCleanupCharEncodingHandlers; EXTDECL; external xml2lib;
  128. procedure xmlRegisterCharEncodingHandler(handler: xmlCharEncodingHandlerPtr); EXTDECL; external xml2lib;
  129. function xmlGetCharEncodingHandler(enc: xmlCharEncoding): xmlCharEncodingHandlerPtr; EXTDECL; external xml2lib;
  130. function xmlFindCharEncodingHandler(name: pchar): xmlCharEncodingHandlerPtr; EXTDECL; external xml2lib;
  131. function xmlNewCharEncodingHandler(name: pchar; input: xmlCharEncodingInputFunc; output: xmlCharEncodingOutputFunc): xmlCharEncodingHandlerPtr; EXTDECL; external xml2lib;
  132. (*
  133. * Interfaces for encoding names and aliases.
  134. *)
  135. function xmlAddEncodingAlias(name: pchar; alias: pchar): cint; EXTDECL; external xml2lib;
  136. function xmlDelEncodingAlias(alias: pchar): cint; EXTDECL; external xml2lib;
  137. function xmlGetEncodingAlias(alias: pchar): pchar; EXTDECL; external xml2lib;
  138. procedure xmlCleanupEncodingAliases; EXTDECL; external xml2lib;
  139. function xmlParseCharEncoding(name: pchar): xmlCharEncoding; EXTDECL; external xml2lib;
  140. function xmlGetCharEncodingName(enc: xmlCharEncoding): pchar; EXTDECL; external xml2lib;
  141. (*
  142. * Interfaces directly used by the parsers.
  143. *)
  144. function xmlDetectCharEncoding(_in: pchar; len: cint): xmlCharEncoding; EXTDECL; external xml2lib;
  145. function xmlCharEncOutFunc(handler: xmlCharEncodingHandlerPtr; _out, _in: xmlBufferPtr): cint; EXTDECL; external xml2lib;
  146. function xmlCharEncInFunc(handler: xmlCharEncodingHandlerPtr; _out, _in: xmlBufferPtr): cint; EXTDECL; external xml2lib;
  147. function xmlCharEncFirstLine(handler: xmlCharEncodingHandlerPtr; _out, _in: xmlBufferPtr): cint; EXTDECL; external xml2lib;
  148. function xmlCharEncCloseFunc(handler: xmlCharEncodingHandlerPtr): cint; EXTDECL; external xml2lib;
  149. (*
  150. * Export a few useful functions
  151. *)
  152. {$IFDEF LIBXML_OUTPUT_ENABLED}
  153. function UTF8Toisolat1(_out: pchar; outlen: pcint; _in: pchar; inlen: pcint): cint; EXTDECL; external xml2lib;
  154. {$ENDIF} (* LIBXML_OUTPUT_ENABLED *)
  155. function isolat1ToUTF8(_out: pchar; outlen: pcint; _in: pchar; inlen: pcint): cint; EXTDECL; external xml2lib;
  156. {$ENDIF}