epoc32/include/stdapis/libxml2/libxml2_encoding.h
branchSymbian3
changeset 4 837f303aceeb
equal deleted inserted replaced
3:e1b950c65cb4 4:837f303aceeb
       
     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  * Portion Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. 
       
    21  */
       
    22 
       
    23 /** @file
       
    24 @publishedAll
       
    25 @released
       
    26 */
       
    27 
       
    28 #ifndef XML_CHAR_ENCODING_H
       
    29 #define XML_CHAR_ENCODING_H
       
    30 
       
    31 //#include "libxml/Libxml2_xmlversion.h" // enable this when dependency on tree.h is removed
       
    32 #include "libxml2_tree.h"
       
    33 
       
    34 #ifdef LIBXML_ICONV_ENABLED
       
    35 #include <iconv.h>
       
    36 #endif
       
    37 
       
    38 #ifdef __cplusplus
       
    39 extern "C" {
       
    40 #endif
       
    41 
       
    42 /*
       
    43  * xmlCharEncoding:
       
    44  *
       
    45  * Predefined values for some standard encodings.
       
    46  * Libxml does not do beforehand translation on UTF8 and ISOLatinX.
       
    47  * It also supports ASCII, ISO-8859-1, and UTF16 (LE and BE) by default.
       
    48  *
       
    49  * Anything else would have to be translated to UTF8 before being
       
    50  * given to the parser itself. The BOM for UTF16 and the encoding
       
    51  * declaration are looked at and a converter is looked for at that
       
    52  * point. If not found the parser stops here as asked by the XML REC. A
       
    53  * converter can be registered by the user using xmlRegisterCharEncodingHandler
       
    54  * but the current form doesn't allow stateful transcoding (a serious
       
    55  * problem agreed !). If iconv has been found it will be used
       
    56  * automatically and allow stateful transcoding, the simplest is then
       
    57  * to be sure to enable iconv and to provide iconv libs for the encoding
       
    58  * support needed.
       
    59  *
       
    60  * Note that the generic "UTF-16" is not a predefined value.  Instead, only
       
    61  * the specific UTF-16LE and UTF-16BE are present.
       
    62  */
       
    63 typedef enum {
       
    64     XML_CHAR_ENCODING_ERROR=   -1, /* No char encoding detected */
       
    65     XML_CHAR_ENCODING_NONE=     0, /* No char encoding detected */
       
    66     XML_CHAR_ENCODING_UTF8=     1, /* UTF-8 */
       
    67     XML_CHAR_ENCODING_UTF16LE=  2, /* UTF-16 little endian */
       
    68     XML_CHAR_ENCODING_UTF16BE=  3, /* UTF-16 big endian */
       
    69     XML_CHAR_ENCODING_UCS4LE=   4, /* UCS-4 little endian */
       
    70     XML_CHAR_ENCODING_UCS4BE=   5, /* UCS-4 big endian */
       
    71     XML_CHAR_ENCODING_EBCDIC=   6, /* EBCDIC uh! */
       
    72     XML_CHAR_ENCODING_UCS4_2143=7, /* UCS-4 unusual ordering */
       
    73     XML_CHAR_ENCODING_UCS4_3412=8, /* UCS-4 unusual ordering */
       
    74     XML_CHAR_ENCODING_UCS2=     9, /* UCS-2 */
       
    75     XML_CHAR_ENCODING_8859_1=   10,/* ISO-8859-1 ISO Latin 1 */
       
    76     XML_CHAR_ENCODING_8859_2=   11,/* ISO-8859-2 ISO Latin 2 */
       
    77     XML_CHAR_ENCODING_8859_3=   12,/* ISO-8859-3 */
       
    78     XML_CHAR_ENCODING_8859_4=   13,/* ISO-8859-4 */
       
    79     XML_CHAR_ENCODING_8859_5=   14,/* ISO-8859-5 */
       
    80     XML_CHAR_ENCODING_8859_6=   15,/* ISO-8859-6 */
       
    81     XML_CHAR_ENCODING_8859_7=   16,/* ISO-8859-7 */
       
    82     XML_CHAR_ENCODING_8859_8=   17,/* ISO-8859-8 */
       
    83     XML_CHAR_ENCODING_8859_9=   18,/* ISO-8859-9 */
       
    84     XML_CHAR_ENCODING_2022_JP=  19,/* ISO-2022-JP */
       
    85     XML_CHAR_ENCODING_SHIFT_JIS=20,/* Shift_JIS */
       
    86     XML_CHAR_ENCODING_EUC_JP=   21,/* EUC-JP */
       
    87     XML_CHAR_ENCODING_ASCII=    22 /* pure ASCII */
       
    88 } xmlCharEncoding;
       
    89 
       
    90 /**
       
    91  * xmlCharEncodingInputFunc:
       
    92  * @param out a pointer to an array of bytes to store the UTF-8 result
       
    93  * @param outlen the length of out
       
    94  * @param in a pointer to an array of chars in the original encoding
       
    95  * @param inlen the length of in
       
    96  *
       
    97  * Take a block of chars in the original encoding and try to convert
       
    98  * it to an UTF-8 block of chars out.
       
    99  *
       
   100  * Returns the number of bytes written, -1 if lack of space, or -2
       
   101  *     if the transcoding failed.
       
   102  * The value of inlen after return is the number of octets consumed
       
   103  *     if the return value is positive, else unpredictiable.
       
   104  * The value of outlen after return is the number of octets consumed.
       
   105  */
       
   106 typedef int (* xmlCharEncodingInputFunc)(unsigned char *out, int *outlen,
       
   107                                          const unsigned char *in, int *inlen);
       
   108 
       
   109 
       
   110 /**
       
   111  * xmlCharEncodingOutputFunc:
       
   112  * @param out a pointer to an array of bytes to store the result
       
   113  * @param outlen the length of out
       
   114  * @param in a pointer to an array of UTF-8 chars
       
   115  * @param inlen the length of in
       
   116  *
       
   117  * Take a block of UTF-8 chars in and try to convert it to another
       
   118  * encoding.
       
   119  * Note: a first call designed to produce heading info is called with
       
   120  * in = NULL. If stateful this should also initialize the encoder state.
       
   121  *
       
   122  * Returns the number of bytes written, -1 if lack of space, or -2
       
   123  *     if the transcoding failed.
       
   124  * The value of inlen after return is the number of octets consumed
       
   125  *     if the return value is positive, else unpredictiable.
       
   126  * The value of outlen after return is the number of octets produced.
       
   127  */
       
   128 typedef int (* xmlCharEncodingOutputFunc)(unsigned char *out, int *outlen,
       
   129                                           const unsigned char *in, int *inlen);
       
   130 
       
   131 
       
   132 /*
       
   133  * Block defining the handlers for non UTF-8 encodings.
       
   134  * If iconv is supported, there are two extra fields.
       
   135  */
       
   136 
       
   137 typedef struct _xmlCharEncodingHandler xmlCharEncodingHandler;
       
   138 typedef xmlCharEncodingHandler *xmlCharEncodingHandlerPtr;
       
   139 struct _xmlCharEncodingHandler {
       
   140     char                       *name;
       
   141     xmlCharEncodingInputFunc   input;
       
   142     xmlCharEncodingOutputFunc  output;
       
   143 #ifdef LIBXML_ICONV_ENABLED
       
   144     iconv_t                    iconv_in;
       
   145     iconv_t                    iconv_out;
       
   146 #endif /* LIBXML_ICONV_ENABLED */
       
   147 };
       
   148 
       
   149 //#ifdef __cplusplus
       
   150 //}
       
   151 //#endif
       
   152 //#ifdef __cplusplus
       
   153 //extern "C" {
       
   154 //#endif
       
   155 
       
   156 /*
       
   157  * Interfaces for encoding handlers.
       
   158  */
       
   159 XMLPUBFUN void XMLCALL
       
   160         xmlInitCharEncodingHandlers     (void);
       
   161 XMLPUBFUN void XMLCALL
       
   162         xmlCleanupCharEncodingHandlers  (void);
       
   163 XMLPUBFUN void XMLCALL
       
   164         xmlRegisterCharEncodingHandler  (xmlCharEncodingHandlerPtr handler);
       
   165 XMLPUBFUN xmlCharEncodingHandlerPtr XMLCALL
       
   166         xmlGetCharEncodingHandler       (xmlCharEncoding enc);
       
   167 XMLPUBFUN xmlCharEncodingHandlerPtr XMLCALL
       
   168         xmlFindCharEncodingHandler      (const char *name);
       
   169 XMLPUBFUN xmlCharEncodingHandlerPtr XMLCALL
       
   170         xmlNewCharEncodingHandler       (const char *name,
       
   171                                          xmlCharEncodingInputFunc input,
       
   172                                          xmlCharEncodingOutputFunc output);
       
   173 
       
   174 /*
       
   175  * Interfaces for encoding names and aliases.
       
   176  */
       
   177 #ifndef XMLENGINE_EXCLUDE_UNUSED
       
   178 XMLPUBFUN int XMLCALL xmlAddEncodingAlias(const char *name, const char *alias);
       
   179 XMLPUBFUN int XMLCALL xmlDelEncodingAlias(const char *alias);
       
   180 #endif
       
   181 
       
   182 XMLPUBFUN const char * XMLCALL  xmlGetEncodingAlias                     (const char *alias);
       
   183 XMLPUBFUN void XMLCALL                  xmlCleanupEncodingAliases       (void);
       
   184 XMLPUBFUN xmlCharEncoding XMLCALL       xmlParseCharEncoding    (const char *name);
       
   185 XMLPUBFUN const char * XMLCALL          xmlGetCharEncodingName  (xmlCharEncoding enc);
       
   186 
       
   187 /*
       
   188  * Interfaces directly used by the parsers.
       
   189  */
       
   190 XMLPUBFUN xmlCharEncoding XMLCALL
       
   191         xmlDetectCharEncoding           (const unsigned char *in,
       
   192                                          int len);
       
   193 
       
   194 XMLPUBFUN int XMLCALL
       
   195         xmlCharEncOutFunc               (xmlCharEncodingHandler *handler,
       
   196                                          xmlBufferPtr out,
       
   197                                          xmlBufferPtr in);
       
   198 
       
   199 XMLPUBFUN int XMLCALL
       
   200         xmlCharEncInFunc                (xmlCharEncodingHandler *handler,
       
   201                                          xmlBufferPtr out,
       
   202                                          xmlBufferPtr in);
       
   203 XMLPUBFUN int XMLCALL
       
   204         xmlCharEncFirstLine             (xmlCharEncodingHandler *handler,
       
   205                                          xmlBufferPtr out,
       
   206                                          xmlBufferPtr in);
       
   207 XMLPUBFUN int XMLCALL
       
   208         xmlCharEncCloseFunc             (xmlCharEncodingHandler *handler);
       
   209 
       
   210 /*
       
   211  * Export a few useful functions
       
   212  */
       
   213 XMLPUBFUN int XMLCALL
       
   214         UTF8Toisolat1                   (unsigned char *out,
       
   215                                          int *outlen,
       
   216                                          const unsigned char *in,
       
   217                                          int *inlen);
       
   218 XMLPUBFUN int XMLCALL
       
   219         isolat1ToUTF8                   (unsigned char *out,
       
   220                                          int *outlen,
       
   221                                          const unsigned char *in,
       
   222                                          int *inlen);
       
   223 #ifdef __cplusplus
       
   224 }
       
   225 #endif
       
   226 
       
   227 #endif /* XML_CHAR_ENCODING_H */
       
   228