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