Home | History | Annotate | Download | only in unicode
      1 /*
      2 **********************************************************************
      3 *   Copyright (C) 1999-2011, International Business Machines
      4 *   Corporation and others.  All Rights Reserved.
      5 **********************************************************************
      6  *  ucnv.h:
      7  *  External APIs for the ICU's codeset conversion library
      8  *  Bertrand A. Damiba
      9  *
     10  * Modification History:
     11  *
     12  *   Date        Name        Description
     13  *   04/04/99    helena      Fixed internal header inclusion.
     14  *   05/11/00    helena      Added setFallback and usesFallback APIs.
     15  *   06/29/2000  helena      Major rewrite of the callback APIs.
     16  *   12/07/2000  srl         Update of documentation
     17  */
     18 
     19 /**
     20  * \file
     21  * \brief C API: Character conversion
     22  *
     23  * <h2>Character Conversion C API</h2>
     24  *
     25  * <p>This API is used to convert codepage or character encoded data to and
     26  * from UTF-16. You can open a converter with {@link ucnv_open() }. With that
     27  * converter, you can get its properties, set options, convert your data and
     28  * close the converter.</p>
     29  *
     30  * <p>Since many software programs recogize different converter names for
     31  * different types of converters, there are other functions in this API to
     32  * iterate over the converter aliases. The functions {@link ucnv_getAvailableName() },
     33  * {@link ucnv_getAlias() } and {@link ucnv_getStandardName() } are some of the
     34  * more frequently used alias functions to get this information.</p>
     35  *
     36  * <p>When a converter encounters an illegal, irregular, invalid or unmappable character
     37  * its default behavior is to use a substitution character to replace the
     38  * bad byte sequence. This behavior can be changed by using {@link ucnv_setFromUCallBack() }
     39  * or {@link ucnv_setToUCallBack() } on the converter. The header ucnv_err.h defines
     40  * many other callback actions that can be used instead of a character substitution.</p>
     41  *
     42  * <p>More information about this API can be found in our
     43  * <a href="http://icu-project.org/userguide/conversion.html">User's
     44  * Guide</a>.</p>
     45  */
     46 
     47 #ifndef UCNV_H
     48 #define UCNV_H
     49 
     50 #include "unicode/ucnv_err.h"
     51 #include "unicode/uenum.h"
     52 #include "unicode/localpointer.h"
     53 
     54 #ifndef __USET_H__
     55 
     56 /**
     57  * USet is the C API type for Unicode sets.
     58  * It is forward-declared here to avoid including the header file if related
     59  * conversion APIs are not used.
     60  * See unicode/uset.h
     61  *
     62  * @see ucnv_getUnicodeSet
     63  * @stable ICU 2.6
     64  */
     65 struct USet;
     66 /** @stable ICU 2.6 */
     67 typedef struct USet USet;
     68 
     69 #endif
     70 
     71 #if !UCONFIG_NO_CONVERSION
     72 
     73 U_CDECL_BEGIN
     74 
     75 /** Maximum length of a converter name including the terminating NULL @stable ICU 2.0 */
     76 #define UCNV_MAX_CONVERTER_NAME_LENGTH 60
     77 /** Maximum length of a converter name including path and terminating NULL @stable ICU 2.0 */
     78 #define UCNV_MAX_FULL_FILE_NAME_LENGTH (600+UCNV_MAX_CONVERTER_NAME_LENGTH)
     79 
     80 /** Shift in for EBDCDIC_STATEFUL and iso2022 states @stable ICU 2.0 */
     81 #define  UCNV_SI 0x0F
     82 /** Shift out for EBDCDIC_STATEFUL and iso2022 states @stable ICU 2.0 */
     83 #define  UCNV_SO 0x0E
     84 
     85 /**
     86  * Enum for specifying basic types of converters
     87  * @see ucnv_getType
     88  * @stable ICU 2.0
     89  */
     90 typedef enum {
     91     /** @stable ICU 2.0 */
     92     UCNV_UNSUPPORTED_CONVERTER = -1,
     93     /** @stable ICU 2.0 */
     94     UCNV_SBCS = 0,
     95     /** @stable ICU 2.0 */
     96     UCNV_DBCS = 1,
     97     /** @stable ICU 2.0 */
     98     UCNV_MBCS = 2,
     99     /** @stable ICU 2.0 */
    100     UCNV_LATIN_1 = 3,
    101     /** @stable ICU 2.0 */
    102     UCNV_UTF8 = 4,
    103     /** @stable ICU 2.0 */
    104     UCNV_UTF16_BigEndian = 5,
    105     /** @stable ICU 2.0 */
    106     UCNV_UTF16_LittleEndian = 6,
    107     /** @stable ICU 2.0 */
    108     UCNV_UTF32_BigEndian = 7,
    109     /** @stable ICU 2.0 */
    110     UCNV_UTF32_LittleEndian = 8,
    111     /** @stable ICU 2.0 */
    112     UCNV_EBCDIC_STATEFUL = 9,
    113     /** @stable ICU 2.0 */
    114     UCNV_ISO_2022 = 10,
    115 
    116     /** @stable ICU 2.0 */
    117     UCNV_LMBCS_1 = 11,
    118     /** @stable ICU 2.0 */
    119     UCNV_LMBCS_2,
    120     /** @stable ICU 2.0 */
    121     UCNV_LMBCS_3,
    122     /** @stable ICU 2.0 */
    123     UCNV_LMBCS_4,
    124     /** @stable ICU 2.0 */
    125     UCNV_LMBCS_5,
    126     /** @stable ICU 2.0 */
    127     UCNV_LMBCS_6,
    128     /** @stable ICU 2.0 */
    129     UCNV_LMBCS_8,
    130     /** @stable ICU 2.0 */
    131     UCNV_LMBCS_11,
    132     /** @stable ICU 2.0 */
    133     UCNV_LMBCS_16,
    134     /** @stable ICU 2.0 */
    135     UCNV_LMBCS_17,
    136     /** @stable ICU 2.0 */
    137     UCNV_LMBCS_18,
    138     /** @stable ICU 2.0 */
    139     UCNV_LMBCS_19,
    140     /** @stable ICU 2.0 */
    141     UCNV_LMBCS_LAST = UCNV_LMBCS_19,
    142     /** @stable ICU 2.0 */
    143     UCNV_HZ,
    144     /** @stable ICU 2.0 */
    145     UCNV_SCSU,
    146     /** @stable ICU 2.0 */
    147     UCNV_ISCII,
    148     /** @stable ICU 2.0 */
    149     UCNV_US_ASCII,
    150     /** @stable ICU 2.0 */
    151     UCNV_UTF7,
    152     /** @stable ICU 2.2 */
    153     UCNV_BOCU1,
    154     /** @stable ICU 2.2 */
    155     UCNV_UTF16,
    156     /** @stable ICU 2.2 */
    157     UCNV_UTF32,
    158     /** @stable ICU 2.2 */
    159     UCNV_CESU8,
    160     /** @stable ICU 2.4 */
    161     UCNV_IMAP_MAILBOX,
    162     /** @draft ICU 4.8 */
    163     UCNV_COMPOUND_TEXT,
    164 
    165     /* Number of converter types for which we have conversion routines. */
    166     UCNV_NUMBER_OF_SUPPORTED_CONVERTER_TYPES
    167 } UConverterType;
    168 
    169 /**
    170  * Enum for specifying which platform a converter ID refers to.
    171  * The use of platform/CCSID is not recommended. See ucnv_openCCSID().
    172  *
    173  * @see ucnv_getPlatform
    174  * @see ucnv_openCCSID
    175  * @see ucnv_getCCSID
    176  * @stable ICU 2.0
    177  */
    178 typedef enum {
    179     UCNV_UNKNOWN = -1,
    180     UCNV_IBM = 0
    181 } UConverterPlatform;
    182 
    183 /**
    184  * Function pointer for error callback in the codepage to unicode direction.
    185  * Called when an error has occured in conversion to unicode, or on open/close of the callback (see reason).
    186  * @param context Pointer to the callback's private data
    187  * @param args Information about the conversion in progress
    188  * @param codeUnits Points to 'length' bytes of the concerned codepage sequence
    189  * @param length Size (in bytes) of the concerned codepage sequence
    190  * @param reason Defines the reason the callback was invoked
    191  * @param pErrorCode    ICU error code in/out parameter.
    192  *                      For converter callback functions, set to a conversion error
    193  *                      before the call, and the callback may reset it to U_ZERO_ERROR.
    194  * @see ucnv_setToUCallBack
    195  * @see UConverterToUnicodeArgs
    196  * @stable ICU 2.0
    197  */
    198 typedef void (U_EXPORT2 *UConverterToUCallback) (
    199                   const void* context,
    200                   UConverterToUnicodeArgs *args,
    201                   const char *codeUnits,
    202                   int32_t length,
    203                   UConverterCallbackReason reason,
    204                   UErrorCode *pErrorCode);
    205 
    206 /**
    207  * Function pointer for error callback in the unicode to codepage direction.
    208  * Called when an error has occured in conversion from unicode, or on open/close of the callback (see reason).
    209  * @param context Pointer to the callback's private data
    210  * @param args Information about the conversion in progress
    211  * @param codeUnits Points to 'length' UChars of the concerned Unicode sequence
    212  * @param length Size (in bytes) of the concerned codepage sequence
    213  * @param codePoint Single UChar32 (UTF-32) containing the concerend Unicode codepoint.
    214  * @param reason Defines the reason the callback was invoked
    215  * @param pErrorCode    ICU error code in/out parameter.
    216  *                      For converter callback functions, set to a conversion error
    217  *                      before the call, and the callback may reset it to U_ZERO_ERROR.
    218  * @see ucnv_setFromUCallBack
    219  * @stable ICU 2.0
    220  */
    221 typedef void (U_EXPORT2 *UConverterFromUCallback) (
    222                     const void* context,
    223                     UConverterFromUnicodeArgs *args,
    224                     const UChar* codeUnits,
    225                     int32_t length,
    226                     UChar32 codePoint,
    227                     UConverterCallbackReason reason,
    228                     UErrorCode *pErrorCode);
    229 
    230 U_CDECL_END
    231 
    232 /**
    233  * Character that separates converter names from options and options from each other.
    234  * @see ucnv_open
    235  * @stable ICU 2.0
    236  */
    237 #define UCNV_OPTION_SEP_CHAR ','
    238 
    239 /**
    240  * String version of UCNV_OPTION_SEP_CHAR.
    241  * @see ucnv_open
    242  * @stable ICU 2.0
    243  */
    244 #define UCNV_OPTION_SEP_STRING ","
    245 
    246 /**
    247  * Character that separates a converter option from its value.
    248  * @see ucnv_open
    249  * @stable ICU 2.0
    250  */
    251 #define UCNV_VALUE_SEP_CHAR '='
    252 
    253 /**
    254  * String version of UCNV_VALUE_SEP_CHAR.
    255  * @see ucnv_open
    256  * @stable ICU 2.0
    257  */
    258 #define UCNV_VALUE_SEP_STRING "="
    259 
    260 /**
    261  * Converter option for specifying a locale.
    262  * For example, ucnv_open("SCSU,locale=ja", &errorCode);
    263  * See convrtrs.txt.
    264  *
    265  * @see ucnv_open
    266  * @stable ICU 2.0
    267  */
    268 #define UCNV_LOCALE_OPTION_STRING ",locale="
    269 
    270 /**
    271  * Converter option for specifying a version selector (0..9) for some converters.
    272  * For example,
    273  * \code
    274  *   ucnv_open("UTF-7,version=1", &errorCode);
    275  * \endcode
    276  * See convrtrs.txt.
    277  *
    278  * @see ucnv_open
    279  * @stable ICU 2.4
    280  */
    281 #define UCNV_VERSION_OPTION_STRING ",version="
    282 
    283 /**
    284  * Converter option for EBCDIC SBCS or mixed-SBCS/DBCS (stateful) codepages.
    285  * Swaps Unicode mappings for EBCDIC LF and NL codes, as used on
    286  * S/390 (z/OS) Unix System Services (Open Edition).
    287  * For example, ucnv_open("ibm-1047,swaplfnl", &errorCode);
    288  * See convrtrs.txt.
    289  *
    290  * @see ucnv_open
    291  * @stable ICU 2.4
    292  */
    293 #define UCNV_SWAP_LFNL_OPTION_STRING ",swaplfnl"
    294 
    295 /**
    296  * Do a fuzzy compare of two converter/alias names.
    297  * The comparison is case-insensitive, ignores leading zeroes if they are not
    298  * followed by further digits, and ignores all but letters and digits.
    299  * Thus the strings "UTF-8", "utf_8", "u*T@f08" and "Utf 8" are exactly equivalent.
    300  * See section 1.4, Charset Alias Matching in Unicode Technical Standard #22
    301  * at http://www.unicode.org/reports/tr22/
    302  *
    303  * @param name1 a converter name or alias, zero-terminated
    304  * @param name2 a converter name or alias, zero-terminated
    305  * @return 0 if the names match, or a negative value if the name1
    306  * lexically precedes name2, or a positive value if the name1
    307  * lexically follows name2.
    308  * @stable ICU 2.0
    309  */
    310 U_STABLE int U_EXPORT2
    311 ucnv_compareNames(const char *name1, const char *name2);
    312 
    313 
    314 /**
    315  * Creates a UConverter object with the name of a coded character set specified as a C string.
    316  * The actual name will be resolved with the alias file
    317  * using a case-insensitive string comparison that ignores
    318  * leading zeroes and all non-alphanumeric characters.
    319  * E.g., the names "UTF8", "utf-8", "u*T@f08" and "Utf 8" are all equivalent.
    320  * (See also ucnv_compareNames().)
    321  * If <code>NULL</code> is passed for the converter name, it will create one with the
    322  * getDefaultName return value.
    323  *
    324  * <p>A converter name for ICU 1.5 and above may contain options
    325  * like a locale specification to control the specific behavior of
    326  * the newly instantiated converter.
    327  * The meaning of the options depends on the particular converter.
    328  * If an option is not defined for or recognized by a given converter, then it is ignored.</p>
    329  *
    330  * <p>Options are appended to the converter name string, with a
    331  * <code>UCNV_OPTION_SEP_CHAR</code> between the name and the first option and
    332  * also between adjacent options.</p>
    333  *
    334  * <p>If the alias is ambiguous, then the preferred converter is used
    335  * and the status is set to U_AMBIGUOUS_ALIAS_WARNING.</p>
    336  *
    337  * <p>The conversion behavior and names can vary between platforms. ICU may
    338  * convert some characters differently from other platforms. Details on this topic
    339  * are in the <a href="http://icu-project.org/userguide/conversion.html">User's
    340  * Guide</a>. Aliases starting with a "cp" prefix have no specific meaning
    341  * other than its an alias starting with the letters "cp". Please do not
    342  * associate any meaning to these aliases.</p>
    343  *
    344  * @param converterName Name of the coded character set table.
    345  *          This may have options appended to the string.
    346  *          IANA alias character set names, IBM CCSIDs starting with "ibm-",
    347  *          Windows codepage numbers starting with "windows-" are frequently
    348  *          used for this parameter. See ucnv_getAvailableName and
    349  *          ucnv_getAlias for a complete list that is available.
    350  *          If this parameter is NULL, the default converter will be used.
    351  * @param err outgoing error status <TT>U_MEMORY_ALLOCATION_ERROR, U_FILE_ACCESS_ERROR</TT>
    352  * @return the created Unicode converter object, or <TT>NULL</TT> if an error occured
    353  * @see ucnv_openU
    354  * @see ucnv_openCCSID
    355  * @see ucnv_getAvailableName
    356  * @see ucnv_getAlias
    357  * @see ucnv_getDefaultName
    358  * @see ucnv_close
    359  * @see ucnv_compareNames
    360  * @stable ICU 2.0
    361  */
    362 U_STABLE UConverter* U_EXPORT2
    363 ucnv_open(const char *converterName, UErrorCode *err);
    364 
    365 
    366 /**
    367  * Creates a Unicode converter with the names specified as unicode string.
    368  * The name should be limited to the ASCII-7 alphanumerics range.
    369  * The actual name will be resolved with the alias file
    370  * using a case-insensitive string comparison that ignores
    371  * leading zeroes and all non-alphanumeric characters.
    372  * E.g., the names "UTF8", "utf-8", "u*T@f08" and "Utf 8" are all equivalent.
    373  * (See also ucnv_compareNames().)
    374  * If <TT>NULL</TT> is passed for the converter name, it will create
    375  * one with the ucnv_getDefaultName() return value.
    376  * If the alias is ambiguous, then the preferred converter is used
    377  * and the status is set to U_AMBIGUOUS_ALIAS_WARNING.
    378  *
    379  * <p>See ucnv_open for the complete details</p>
    380  * @param name Name of the UConverter table in a zero terminated
    381  *        Unicode string
    382  * @param err outgoing error status <TT>U_MEMORY_ALLOCATION_ERROR,
    383  *        U_FILE_ACCESS_ERROR</TT>
    384  * @return the created Unicode converter object, or <TT>NULL</TT> if an
    385  *        error occured
    386  * @see ucnv_open
    387  * @see ucnv_openCCSID
    388  * @see ucnv_close
    389  * @see ucnv_compareNames
    390  * @stable ICU 2.0
    391  */
    392 U_STABLE UConverter* U_EXPORT2
    393 ucnv_openU(const UChar *name,
    394            UErrorCode *err);
    395 
    396 /**
    397  * Creates a UConverter object from a CCSID number and platform pair.
    398  * Note that the usefulness of this function is limited to platforms with numeric
    399  * encoding IDs. Only IBM and Microsoft platforms use numeric (16-bit) identifiers for
    400  * encodings.
    401  *
    402  * In addition, IBM CCSIDs and Unicode conversion tables are not 1:1 related.
    403  * For many IBM CCSIDs there are multiple (up to six) Unicode conversion tables, and
    404  * for some Unicode conversion tables there are multiple CCSIDs.
    405  * Some "alternate" Unicode conversion tables are provided by the
    406  * IBM CDRA conversion table registry.
    407  * The most prominent example of a systematic modification of conversion tables that is
    408  * not provided in the form of conversion table files in the repository is
    409  * that S/390 Unix System Services swaps the codes for Line Feed and New Line in all
    410  * EBCDIC codepages, which requires such a swap in the Unicode conversion tables as well.
    411  *
    412  * Only IBM default conversion tables are accessible with ucnv_openCCSID().
    413  * ucnv_getCCSID() will return the same CCSID for all conversion tables that are associated
    414  * with that CCSID.
    415  *
    416  * Currently, the only "platform" supported in the ICU converter API is UCNV_IBM.
    417  *
    418  * In summary, the use of CCSIDs and the associated API functions is not recommended.
    419  *
    420  * In order to open a converter with the default IBM CDRA Unicode conversion table,
    421  * you can use this function or use the prefix "ibm-":
    422  * \code
    423  *     char name[20];
    424  *     sprintf(name, "ibm-%hu", ccsid);
    425  *     cnv=ucnv_open(name, &errorCode);
    426  * \endcode
    427  *
    428  * In order to open a converter with the IBM S/390 Unix System Services variant
    429  * of a Unicode/EBCDIC conversion table,
    430  * you can use the prefix "ibm-" together with the option string UCNV_SWAP_LFNL_OPTION_STRING:
    431  * \code
    432  *     char name[20];
    433  *     sprintf(name, "ibm-%hu" UCNV_SWAP_LFNL_OPTION_STRING, ccsid);
    434  *     cnv=ucnv_open(name, &errorCode);
    435  * \endcode
    436  *
    437  * In order to open a converter from a Microsoft codepage number, use the prefix "cp":
    438  * \code
    439  *     char name[20];
    440  *     sprintf(name, "cp%hu", codepageID);
    441  *     cnv=ucnv_open(name, &errorCode);
    442  * \endcode
    443  *
    444  * If the alias is ambiguous, then the preferred converter is used
    445  * and the status is set to U_AMBIGUOUS_ALIAS_WARNING.
    446  *
    447  * @param codepage codepage number to create
    448  * @param platform the platform in which the codepage number exists
    449  * @param err error status <TT>U_MEMORY_ALLOCATION_ERROR, U_FILE_ACCESS_ERROR</TT>
    450  * @return the created Unicode converter object, or <TT>NULL</TT> if an error
    451  *   occured.
    452  * @see ucnv_open
    453  * @see ucnv_openU
    454  * @see ucnv_close
    455  * @see ucnv_getCCSID
    456  * @see ucnv_getPlatform
    457  * @see UConverterPlatform
    458  * @stable ICU 2.0
    459  */
    460 U_STABLE UConverter* U_EXPORT2
    461 ucnv_openCCSID(int32_t codepage,
    462                UConverterPlatform platform,
    463                UErrorCode * err);
    464 
    465 /**
    466  * <p>Creates a UConverter object specified from a packageName and a converterName.</p>
    467  *
    468  * <p>The packageName and converterName must point to an ICU udata object, as defined by
    469  *   <code> udata_open( packageName, "cnv", converterName, err) </code> or equivalent.
    470  * Typically, packageName will refer to a (.dat) file, or to a package registered with
    471  * udata_setAppData(). Using a full file or directory pathname for packageName is deprecated.</p>
    472  *
    473  * <p>The name will NOT be looked up in the alias mechanism, nor will the converter be
    474  * stored in the converter cache or the alias table. The only way to open further converters
    475  * is call this function multiple times, or use the ucnv_safeClone() function to clone a
    476  * 'master' converter.</p>
    477  *
    478  * <p>A future version of ICU may add alias table lookups and/or caching
    479  * to this function.</p>
    480  *
    481  * <p>Example Use:
    482  *      <code>cnv = ucnv_openPackage("myapp", "myconverter", &err);</code>
    483  * </p>
    484  *
    485  * @param packageName name of the package (equivalent to 'path' in udata_open() call)
    486  * @param converterName name of the data item to be used, without suffix.
    487  * @param err outgoing error status <TT>U_MEMORY_ALLOCATION_ERROR, U_FILE_ACCESS_ERROR</TT>
    488  * @return the created Unicode converter object, or <TT>NULL</TT> if an error occured
    489  * @see udata_open
    490  * @see ucnv_open
    491  * @see ucnv_safeClone
    492  * @see ucnv_close
    493  * @stable ICU 2.2
    494  */
    495 U_STABLE UConverter* U_EXPORT2
    496 ucnv_openPackage(const char *packageName, const char *converterName, UErrorCode *err);
    497 
    498 /**
    499  * Thread safe converter cloning operation.
    500  * For most efficient operation, pass in a stackBuffer (and a *pBufferSize)
    501  * with at least U_CNV_SAFECLONE_BUFFERSIZE bytes of space.
    502  * If the buffer size is sufficient, then the clone will use the stack buffer;
    503  * otherwise, it will be allocated, and *pBufferSize will indicate
    504  * the actual size. (This should not occur with U_CNV_SAFECLONE_BUFFERSIZE.)
    505  *
    506  * You must ucnv_close() the clone in any case.
    507  *
    508  * If *pBufferSize==0, (regardless of whether stackBuffer==NULL or not)
    509  * then *pBufferSize will be changed to a sufficient size
    510  * for cloning this converter,
    511  * without actually cloning the converter ("pure pre-flighting").
    512  *
    513  * If *pBufferSize is greater than zero but not large enough for a stack-based
    514  * clone, then the converter is cloned using newly allocated memory
    515  * and *pBufferSize is changed to the necessary size.
    516  *
    517  * If the converter clone fits into the stack buffer but the stack buffer is not
    518  * sufficiently aligned for the clone, then the clone will use an
    519  * adjusted pointer and use an accordingly smaller buffer size.
    520  *
    521  * @param cnv converter to be cloned
    522  * @param stackBuffer user allocated space for the new clone. If NULL new memory will be allocated.
    523  *  If buffer is not large enough, new memory will be allocated.
    524  *  Clients can use the U_CNV_SAFECLONE_BUFFERSIZE. This will probably be enough to avoid memory allocations.
    525  * @param pBufferSize pointer to size of allocated space. pBufferSize must not be NULL.
    526  * @param status to indicate whether the operation went on smoothly or there were errors
    527  *  An informational status value, U_SAFECLONE_ALLOCATED_WARNING,
    528  *  is used if any allocations were necessary.
    529  *  However, it is better to check if *pBufferSize grew for checking for
    530  *  allocations because warning codes can be overridden by subsequent
    531  *  function calls.
    532  * @return pointer to the new clone
    533  * @stable ICU 2.0
    534  */
    535 U_STABLE UConverter * U_EXPORT2
    536 ucnv_safeClone(const UConverter *cnv,
    537                void             *stackBuffer,
    538                int32_t          *pBufferSize,
    539                UErrorCode       *status);
    540 
    541 /**
    542  * \def U_CNV_SAFECLONE_BUFFERSIZE
    543  * Definition of a buffer size that is designed to be large enough for
    544  * converters to be cloned with ucnv_safeClone().
    545  * @stable ICU 2.0
    546  */
    547 #define U_CNV_SAFECLONE_BUFFERSIZE  1024
    548 
    549 /**
    550  * Deletes the unicode converter and releases resources associated
    551  * with just this instance.
    552  * Does not free up shared converter tables.
    553  *
    554  * @param converter the converter object to be deleted
    555  * @see ucnv_open
    556  * @see ucnv_openU
    557  * @see ucnv_openCCSID
    558  * @stable ICU 2.0
    559  */
    560 U_STABLE void  U_EXPORT2
    561 ucnv_close(UConverter * converter);
    562 
    563 #if U_SHOW_CPLUSPLUS_API
    564 
    565 U_NAMESPACE_BEGIN
    566 
    567 /**
    568  * \class LocalUConverterPointer
    569  * "Smart pointer" class, closes a UConverter via ucnv_close().
    570  * For most methods see the LocalPointerBase base class.
    571  *
    572  * @see LocalPointerBase
    573  * @see LocalPointer
    574  * @stable ICU 4.4
    575  */
    576 U_DEFINE_LOCAL_OPEN_POINTER(LocalUConverterPointer, UConverter, ucnv_close);
    577 
    578 U_NAMESPACE_END
    579 
    580 #endif
    581 
    582 /**
    583  * Fills in the output parameter, subChars, with the substitution characters
    584  * as multiple bytes.
    585  * If ucnv_setSubstString() set a Unicode string because the converter is
    586  * stateful, then subChars will be an empty string.
    587  *
    588  * @param converter the Unicode converter
    589  * @param subChars the subsitution characters
    590  * @param len on input the capacity of subChars, on output the number
    591  * of bytes copied to it
    592  * @param  err the outgoing error status code.
    593  * If the substitution character array is too small, an
    594  * <TT>U_INDEX_OUTOFBOUNDS_ERROR</TT> will be returned.
    595  * @see ucnv_setSubstString
    596  * @see ucnv_setSubstChars
    597  * @stable ICU 2.0
    598  */
    599 U_STABLE void U_EXPORT2
    600 ucnv_getSubstChars(const UConverter *converter,
    601                    char *subChars,
    602                    int8_t *len,
    603                    UErrorCode *err);
    604 
    605 /**
    606  * Sets the substitution chars when converting from unicode to a codepage. The
    607  * substitution is specified as a string of 1-4 bytes, and may contain
    608  * <TT>NULL</TT> bytes.
    609  * The subChars must represent a single character. The caller needs to know the
    610  * byte sequence of a valid character in the converter's charset.
    611  * For some converters, for example some ISO 2022 variants, only single-byte
    612  * substitution characters may be supported.
    613  * The newer ucnv_setSubstString() function relaxes these limitations.
    614  *
    615  * @param converter the Unicode converter
    616  * @param subChars the substitution character byte sequence we want set
    617  * @param len the number of bytes in subChars
    618  * @param err the error status code.  <TT>U_INDEX_OUTOFBOUNDS_ERROR </TT> if
    619  * len is bigger than the maximum number of bytes allowed in subchars
    620  * @see ucnv_setSubstString
    621  * @see ucnv_getSubstChars
    622  * @stable ICU 2.0
    623  */
    624 U_STABLE void U_EXPORT2
    625 ucnv_setSubstChars(UConverter *converter,
    626                    const char *subChars,
    627                    int8_t len,
    628                    UErrorCode *err);
    629 
    630 /**
    631  * Set a substitution string for converting from Unicode to a charset.
    632  * The caller need not know the charset byte sequence for each charset.
    633  *
    634  * Unlike ucnv_setSubstChars() which is designed to set a charset byte sequence
    635  * for a single character, this function takes a Unicode string with
    636  * zero, one or more characters, and immediately verifies that the string can be
    637  * converted to the charset.
    638  * If not, or if the result is too long (more than 32 bytes as of ICU 3.6),
    639  * then the function returns with an error accordingly.
    640  *
    641  * Also unlike ucnv_setSubstChars(), this function works for stateful charsets
    642  * by converting on the fly at the point of substitution rather than setting
    643  * a fixed byte sequence.
    644  *
    645  * @param cnv The UConverter object.
    646  * @param s The Unicode string.
    647  * @param length The number of UChars in s, or -1 for a NUL-terminated string.
    648  * @param err Pointer to a standard ICU error code. Its input value must
    649  *            pass the U_SUCCESS() test, or else the function returns
    650  *            immediately. Check for U_FAILURE() on output or use with
    651  *            function chaining. (See User Guide for details.)
    652  *
    653  * @see ucnv_setSubstChars
    654  * @see ucnv_getSubstChars
    655  * @stable ICU 3.6
    656  */
    657 U_STABLE void U_EXPORT2
    658 ucnv_setSubstString(UConverter *cnv,
    659                     const UChar *s,
    660                     int32_t length,
    661                     UErrorCode *err);
    662 
    663 /**
    664  * Fills in the output parameter, errBytes, with the error characters from the
    665  * last failing conversion.
    666  *
    667  * @param converter the Unicode converter
    668  * @param errBytes the codepage bytes which were in error
    669  * @param len on input the capacity of errBytes, on output the number of
    670  *  bytes which were copied to it
    671  * @param err the error status code.
    672  * If the substitution character array is too small, an
    673  * <TT>U_INDEX_OUTOFBOUNDS_ERROR</TT> will be returned.
    674  * @stable ICU 2.0
    675  */
    676 U_STABLE void U_EXPORT2
    677 ucnv_getInvalidChars(const UConverter *converter,
    678                      char *errBytes,
    679                      int8_t *len,
    680                      UErrorCode *err);
    681 
    682 /**
    683  * Fills in the output parameter, errChars, with the error characters from the
    684  * last failing conversion.
    685  *
    686  * @param converter the Unicode converter
    687  * @param errUChars the UChars which were in error
    688  * @param len on input the capacity of errUChars, on output the number of
    689  *  UChars which were copied to it
    690  * @param err the error status code.
    691  * If the substitution character array is too small, an
    692  * <TT>U_INDEX_OUTOFBOUNDS_ERROR</TT> will be returned.
    693  * @stable ICU 2.0
    694  */
    695 U_STABLE void U_EXPORT2
    696 ucnv_getInvalidUChars(const UConverter *converter,
    697                       UChar *errUChars,
    698                       int8_t *len,
    699                       UErrorCode *err);
    700 
    701 /**
    702  * Resets the state of a converter to the default state. This is used
    703  * in the case of an error, to restart a conversion from a known default state.
    704  * It will also empty the internal output buffers.
    705  * @param converter the Unicode converter
    706  * @stable ICU 2.0
    707  */
    708 U_STABLE void U_EXPORT2
    709 ucnv_reset(UConverter *converter);
    710 
    711 /**
    712  * Resets the to-Unicode part of a converter state to the default state.
    713  * This is used in the case of an error to restart a conversion to
    714  * Unicode to a known default state. It will also empty the internal
    715  * output buffers used for the conversion to Unicode codepoints.
    716  * @param converter the Unicode converter
    717  * @stable ICU 2.0
    718  */
    719 U_STABLE void U_EXPORT2
    720 ucnv_resetToUnicode(UConverter *converter);
    721 
    722 /**
    723  * Resets the from-Unicode part of a converter state to the default state.
    724  * This is used in the case of an error to restart a conversion from
    725  * Unicode to a known default state. It will also empty the internal output
    726  * buffers used for the conversion from Unicode codepoints.
    727  * @param converter the Unicode converter
    728  * @stable ICU 2.0
    729  */
    730 U_STABLE void U_EXPORT2
    731 ucnv_resetFromUnicode(UConverter *converter);
    732 
    733 /**
    734  * Returns the maximum number of bytes that are output per UChar in conversion
    735  * from Unicode using this converter.
    736  * The returned number can be used with UCNV_GET_MAX_BYTES_FOR_STRING
    737  * to calculate the size of a target buffer for conversion from Unicode.
    738  *
    739  * Note: Before ICU 2.8, this function did not return reliable numbers for
    740  * some stateful converters (EBCDIC_STATEFUL, ISO-2022) and LMBCS.
    741  *
    742  * This number may not be the same as the maximum number of bytes per
    743  * "conversion unit". In other words, it may not be the intuitively expected
    744  * number of bytes per character that would be published for a charset,
    745  * and may not fulfill any other purpose than the allocation of an output
    746  * buffer of guaranteed sufficient size for a given input length and converter.
    747  *
    748  * Examples for special cases that are taken into account:
    749  * - Supplementary code points may convert to more bytes than BMP code points.
    750  *   This function returns bytes per UChar (UTF-16 code unit), not per
    751  *   Unicode code point, for efficient buffer allocation.
    752  * - State-shifting output (SI/SO, escapes, etc.) from stateful converters.
    753  * - When m input UChars are converted to n output bytes, then the maximum m/n
    754  *   is taken into account.
    755  *
    756  * The number returned here does not take into account
    757  * (see UCNV_GET_MAX_BYTES_FOR_STRING):
    758  * - callbacks which output more than one charset character sequence per call,
    759  *   like escape callbacks
    760  * - initial and final non-character bytes that are output by some converters
    761  *   (automatic BOMs, initial escape sequence, final SI, etc.)
    762  *
    763  * Examples for returned values:
    764  * - SBCS charsets: 1
    765  * - Shift-JIS: 2
    766  * - UTF-16: 2 (2 per BMP, 4 per surrogate _pair_, BOM not counted)
    767  * - UTF-8: 3 (3 per BMP, 4 per surrogate _pair_)
    768  * - EBCDIC_STATEFUL (EBCDIC mixed SBCS/DBCS): 3 (SO + DBCS)
    769  * - ISO-2022: 3 (always outputs UTF-8)
    770  * - ISO-2022-JP: 6 (4-byte escape sequences + DBCS)
    771  * - ISO-2022-CN: 8 (4-byte designator sequences + 2-byte SS2/SS3 + DBCS)
    772  *
    773  * @param converter The Unicode converter.
    774  * @return The maximum number of bytes per UChar that are output by ucnv_fromUnicode(),
    775  *         to be used together with UCNV_GET_MAX_BYTES_FOR_STRING for buffer allocation.
    776  *
    777  * @see UCNV_GET_MAX_BYTES_FOR_STRING
    778  * @see ucnv_getMinCharSize
    779  * @stable ICU 2.0
    780  */
    781 U_STABLE int8_t U_EXPORT2
    782 ucnv_getMaxCharSize(const UConverter *converter);
    783 
    784 /**
    785  * Calculates the size of a buffer for conversion from Unicode to a charset.
    786  * The calculated size is guaranteed to be sufficient for this conversion.
    787  *
    788  * It takes into account initial and final non-character bytes that are output
    789  * by some converters.
    790  * It does not take into account callbacks which output more than one charset
    791  * character sequence per call, like escape callbacks.
    792  * The default (substitution) callback only outputs one charset character sequence.
    793  *
    794  * @param length Number of UChars to be converted.
    795  * @param maxCharSize Return value from ucnv_getMaxCharSize() for the converter
    796  *                    that will be used.
    797  * @return Size of a buffer that will be large enough to hold the output bytes of
    798  *         converting length UChars with the converter that returned the maxCharSize.
    799  *
    800  * @see ucnv_getMaxCharSize
    801  * @stable ICU 2.8
    802  */
    803 #define UCNV_GET_MAX_BYTES_FOR_STRING(length, maxCharSize) \
    804      (((int32_t)(length)+10)*(int32_t)(maxCharSize))
    805 
    806 /**
    807  * Returns the minimum byte length for characters in this codepage.
    808  * This is usually either 1 or 2.
    809  * @param converter the Unicode converter
    810  * @return the minimum number of bytes allowed by this particular converter
    811  * @see ucnv_getMaxCharSize
    812  * @stable ICU 2.0
    813  */
    814 U_STABLE int8_t U_EXPORT2
    815 ucnv_getMinCharSize(const UConverter *converter);
    816 
    817 /**
    818  * Returns the display name of the converter passed in based on the Locale
    819  * passed in. If the locale contains no display name, the internal ASCII
    820  * name will be filled in.
    821  *
    822  * @param converter the Unicode converter.
    823  * @param displayLocale is the specific Locale we want to localised for
    824  * @param displayName user provided buffer to be filled in
    825  * @param displayNameCapacity size of displayName Buffer
    826  * @param err error status code
    827  * @return displayNameLength number of UChar needed in displayName
    828  * @see ucnv_getName
    829  * @stable ICU 2.0
    830  */
    831 U_STABLE int32_t U_EXPORT2
    832 ucnv_getDisplayName(const UConverter *converter,
    833                     const char *displayLocale,
    834                     UChar *displayName,
    835                     int32_t displayNameCapacity,
    836                     UErrorCode *err);
    837 
    838 /**
    839  * Gets the internal, canonical name of the converter (zero-terminated).
    840  * The lifetime of the returned string will be that of the converter
    841  * passed to this function.
    842  * @param converter the Unicode converter
    843  * @param err UErrorCode status
    844  * @return the internal name of the converter
    845  * @see ucnv_getDisplayName
    846  * @stable ICU 2.0
    847  */
    848 U_STABLE const char * U_EXPORT2
    849 ucnv_getName(const UConverter *converter, UErrorCode *err);
    850 
    851 /**
    852  * Gets a codepage number associated with the converter. This is not guaranteed
    853  * to be the one used to create the converter. Some converters do not represent
    854  * platform registered codepages and return zero for the codepage number.
    855  * The error code fill-in parameter indicates if the codepage number
    856  * is available.
    857  * Does not check if the converter is <TT>NULL</TT> or if converter's data
    858  * table is <TT>NULL</TT>.
    859  *
    860  * Important: The use of CCSIDs is not recommended because it is limited
    861  * to only two platforms in principle and only one (UCNV_IBM) in the current
    862  * ICU converter API.
    863  * Also, CCSIDs are insufficient to identify IBM Unicode conversion tables precisely.
    864  * For more details see ucnv_openCCSID().
    865  *
    866  * @param converter the Unicode converter
    867  * @param err the error status code.
    868  * @return If any error occurrs, -1 will be returned otherwise, the codepage number
    869  * will be returned
    870  * @see ucnv_openCCSID
    871  * @see ucnv_getPlatform
    872  * @stable ICU 2.0
    873  */
    874 U_STABLE int32_t U_EXPORT2
    875 ucnv_getCCSID(const UConverter *converter,
    876               UErrorCode *err);
    877 
    878 /**
    879  * Gets a codepage platform associated with the converter. Currently,
    880  * only <TT>UCNV_IBM</TT> will be returned.
    881  * Does not test if the converter is <TT>NULL</TT> or if converter's data
    882  * table is <TT>NULL</TT>.
    883  * @param converter the Unicode converter
    884  * @param err the error status code.
    885  * @return The codepage platform
    886  * @stable ICU 2.0
    887  */
    888 U_STABLE UConverterPlatform U_EXPORT2
    889 ucnv_getPlatform(const UConverter *converter,
    890                  UErrorCode *err);
    891 
    892 /**
    893  * Gets the type of the converter
    894  * e.g. SBCS, MBCS, DBCS, UTF8, UTF16_BE, UTF16_LE, ISO_2022,
    895  * EBCDIC_STATEFUL, LATIN_1
    896  * @param converter a valid, opened converter
    897  * @return the type of the converter
    898  * @stable ICU 2.0
    899  */
    900 U_STABLE UConverterType U_EXPORT2
    901 ucnv_getType(const UConverter * converter);
    902 
    903 /**
    904  * Gets the "starter" (lead) bytes for converters of type MBCS.
    905  * Will fill in an <TT>U_ILLEGAL_ARGUMENT_ERROR</TT> if converter passed in
    906  * is not MBCS. Fills in an array of type UBool, with the value of the byte
    907  * as offset to the array. For example, if (starters[0x20] == TRUE) at return,
    908  * it means that the byte 0x20 is a starter byte in this converter.
    909  * Context pointers are always owned by the caller.
    910  *
    911  * @param converter a valid, opened converter of type MBCS
    912  * @param starters an array of size 256 to be filled in
    913  * @param err error status, <TT>U_ILLEGAL_ARGUMENT_ERROR</TT> if the
    914  * converter is not a type which can return starters.
    915  * @see ucnv_getType
    916  * @stable ICU 2.0
    917  */
    918 U_STABLE void U_EXPORT2
    919 ucnv_getStarters(const UConverter* converter,
    920                  UBool starters[256],
    921                  UErrorCode* err);
    922 
    923 
    924 /**
    925  * Selectors for Unicode sets that can be returned by ucnv_getUnicodeSet().
    926  * @see ucnv_getUnicodeSet
    927  * @stable ICU 2.6
    928  */
    929 typedef enum UConverterUnicodeSet {
    930     /** Select the set of roundtrippable Unicode code points. @stable ICU 2.6 */
    931     UCNV_ROUNDTRIP_SET,
    932     /** Select the set of Unicode code points with roundtrip or fallback mappings. @stable ICU 4.0 */
    933     UCNV_ROUNDTRIP_AND_FALLBACK_SET,
    934     /** Number of UConverterUnicodeSet selectors. @stable ICU 2.6 */
    935     UCNV_SET_COUNT
    936 } UConverterUnicodeSet;
    937 
    938 
    939 /**
    940  * Returns the set of Unicode code points that can be converted by an ICU converter.
    941  *
    942  * Returns one of several kinds of set:
    943  *
    944  * 1. UCNV_ROUNDTRIP_SET
    945  *
    946  * The set of all Unicode code points that can be roundtrip-converted
    947  * (converted without any data loss) with the converter (ucnv_fromUnicode()).
    948  * This set will not include code points that have fallback mappings
    949  * or are only the result of reverse fallback mappings.
    950  * This set will also not include PUA code points with fallbacks, although
    951  * ucnv_fromUnicode() will always uses those mappings despite ucnv_setFallback().
    952  * See UTR #22 "Character Mapping Markup Language"
    953  * at http://www.unicode.org/reports/tr22/
    954  *
    955  * This is useful for example for
    956  * - checking that a string or document can be roundtrip-converted with a converter,
    957  *   without/before actually performing the conversion
    958  * - testing if a converter can be used for text for typical text for a certain locale,
    959  *   by comparing its roundtrip set with the set of ExemplarCharacters from
    960  *   ICU's locale data or other sources
    961  *
    962  * 2. UCNV_ROUNDTRIP_AND_FALLBACK_SET
    963  *
    964  * The set of all Unicode code points that can be converted with the converter (ucnv_fromUnicode())
    965  * when fallbacks are turned on (see ucnv_setFallback()).
    966  * This set includes all code points with roundtrips and fallbacks (but not reverse fallbacks).
    967  *
    968  * In the future, there may be more UConverterUnicodeSet choices to select
    969  * sets with different properties.
    970  *
    971  * @param cnv The converter for which a set is requested.
    972  * @param setFillIn A valid USet *. It will be cleared by this function before
    973  *            the converter's specific set is filled into the USet.
    974  * @param whichSet A UConverterUnicodeSet selector;
    975  *              currently UCNV_ROUNDTRIP_SET is the only supported value.
    976  * @param pErrorCode ICU error code in/out parameter.
    977  *                   Must fulfill U_SUCCESS before the function call.
    978  *
    979  * @see UConverterUnicodeSet
    980  * @see uset_open
    981  * @see uset_close
    982  * @stable ICU 2.6
    983  */
    984 U_STABLE void U_EXPORT2
    985 ucnv_getUnicodeSet(const UConverter *cnv,
    986                    USet *setFillIn,
    987                    UConverterUnicodeSet whichSet,
    988                    UErrorCode *pErrorCode);
    989 
    990 /**
    991  * Gets the current calback function used by the converter when an illegal
    992  *  or invalid codepage sequence is found.
    993  * Context pointers are always owned by the caller.
    994  *
    995  * @param converter the unicode converter
    996  * @param action fillin: returns the callback function pointer
    997  * @param context fillin: returns the callback's private void* context
    998  * @see ucnv_setToUCallBack
    999  * @stable ICU 2.0
   1000  */
   1001 U_STABLE void U_EXPORT2
   1002 ucnv_getToUCallBack (const UConverter * converter,
   1003                      UConverterToUCallback *action,
   1004                      const void **context);
   1005 
   1006 /**
   1007  * Gets the current callback function used by the converter when illegal
   1008  * or invalid Unicode sequence is found.
   1009  * Context pointers are always owned by the caller.
   1010  *
   1011  * @param converter the unicode converter
   1012  * @param action fillin: returns the callback function pointer
   1013  * @param context fillin: returns the callback's private void* context
   1014  * @see ucnv_setFromUCallBack
   1015  * @stable ICU 2.0
   1016  */
   1017 U_STABLE void U_EXPORT2
   1018 ucnv_getFromUCallBack (const UConverter * converter,
   1019                        UConverterFromUCallback *action,
   1020                        const void **context);
   1021 
   1022 /**
   1023  * Changes the callback function used by the converter when
   1024  * an illegal or invalid sequence is found.
   1025  * Context pointers are always owned by the caller.
   1026  * Predefined actions and contexts can be found in the ucnv_err.h header.
   1027  *
   1028  * @param converter the unicode converter
   1029  * @param newAction the new callback function
   1030  * @param newContext the new toUnicode callback context pointer. This can be NULL.
   1031  * @param oldAction fillin: returns the old callback function pointer. This can be NULL.
   1032  * @param oldContext fillin: returns the old callback's private void* context. This can be NULL.
   1033  * @param err The error code status
   1034  * @see ucnv_getToUCallBack
   1035  * @stable ICU 2.0
   1036  */
   1037 U_STABLE void U_EXPORT2
   1038 ucnv_setToUCallBack (UConverter * converter,
   1039                      UConverterToUCallback newAction,
   1040                      const void* newContext,
   1041                      UConverterToUCallback *oldAction,
   1042                      const void** oldContext,
   1043                      UErrorCode * err);
   1044 
   1045 /**
   1046  * Changes the current callback function used by the converter when
   1047  * an illegal or invalid sequence is found.
   1048  * Context pointers are always owned by the caller.
   1049  * Predefined actions and contexts can be found in the ucnv_err.h header.
   1050  *
   1051  * @param converter the unicode converter
   1052  * @param newAction the new callback function
   1053  * @param newContext the new fromUnicode callback context pointer. This can be NULL.
   1054  * @param oldAction fillin: returns the old callback function pointer. This can be NULL.
   1055  * @param oldContext fillin: returns the old callback's private void* context. This can be NULL.
   1056  * @param err The error code status
   1057  * @see ucnv_getFromUCallBack
   1058  * @stable ICU 2.0
   1059  */
   1060 U_STABLE void U_EXPORT2
   1061 ucnv_setFromUCallBack (UConverter * converter,
   1062                        UConverterFromUCallback newAction,
   1063                        const void *newContext,
   1064                        UConverterFromUCallback *oldAction,
   1065                        const void **oldContext,
   1066                        UErrorCode * err);
   1067 
   1068 /**
   1069  * Converts an array of unicode characters to an array of codepage
   1070  * characters. This function is optimized for converting a continuous
   1071  * stream of data in buffer-sized chunks, where the entire source and
   1072  * target does not fit in available buffers.
   1073  *
   1074  * The source pointer is an in/out parameter. It starts out pointing where the
   1075  * conversion is to begin, and ends up pointing after the last UChar consumed.
   1076  *
   1077  * Target similarly starts out pointer at the first available byte in the output
   1078  * buffer, and ends up pointing after the last byte written to the output.
   1079  *
   1080  * The converter always attempts to consume the entire source buffer, unless
   1081  * (1.) the target buffer is full, or (2.) a failing error is returned from the
   1082  * current callback function.  When a successful error status has been
   1083  * returned, it means that all of the source buffer has been
   1084  *  consumed. At that point, the caller should reset the source and
   1085  *  sourceLimit pointers to point to the next chunk.
   1086  *
   1087  * At the end of the stream (flush==TRUE), the input is completely consumed
   1088  * when *source==sourceLimit and no error code is set.
   1089  * The converter object is then automatically reset by this function.
   1090  * (This means that a converter need not be reset explicitly between data
   1091  * streams if it finishes the previous stream without errors.)
   1092  *
   1093  * This is a <I>stateful</I> conversion. Additionally, even when all source data has
   1094  * been consumed, some data may be in the converters' internal state.
   1095  * Call this function repeatedly, updating the target pointers with
   1096  * the next empty chunk of target in case of a
   1097  * <TT>U_BUFFER_OVERFLOW_ERROR</TT>, and updating the source  pointers
   1098  *  with the next chunk of source when a successful error status is
   1099  * returned, until there are no more chunks of source data.
   1100  * @param converter the Unicode converter
   1101  * @param target I/O parameter. Input : Points to the beginning of the buffer to copy
   1102  *  codepage characters to. Output : points to after the last codepage character copied
   1103  *  to <TT>target</TT>.
   1104  * @param targetLimit the pointer just after last of the <TT>target</TT> buffer
   1105  * @param source I/O parameter, pointer to pointer to the source Unicode character buffer.
   1106  * @param sourceLimit the pointer just after the last of the source buffer
   1107  * @param offsets if NULL is passed, nothing will happen to it, otherwise it needs to have the same number
   1108  * of allocated cells as <TT>target</TT>. Will fill in offsets from target to source pointer
   1109  * e.g: <TT>offsets[3]</TT> is equal to 6, it means that the <TT>target[3]</TT> was a result of transcoding <TT>source[6]</TT>
   1110  * For output data carried across calls, and other data without a specific source character
   1111  * (such as from escape sequences or callbacks)  -1 will be placed for offsets.
   1112  * @param flush set to <TT>TRUE</TT> if the current source buffer is the last available
   1113  * chunk of the source, <TT>FALSE</TT> otherwise. Note that if a failing status is returned,
   1114  * this function may have to be called multiple times with flush set to <TT>TRUE</TT> until
   1115  * the source buffer is consumed.
   1116  * @param err the error status.  <TT>U_ILLEGAL_ARGUMENT_ERROR</TT> will be set if the
   1117  * converter is <TT>NULL</TT>.
   1118  * <code>U_BUFFER_OVERFLOW_ERROR</code> will be set if the target is full and there is
   1119  * still data to be written to the target.
   1120  * @see ucnv_fromUChars
   1121  * @see ucnv_convert
   1122  * @see ucnv_getMinCharSize
   1123  * @see ucnv_setToUCallBack
   1124  * @stable ICU 2.0
   1125  */
   1126 U_STABLE void U_EXPORT2
   1127 ucnv_fromUnicode (UConverter * converter,
   1128                   char **target,
   1129                   const char *targetLimit,
   1130                   const UChar ** source,
   1131                   const UChar * sourceLimit,
   1132                   int32_t* offsets,
   1133                   UBool flush,
   1134                   UErrorCode * err);
   1135 
   1136 /**
   1137  * Converts a buffer of codepage bytes into an array of unicode UChars
   1138  * characters. This function is optimized for converting a continuous
   1139  * stream of data in buffer-sized chunks, where the entire source and
   1140  * target does not fit in available buffers.
   1141  *
   1142  * The source pointer is an in/out parameter. It starts out pointing where the
   1143  * conversion is to begin, and ends up pointing after the last byte of source consumed.
   1144  *
   1145  * Target similarly starts out pointer at the first available UChar in the output
   1146  * buffer, and ends up pointing after the last UChar written to the output.
   1147  * It does NOT necessarily keep UChar sequences together.
   1148  *
   1149  * The converter always attempts to consume the entire source buffer, unless
   1150  * (1.) the target buffer is full, or (2.) a failing error is returned from the
   1151  * current callback function.  When a successful error status has been
   1152  * returned, it means that all of the source buffer has been
   1153  *  consumed. At that point, the caller should reset the source and
   1154  *  sourceLimit pointers to point to the next chunk.
   1155  *
   1156  * At the end of the stream (flush==TRUE), the input is completely consumed
   1157  * when *source==sourceLimit and no error code is set
   1158  * The converter object is then automatically reset by this function.
   1159  * (This means that a converter need not be reset explicitly between data
   1160  * streams if it finishes the previous stream without errors.)
   1161  *
   1162  * This is a <I>stateful</I> conversion. Additionally, even when all source data has
   1163  * been consumed, some data may be in the converters' internal state.
   1164  * Call this function repeatedly, updating the target pointers with
   1165  * the next empty chunk of target in case of a
   1166  * <TT>U_BUFFER_OVERFLOW_ERROR</TT>, and updating the source  pointers
   1167  *  with the next chunk of source when a successful error status is
   1168  * returned, until there are no more chunks of source data.
   1169  * @param converter the Unicode converter
   1170  * @param target I/O parameter. Input : Points to the beginning of the buffer to copy
   1171  *  UChars into. Output : points to after the last UChar copied.
   1172  * @param targetLimit the pointer just after the end of the <TT>target</TT> buffer
   1173  * @param source I/O parameter, pointer to pointer to the source codepage buffer.
   1174  * @param sourceLimit the pointer to the byte after the end of the source buffer
   1175  * @param offsets if NULL is passed, nothing will happen to it, otherwise it needs to have the same number
   1176  * of allocated cells as <TT>target</TT>. Will fill in offsets from target to source pointer
   1177  * e.g: <TT>offsets[3]</TT> is equal to 6, it means that the <TT>target[3]</TT> was a result of transcoding <TT>source[6]</TT>
   1178  * For output data carried across calls, and other data without a specific source character
   1179  * (such as from escape sequences or callbacks)  -1 will be placed for offsets.
   1180  * @param flush set to <TT>TRUE</TT> if the current source buffer is the last available
   1181  * chunk of the source, <TT>FALSE</TT> otherwise. Note that if a failing status is returned,
   1182  * this function may have to be called multiple times with flush set to <TT>TRUE</TT> until
   1183  * the source buffer is consumed.
   1184  * @param err the error status.  <TT>U_ILLEGAL_ARGUMENT_ERROR</TT> will be set if the
   1185  * converter is <TT>NULL</TT>.
   1186  * <code>U_BUFFER_OVERFLOW_ERROR</code> will be set if the target is full and there is
   1187  * still data to be written to the target.
   1188  * @see ucnv_fromUChars
   1189  * @see ucnv_convert
   1190  * @see ucnv_getMinCharSize
   1191  * @see ucnv_setFromUCallBack
   1192  * @see ucnv_getNextUChar
   1193  * @stable ICU 2.0
   1194  */
   1195 U_STABLE void U_EXPORT2
   1196 ucnv_toUnicode(UConverter *converter,
   1197                UChar **target,
   1198                const UChar *targetLimit,
   1199                const char **source,
   1200                const char *sourceLimit,
   1201                int32_t *offsets,
   1202                UBool flush,
   1203                UErrorCode *err);
   1204 
   1205 /**
   1206  * Convert the Unicode string into a codepage string using an existing UConverter.
   1207  * The output string is NUL-terminated if possible.
   1208  *
   1209  * This function is a more convenient but less powerful version of ucnv_fromUnicode().
   1210  * It is only useful for whole strings, not for streaming conversion.
   1211  *
   1212  * The maximum output buffer capacity required (barring output from callbacks) will be
   1213  * UCNV_GET_MAX_BYTES_FOR_STRING(srcLength, ucnv_getMaxCharSize(cnv)).
   1214  *
   1215  * @param cnv the converter object to be used (ucnv_resetFromUnicode() will be called)
   1216  * @param src the input Unicode string
   1217  * @param srcLength the input string length, or -1 if NUL-terminated
   1218  * @param dest destination string buffer, can be NULL if destCapacity==0
   1219  * @param destCapacity the number of chars available at dest
   1220  * @param pErrorCode normal ICU error code;
   1221  *                  common error codes that may be set by this function include
   1222  *                  U_BUFFER_OVERFLOW_ERROR, U_STRING_NOT_TERMINATED_WARNING,
   1223  *                  U_ILLEGAL_ARGUMENT_ERROR, and conversion errors
   1224  * @return the length of the output string, not counting the terminating NUL;
   1225  *         if the length is greater than destCapacity, then the string will not fit
   1226  *         and a buffer of the indicated length would need to be passed in
   1227  * @see ucnv_fromUnicode
   1228  * @see ucnv_convert
   1229  * @see UCNV_GET_MAX_BYTES_FOR_STRING
   1230  * @stable ICU 2.0
   1231  */
   1232 U_STABLE int32_t U_EXPORT2
   1233 ucnv_fromUChars(UConverter *cnv,
   1234                 char *dest, int32_t destCapacity,
   1235                 const UChar *src, int32_t srcLength,
   1236                 UErrorCode *pErrorCode);
   1237 
   1238 /**
   1239  * Convert the codepage string into a Unicode string using an existing UConverter.
   1240  * The output string is NUL-terminated if possible.
   1241  *
   1242  * This function is a more convenient but less powerful version of ucnv_toUnicode().
   1243  * It is only useful for whole strings, not for streaming conversion.
   1244  *
   1245  * The maximum output buffer capacity required (barring output from callbacks) will be
   1246  * 2*srcLength (each char may be converted into a surrogate pair).
   1247  *
   1248  * @param cnv the converter object to be used (ucnv_resetToUnicode() will be called)
   1249  * @param src the input codepage string
   1250  * @param srcLength the input string length, or -1 if NUL-terminated
   1251  * @param dest destination string buffer, can be NULL if destCapacity==0
   1252  * @param destCapacity the number of UChars available at dest
   1253  * @param pErrorCode normal ICU error code;
   1254  *                  common error codes that may be set by this function include
   1255  *                  U_BUFFER_OVERFLOW_ERROR, U_STRING_NOT_TERMINATED_WARNING,
   1256  *                  U_ILLEGAL_ARGUMENT_ERROR, and conversion errors
   1257  * @return the length of the output string, not counting the terminating NUL;
   1258  *         if the length is greater than destCapacity, then the string will not fit
   1259  *         and a buffer of the indicated length would need to be passed in
   1260  * @see ucnv_toUnicode
   1261  * @see ucnv_convert
   1262  * @stable ICU 2.0
   1263  */
   1264 U_STABLE int32_t U_EXPORT2
   1265 ucnv_toUChars(UConverter *cnv,
   1266               UChar *dest, int32_t destCapacity,
   1267               const char *src, int32_t srcLength,
   1268               UErrorCode *pErrorCode);
   1269 
   1270 /**
   1271  * Convert a codepage buffer into Unicode one character at a time.
   1272  * The input is completely consumed when the U_INDEX_OUTOFBOUNDS_ERROR is set.
   1273  *
   1274  * Advantage compared to ucnv_toUnicode() or ucnv_toUChars():
   1275  * - Faster for small amounts of data, for most converters, e.g.,
   1276  *   US-ASCII, ISO-8859-1, UTF-8/16/32, and most "normal" charsets.
   1277  *   (For complex converters, e.g., SCSU, UTF-7 and ISO 2022 variants,
   1278  *    it uses ucnv_toUnicode() internally.)
   1279  * - Convenient.
   1280  *
   1281  * Limitations compared to ucnv_toUnicode():
   1282  * - Always assumes flush=TRUE.
   1283  *   This makes ucnv_getNextUChar() unsuitable for "streaming" conversion,
   1284  *   that is, for where the input is supplied in multiple buffers,
   1285  *   because ucnv_getNextUChar() will assume the end of the input at the end
   1286  *   of the first buffer.
   1287  * - Does not provide offset output.
   1288  *
   1289  * It is possible to "mix" ucnv_getNextUChar() and ucnv_toUnicode() because
   1290  * ucnv_getNextUChar() uses the current state of the converter
   1291  * (unlike ucnv_toUChars() which always resets first).
   1292  * However, if ucnv_getNextUChar() is called after ucnv_toUnicode()
   1293  * stopped in the middle of a character sequence (with flush=FALSE),
   1294  * then ucnv_getNextUChar() will always use the slower ucnv_toUnicode()
   1295  * internally until the next character boundary.
   1296  * (This is new in ICU 2.6. In earlier releases, ucnv_getNextUChar() had to
   1297  * start at a character boundary.)
   1298  *
   1299  * Instead of using ucnv_getNextUChar(), it is recommended
   1300  * to convert using ucnv_toUnicode() or ucnv_toUChars()
   1301  * and then iterate over the text using U16_NEXT() or a UCharIterator (uiter.h)
   1302  * or a C++ CharacterIterator or similar.
   1303  * This allows streaming conversion and offset output, for example.
   1304  *
   1305  * <p>Handling of surrogate pairs and supplementary-plane code points:<br>
   1306  * There are two different kinds of codepages that provide mappings for surrogate characters:
   1307  * <ul>
   1308  *   <li>Codepages like UTF-8, UTF-32, and GB 18030 provide direct representations for Unicode
   1309  *       code points U+10000-U+10ffff as well as for single surrogates U+d800-U+dfff.
   1310  *       Each valid sequence will result in exactly one returned code point.
   1311  *       If a sequence results in a single surrogate, then that will be returned
   1312  *       by itself, even if a neighboring sequence encodes the matching surrogate.</li>
   1313  *   <li>Codepages like SCSU and LMBCS (and UTF-16) provide direct representations only for BMP code points
   1314  *       including surrogates. Code points in supplementary planes are represented with
   1315  *       two sequences, each encoding a surrogate.
   1316  *       For these codepages, matching pairs of surrogates will be combined into single
   1317  *       code points for returning from this function.
   1318  *       (Note that SCSU is actually a mix of these codepage types.)</li>
   1319  * </ul></p>
   1320  *
   1321  * @param converter an open UConverter
   1322  * @param source the address of a pointer to the codepage buffer, will be
   1323  *  updated to point after the bytes consumed in the conversion call.
   1324  * @param sourceLimit points to the end of the input buffer
   1325  * @param err fills in error status (see ucnv_toUnicode)
   1326  * <code>U_INDEX_OUTOFBOUNDS_ERROR</code> will be set if the input
   1327  * is empty or does not convert to any output (e.g.: pure state-change
   1328  * codes SI/SO, escape sequences for ISO 2022,
   1329  * or if the callback did not output anything, ...).
   1330  * This function will not set a <code>U_BUFFER_OVERFLOW_ERROR</code> because
   1331  *  the "buffer" is the return code. However, there might be subsequent output
   1332  *  stored in the converter object
   1333  * that will be returned in following calls to this function.
   1334  * @return a UChar32 resulting from the partial conversion of source
   1335  * @see ucnv_toUnicode
   1336  * @see ucnv_toUChars
   1337  * @see ucnv_convert
   1338  * @stable ICU 2.0
   1339  */
   1340 U_STABLE UChar32 U_EXPORT2
   1341 ucnv_getNextUChar(UConverter * converter,
   1342                   const char **source,
   1343                   const char * sourceLimit,
   1344                   UErrorCode * err);
   1345 
   1346 /**
   1347  * Convert from one external charset to another using two existing UConverters.
   1348  * Internally, two conversions - ucnv_toUnicode() and ucnv_fromUnicode() -
   1349  * are used, "pivoting" through 16-bit Unicode.
   1350  *
   1351  * Important: For streaming conversion (multiple function calls for successive
   1352  * parts of a text stream), the caller must provide a pivot buffer explicitly,
   1353  * and must preserve the pivot buffer and associated pointers from one
   1354  * call to another. (The buffer may be moved if its contents and the relative
   1355  * pointer positions are preserved.)
   1356  *
   1357  * There is a similar function, ucnv_convert(),
   1358  * which has the following limitations:
   1359  * - it takes charset names, not converter objects, so that
   1360  *   - two converters are opened for each call
   1361  *   - only single-string conversion is possible, not streaming operation
   1362  * - it does not provide enough information to find out,
   1363  *   in case of failure, whether the toUnicode or
   1364  *   the fromUnicode conversion failed
   1365  *
   1366  * By contrast, ucnv_convertEx()
   1367  * - takes UConverter parameters instead of charset names
   1368  * - fully exposes the pivot buffer for streaming conversion and complete error handling
   1369  *
   1370  * ucnv_convertEx() also provides further convenience:
   1371  * - an option to reset the converters at the beginning
   1372  *   (if reset==TRUE, see parameters;
   1373  *    also sets *pivotTarget=*pivotSource=pivotStart)
   1374  * - allow NUL-terminated input
   1375  *   (only a single NUL byte, will not work for charsets with multi-byte NULs)
   1376  *   (if sourceLimit==NULL, see parameters)
   1377  * - terminate with a NUL on output
   1378  *   (only a single NUL byte, not useful for charsets with multi-byte NULs),
   1379  *   or set U_STRING_NOT_TERMINATED_WARNING if the output exactly fills
   1380  *   the target buffer
   1381  * - the pivot buffer can be provided internally;
   1382  *   possible only for whole-string conversion, not streaming conversion;
   1383  *   in this case, the caller will not be able to get details about where an
   1384  *   error occurred
   1385  *   (if pivotStart==NULL, see below)
   1386  *
   1387  * The function returns when one of the following is true:
   1388  * - the entire source text has been converted successfully to the target buffer
   1389  * - a target buffer overflow occurred (U_BUFFER_OVERFLOW_ERROR)
   1390  * - a conversion error occurred
   1391  *   (other U_FAILURE(), see description of pErrorCode)
   1392  *
   1393  * Limitation compared to the direct use of
   1394  * ucnv_fromUnicode() and ucnv_toUnicode():
   1395  * ucnv_convertEx() does not provide offset information.
   1396  *
   1397  * Limitation compared to ucnv_fromUChars() and ucnv_toUChars():
   1398  * ucnv_convertEx() does not support preflighting directly.
   1399  *
   1400  * Sample code for converting a single string from
   1401  * one external charset to UTF-8, ignoring the location of errors:
   1402  *
   1403  * \code
   1404  * int32_t
   1405  * myToUTF8(UConverter *cnv,
   1406  *          const char *s, int32_t length,
   1407  *          char *u8, int32_t capacity,
   1408  *          UErrorCode *pErrorCode) {
   1409  *     UConverter *utf8Cnv;
   1410  *     char *target;
   1411  *
   1412  *     if(U_FAILURE(*pErrorCode)) {
   1413  *         return 0;
   1414  *     }
   1415  *
   1416  *     utf8Cnv=myGetCachedUTF8Converter(pErrorCode);
   1417  *     if(U_FAILURE(*pErrorCode)) {
   1418  *         return 0;
   1419  *     }
   1420  *
   1421  *     if(length<0) {
   1422  *         length=strlen(s);
   1423  *     }
   1424  *     target=u8;
   1425  *     ucnv_convertEx(utf8Cnv, cnv,
   1426  *                    &target, u8+capacity,
   1427  *                    &s, s+length,
   1428  *                    NULL, NULL, NULL, NULL,
   1429  *                    TRUE, TRUE,
   1430  *                    pErrorCode);
   1431  *
   1432  *     myReleaseCachedUTF8Converter(utf8Cnv);
   1433  *
   1434  *     // return the output string length, but without preflighting
   1435  *     return (int32_t)(target-u8);
   1436  * }
   1437  * \endcode
   1438  *
   1439  * @param targetCnv     Output converter, used to convert from the UTF-16 pivot
   1440  *                      to the target using ucnv_fromUnicode().
   1441  * @param sourceCnv     Input converter, used to convert from the source to
   1442  *                      the UTF-16 pivot using ucnv_toUnicode().
   1443  * @param target        I/O parameter, same as for ucnv_fromUChars().
   1444  *                      Input: *target points to the beginning of the target buffer.
   1445  *                      Output: *target points to the first unit after the last char written.
   1446  * @param targetLimit   Pointer to the first unit after the target buffer.
   1447  * @param source        I/O parameter, same as for ucnv_toUChars().
   1448  *                      Input: *source points to the beginning of the source buffer.
   1449  *                      Output: *source points to the first unit after the last char read.
   1450  * @param sourceLimit   Pointer to the first unit after the source buffer.
   1451  * @param pivotStart    Pointer to the UTF-16 pivot buffer. If pivotStart==NULL,
   1452  *                      then an internal buffer is used and the other pivot
   1453  *                      arguments are ignored and can be NULL as well.
   1454  * @param pivotSource   I/O parameter, same as source in ucnv_fromUChars() for
   1455  *                      conversion from the pivot buffer to the target buffer.
   1456  * @param pivotTarget   I/O parameter, same as target in ucnv_toUChars() for
   1457  *                      conversion from the source buffer to the pivot buffer.
   1458  *                      It must be pivotStart<=*pivotSource<=*pivotTarget<=pivotLimit
   1459  *                      and pivotStart<pivotLimit (unless pivotStart==NULL).
   1460  * @param pivotLimit    Pointer to the first unit after the pivot buffer.
   1461  * @param reset         If TRUE, then ucnv_resetToUnicode(sourceCnv) and
   1462  *                      ucnv_resetFromUnicode(targetCnv) are called, and the
   1463  *                      pivot pointers are reset (*pivotTarget=*pivotSource=pivotStart).
   1464  * @param flush         If true, indicates the end of the input.
   1465  *                      Passed directly to ucnv_toUnicode(), and carried over to
   1466  *                      ucnv_fromUnicode() when the source is empty as well.
   1467  * @param pErrorCode    ICU error code in/out parameter.
   1468  *                      Must fulfill U_SUCCESS before the function call.
   1469  *                      U_BUFFER_OVERFLOW_ERROR always refers to the target buffer
   1470  *                      because overflows into the pivot buffer are handled internally.
   1471  *                      Other conversion errors are from the source-to-pivot
   1472  *                      conversion if *pivotSource==pivotStart, otherwise from
   1473  *                      the pivot-to-target conversion.
   1474  *
   1475  * @see ucnv_convert
   1476  * @see ucnv_fromAlgorithmic
   1477  * @see ucnv_toAlgorithmic
   1478  * @see ucnv_fromUnicode
   1479  * @see ucnv_toUnicode
   1480  * @see ucnv_fromUChars
   1481  * @see ucnv_toUChars
   1482  * @stable ICU 2.6
   1483  */
   1484 U_STABLE void U_EXPORT2
   1485 ucnv_convertEx(UConverter *targetCnv, UConverter *sourceCnv,
   1486                char **target, const char *targetLimit,
   1487                const char **source, const char *sourceLimit,
   1488                UChar *pivotStart, UChar **pivotSource,
   1489                UChar **pivotTarget, const UChar *pivotLimit,
   1490                UBool reset, UBool flush,
   1491                UErrorCode *pErrorCode);
   1492 
   1493 /**
   1494  * Convert from one external charset to another.
   1495  * Internally, two converters are opened according to the name arguments,
   1496  * then the text is converted to and from the 16-bit Unicode "pivot"
   1497  * using ucnv_convertEx(), then the converters are closed again.
   1498  *
   1499  * This is a convenience function, not an efficient way to convert a lot of text:
   1500  * ucnv_convert()
   1501  * - takes charset names, not converter objects, so that
   1502  *   - two converters are opened for each call
   1503  *   - only single-string conversion is possible, not streaming operation
   1504  * - does not provide enough information to find out,
   1505  *   in case of failure, whether the toUnicode or
   1506  *   the fromUnicode conversion failed
   1507  * - allows NUL-terminated input
   1508  *   (only a single NUL byte, will not work for charsets with multi-byte NULs)
   1509  *   (if sourceLength==-1, see parameters)
   1510  * - terminate with a NUL on output
   1511  *   (only a single NUL byte, not useful for charsets with multi-byte NULs),
   1512  *   or set U_STRING_NOT_TERMINATED_WARNING if the output exactly fills
   1513  *   the target buffer
   1514  * - a pivot buffer is provided internally
   1515  *
   1516  * The function returns when one of the following is true:
   1517  * - the entire source text has been converted successfully to the target buffer
   1518  *   and either the target buffer is terminated with a single NUL byte
   1519  *   or the error code is set to U_STRING_NOT_TERMINATED_WARNING
   1520  * - a target buffer overflow occurred (U_BUFFER_OVERFLOW_ERROR)
   1521  *   and the full output string length is returned ("preflighting")
   1522  * - a conversion error occurred
   1523  *   (other U_FAILURE(), see description of pErrorCode)
   1524  *
   1525  * @param toConverterName   The name of the converter that is used to convert
   1526  *                          from the UTF-16 pivot buffer to the target.
   1527  * @param fromConverterName The name of the converter that is used to convert
   1528  *                          from the source to the UTF-16 pivot buffer.
   1529  * @param target            Pointer to the output buffer.
   1530  * @param targetCapacity    Capacity of the target, in bytes.
   1531  * @param source            Pointer to the input buffer.
   1532  * @param sourceLength      Length of the input text, in bytes, or -1 for NUL-terminated input.
   1533  * @param pErrorCode        ICU error code in/out parameter.
   1534  *                          Must fulfill U_SUCCESS before the function call.
   1535  * @return Length of the complete output text in bytes, even if it exceeds the targetCapacity
   1536  *         and a U_BUFFER_OVERFLOW_ERROR is set.
   1537  *
   1538  * @see ucnv_convertEx
   1539  * @see ucnv_fromAlgorithmic
   1540  * @see ucnv_toAlgorithmic
   1541  * @see ucnv_fromUnicode
   1542  * @see ucnv_toUnicode
   1543  * @see ucnv_fromUChars
   1544  * @see ucnv_toUChars
   1545  * @see ucnv_getNextUChar
   1546  * @stable ICU 2.0
   1547  */
   1548 U_STABLE int32_t U_EXPORT2
   1549 ucnv_convert(const char *toConverterName,
   1550              const char *fromConverterName,
   1551              char *target,
   1552              int32_t targetCapacity,
   1553              const char *source,
   1554              int32_t sourceLength,
   1555              UErrorCode *pErrorCode);
   1556 
   1557 /**
   1558  * Convert from one external charset to another.
   1559  * Internally, the text is converted to and from the 16-bit Unicode "pivot"
   1560  * using ucnv_convertEx(). ucnv_toAlgorithmic() works exactly like ucnv_convert()
   1561  * except that the two converters need not be looked up and opened completely.
   1562  *
   1563  * The source-to-pivot conversion uses the cnv converter parameter.
   1564  * The pivot-to-target conversion uses a purely algorithmic converter
   1565  * according to the specified type, e.g., UCNV_UTF8 for a UTF-8 converter.
   1566  *
   1567  * Internally, the algorithmic converter is opened and closed for each
   1568  * function call, which is more efficient than using the public ucnv_open()
   1569  * but somewhat less efficient than only resetting an existing converter
   1570  * and using ucnv_convertEx().
   1571  *
   1572  * This function is more convenient than ucnv_convertEx() for single-string
   1573  * conversions, especially when "preflighting" is desired (returning the length
   1574  * of the complete output even if it does not fit into the target buffer;
   1575  * see the User Guide Strings chapter). See ucnv_convert() for details.
   1576  *
   1577  * @param algorithmicType   UConverterType constant identifying the desired target
   1578  *                          charset as a purely algorithmic converter.
   1579  *                          Those are converters for Unicode charsets like
   1580  *                          UTF-8, BOCU-1, SCSU, UTF-7, IMAP-mailbox-name, etc.,
   1581  *                          as well as US-ASCII and ISO-8859-1.
   1582  * @param cnv               The converter that is used to convert
   1583  *                          from the source to the UTF-16 pivot buffer.
   1584  * @param target            Pointer to the output buffer.
   1585  * @param targetCapacity    Capacity of the target, in bytes.
   1586  * @param source            Pointer to the input buffer.
   1587  * @param sourceLength      Length of the input text, in bytes
   1588  * @param pErrorCode        ICU error code in/out parameter.
   1589  *                          Must fulfill U_SUCCESS before the function call.
   1590  * @return Length of the complete output text in bytes, even if it exceeds the targetCapacity
   1591  *         and a U_BUFFER_OVERFLOW_ERROR is set.
   1592  *
   1593  * @see ucnv_fromAlgorithmic
   1594  * @see ucnv_convert
   1595  * @see ucnv_convertEx
   1596  * @see ucnv_fromUnicode
   1597  * @see ucnv_toUnicode
   1598  * @see ucnv_fromUChars
   1599  * @see ucnv_toUChars
   1600  * @stable ICU 2.6
   1601  */
   1602 U_STABLE int32_t U_EXPORT2
   1603 ucnv_toAlgorithmic(UConverterType algorithmicType,
   1604                    UConverter *cnv,
   1605                    char *target, int32_t targetCapacity,
   1606                    const char *source, int32_t sourceLength,
   1607                    UErrorCode *pErrorCode);
   1608 
   1609 /**
   1610  * Convert from one external charset to another.
   1611  * Internally, the text is converted to and from the 16-bit Unicode "pivot"
   1612  * using ucnv_convertEx(). ucnv_fromAlgorithmic() works exactly like ucnv_convert()
   1613  * except that the two converters need not be looked up and opened completely.
   1614  *
   1615  * The source-to-pivot conversion uses a purely algorithmic converter
   1616  * according to the specified type, e.g., UCNV_UTF8 for a UTF-8 converter.
   1617  * The pivot-to-target conversion uses the cnv converter parameter.
   1618  *
   1619  * Internally, the algorithmic converter is opened and closed for each
   1620  * function call, which is more efficient than using the public ucnv_open()
   1621  * but somewhat less efficient than only resetting an existing converter
   1622  * and using ucnv_convertEx().
   1623  *
   1624  * This function is more convenient than ucnv_convertEx() for single-string
   1625  * conversions, especially when "preflighting" is desired (returning the length
   1626  * of the complete output even if it does not fit into the target buffer;
   1627  * see the User Guide Strings chapter). See ucnv_convert() for details.
   1628  *
   1629  * @param cnv               The converter that is used to convert
   1630  *                          from the UTF-16 pivot buffer to the target.
   1631  * @param algorithmicType   UConverterType constant identifying the desired source
   1632  *                          charset as a purely algorithmic converter.
   1633  *                          Those are converters for Unicode charsets like
   1634  *                          UTF-8, BOCU-1, SCSU, UTF-7, IMAP-mailbox-name, etc.,
   1635  *                          as well as US-ASCII and ISO-8859-1.
   1636  * @param target            Pointer to the output buffer.
   1637  * @param targetCapacity    Capacity of the target, in bytes.
   1638  * @param source            Pointer to the input buffer.
   1639  * @param sourceLength      Length of the input text, in bytes
   1640  * @param pErrorCode        ICU error code in/out parameter.
   1641  *                          Must fulfill U_SUCCESS before the function call.
   1642  * @return Length of the complete output text in bytes, even if it exceeds the targetCapacity
   1643  *         and a U_BUFFER_OVERFLOW_ERROR is set.
   1644  *
   1645  * @see ucnv_fromAlgorithmic
   1646  * @see ucnv_convert
   1647  * @see ucnv_convertEx
   1648  * @see ucnv_fromUnicode
   1649  * @see ucnv_toUnicode
   1650  * @see ucnv_fromUChars
   1651  * @see ucnv_toUChars
   1652  * @stable ICU 2.6
   1653  */
   1654 U_STABLE int32_t U_EXPORT2
   1655 ucnv_fromAlgorithmic(UConverter *cnv,
   1656                      UConverterType algorithmicType,
   1657                      char *target, int32_t targetCapacity,
   1658                      const char *source, int32_t sourceLength,
   1659                      UErrorCode *pErrorCode);
   1660 
   1661 /**
   1662  * Frees up memory occupied by unused, cached converter shared data.
   1663  *
   1664  * @return the number of cached converters successfully deleted
   1665  * @see ucnv_close
   1666  * @stable ICU 2.0
   1667  */
   1668 U_STABLE int32_t U_EXPORT2
   1669 ucnv_flushCache(void);
   1670 
   1671 /**
   1672  * Returns the number of available converters, as per the alias file.
   1673  *
   1674  * @return the number of available converters
   1675  * @see ucnv_getAvailableName
   1676  * @stable ICU 2.0
   1677  */
   1678 U_STABLE int32_t U_EXPORT2
   1679 ucnv_countAvailable(void);
   1680 
   1681 /**
   1682  * Gets the canonical converter name of the specified converter from a list of
   1683  * all available converters contaied in the alias file. All converters
   1684  * in this list can be opened.
   1685  *
   1686  * @param n the index to a converter available on the system (in the range <TT>[0..ucnv_countAvaiable()]</TT>)
   1687  * @return a pointer a string (library owned), or <TT>NULL</TT> if the index is out of bounds.
   1688  * @see ucnv_countAvailable
   1689  * @stable ICU 2.0
   1690  */
   1691 U_STABLE const char* U_EXPORT2
   1692 ucnv_getAvailableName(int32_t n);
   1693 
   1694 /**
   1695  * Returns a UEnumeration to enumerate all of the canonical converter
   1696  * names, as per the alias file, regardless of the ability to open each
   1697  * converter.
   1698  *
   1699  * @return A UEnumeration object for getting all the recognized canonical
   1700  *   converter names.
   1701  * @see ucnv_getAvailableName
   1702  * @see uenum_close
   1703  * @see uenum_next
   1704  * @stable ICU 2.4
   1705  */
   1706 U_STABLE UEnumeration * U_EXPORT2
   1707 ucnv_openAllNames(UErrorCode *pErrorCode);
   1708 
   1709 /**
   1710  * Gives the number of aliases for a given converter or alias name.
   1711  * If the alias is ambiguous, then the preferred converter is used
   1712  * and the status is set to U_AMBIGUOUS_ALIAS_WARNING.
   1713  * This method only enumerates the listed entries in the alias file.
   1714  * @param alias alias name
   1715  * @param pErrorCode error status
   1716  * @return number of names on alias list for given alias
   1717  * @stable ICU 2.0
   1718  */
   1719 U_STABLE uint16_t U_EXPORT2
   1720 ucnv_countAliases(const char *alias, UErrorCode *pErrorCode);
   1721 
   1722 /**
   1723  * Gives the name of the alias at given index of alias list.
   1724  * This method only enumerates the listed entries in the alias file.
   1725  * If the alias is ambiguous, then the preferred converter is used
   1726  * and the status is set to U_AMBIGUOUS_ALIAS_WARNING.
   1727  * @param alias alias name
   1728  * @param n index in alias list
   1729  * @param pErrorCode result of operation
   1730  * @return returns the name of the alias at given index
   1731  * @see ucnv_countAliases
   1732  * @stable ICU 2.0
   1733  */
   1734 U_STABLE const char * U_EXPORT2
   1735 ucnv_getAlias(const char *alias, uint16_t n, UErrorCode *pErrorCode);
   1736 
   1737 /**
   1738  * Fill-up the list of alias names for the given alias.
   1739  * This method only enumerates the listed entries in the alias file.
   1740  * If the alias is ambiguous, then the preferred converter is used
   1741  * and the status is set to U_AMBIGUOUS_ALIAS_WARNING.
   1742  * @param alias alias name
   1743  * @param aliases fill-in list, aliases is a pointer to an array of
   1744  *        <code>ucnv_countAliases()</code> string-pointers
   1745  *        (<code>const char *</code>) that will be filled in.
   1746  *        The strings themselves are owned by the library.
   1747  * @param pErrorCode result of operation
   1748  * @stable ICU 2.0
   1749  */
   1750 U_STABLE void U_EXPORT2
   1751 ucnv_getAliases(const char *alias, const char **aliases, UErrorCode *pErrorCode);
   1752 
   1753 /**
   1754  * Return a new UEnumeration object for enumerating all the
   1755  * alias names for a given converter that are recognized by a standard.
   1756  * This method only enumerates the listed entries in the alias file.
   1757  * The convrtrs.txt file can be modified to change the results of
   1758  * this function.
   1759  * The first result in this list is the same result given by
   1760  * <code>ucnv_getStandardName</code>, which is the default alias for
   1761  * the specified standard name. The returned object must be closed with
   1762  * <code>uenum_close</code> when you are done with the object.
   1763  *
   1764  * @param convName original converter name
   1765  * @param standard name of the standard governing the names; MIME and IANA
   1766  *      are such standards
   1767  * @param pErrorCode The error code
   1768  * @return A UEnumeration object for getting all aliases that are recognized
   1769  *      by a standard. If any of the parameters are invalid, NULL
   1770  *      is returned.
   1771  * @see ucnv_getStandardName
   1772  * @see uenum_close
   1773  * @see uenum_next
   1774  * @stable ICU 2.2
   1775  */
   1776 U_STABLE UEnumeration * U_EXPORT2
   1777 ucnv_openStandardNames(const char *convName,
   1778                        const char *standard,
   1779                        UErrorCode *pErrorCode);
   1780 
   1781 /**
   1782  * Gives the number of standards associated to converter names.
   1783  * @return number of standards
   1784  * @stable ICU 2.0
   1785  */
   1786 U_STABLE uint16_t U_EXPORT2
   1787 ucnv_countStandards(void);
   1788 
   1789 /**
   1790  * Gives the name of the standard at given index of standard list.
   1791  * @param n index in standard list
   1792  * @param pErrorCode result of operation
   1793  * @return returns the name of the standard at given index. Owned by the library.
   1794  * @stable ICU 2.0
   1795  */
   1796 U_STABLE const char * U_EXPORT2
   1797 ucnv_getStandard(uint16_t n, UErrorCode *pErrorCode);
   1798 
   1799 /**
   1800  * Returns a standard name for a given converter name.
   1801  * <p>
   1802  * Example alias table:<br>
   1803  * conv alias1 { STANDARD1 } alias2 { STANDARD1* }
   1804  * <p>
   1805  * Result of ucnv_getStandardName("conv", "STANDARD1") from example
   1806  * alias table:<br>
   1807  * <b>"alias2"</b>
   1808  *
   1809  * @param name original converter name
   1810  * @param standard name of the standard governing the names; MIME and IANA
   1811  *        are such standards
   1812  * @param pErrorCode result of operation
   1813  * @return returns the standard converter name;
   1814  *         if a standard converter name cannot be determined,
   1815  *         then <code>NULL</code> is returned. Owned by the library.
   1816  * @stable ICU 2.0
   1817  */
   1818 U_STABLE const char * U_EXPORT2
   1819 ucnv_getStandardName(const char *name, const char *standard, UErrorCode *pErrorCode);
   1820 
   1821 /**
   1822  * This function will return the internal canonical converter name of the
   1823  * tagged alias. This is the opposite of ucnv_openStandardNames, which
   1824  * returns the tagged alias given the canonical name.
   1825  * <p>
   1826  * Example alias table:<br>
   1827  * conv alias1 { STANDARD1 } alias2 { STANDARD1* }
   1828  * <p>
   1829  * Result of ucnv_getStandardName("alias1", "STANDARD1") from example
   1830  * alias table:<br>
   1831  * <b>"conv"</b>
   1832  *
   1833  * @return returns the canonical converter name;
   1834  *         if a standard or alias name cannot be determined,
   1835  *         then <code>NULL</code> is returned. The returned string is
   1836  *         owned by the library.
   1837  * @see ucnv_getStandardName
   1838  * @stable ICU 2.4
   1839  */
   1840 U_STABLE const char * U_EXPORT2
   1841 ucnv_getCanonicalName(const char *alias, const char *standard, UErrorCode *pErrorCode);
   1842 
   1843 /**
   1844  * Returns the current default converter name. If you want to open
   1845  * a default converter, you do not need to use this function.
   1846  * It is faster if you pass a NULL argument to ucnv_open the
   1847  * default converter.
   1848  *
   1849  * If U_CHARSET_IS_UTF8 is defined to 1 in utypes.h then this function
   1850  * always returns "UTF-8".
   1851  *
   1852  * @return returns the current default converter name.
   1853  *         Storage owned by the library
   1854  * @see ucnv_setDefaultName
   1855  * @stable ICU 2.0
   1856  */
   1857 U_STABLE const char * U_EXPORT2
   1858 ucnv_getDefaultName(void);
   1859 
   1860 /**
   1861  * This function is not thread safe. DO NOT call this function when ANY ICU
   1862  * function is being used from more than one thread! This function sets the
   1863  * current default converter name. If this function needs to be called, it
   1864  * should be called during application initialization. Most of the time, the
   1865  * results from ucnv_getDefaultName() or ucnv_open with a NULL string argument
   1866  * is sufficient for your application.
   1867  *
   1868  * If U_CHARSET_IS_UTF8 is defined to 1 in utypes.h then this function
   1869  * does nothing.
   1870  *
   1871  * @param name the converter name to be the default (must be known by ICU).
   1872  * @see ucnv_getDefaultName
   1873  * @system
   1874  * @stable ICU 2.0
   1875  */
   1876 U_STABLE void U_EXPORT2
   1877 ucnv_setDefaultName(const char *name);
   1878 
   1879 /**
   1880  * Fixes the backslash character mismapping.  For example, in SJIS, the backslash
   1881  * character in the ASCII portion is also used to represent the yen currency sign.
   1882  * When mapping from Unicode character 0x005C, it's unclear whether to map the
   1883  * character back to yen or backslash in SJIS.  This function will take the input
   1884  * buffer and replace all the yen sign characters with backslash.  This is necessary
   1885  * when the user tries to open a file with the input buffer on Windows.
   1886  * This function will test the converter to see whether such mapping is
   1887  * required.  You can sometimes avoid using this function by using the correct version
   1888  * of Shift-JIS.
   1889  *
   1890  * @param cnv The converter representing the target codepage.
   1891  * @param source the input buffer to be fixed
   1892  * @param sourceLen the length of the input buffer
   1893  * @see ucnv_isAmbiguous
   1894  * @stable ICU 2.0
   1895  */
   1896 U_STABLE void U_EXPORT2
   1897 ucnv_fixFileSeparator(const UConverter *cnv, UChar *source, int32_t sourceLen);
   1898 
   1899 /**
   1900  * Determines if the converter contains ambiguous mappings of the same
   1901  * character or not.
   1902  * @param cnv the converter to be tested
   1903  * @return TRUE if the converter contains ambiguous mapping of the same
   1904  * character, FALSE otherwise.
   1905  * @stable ICU 2.0
   1906  */
   1907 U_STABLE UBool U_EXPORT2
   1908 ucnv_isAmbiguous(const UConverter *cnv);
   1909 
   1910 /**
   1911  * Sets the converter to use fallback mappings or not.
   1912  * Regardless of this flag, the converter will always use
   1913  * fallbacks from Unicode Private Use code points, as well as
   1914  * reverse fallbacks (to Unicode).
   1915  * For details see ".ucm File Format"
   1916  * in the Conversion Data chapter of the ICU User Guide:
   1917  * http://www.icu-project.org/userguide/conversion-data.html#ucmformat
   1918  *
   1919  * @param cnv The converter to set the fallback mapping usage on.
   1920  * @param usesFallback TRUE if the user wants the converter to take advantage of the fallback
   1921  * mapping, FALSE otherwise.
   1922  * @stable ICU 2.0
   1923  * @see ucnv_usesFallback
   1924  */
   1925 U_STABLE void U_EXPORT2
   1926 ucnv_setFallback(UConverter *cnv, UBool usesFallback);
   1927 
   1928 /**
   1929  * Determines if the converter uses fallback mappings or not.
   1930  * This flag has restrictions, see ucnv_setFallback().
   1931  *
   1932  * @param cnv The converter to be tested
   1933  * @return TRUE if the converter uses fallback, FALSE otherwise.
   1934  * @stable ICU 2.0
   1935  * @see ucnv_setFallback
   1936  */
   1937 U_STABLE UBool U_EXPORT2
   1938 ucnv_usesFallback(const UConverter *cnv);
   1939 
   1940 /**
   1941  * Detects Unicode signature byte sequences at the start of the byte stream
   1942  * and returns the charset name of the indicated Unicode charset.
   1943  * NULL is returned when no Unicode signature is recognized.
   1944  * The number of bytes in the signature is output as well.
   1945  *
   1946  * The caller can ucnv_open() a converter using the charset name.
   1947  * The first code unit (UChar) from the start of the stream will be U+FEFF
   1948  * (the Unicode BOM/signature character) and can usually be ignored.
   1949  *
   1950  * For most Unicode charsets it is also possible to ignore the indicated
   1951  * number of initial stream bytes and start converting after them.
   1952  * However, there are stateful Unicode charsets (UTF-7 and BOCU-1) for which
   1953  * this will not work. Therefore, it is best to ignore the first output UChar
   1954  * instead of the input signature bytes.
   1955  * <p>
   1956  * Usage:
   1957  * @code
   1958  *      UErrorCode err = U_ZERO_ERROR;
   1959  *      char input[] = { '\xEF','\xBB', '\xBF','\x41','\x42','\x43' };
   1960  *      int32_t signatureLength = 0;
   1961  *      char *encoding = ucnv_detectUnicodeSignature(input,sizeof(input),&signatureLength,&err);
   1962  *      UConverter *conv = NULL;
   1963  *      UChar output[100];
   1964  *      UChar *target = output, *out;
   1965  *      char *source = input;
   1966  *      if(encoding!=NULL && U_SUCCESS(err)){
   1967  *          // should signature be discarded ?
   1968  *          conv = ucnv_open(encoding, &err);
   1969  *          // do the conversion
   1970  *          ucnv_toUnicode(conv,
   1971  *                         target, output + sizeof(output)/U_SIZEOF_UCHAR,
   1972  *                         source, input + sizeof(input),
   1973  *                         NULL, TRUE, &err);
   1974  *          out = output;
   1975  *          if (discardSignature){
   1976  *              ++out; // ignore initial U+FEFF
   1977  *          }
   1978  *          while(out != target) {
   1979  *              printf("%04x ", *out++);
   1980  *          }
   1981  *          puts("");
   1982  *      }
   1983  *
   1984  * @endcode
   1985  *
   1986  * @param source            The source string in which the signature should be detected.
   1987  * @param sourceLength      Length of the input string, or -1 if terminated with a NUL byte.
   1988  * @param signatureLength   A pointer to int32_t to receive the number of bytes that make up the signature
   1989  *                          of the detected UTF. 0 if not detected.
   1990  *                          Can be a NULL pointer.
   1991  * @param pErrorCode        ICU error code in/out parameter.
   1992  *                          Must fulfill U_SUCCESS before the function call.
   1993  * @return The name of the encoding detected. NULL if encoding is not detected.
   1994  * @stable ICU 2.4
   1995  */
   1996 U_STABLE const char* U_EXPORT2
   1997 ucnv_detectUnicodeSignature(const char* source,
   1998                             int32_t sourceLength,
   1999                             int32_t *signatureLength,
   2000                             UErrorCode *pErrorCode);
   2001 
   2002 /**
   2003  * Returns the number of UChars held in the converter's internal state
   2004  * because more input is needed for completing the conversion. This function is
   2005  * useful for mapping semantics of ICU's converter interface to those of iconv,
   2006  * and this information is not needed for normal conversion.
   2007  * @param cnv       The converter in which the input is held
   2008  * @param status    ICU error code in/out parameter.
   2009  *                  Must fulfill U_SUCCESS before the function call.
   2010  * @return The number of UChars in the state. -1 if an error is encountered.
   2011  * @stable ICU 3.4
   2012  */
   2013 U_STABLE int32_t U_EXPORT2
   2014 ucnv_fromUCountPending(const UConverter* cnv, UErrorCode* status);
   2015 
   2016 /**
   2017  * Returns the number of chars held in the converter's internal state
   2018  * because more input is needed for completing the conversion. This function is
   2019  * useful for mapping semantics of ICU's converter interface to those of iconv,
   2020  * and this information is not needed for normal conversion.
   2021  * @param cnv       The converter in which the input is held as internal state
   2022  * @param status    ICU error code in/out parameter.
   2023  *                  Must fulfill U_SUCCESS before the function call.
   2024  * @return The number of chars in the state. -1 if an error is encountered.
   2025  * @stable ICU 3.4
   2026  */
   2027 U_STABLE int32_t U_EXPORT2
   2028 ucnv_toUCountPending(const UConverter* cnv, UErrorCode* status);
   2029 
   2030 /**
   2031  * Returns whether or not the charset of the converter has a fixed number of bytes
   2032  * per charset character.
   2033  * An example of this are converters that are of the type UCNV_SBCS or UCNV_DBCS.
   2034  * Another example is UTF-32 which is always 4 bytes per character.
   2035  * A Unicode code point may be represented by more than one UTF-8 or UTF-16 code unit
   2036  * but a UTF-32 converter encodes each code point with 4 bytes.
   2037  * Note: This method is not intended to be used to determine whether the charset has a
   2038  * fixed ratio of bytes to Unicode codes <i>units</i> for any particular Unicode encoding form.
   2039  * FALSE is returned with the UErrorCode if error occurs or cnv is NULL.
   2040  * @param cnv       The converter to be tested
   2041  * @param status    ICU error code in/out paramter
   2042  * @return TRUE if the converter is fixed-width
   2043  * @draft ICU 4.8
   2044  */
   2045 U_DRAFT UBool U_EXPORT2
   2046 ucnv_isFixedWidth(UConverter *cnv, UErrorCode *status);
   2047 
   2048 #endif
   2049 
   2050 #endif
   2051 /*_UCNV*/
   2052