Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/unicode/ucnv.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // © 2016 and later: Unicode, Inc. and others.
0002 // License & terms of use: http://www.unicode.org/copyright.html
0003 /*
0004 **********************************************************************
0005 *   Copyright (C) 1999-2014, International Business Machines
0006 *   Corporation and others.  All Rights Reserved.
0007 **********************************************************************
0008  *  ucnv.h:
0009  *  External APIs for the ICU's codeset conversion library
0010  *  Bertrand A. Damiba
0011  *
0012  * Modification History:
0013  *
0014  *   Date        Name        Description
0015  *   04/04/99    helena      Fixed internal header inclusion.
0016  *   05/11/00    helena      Added setFallback and usesFallback APIs.
0017  *   06/29/2000  helena      Major rewrite of the callback APIs.
0018  *   12/07/2000  srl         Update of documentation
0019  */
0020 
0021 /**
0022  * \file
0023  * \brief C API: Character conversion
0024  *
0025  * <h2>Character Conversion C API</h2>
0026  *
0027  * <p>This API is used to convert codepage or character encoded data to and
0028  * from UTF-16. You can open a converter with {@link ucnv_open() }. With that
0029  * converter, you can get its properties, set options, convert your data and
0030  * close the converter.</p>
0031  *
0032  * <p>Since many software programs recognize different converter names for
0033  * different types of converters, there are other functions in this API to
0034  * iterate over the converter aliases. The functions {@link ucnv_getAvailableName() },
0035  * {@link ucnv_getAlias() } and {@link ucnv_getStandardName() } are some of the
0036  * more frequently used alias functions to get this information.</p>
0037  *
0038  * <p>When a converter encounters an illegal, irregular, invalid or unmappable character
0039  * its default behavior is to use a substitution character to replace the
0040  * bad byte sequence. This behavior can be changed by using {@link ucnv_setFromUCallBack() }
0041  * or {@link ucnv_setToUCallBack() } on the converter. The header ucnv_err.h defines
0042  * many other callback actions that can be used instead of a character substitution.</p>
0043  *
0044  * <p>More information about this API can be found in our
0045  * <a href="https://unicode-org.github.io/icu/userguide/conversion/">User Guide</a>.</p>
0046  */
0047 
0048 #ifndef UCNV_H
0049 #define UCNV_H
0050 
0051 #include "unicode/ucnv_err.h"
0052 #include "unicode/uenum.h"
0053 
0054 #if U_SHOW_CPLUSPLUS_API
0055 #include "unicode/localpointer.h"
0056 #endif   // U_SHOW_CPLUSPLUS_API
0057 
0058 #if !defined(USET_DEFINED) && !defined(U_IN_DOXYGEN)
0059 
0060 #define USET_DEFINED
0061 
0062 /**
0063  * USet is the C API type corresponding to C++ class UnicodeSet.
0064  * It is forward-declared here to avoid including unicode/uset.h file if related
0065  * conversion APIs are not used.
0066  *
0067  * @see ucnv_getUnicodeSet
0068  * @stable ICU 2.4
0069  */
0070 typedef struct USet USet;
0071 
0072 #endif
0073 
0074 #if !UCONFIG_NO_CONVERSION
0075 
0076 U_CDECL_BEGIN
0077 
0078 /** Maximum length of a converter name including the terminating NULL @stable ICU 2.0 */
0079 #define UCNV_MAX_CONVERTER_NAME_LENGTH 60
0080 /** Maximum length of a converter name including path and terminating NULL @stable ICU 2.0 */
0081 #define UCNV_MAX_FULL_FILE_NAME_LENGTH (600+UCNV_MAX_CONVERTER_NAME_LENGTH)
0082 
0083 /** Shift in for EBDCDIC_STATEFUL and iso2022 states @stable ICU 2.0 */
0084 #define  UCNV_SI 0x0F
0085 /** Shift out for EBDCDIC_STATEFUL and iso2022 states @stable ICU 2.0 */
0086 #define  UCNV_SO 0x0E
0087 
0088 /**
0089  * Enum for specifying basic types of converters
0090  * @see ucnv_getType
0091  * @stable ICU 2.0
0092  */
0093 typedef enum {
0094     /** @stable ICU 2.0 */
0095     UCNV_UNSUPPORTED_CONVERTER = -1,
0096     /** @stable ICU 2.0 */
0097     UCNV_SBCS = 0,
0098     /** @stable ICU 2.0 */
0099     UCNV_DBCS = 1,
0100     /** @stable ICU 2.0 */
0101     UCNV_MBCS = 2,
0102     /** @stable ICU 2.0 */
0103     UCNV_LATIN_1 = 3,
0104     /** @stable ICU 2.0 */
0105     UCNV_UTF8 = 4,
0106     /** @stable ICU 2.0 */
0107     UCNV_UTF16_BigEndian = 5,
0108     /** @stable ICU 2.0 */
0109     UCNV_UTF16_LittleEndian = 6,
0110     /** @stable ICU 2.0 */
0111     UCNV_UTF32_BigEndian = 7,
0112     /** @stable ICU 2.0 */
0113     UCNV_UTF32_LittleEndian = 8,
0114     /** @stable ICU 2.0 */
0115     UCNV_EBCDIC_STATEFUL = 9,
0116     /** @stable ICU 2.0 */
0117     UCNV_ISO_2022 = 10,
0118 
0119     /** @stable ICU 2.0 */
0120     UCNV_LMBCS_1 = 11,
0121     /** @stable ICU 2.0 */
0122     UCNV_LMBCS_2,
0123     /** @stable ICU 2.0 */
0124     UCNV_LMBCS_3,
0125     /** @stable ICU 2.0 */
0126     UCNV_LMBCS_4,
0127     /** @stable ICU 2.0 */
0128     UCNV_LMBCS_5,
0129     /** @stable ICU 2.0 */
0130     UCNV_LMBCS_6,
0131     /** @stable ICU 2.0 */
0132     UCNV_LMBCS_8,
0133     /** @stable ICU 2.0 */
0134     UCNV_LMBCS_11,
0135     /** @stable ICU 2.0 */
0136     UCNV_LMBCS_16,
0137     /** @stable ICU 2.0 */
0138     UCNV_LMBCS_17,
0139     /** @stable ICU 2.0 */
0140     UCNV_LMBCS_18,
0141     /** @stable ICU 2.0 */
0142     UCNV_LMBCS_19,
0143     /** @stable ICU 2.0 */
0144     UCNV_LMBCS_LAST = UCNV_LMBCS_19,
0145     /** @stable ICU 2.0 */
0146     UCNV_HZ,
0147     /** @stable ICU 2.0 */
0148     UCNV_SCSU,
0149     /** @stable ICU 2.0 */
0150     UCNV_ISCII,
0151     /** @stable ICU 2.0 */
0152     UCNV_US_ASCII,
0153     /** @stable ICU 2.0 */
0154     UCNV_UTF7,
0155     /** @stable ICU 2.2 */
0156     UCNV_BOCU1,
0157     /** @stable ICU 2.2 */
0158     UCNV_UTF16,
0159     /** @stable ICU 2.2 */
0160     UCNV_UTF32,
0161     /** @stable ICU 2.2 */
0162     UCNV_CESU8,
0163     /** @stable ICU 2.4 */
0164     UCNV_IMAP_MAILBOX,
0165     /** @stable ICU 4.8 */
0166     UCNV_COMPOUND_TEXT,
0167 
0168     /* Number of converter types for which we have conversion routines. */
0169     UCNV_NUMBER_OF_SUPPORTED_CONVERTER_TYPES
0170 } UConverterType;
0171 
0172 /**
0173  * Enum for specifying which platform a converter ID refers to.
0174  * The use of platform/CCSID is not recommended. See ucnv_openCCSID().
0175  *
0176  * @see ucnv_getPlatform
0177  * @see ucnv_openCCSID
0178  * @see ucnv_getCCSID
0179  * @stable ICU 2.0
0180  */
0181 typedef enum {
0182     UCNV_UNKNOWN = -1,
0183     UCNV_IBM = 0
0184 } UConverterPlatform;
0185 
0186 /**
0187  * Function pointer for error callback in the codepage to unicode direction.
0188  * Called when an error has occurred in conversion to unicode, or on open/close of the callback (see reason).
0189  * @param context Pointer to the callback's private data
0190  * @param args Information about the conversion in progress
0191  * @param codeUnits Points to 'length' bytes of the concerned codepage sequence
0192  * @param length Size (in bytes) of the concerned codepage sequence
0193  * @param reason Defines the reason the callback was invoked
0194  * @param pErrorCode    ICU error code in/out parameter.
0195  *                      For converter callback functions, set to a conversion error
0196  *                      before the call, and the callback may reset it to U_ZERO_ERROR.
0197  * @see ucnv_setToUCallBack
0198  * @see UConverterToUnicodeArgs
0199  * @stable ICU 2.0
0200  */
0201 typedef void (U_EXPORT2 *UConverterToUCallback) (
0202                   const void* context,
0203                   UConverterToUnicodeArgs *args,
0204                   const char *codeUnits,
0205                   int32_t length,
0206                   UConverterCallbackReason reason,
0207                   UErrorCode *pErrorCode);
0208 
0209 /**
0210  * Function pointer for error callback in the unicode to codepage direction.
0211  * Called when an error has occurred in conversion from unicode, or on open/close of the callback (see reason).
0212  * @param context Pointer to the callback's private data
0213  * @param args Information about the conversion in progress
0214  * @param codeUnits Points to 'length' UChars of the concerned Unicode sequence
0215  * @param length Size (in bytes) of the concerned codepage sequence
0216  * @param codePoint Single UChar32 (UTF-32) containing the concerend Unicode codepoint.
0217  * @param reason Defines the reason the callback was invoked
0218  * @param pErrorCode    ICU error code in/out parameter.
0219  *                      For converter callback functions, set to a conversion error
0220  *                      before the call, and the callback may reset it to U_ZERO_ERROR.
0221  * @see ucnv_setFromUCallBack
0222  * @stable ICU 2.0
0223  */
0224 typedef void (U_EXPORT2 *UConverterFromUCallback) (
0225                     const void* context,
0226                     UConverterFromUnicodeArgs *args,
0227                     const UChar* codeUnits,
0228                     int32_t length,
0229                     UChar32 codePoint,
0230                     UConverterCallbackReason reason,
0231                     UErrorCode *pErrorCode);
0232 
0233 U_CDECL_END
0234 
0235 /**
0236  * Character that separates converter names from options and options from each other.
0237  * @see ucnv_open
0238  * @stable ICU 2.0
0239  */
0240 #define UCNV_OPTION_SEP_CHAR ','
0241 
0242 /**
0243  * String version of UCNV_OPTION_SEP_CHAR.
0244  * @see ucnv_open
0245  * @stable ICU 2.0
0246  */
0247 #define UCNV_OPTION_SEP_STRING ","
0248 
0249 /**
0250  * Character that separates a converter option from its value.
0251  * @see ucnv_open
0252  * @stable ICU 2.0
0253  */
0254 #define UCNV_VALUE_SEP_CHAR '='
0255 
0256 /**
0257  * String version of UCNV_VALUE_SEP_CHAR.
0258  * @see ucnv_open
0259  * @stable ICU 2.0
0260  */
0261 #define UCNV_VALUE_SEP_STRING "="
0262 
0263 /**
0264  * Converter option for specifying a locale.
0265  * For example, ucnv_open("SCSU,locale=ja", &errorCode);
0266  * See convrtrs.txt.
0267  *
0268  * @see ucnv_open
0269  * @stable ICU 2.0
0270  */
0271 #define UCNV_LOCALE_OPTION_STRING ",locale="
0272 
0273 /**
0274  * Converter option for specifying a version selector (0..9) for some converters.
0275  * For example,
0276  * \code
0277  *   ucnv_open("UTF-7,version=1", &errorCode);
0278  * \endcode
0279  * See convrtrs.txt.
0280  *
0281  * @see ucnv_open
0282  * @stable ICU 2.4
0283  */
0284 #define UCNV_VERSION_OPTION_STRING ",version="
0285 
0286 /**
0287  * Converter option for EBCDIC SBCS or mixed-SBCS/DBCS (stateful) codepages.
0288  * Swaps Unicode mappings for EBCDIC LF and NL codes, as used on
0289  * S/390 (z/OS) Unix System Services (Open Edition).
0290  * For example, ucnv_open("ibm-1047,swaplfnl", &errorCode);
0291  * See convrtrs.txt.
0292  *
0293  * @see ucnv_open
0294  * @stable ICU 2.4
0295  */
0296 #define UCNV_SWAP_LFNL_OPTION_STRING ",swaplfnl"
0297 
0298 /**
0299  * Do a fuzzy compare of two converter/alias names.
0300  * The comparison is case-insensitive, ignores leading zeroes if they are not
0301  * followed by further digits, and ignores all but letters and digits.
0302  * Thus the strings "UTF-8", "utf_8", "u*T@f08" and "Utf 8" are exactly equivalent.
0303  * See section 1.4, Charset Alias Matching in Unicode Technical Standard #22
0304  * at http://www.unicode.org/reports/tr22/
0305  *
0306  * @param name1 a converter name or alias, zero-terminated
0307  * @param name2 a converter name or alias, zero-terminated
0308  * @return 0 if the names match, or a negative value if the name1
0309  * lexically precedes name2, or a positive value if the name1
0310  * lexically follows name2.
0311  * @stable ICU 2.0
0312  */
0313 U_CAPI int U_EXPORT2
0314 ucnv_compareNames(const char *name1, const char *name2);
0315 
0316 
0317 /**
0318  * Creates a UConverter object with the name of a coded character set specified as a C string.
0319  * The actual name will be resolved with the alias file
0320  * using a case-insensitive string comparison that ignores
0321  * leading zeroes and all non-alphanumeric characters.
0322  * E.g., the names "UTF8", "utf-8", "u*T@f08" and "Utf 8" are all equivalent.
0323  * (See also ucnv_compareNames().)
0324  * If <code>NULL</code> is passed for the converter name, it will create one with the
0325  * getDefaultName return value.
0326  *
0327  * <p>A converter name for ICU 1.5 and above may contain options
0328  * like a locale specification to control the specific behavior of
0329  * the newly instantiated converter.
0330  * The meaning of the options depends on the particular converter.
0331  * If an option is not defined for or recognized by a given converter, then it is ignored.</p>
0332  *
0333  * <p>Options are appended to the converter name string, with a
0334  * <code>UCNV_OPTION_SEP_CHAR</code> between the name and the first option and
0335  * also between adjacent options.</p>
0336  *
0337  * <p>If the alias is ambiguous, then the preferred converter is used
0338  * and the status is set to U_AMBIGUOUS_ALIAS_WARNING.</p>
0339  *
0340  * <p>The conversion behavior and names can vary between platforms. ICU may
0341  * convert some characters differently from other platforms. Details on this topic
0342  * are in the <a href="https://unicode-org.github.io/icu/userguide/conversion/">User
0343  * Guide</a>. Aliases starting with a "cp" prefix have no specific meaning
0344  * other than its an alias starting with the letters "cp". Please do not
0345  * associate any meaning to these aliases.</p>
0346  *
0347  * \snippet samples/ucnv/convsamp.cpp ucnv_open
0348  *
0349  * @param converterName Name of the coded character set table.
0350  *          This may have options appended to the string.
0351  *          IANA alias character set names, IBM CCSIDs starting with "ibm-",
0352  *          Windows codepage numbers starting with "windows-" are frequently
0353  *          used for this parameter. See ucnv_getAvailableName and
0354  *          ucnv_getAlias for a complete list that is available.
0355  *          If this parameter is NULL, the default converter will be used.
0356  * @param err outgoing error status <TT>U_MEMORY_ALLOCATION_ERROR, U_FILE_ACCESS_ERROR</TT>
0357  * @return the created Unicode converter object, or <TT>NULL</TT> if an error occurred
0358  * @see ucnv_openU
0359  * @see ucnv_openCCSID
0360  * @see ucnv_getAvailableName
0361  * @see ucnv_getAlias
0362  * @see ucnv_getDefaultName
0363  * @see ucnv_close
0364  * @see ucnv_compareNames
0365  * @stable ICU 2.0
0366  */
0367 U_CAPI UConverter* U_EXPORT2
0368 ucnv_open(const char *converterName, UErrorCode *err);
0369 
0370 
0371 /**
0372  * Creates a Unicode converter with the names specified as unicode string.
0373  * The name should be limited to the ASCII-7 alphanumerics range.
0374  * The actual name will be resolved with the alias file
0375  * using a case-insensitive string comparison that ignores
0376  * leading zeroes and all non-alphanumeric characters.
0377  * E.g., the names "UTF8", "utf-8", "u*T@f08" and "Utf 8" are all equivalent.
0378  * (See also ucnv_compareNames().)
0379  * If <TT>NULL</TT> is passed for the converter name, it will create
0380  * one with the ucnv_getDefaultName() return value.
0381  * If the alias is ambiguous, then the preferred converter is used
0382  * and the status is set to U_AMBIGUOUS_ALIAS_WARNING.
0383  *
0384  * <p>See ucnv_open for the complete details</p>
0385  * @param name Name of the UConverter table in a zero terminated
0386  *        Unicode string
0387  * @param err outgoing error status <TT>U_MEMORY_ALLOCATION_ERROR,
0388  *        U_FILE_ACCESS_ERROR</TT>
0389  * @return the created Unicode converter object, or <TT>NULL</TT> if an
0390  *        error occurred
0391  * @see ucnv_open
0392  * @see ucnv_openCCSID
0393  * @see ucnv_close
0394  * @see ucnv_compareNames
0395  * @stable ICU 2.0
0396  */
0397 U_CAPI UConverter* U_EXPORT2
0398 ucnv_openU(const UChar *name,
0399            UErrorCode *err);
0400 
0401 /**
0402  * Creates a UConverter object from a CCSID number and platform pair.
0403  * Note that the usefulness of this function is limited to platforms with numeric
0404  * encoding IDs. Only IBM and Microsoft platforms use numeric (16-bit) identifiers for
0405  * encodings.
0406  *
0407  * In addition, IBM CCSIDs and Unicode conversion tables are not 1:1 related.
0408  * For many IBM CCSIDs there are multiple (up to six) Unicode conversion tables, and
0409  * for some Unicode conversion tables there are multiple CCSIDs.
0410  * Some "alternate" Unicode conversion tables are provided by the
0411  * IBM CDRA conversion table registry.
0412  * The most prominent example of a systematic modification of conversion tables that is
0413  * not provided in the form of conversion table files in the repository is
0414  * that S/390 Unix System Services swaps the codes for Line Feed and New Line in all
0415  * EBCDIC codepages, which requires such a swap in the Unicode conversion tables as well.
0416  *
0417  * Only IBM default conversion tables are accessible with ucnv_openCCSID().
0418  * ucnv_getCCSID() will return the same CCSID for all conversion tables that are associated
0419  * with that CCSID.
0420  *
0421  * Currently, the only "platform" supported in the ICU converter API is UCNV_IBM.
0422  *
0423  * In summary, the use of CCSIDs and the associated API functions is not recommended.
0424  *
0425  * In order to open a converter with the default IBM CDRA Unicode conversion table,
0426  * you can use this function or use the prefix "ibm-":
0427  * \code
0428  *     char name[20];
0429  *     sprintf(name, "ibm-%hu", ccsid);
0430  *     cnv=ucnv_open(name, &errorCode);
0431  * \endcode
0432  *
0433  * In order to open a converter with the IBM S/390 Unix System Services variant
0434  * of a Unicode/EBCDIC conversion table,
0435  * you can use the prefix "ibm-" together with the option string UCNV_SWAP_LFNL_OPTION_STRING:
0436  * \code
0437  *     char name[20];
0438  *     sprintf(name, "ibm-%hu" UCNV_SWAP_LFNL_OPTION_STRING, ccsid);
0439  *     cnv=ucnv_open(name, &errorCode);
0440  * \endcode
0441  *
0442  * In order to open a converter from a Microsoft codepage number, use the prefix "cp":
0443  * \code
0444  *     char name[20];
0445  *     sprintf(name, "cp%hu", codepageID);
0446  *     cnv=ucnv_open(name, &errorCode);
0447  * \endcode
0448  *
0449  * If the alias is ambiguous, then the preferred converter is used
0450  * and the status is set to U_AMBIGUOUS_ALIAS_WARNING.
0451  *
0452  * @param codepage codepage number to create
0453  * @param platform the platform in which the codepage number exists
0454  * @param err error status <TT>U_MEMORY_ALLOCATION_ERROR, U_FILE_ACCESS_ERROR</TT>
0455  * @return the created Unicode converter object, or <TT>NULL</TT> if an error
0456  *   occurred.
0457  * @see ucnv_open
0458  * @see ucnv_openU
0459  * @see ucnv_close
0460  * @see ucnv_getCCSID
0461  * @see ucnv_getPlatform
0462  * @see UConverterPlatform
0463  * @stable ICU 2.0
0464  */
0465 U_CAPI UConverter* U_EXPORT2
0466 ucnv_openCCSID(int32_t codepage,
0467                UConverterPlatform platform,
0468                UErrorCode * err);
0469 
0470 /**
0471  * <p>Creates a UConverter object specified from a packageName and a converterName.</p>
0472  *
0473  * <p>The packageName and converterName must point to an ICU udata object, as defined by
0474  *   <code> udata_open( packageName, "cnv", converterName, err) </code> or equivalent.
0475  * Typically, packageName will refer to a (.dat) file, or to a package registered with
0476  * udata_setAppData(). Using a full file or directory pathname for packageName is deprecated.</p>
0477  *
0478  * <p>The name will NOT be looked up in the alias mechanism, nor will the converter be
0479  * stored in the converter cache or the alias table. The only way to open further converters
0480  * is call this function multiple times, or use the ucnv_clone() function to clone a
0481  * 'primary' converter.</p>
0482  *
0483  * <p>A future version of ICU may add alias table lookups and/or caching
0484  * to this function.</p>
0485  *
0486  * <p>Example Use:
0487  *      <code>cnv = ucnv_openPackage("myapp", "myconverter", &err);</code>
0488  * </p>
0489  *
0490  * @param packageName name of the package (equivalent to 'path' in udata_open() call)
0491  * @param converterName name of the data item to be used, without suffix.
0492  * @param err outgoing error status <TT>U_MEMORY_ALLOCATION_ERROR, U_FILE_ACCESS_ERROR</TT>
0493  * @return the created Unicode converter object, or <TT>NULL</TT> if an error occurred
0494  * @see udata_open
0495  * @see ucnv_open
0496  * @see ucnv_clone
0497  * @see ucnv_close
0498  * @stable ICU 2.2
0499  */
0500 U_CAPI UConverter* U_EXPORT2
0501 ucnv_openPackage(const char *packageName, const char *converterName, UErrorCode *err);
0502 
0503 /**
0504  * Thread safe converter cloning operation.
0505  *
0506  * You must ucnv_close() the clone.
0507  *
0508  * @param cnv converter to be cloned
0509  * @param status to indicate whether the operation went on smoothly or there were errors
0510  * @return pointer to the new clone
0511  * @stable ICU 71
0512  */
0513 U_CAPI UConverter* U_EXPORT2 ucnv_clone(const UConverter *cnv, UErrorCode *status);
0514 
0515 #ifndef U_HIDE_DEPRECATED_API
0516 
0517 /**
0518  * Thread safe converter cloning operation.
0519  * For most efficient operation, pass in a stackBuffer (and a *pBufferSize)
0520  * with at least U_CNV_SAFECLONE_BUFFERSIZE bytes of space.
0521  * If the buffer size is sufficient, then the clone will use the stack buffer;
0522  * otherwise, it will be allocated, and *pBufferSize will indicate
0523  * the actual size. (This should not occur with U_CNV_SAFECLONE_BUFFERSIZE.)
0524  *
0525  * You must ucnv_close() the clone in any case.
0526  *
0527  * If *pBufferSize==0, (regardless of whether stackBuffer==NULL or not)
0528  * then *pBufferSize will be changed to a sufficient size
0529  * for cloning this converter,
0530  * without actually cloning the converter ("pure pre-flighting").
0531  *
0532  * If *pBufferSize is greater than zero but not large enough for a stack-based
0533  * clone, then the converter is cloned using newly allocated memory
0534  * and *pBufferSize is changed to the necessary size.
0535  *
0536  * If the converter clone fits into the stack buffer but the stack buffer is not
0537  * sufficiently aligned for the clone, then the clone will use an
0538  * adjusted pointer and use an accordingly smaller buffer size.
0539  *
0540  * @param cnv converter to be cloned
0541  * @param stackBuffer <em>Deprecated functionality as of ICU 52, use NULL.</em><br>
0542  *  user allocated space for the new clone. If NULL new memory will be allocated.
0543  *  If buffer is not large enough, new memory will be allocated.
0544  *  Clients can use the U_CNV_SAFECLONE_BUFFERSIZE. This will probably be enough to avoid memory allocations.
0545  * @param pBufferSize <em>Deprecated functionality as of ICU 52, use NULL or 1.</em><br>
0546  *  pointer to size of allocated space.
0547  * @param status to indicate whether the operation went on smoothly or there were errors
0548  *  An informational status value, U_SAFECLONE_ALLOCATED_WARNING,
0549  *  is used if pBufferSize != NULL and any allocations were necessary
0550  *  However, it is better to check if *pBufferSize grew for checking for
0551  *  allocations because warning codes can be overridden by subsequent
0552  *  function calls.
0553  * @return pointer to the new clone
0554  * @deprecated ICU 71 Use ucnv_clone() instead.
0555  */
0556 U_DEPRECATED UConverter * U_EXPORT2
0557 ucnv_safeClone(const UConverter *cnv,
0558                void             *stackBuffer,
0559                int32_t          *pBufferSize,
0560                UErrorCode       *status);
0561 
0562 /**
0563  * \def U_CNV_SAFECLONE_BUFFERSIZE
0564  * Definition of a buffer size that is designed to be large enough for
0565  * converters to be cloned with ucnv_safeClone().
0566  * @deprecated ICU 52. Do not rely on ucnv_safeClone() cloning into any provided buffer.
0567  */
0568 #define U_CNV_SAFECLONE_BUFFERSIZE  1024
0569 
0570 #endif /* U_HIDE_DEPRECATED_API */
0571 
0572 /**
0573  * Deletes the unicode converter and releases resources associated
0574  * with just this instance.
0575  * Does not free up shared converter tables.
0576  *
0577  * @param converter the converter object to be deleted
0578  * @see ucnv_open
0579  * @see ucnv_openU
0580  * @see ucnv_openCCSID
0581  * @stable ICU 2.0
0582  */
0583 U_CAPI void  U_EXPORT2
0584 ucnv_close(UConverter * converter);
0585 
0586 #if U_SHOW_CPLUSPLUS_API
0587 
0588 U_NAMESPACE_BEGIN
0589 
0590 /**
0591  * \class LocalUConverterPointer
0592  * "Smart pointer" class, closes a UConverter via ucnv_close().
0593  * For most methods see the LocalPointerBase base class.
0594  *
0595  * @see LocalPointerBase
0596  * @see LocalPointer
0597  * @stable ICU 4.4
0598  */
0599 U_DEFINE_LOCAL_OPEN_POINTER(LocalUConverterPointer, UConverter, ucnv_close);
0600 
0601 U_NAMESPACE_END
0602 
0603 #endif
0604 
0605 /**
0606  * Fills in the output parameter, subChars, with the substitution characters
0607  * as multiple bytes.
0608  * If ucnv_setSubstString() set a Unicode string because the converter is
0609  * stateful, then subChars will be an empty string.
0610  *
0611  * @param converter the Unicode converter
0612  * @param subChars the substitution characters
0613  * @param len on input the capacity of subChars, on output the number
0614  * of bytes copied to it
0615  * @param  err the outgoing error status code.
0616  * If the substitution character array is too small, an
0617  * <TT>U_INDEX_OUTOFBOUNDS_ERROR</TT> will be returned.
0618  * @see ucnv_setSubstString
0619  * @see ucnv_setSubstChars
0620  * @stable ICU 2.0
0621  */
0622 U_CAPI void U_EXPORT2
0623 ucnv_getSubstChars(const UConverter *converter,
0624                    char *subChars,
0625                    int8_t *len,
0626                    UErrorCode *err);
0627 
0628 /**
0629  * Sets the substitution chars when converting from unicode to a codepage. The
0630  * substitution is specified as a string of 1-4 bytes, and may contain
0631  * <TT>NULL</TT> bytes.
0632  * The subChars must represent a single character. The caller needs to know the
0633  * byte sequence of a valid character in the converter's charset.
0634  * For some converters, for example some ISO 2022 variants, only single-byte
0635  * substitution characters may be supported.
0636  * The newer ucnv_setSubstString() function relaxes these limitations.
0637  *
0638  * @param converter the Unicode converter
0639  * @param subChars the substitution character byte sequence we want set
0640  * @param len the number of bytes in subChars
0641  * @param err the error status code.  <TT>U_INDEX_OUTOFBOUNDS_ERROR </TT> if
0642  * len is bigger than the maximum number of bytes allowed in subchars
0643  * @see ucnv_setSubstString
0644  * @see ucnv_getSubstChars
0645  * @stable ICU 2.0
0646  */
0647 U_CAPI void U_EXPORT2
0648 ucnv_setSubstChars(UConverter *converter,
0649                    const char *subChars,
0650                    int8_t len,
0651                    UErrorCode *err);
0652 
0653 /**
0654  * Set a substitution string for converting from Unicode to a charset.
0655  * The caller need not know the charset byte sequence for each charset.
0656  *
0657  * Unlike ucnv_setSubstChars() which is designed to set a charset byte sequence
0658  * for a single character, this function takes a Unicode string with
0659  * zero, one or more characters, and immediately verifies that the string can be
0660  * converted to the charset.
0661  * If not, or if the result is too long (more than 32 bytes as of ICU 3.6),
0662  * then the function returns with an error accordingly.
0663  *
0664  * Also unlike ucnv_setSubstChars(), this function works for stateful charsets
0665  * by converting on the fly at the point of substitution rather than setting
0666  * a fixed byte sequence.
0667  *
0668  * @param cnv The UConverter object.
0669  * @param s The Unicode string.
0670  * @param length The number of UChars in s, or -1 for a NUL-terminated string.
0671  * @param err Pointer to a standard ICU error code. Its input value must
0672  *            pass the U_SUCCESS() test, or else the function returns
0673  *            immediately. Check for U_FAILURE() on output or use with
0674  *            function chaining. (See User Guide for details.)
0675  *
0676  * @see ucnv_setSubstChars
0677  * @see ucnv_getSubstChars
0678  * @stable ICU 3.6
0679  */
0680 U_CAPI void U_EXPORT2
0681 ucnv_setSubstString(UConverter *cnv,
0682                     const UChar *s,
0683                     int32_t length,
0684                     UErrorCode *err);
0685 
0686 /**
0687  * Fills in the output parameter, errBytes, with the error characters from the
0688  * last failing conversion.
0689  *
0690  * @param converter the Unicode converter
0691  * @param errBytes the codepage bytes which were in error
0692  * @param len on input the capacity of errBytes, on output the number of
0693  *  bytes which were copied to it
0694  * @param err the error status code.
0695  * If the substitution character array is too small, an
0696  * <TT>U_INDEX_OUTOFBOUNDS_ERROR</TT> will be returned.
0697  * @stable ICU 2.0
0698  */
0699 U_CAPI void U_EXPORT2
0700 ucnv_getInvalidChars(const UConverter *converter,
0701                      char *errBytes,
0702                      int8_t *len,
0703                      UErrorCode *err);
0704 
0705 /**
0706  * Fills in the output parameter, errChars, with the error characters from the
0707  * last failing conversion.
0708  *
0709  * @param converter the Unicode converter
0710  * @param errUChars the UChars which were in error
0711  * @param len on input the capacity of errUChars, on output the number of
0712  *  UChars which were copied to it
0713  * @param err the error status code.
0714  * If the substitution character array is too small, an
0715  * <TT>U_INDEX_OUTOFBOUNDS_ERROR</TT> will be returned.
0716  * @stable ICU 2.0
0717  */
0718 U_CAPI void U_EXPORT2
0719 ucnv_getInvalidUChars(const UConverter *converter,
0720                       UChar *errUChars,
0721                       int8_t *len,
0722                       UErrorCode *err);
0723 
0724 /**
0725  * Resets the state of a converter to the default state. This is used
0726  * in the case of an error, to restart a conversion from a known default state.
0727  * It will also empty the internal output buffers.
0728  * @param converter the Unicode converter
0729  * @stable ICU 2.0
0730  */
0731 U_CAPI void U_EXPORT2
0732 ucnv_reset(UConverter *converter);
0733 
0734 /**
0735  * Resets the to-Unicode part of a converter state to the default state.
0736  * This is used in the case of an error to restart a conversion to
0737  * Unicode to a known default state. It will also empty the internal
0738  * output buffers used for the conversion to Unicode codepoints.
0739  * @param converter the Unicode converter
0740  * @stable ICU 2.0
0741  */
0742 U_CAPI void U_EXPORT2
0743 ucnv_resetToUnicode(UConverter *converter);
0744 
0745 /**
0746  * Resets the from-Unicode part of a converter state to the default state.
0747  * This is used in the case of an error to restart a conversion from
0748  * Unicode to a known default state. It will also empty the internal output
0749  * buffers used for the conversion from Unicode codepoints.
0750  * @param converter the Unicode converter
0751  * @stable ICU 2.0
0752  */
0753 U_CAPI void U_EXPORT2
0754 ucnv_resetFromUnicode(UConverter *converter);
0755 
0756 /**
0757  * Returns the maximum number of bytes that are output per UChar in conversion
0758  * from Unicode using this converter.
0759  * The returned number can be used with UCNV_GET_MAX_BYTES_FOR_STRING
0760  * to calculate the size of a target buffer for conversion from Unicode.
0761  *
0762  * Note: Before ICU 2.8, this function did not return reliable numbers for
0763  * some stateful converters (EBCDIC_STATEFUL, ISO-2022) and LMBCS.
0764  *
0765  * This number may not be the same as the maximum number of bytes per
0766  * "conversion unit". In other words, it may not be the intuitively expected
0767  * number of bytes per character that would be published for a charset,
0768  * and may not fulfill any other purpose than the allocation of an output
0769  * buffer of guaranteed sufficient size for a given input length and converter.
0770  *
0771  * Examples for special cases that are taken into account:
0772  * - Supplementary code points may convert to more bytes than BMP code points.
0773  *   This function returns bytes per UChar (UTF-16 code unit), not per
0774  *   Unicode code point, for efficient buffer allocation.
0775  * - State-shifting output (SI/SO, escapes, etc.) from stateful converters.
0776  * - When m input UChars are converted to n output bytes, then the maximum m/n
0777  *   is taken into account.
0778  *
0779  * The number returned here does not take into account
0780  * (see UCNV_GET_MAX_BYTES_FOR_STRING):
0781  * - callbacks which output more than one charset character sequence per call,
0782  *   like escape callbacks
0783  * - initial and final non-character bytes that are output by some converters
0784  *   (automatic BOMs, initial escape sequence, final SI, etc.)
0785  *
0786  * Examples for returned values:
0787  * - SBCS charsets: 1
0788  * - Shift-JIS: 2
0789  * - UTF-16: 2 (2 per BMP, 4 per surrogate _pair_, BOM not counted)
0790  * - UTF-8: 3 (3 per BMP, 4 per surrogate _pair_)
0791  * - EBCDIC_STATEFUL (EBCDIC mixed SBCS/DBCS): 3 (SO + DBCS)
0792  * - ISO-2022: 3 (always outputs UTF-8)
0793  * - ISO-2022-JP: 6 (4-byte escape sequences + DBCS)
0794  * - ISO-2022-CN: 8 (4-byte designator sequences + 2-byte SS2/SS3 + DBCS)
0795  *
0796  * @param converter The Unicode converter.
0797  * @return The maximum number of bytes per UChar (16 bit code unit)
0798  *    that are output by ucnv_fromUnicode(),
0799  *    to be used together with UCNV_GET_MAX_BYTES_FOR_STRING
0800  *    for buffer allocation.
0801  *
0802  * @see UCNV_GET_MAX_BYTES_FOR_STRING
0803  * @see ucnv_getMinCharSize
0804  * @stable ICU 2.0
0805  */
0806 U_CAPI int8_t U_EXPORT2
0807 ucnv_getMaxCharSize(const UConverter *converter);
0808 
0809 /**
0810  * Calculates the size of a buffer for conversion from Unicode to a charset.
0811  * The calculated size is guaranteed to be sufficient for this conversion.
0812  *
0813  * It takes into account initial and final non-character bytes that are output
0814  * by some converters.
0815  * It does not take into account callbacks which output more than one charset
0816  * character sequence per call, like escape callbacks.
0817  * The default (substitution) callback only outputs one charset character sequence.
0818  *
0819  * @param length Number of UChars to be converted.
0820  * @param maxCharSize Return value from ucnv_getMaxCharSize() for the converter
0821  *                    that will be used.
0822  * @return Size of a buffer that will be large enough to hold the output bytes of
0823  *         converting length UChars with the converter that returned the maxCharSize.
0824  *
0825  * @see ucnv_getMaxCharSize
0826  * @stable ICU 2.8
0827  */
0828 #define UCNV_GET_MAX_BYTES_FOR_STRING(length, maxCharSize) \
0829      (((int32_t)(length)+10)*(int32_t)(maxCharSize))
0830 
0831 /**
0832  * Returns the minimum byte length (per codepoint) for characters in this codepage.
0833  * This is usually either 1 or 2.
0834  * @param converter the Unicode converter
0835  * @return the minimum number of bytes per codepoint allowed by this particular converter
0836  * @see ucnv_getMaxCharSize
0837  * @stable ICU 2.0
0838  */
0839 U_CAPI int8_t U_EXPORT2
0840 ucnv_getMinCharSize(const UConverter *converter);
0841 
0842 /**
0843  * Returns the display name of the converter passed in based on the Locale
0844  * passed in. If the locale contains no display name, the internal ASCII
0845  * name will be filled in.
0846  *
0847  * @param converter the Unicode converter.
0848  * @param displayLocale is the specific Locale we want to localized for
0849  * @param displayName user provided buffer to be filled in
0850  * @param displayNameCapacity size of displayName Buffer
0851  * @param err error status code
0852  * @return displayNameLength number of UChar needed in displayName
0853  * @see ucnv_getName
0854  * @stable ICU 2.0
0855  */
0856 U_CAPI int32_t U_EXPORT2
0857 ucnv_getDisplayName(const UConverter *converter,
0858                     const char *displayLocale,
0859                     UChar *displayName,
0860                     int32_t displayNameCapacity,
0861                     UErrorCode *err);
0862 
0863 /**
0864  * Gets the internal, canonical name of the converter (zero-terminated).
0865  * The lifetime of the returned string will be that of the converter
0866  * passed to this function.
0867  * @param converter the Unicode converter
0868  * @param err UErrorCode status
0869  * @return the internal name of the converter
0870  * @see ucnv_getDisplayName
0871  * @stable ICU 2.0
0872  */
0873 U_CAPI const char * U_EXPORT2
0874 ucnv_getName(const UConverter *converter, UErrorCode *err);
0875 
0876 /**
0877  * Gets a codepage number associated with the converter. This is not guaranteed
0878  * to be the one used to create the converter. Some converters do not represent
0879  * platform registered codepages and return zero for the codepage number.
0880  * The error code fill-in parameter indicates if the codepage number
0881  * is available.
0882  * Does not check if the converter is <TT>NULL</TT> or if converter's data
0883  * table is <TT>NULL</TT>.
0884  *
0885  * Important: The use of CCSIDs is not recommended because it is limited
0886  * to only two platforms in principle and only one (UCNV_IBM) in the current
0887  * ICU converter API.
0888  * Also, CCSIDs are insufficient to identify IBM Unicode conversion tables precisely.
0889  * For more details see ucnv_openCCSID().
0890  *
0891  * @param converter the Unicode converter
0892  * @param err the error status code.
0893  * @return If any error occurs, -1 will be returned otherwise, the codepage number
0894  * will be returned
0895  * @see ucnv_openCCSID
0896  * @see ucnv_getPlatform
0897  * @stable ICU 2.0
0898  */
0899 U_CAPI int32_t U_EXPORT2
0900 ucnv_getCCSID(const UConverter *converter,
0901               UErrorCode *err);
0902 
0903 /**
0904  * Gets a codepage platform associated with the converter. Currently,
0905  * only <TT>UCNV_IBM</TT> will be returned.
0906  * Does not test if the converter is <TT>NULL</TT> or if converter's data
0907  * table is <TT>NULL</TT>.
0908  * @param converter the Unicode converter
0909  * @param err the error status code.
0910  * @return The codepage platform
0911  * @stable ICU 2.0
0912  */
0913 U_CAPI UConverterPlatform U_EXPORT2
0914 ucnv_getPlatform(const UConverter *converter,
0915                  UErrorCode *err);
0916 
0917 /**
0918  * Gets the type of the converter
0919  * e.g. SBCS, MBCS, DBCS, UTF8, UTF16_BE, UTF16_LE, ISO_2022,
0920  * EBCDIC_STATEFUL, LATIN_1
0921  * @param converter a valid, opened converter
0922  * @return the type of the converter
0923  * @stable ICU 2.0
0924  */
0925 U_CAPI UConverterType U_EXPORT2
0926 ucnv_getType(const UConverter * converter);
0927 
0928 /**
0929  * Gets the "starter" (lead) bytes for converters of type MBCS.
0930  * Will fill in an <TT>U_ILLEGAL_ARGUMENT_ERROR</TT> if converter passed in
0931  * is not MBCS. Fills in an array of type UBool, with the value of the byte
0932  * as offset to the array. For example, if (starters[0x20] == true) at return,
0933  * it means that the byte 0x20 is a starter byte in this converter.
0934  * Context pointers are always owned by the caller.
0935  *
0936  * @param converter a valid, opened converter of type MBCS
0937  * @param starters an array of size 256 to be filled in
0938  * @param err error status, <TT>U_ILLEGAL_ARGUMENT_ERROR</TT> if the
0939  * converter is not a type which can return starters.
0940  * @see ucnv_getType
0941  * @stable ICU 2.0
0942  */
0943 U_CAPI void U_EXPORT2
0944 ucnv_getStarters(const UConverter* converter,
0945                  UBool starters[256],
0946                  UErrorCode* err);
0947 
0948 
0949 /**
0950  * Selectors for Unicode sets that can be returned by ucnv_getUnicodeSet().
0951  * @see ucnv_getUnicodeSet
0952  * @stable ICU 2.6
0953  */
0954 typedef enum UConverterUnicodeSet {
0955     /** Select the set of roundtrippable Unicode code points. @stable ICU 2.6 */
0956     UCNV_ROUNDTRIP_SET,
0957     /** Select the set of Unicode code points with roundtrip or fallback mappings. @stable ICU 4.0 */
0958     UCNV_ROUNDTRIP_AND_FALLBACK_SET,
0959 #ifndef U_HIDE_DEPRECATED_API
0960     /**
0961      * Number of UConverterUnicodeSet selectors.
0962      * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
0963      */
0964     UCNV_SET_COUNT
0965 #endif  // U_HIDE_DEPRECATED_API
0966 } UConverterUnicodeSet;
0967 
0968 
0969 /**
0970  * Returns the set of Unicode code points that can be converted by an ICU converter.
0971  *
0972  * Returns one of several kinds of set:
0973  *
0974  * 1. UCNV_ROUNDTRIP_SET
0975  *
0976  * The set of all Unicode code points that can be roundtrip-converted
0977  * (converted without any data loss) with the converter (ucnv_fromUnicode()).
0978  * This set will not include code points that have fallback mappings
0979  * or are only the result of reverse fallback mappings.
0980  * This set will also not include PUA code points with fallbacks, although
0981  * ucnv_fromUnicode() will always uses those mappings despite ucnv_setFallback().
0982  * See UTR #22 "Character Mapping Markup Language"
0983  * at http://www.unicode.org/reports/tr22/
0984  *
0985  * This is useful for example for
0986  * - checking that a string or document can be roundtrip-converted with a converter,
0987  *   without/before actually performing the conversion
0988  * - testing if a converter can be used for text for typical text for a certain locale,
0989  *   by comparing its roundtrip set with the set of ExemplarCharacters from
0990  *   ICU's locale data or other sources
0991  *
0992  * 2. UCNV_ROUNDTRIP_AND_FALLBACK_SET
0993  *
0994  * The set of all Unicode code points that can be converted with the converter (ucnv_fromUnicode())
0995  * when fallbacks are turned on (see ucnv_setFallback()).
0996  * This set includes all code points with roundtrips and fallbacks (but not reverse fallbacks).
0997  *
0998  * In the future, there may be more UConverterUnicodeSet choices to select
0999  * sets with different properties.
1000  *
1001  * @param cnv The converter for which a set is requested.
1002  * @param setFillIn A valid USet *. It will be cleared by this function before
1003  *            the converter's specific set is filled into the USet.
1004  * @param whichSet A UConverterUnicodeSet selector;
1005  *              currently UCNV_ROUNDTRIP_SET is the only supported value.
1006  * @param pErrorCode ICU error code in/out parameter.
1007  *                   Must fulfill U_SUCCESS before the function call.
1008  *
1009  * @see UConverterUnicodeSet
1010  * @see uset_open
1011  * @see uset_close
1012  * @stable ICU 2.6
1013  */
1014 U_CAPI void U_EXPORT2
1015 ucnv_getUnicodeSet(const UConverter *cnv,
1016                    USet *setFillIn,
1017                    UConverterUnicodeSet whichSet,
1018                    UErrorCode *pErrorCode);
1019 
1020 /**
1021  * Gets the current callback function used by the converter when an illegal
1022  *  or invalid codepage sequence is found.
1023  * Context pointers are always owned by the caller.
1024  *
1025  * @param converter the unicode converter
1026  * @param action fillin: returns the callback function pointer
1027  * @param context fillin: returns the callback's private void* context
1028  * @see ucnv_setToUCallBack
1029  * @stable ICU 2.0
1030  */
1031 U_CAPI void U_EXPORT2
1032 ucnv_getToUCallBack (const UConverter * converter,
1033                      UConverterToUCallback *action,
1034                      const void **context);
1035 
1036 /**
1037  * Gets the current callback function used by the converter when illegal
1038  * or invalid Unicode sequence is found.
1039  * Context pointers are always owned by the caller.
1040  *
1041  * @param converter the unicode converter
1042  * @param action fillin: returns the callback function pointer
1043  * @param context fillin: returns the callback's private void* context
1044  * @see ucnv_setFromUCallBack
1045  * @stable ICU 2.0
1046  */
1047 U_CAPI void U_EXPORT2
1048 ucnv_getFromUCallBack (const UConverter * converter,
1049                        UConverterFromUCallback *action,
1050                        const void **context);
1051 
1052 /**
1053  * Changes the callback function used by the converter when
1054  * an illegal or invalid sequence is found.
1055  * Context pointers are always owned by the caller.
1056  * Predefined actions and contexts can be found in the ucnv_err.h header.
1057  *
1058  * @param converter the unicode converter
1059  * @param newAction the new callback function
1060  * @param newContext the new toUnicode callback context pointer. This can be NULL.
1061  * @param oldAction fillin: returns the old callback function pointer. This can be NULL.
1062  * @param oldContext fillin: returns the old callback's private void* context. This can be NULL.
1063  * @param err The error code status
1064  * @see ucnv_getToUCallBack
1065  * @stable ICU 2.0
1066  */
1067 U_CAPI void U_EXPORT2
1068 ucnv_setToUCallBack (UConverter * converter,
1069                      UConverterToUCallback newAction,
1070                      const void* newContext,
1071                      UConverterToUCallback *oldAction,
1072                      const void** oldContext,
1073                      UErrorCode * err);
1074 
1075 /**
1076  * Changes the current callback function used by the converter when
1077  * an illegal or invalid sequence is found.
1078  * Context pointers are always owned by the caller.
1079  * Predefined actions and contexts can be found in the ucnv_err.h header.
1080  *
1081  * @param converter the unicode converter
1082  * @param newAction the new callback function
1083  * @param newContext the new fromUnicode callback context pointer. This can be NULL.
1084  * @param oldAction fillin: returns the old callback function pointer. This can be NULL.
1085  * @param oldContext fillin: returns the old callback's private void* context. This can be NULL.
1086  * @param err The error code status
1087  * @see ucnv_getFromUCallBack
1088  * @stable ICU 2.0
1089  */
1090 U_CAPI void U_EXPORT2
1091 ucnv_setFromUCallBack (UConverter * converter,
1092                        UConverterFromUCallback newAction,
1093                        const void *newContext,
1094                        UConverterFromUCallback *oldAction,
1095                        const void **oldContext,
1096                        UErrorCode * err);
1097 
1098 /**
1099  * Converts an array of unicode characters to an array of codepage
1100  * characters. This function is optimized for converting a continuous
1101  * stream of data in buffer-sized chunks, where the entire source and
1102  * target does not fit in available buffers.
1103  *
1104  * The source pointer is an in/out parameter. It starts out pointing where the
1105  * conversion is to begin, and ends up pointing after the last UChar consumed.
1106  *
1107  * Target similarly starts out pointer at the first available byte in the output
1108  * buffer, and ends up pointing after the last byte written to the output.
1109  *
1110  * The converter always attempts to consume the entire source buffer, unless
1111  * (1.) the target buffer is full, or (2.) a failing error is returned from the
1112  * current callback function.  When a successful error status has been
1113  * returned, it means that all of the source buffer has been
1114  *  consumed. At that point, the caller should reset the source and
1115  *  sourceLimit pointers to point to the next chunk.
1116  *
1117  * At the end of the stream (flush==true), the input is completely consumed
1118  * when *source==sourceLimit and no error code is set.
1119  * The converter object is then automatically reset by this function.
1120  * (This means that a converter need not be reset explicitly between data
1121  * streams if it finishes the previous stream without errors.)
1122  *
1123  * This is a <I>stateful</I> conversion. Additionally, even when all source data has
1124  * been consumed, some data may be in the converters' internal state.
1125  * Call this function repeatedly, updating the target pointers with
1126  * the next empty chunk of target in case of a
1127  * <TT>U_BUFFER_OVERFLOW_ERROR</TT>, and updating the source  pointers
1128  *  with the next chunk of source when a successful error status is
1129  * returned, until there are no more chunks of source data.
1130  * @param converter the Unicode converter
1131  * @param target I/O parameter. Input : Points to the beginning of the buffer to copy
1132  *  codepage characters to. Output : points to after the last codepage character copied
1133  *  to <TT>target</TT>.
1134  * @param targetLimit the pointer just after last of the <TT>target</TT> buffer
1135  * @param source I/O parameter, pointer to pointer to the source Unicode character buffer.
1136  * @param sourceLimit the pointer just after the last of the source buffer
1137  * @param offsets if NULL is passed, nothing will happen to it, otherwise it needs to have the same number
1138  * of allocated cells as <TT>target</TT>. Will fill in offsets from target to source pointer
1139  * 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>
1140  * For output data carried across calls, and other data without a specific source character
1141  * (such as from escape sequences or callbacks)  -1 will be placed for offsets.
1142  * @param flush set to <TT>true</TT> if the current source buffer is the last available
1143  * chunk of the source, <TT>false</TT> otherwise. Note that if a failing status is returned,
1144  * this function may have to be called multiple times with flush set to <TT>true</TT> until
1145  * the source buffer is consumed.
1146  * @param err the error status.  <TT>U_ILLEGAL_ARGUMENT_ERROR</TT> will be set if the
1147  * converter is <TT>NULL</TT>.
1148  * <code>U_BUFFER_OVERFLOW_ERROR</code> will be set if the target is full and there is
1149  * still data to be written to the target.
1150  * @see ucnv_fromUChars
1151  * @see ucnv_convert
1152  * @see ucnv_getMinCharSize
1153  * @see ucnv_setToUCallBack
1154  * @stable ICU 2.0
1155  */
1156 U_CAPI void U_EXPORT2
1157 ucnv_fromUnicode (UConverter * converter,
1158                   char **target,
1159                   const char *targetLimit,
1160                   const UChar ** source,
1161                   const UChar * sourceLimit,
1162                   int32_t* offsets,
1163                   UBool flush,
1164                   UErrorCode * err);
1165 
1166 /**
1167  * Converts a buffer of codepage bytes into an array of unicode UChars
1168  * characters. This function is optimized for converting a continuous
1169  * stream of data in buffer-sized chunks, where the entire source and
1170  * target does not fit in available buffers.
1171  *
1172  * The source pointer is an in/out parameter. It starts out pointing where the
1173  * conversion is to begin, and ends up pointing after the last byte of source consumed.
1174  *
1175  * Target similarly starts out pointer at the first available UChar in the output
1176  * buffer, and ends up pointing after the last UChar written to the output.
1177  * It does NOT necessarily keep UChar sequences together.
1178  *
1179  * The converter always attempts to consume the entire source buffer, unless
1180  * (1.) the target buffer is full, or (2.) a failing error is returned from the
1181  * current callback function.  When a successful error status has been
1182  * returned, it means that all of the source buffer has been
1183  *  consumed. At that point, the caller should reset the source and
1184  *  sourceLimit pointers to point to the next chunk.
1185  *
1186  * At the end of the stream (flush==true), the input is completely consumed
1187  * when *source==sourceLimit and no error code is set
1188  * The converter object is then automatically reset by this function.
1189  * (This means that a converter need not be reset explicitly between data
1190  * streams if it finishes the previous stream without errors.)
1191  *
1192  * This is a <I>stateful</I> conversion. Additionally, even when all source data has
1193  * been consumed, some data may be in the converters' internal state.
1194  * Call this function repeatedly, updating the target pointers with
1195  * the next empty chunk of target in case of a
1196  * <TT>U_BUFFER_OVERFLOW_ERROR</TT>, and updating the source  pointers
1197  *  with the next chunk of source when a successful error status is
1198  * returned, until there are no more chunks of source data.
1199  * @param converter the Unicode converter
1200  * @param target I/O parameter. Input : Points to the beginning of the buffer to copy
1201  *  UChars into. Output : points to after the last UChar copied.
1202  * @param targetLimit the pointer just after the end of the <TT>target</TT> buffer
1203  * @param source I/O parameter, pointer to pointer to the source codepage buffer.
1204  * @param sourceLimit the pointer to the byte after the end of the source buffer
1205  * @param offsets if NULL is passed, nothing will happen to it, otherwise it needs to have the same number
1206  * of allocated cells as <TT>target</TT>. Will fill in offsets from target to source pointer
1207  * 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>
1208  * For output data carried across calls, and other data without a specific source character
1209  * (such as from escape sequences or callbacks)  -1 will be placed for offsets.
1210  * @param flush set to <TT>true</TT> if the current source buffer is the last available
1211  * chunk of the source, <TT>false</TT> otherwise. Note that if a failing status is returned,
1212  * this function may have to be called multiple times with flush set to <TT>true</TT> until
1213  * the source buffer is consumed.
1214  * @param err the error status.  <TT>U_ILLEGAL_ARGUMENT_ERROR</TT> will be set if the
1215  * converter is <TT>NULL</TT>.
1216  * <code>U_BUFFER_OVERFLOW_ERROR</code> will be set if the target is full and there is
1217  * still data to be written to the target.
1218  * @see ucnv_fromUChars
1219  * @see ucnv_convert
1220  * @see ucnv_getMinCharSize
1221  * @see ucnv_setFromUCallBack
1222  * @see ucnv_getNextUChar
1223  * @stable ICU 2.0
1224  */
1225 U_CAPI void U_EXPORT2
1226 ucnv_toUnicode(UConverter *converter,
1227                UChar **target,
1228                const UChar *targetLimit,
1229                const char **source,
1230                const char *sourceLimit,
1231                int32_t *offsets,
1232                UBool flush,
1233                UErrorCode *err);
1234 
1235 /**
1236  * Convert the Unicode string into a codepage string using an existing UConverter.
1237  * The output string is NUL-terminated if possible.
1238  *
1239  * This function is a more convenient but less powerful version of ucnv_fromUnicode().
1240  * It is only useful for whole strings, not for streaming conversion.
1241  *
1242  * The maximum output buffer capacity required (barring output from callbacks) will be
1243  * UCNV_GET_MAX_BYTES_FOR_STRING(srcLength, ucnv_getMaxCharSize(cnv)).
1244  *
1245  * @param cnv the converter object to be used (ucnv_resetFromUnicode() will be called)
1246  * @param src the input Unicode string
1247  * @param srcLength the input string length, or -1 if NUL-terminated
1248  * @param dest destination string buffer, can be NULL if destCapacity==0
1249  * @param destCapacity the number of chars available at dest
1250  * @param pErrorCode normal ICU error code;
1251  *                  common error codes that may be set by this function include
1252  *                  U_BUFFER_OVERFLOW_ERROR, U_STRING_NOT_TERMINATED_WARNING,
1253  *                  U_ILLEGAL_ARGUMENT_ERROR, and conversion errors
1254  * @return the length of the output string, not counting the terminating NUL;
1255  *         if the length is greater than destCapacity, then the string will not fit
1256  *         and a buffer of the indicated length would need to be passed in
1257  * @see ucnv_fromUnicode
1258  * @see ucnv_convert
1259  * @see UCNV_GET_MAX_BYTES_FOR_STRING
1260  * @stable ICU 2.0
1261  */
1262 U_CAPI int32_t U_EXPORT2
1263 ucnv_fromUChars(UConverter *cnv,
1264                 char *dest, int32_t destCapacity,
1265                 const UChar *src, int32_t srcLength,
1266                 UErrorCode *pErrorCode);
1267 
1268 /**
1269  * Convert the codepage string into a Unicode string using an existing UConverter.
1270  * The output string is NUL-terminated if possible.
1271  *
1272  * This function is a more convenient but less powerful version of ucnv_toUnicode().
1273  * It is only useful for whole strings, not for streaming conversion.
1274  *
1275  * The maximum output buffer capacity required (barring output from callbacks) will be
1276  * 2*srcLength (each char may be converted into a surrogate pair).
1277  *
1278  * @param cnv the converter object to be used (ucnv_resetToUnicode() will be called)
1279  * @param src the input codepage string
1280  * @param srcLength the input string length, or -1 if NUL-terminated
1281  * @param dest destination string buffer, can be NULL if destCapacity==0
1282  * @param destCapacity the number of UChars available at dest
1283  * @param pErrorCode normal ICU error code;
1284  *                  common error codes that may be set by this function include
1285  *                  U_BUFFER_OVERFLOW_ERROR, U_STRING_NOT_TERMINATED_WARNING,
1286  *                  U_ILLEGAL_ARGUMENT_ERROR, and conversion errors
1287  * @return the length of the output string, not counting the terminating NUL;
1288  *         if the length is greater than destCapacity, then the string will not fit
1289  *         and a buffer of the indicated length would need to be passed in
1290  * @see ucnv_toUnicode
1291  * @see ucnv_convert
1292  * @stable ICU 2.0
1293  */
1294 U_CAPI int32_t U_EXPORT2
1295 ucnv_toUChars(UConverter *cnv,
1296               UChar *dest, int32_t destCapacity,
1297               const char *src, int32_t srcLength,
1298               UErrorCode *pErrorCode);
1299 
1300 /**
1301  * Convert a codepage buffer into Unicode one character at a time.
1302  * The input is completely consumed when the U_INDEX_OUTOFBOUNDS_ERROR is set.
1303  *
1304  * Advantage compared to ucnv_toUnicode() or ucnv_toUChars():
1305  * - Faster for small amounts of data, for most converters, e.g.,
1306  *   US-ASCII, ISO-8859-1, UTF-8/16/32, and most "normal" charsets.
1307  *   (For complex converters, e.g., SCSU, UTF-7 and ISO 2022 variants,
1308  *    it uses ucnv_toUnicode() internally.)
1309  * - Convenient.
1310  *
1311  * Limitations compared to ucnv_toUnicode():
1312  * - Always assumes flush=true.
1313  *   This makes ucnv_getNextUChar() unsuitable for "streaming" conversion,
1314  *   that is, for where the input is supplied in multiple buffers,
1315  *   because ucnv_getNextUChar() will assume the end of the input at the end
1316  *   of the first buffer.
1317  * - Does not provide offset output.
1318  *
1319  * It is possible to "mix" ucnv_getNextUChar() and ucnv_toUnicode() because
1320  * ucnv_getNextUChar() uses the current state of the converter
1321  * (unlike ucnv_toUChars() which always resets first).
1322  * However, if ucnv_getNextUChar() is called after ucnv_toUnicode()
1323  * stopped in the middle of a character sequence (with flush=false),
1324  * then ucnv_getNextUChar() will always use the slower ucnv_toUnicode()
1325  * internally until the next character boundary.
1326  * (This is new in ICU 2.6. In earlier releases, ucnv_getNextUChar() had to
1327  * start at a character boundary.)
1328  *
1329  * Instead of using ucnv_getNextUChar(), it is recommended
1330  * to convert using ucnv_toUnicode() or ucnv_toUChars()
1331  * and then iterate over the text using U16_NEXT() or a UCharIterator (uiter.h)
1332  * or a C++ CharacterIterator or similar.
1333  * This allows streaming conversion and offset output, for example.
1334  *
1335  * <p>Handling of surrogate pairs and supplementary-plane code points:<br>
1336  * There are two different kinds of codepages that provide mappings for surrogate characters:
1337  * <ul>
1338  *   <li>Codepages like UTF-8, UTF-32, and GB 18030 provide direct representations for Unicode
1339  *       code points U+10000-U+10ffff as well as for single surrogates U+d800-U+dfff.
1340  *       Each valid sequence will result in exactly one returned code point.
1341  *       If a sequence results in a single surrogate, then that will be returned
1342  *       by itself, even if a neighboring sequence encodes the matching surrogate.</li>
1343  *   <li>Codepages like SCSU and LMBCS (and UTF-16) provide direct representations only for BMP code points
1344  *       including surrogates. Code points in supplementary planes are represented with
1345  *       two sequences, each encoding a surrogate.
1346  *       For these codepages, matching pairs of surrogates will be combined into single
1347  *       code points for returning from this function.
1348  *       (Note that SCSU is actually a mix of these codepage types.)</li>
1349  * </ul></p>
1350  *
1351  * @param converter an open UConverter
1352  * @param source the address of a pointer to the codepage buffer, will be
1353  *  updated to point after the bytes consumed in the conversion call.
1354  * @param sourceLimit points to the end of the input buffer
1355  * @param err fills in error status (see ucnv_toUnicode)
1356  * <code>U_INDEX_OUTOFBOUNDS_ERROR</code> will be set if the input
1357  * is empty or does not convert to any output (e.g.: pure state-change
1358  * codes SI/SO, escape sequences for ISO 2022,
1359  * or if the callback did not output anything, ...).
1360  * This function will not set a <code>U_BUFFER_OVERFLOW_ERROR</code> because
1361  *  the "buffer" is the return code. However, there might be subsequent output
1362  *  stored in the converter object
1363  * that will be returned in following calls to this function.
1364  * @return a UChar32 resulting from the partial conversion of source
1365  * @see ucnv_toUnicode
1366  * @see ucnv_toUChars
1367  * @see ucnv_convert
1368  * @stable ICU 2.0
1369  */
1370 U_CAPI UChar32 U_EXPORT2
1371 ucnv_getNextUChar(UConverter * converter,
1372                   const char **source,
1373                   const char * sourceLimit,
1374                   UErrorCode * err);
1375 
1376 /**
1377  * Convert from one external charset to another using two existing UConverters.
1378  * Internally, two conversions - ucnv_toUnicode() and ucnv_fromUnicode() -
1379  * are used, "pivoting" through 16-bit Unicode.
1380  *
1381  * Important: For streaming conversion (multiple function calls for successive
1382  * parts of a text stream), the caller must provide a pivot buffer explicitly,
1383  * and must preserve the pivot buffer and associated pointers from one
1384  * call to another. (The buffer may be moved if its contents and the relative
1385  * pointer positions are preserved.)
1386  *
1387  * There is a similar function, ucnv_convert(),
1388  * which has the following limitations:
1389  * - it takes charset names, not converter objects, so that
1390  *   - two converters are opened for each call
1391  *   - only single-string conversion is possible, not streaming operation
1392  * - it does not provide enough information to find out,
1393  *   in case of failure, whether the toUnicode or
1394  *   the fromUnicode conversion failed
1395  *
1396  * By contrast, ucnv_convertEx()
1397  * - takes UConverter parameters instead of charset names
1398  * - fully exposes the pivot buffer for streaming conversion and complete error handling
1399  *
1400  * ucnv_convertEx() also provides further convenience:
1401  * - an option to reset the converters at the beginning
1402  *   (if reset==true, see parameters;
1403  *    also sets *pivotTarget=*pivotSource=pivotStart)
1404  * - allow NUL-terminated input
1405  *   (only a single NUL byte, will not work for charsets with multi-byte NULs)
1406  *   (if sourceLimit==NULL, see parameters)
1407  * - terminate with a NUL on output
1408  *   (only a single NUL byte, not useful for charsets with multi-byte NULs),
1409  *   or set U_STRING_NOT_TERMINATED_WARNING if the output exactly fills
1410  *   the target buffer
1411  * - the pivot buffer can be provided internally;
1412  *   possible only for whole-string conversion, not streaming conversion;
1413  *   in this case, the caller will not be able to get details about where an
1414  *   error occurred
1415  *   (if pivotStart==NULL, see below)
1416  *
1417  * The function returns when one of the following is true:
1418  * - the entire source text has been converted successfully to the target buffer
1419  * - a target buffer overflow occurred (U_BUFFER_OVERFLOW_ERROR)
1420  * - a conversion error occurred
1421  *   (other U_FAILURE(), see description of pErrorCode)
1422  *
1423  * Limitation compared to the direct use of
1424  * ucnv_fromUnicode() and ucnv_toUnicode():
1425  * ucnv_convertEx() does not provide offset information.
1426  *
1427  * Limitation compared to ucnv_fromUChars() and ucnv_toUChars():
1428  * ucnv_convertEx() does not support preflighting directly.
1429  *
1430  * Sample code for converting a single string from
1431  * one external charset to UTF-8, ignoring the location of errors:
1432  *
1433  * \code
1434  * int32_t
1435  * myToUTF8(UConverter *cnv,
1436  *          const char *s, int32_t length,
1437  *          char *u8, int32_t capacity,
1438  *          UErrorCode *pErrorCode) {
1439  *     UConverter *utf8Cnv;
1440  *     char *target;
1441  *
1442  *     if(U_FAILURE(*pErrorCode)) {
1443  *         return 0;
1444  *     }
1445  *
1446  *     utf8Cnv=myGetCachedUTF8Converter(pErrorCode);
1447  *     if(U_FAILURE(*pErrorCode)) {
1448  *         return 0;
1449  *     }
1450  *
1451  *     if(length<0) {
1452  *         length=strlen(s);
1453  *     }
1454  *     target=u8;
1455  *     ucnv_convertEx(utf8Cnv, cnv,
1456  *                    &target, u8+capacity,
1457  *                    &s, s+length,
1458  *                    NULL, NULL, NULL, NULL,
1459  *                    true, true,
1460  *                    pErrorCode);
1461  *
1462  *     myReleaseCachedUTF8Converter(utf8Cnv);
1463  *
1464  *     // return the output string length, but without preflighting
1465  *     return (int32_t)(target-u8);
1466  * }
1467  * \endcode
1468  *
1469  * @param targetCnv     Output converter, used to convert from the UTF-16 pivot
1470  *                      to the target using ucnv_fromUnicode().
1471  * @param sourceCnv     Input converter, used to convert from the source to
1472  *                      the UTF-16 pivot using ucnv_toUnicode().
1473  * @param target        I/O parameter, same as for ucnv_fromUChars().
1474  *                      Input: *target points to the beginning of the target buffer.
1475  *                      Output: *target points to the first unit after the last char written.
1476  * @param targetLimit   Pointer to the first unit after the target buffer.
1477  * @param source        I/O parameter, same as for ucnv_toUChars().
1478  *                      Input: *source points to the beginning of the source buffer.
1479  *                      Output: *source points to the first unit after the last char read.
1480  * @param sourceLimit   Pointer to the first unit after the source buffer.
1481  * @param pivotStart    Pointer to the UTF-16 pivot buffer. If pivotStart==NULL,
1482  *                      then an internal buffer is used and the other pivot
1483  *                      arguments are ignored and can be NULL as well.
1484  * @param pivotSource   I/O parameter, same as source in ucnv_fromUChars() for
1485  *                      conversion from the pivot buffer to the target buffer.
1486  * @param pivotTarget   I/O parameter, same as target in ucnv_toUChars() for
1487  *                      conversion from the source buffer to the pivot buffer.
1488  *                      It must be pivotStart<=*pivotSource<=*pivotTarget<=pivotLimit
1489  *                      and pivotStart<pivotLimit (unless pivotStart==NULL).
1490  * @param pivotLimit    Pointer to the first unit after the pivot buffer.
1491  * @param reset         If true, then ucnv_resetToUnicode(sourceCnv) and
1492  *                      ucnv_resetFromUnicode(targetCnv) are called, and the
1493  *                      pivot pointers are reset (*pivotTarget=*pivotSource=pivotStart).
1494  * @param flush         If true, indicates the end of the input.
1495  *                      Passed directly to ucnv_toUnicode(), and carried over to
1496  *                      ucnv_fromUnicode() when the source is empty as well.
1497  * @param pErrorCode    ICU error code in/out parameter.
1498  *                      Must fulfill U_SUCCESS before the function call.
1499  *                      U_BUFFER_OVERFLOW_ERROR always refers to the target buffer
1500  *                      because overflows into the pivot buffer are handled internally.
1501  *                      Other conversion errors are from the source-to-pivot
1502  *                      conversion if *pivotSource==pivotStart, otherwise from
1503  *                      the pivot-to-target conversion.
1504  *
1505  * @see ucnv_convert
1506  * @see ucnv_fromAlgorithmic
1507  * @see ucnv_toAlgorithmic
1508  * @see ucnv_fromUnicode
1509  * @see ucnv_toUnicode
1510  * @see ucnv_fromUChars
1511  * @see ucnv_toUChars
1512  * @stable ICU 2.6
1513  */
1514 U_CAPI void U_EXPORT2
1515 ucnv_convertEx(UConverter *targetCnv, UConverter *sourceCnv,
1516                char **target, const char *targetLimit,
1517                const char **source, const char *sourceLimit,
1518                UChar *pivotStart, UChar **pivotSource,
1519                UChar **pivotTarget, const UChar *pivotLimit,
1520                UBool reset, UBool flush,
1521                UErrorCode *pErrorCode);
1522 
1523 /**
1524  * Convert from one external charset to another.
1525  * Internally, two converters are opened according to the name arguments,
1526  * then the text is converted to and from the 16-bit Unicode "pivot"
1527  * using ucnv_convertEx(), then the converters are closed again.
1528  *
1529  * This is a convenience function, not an efficient way to convert a lot of text:
1530  * ucnv_convert()
1531  * - takes charset names, not converter objects, so that
1532  *   - two converters are opened for each call
1533  *   - only single-string conversion is possible, not streaming operation
1534  * - does not provide enough information to find out,
1535  *   in case of failure, whether the toUnicode or
1536  *   the fromUnicode conversion failed
1537  * - allows NUL-terminated input
1538  *   (only a single NUL byte, will not work for charsets with multi-byte NULs)
1539  *   (if sourceLength==-1, see parameters)
1540  * - terminate with a NUL on output
1541  *   (only a single NUL byte, not useful for charsets with multi-byte NULs),
1542  *   or set U_STRING_NOT_TERMINATED_WARNING if the output exactly fills
1543  *   the target buffer
1544  * - a pivot buffer is provided internally
1545  *
1546  * The function returns when one of the following is true:
1547  * - the entire source text has been converted successfully to the target buffer
1548  *   and either the target buffer is terminated with a single NUL byte
1549  *   or the error code is set to U_STRING_NOT_TERMINATED_WARNING
1550  * - a target buffer overflow occurred (U_BUFFER_OVERFLOW_ERROR)
1551  *   and the full output string length is returned ("preflighting")
1552  * - a conversion error occurred
1553  *   (other U_FAILURE(), see description of pErrorCode)
1554  *
1555  * @param toConverterName   The name of the converter that is used to convert
1556  *                          from the UTF-16 pivot buffer to the target.
1557  * @param fromConverterName The name of the converter that is used to convert
1558  *                          from the source to the UTF-16 pivot buffer.
1559  * @param target            Pointer to the output buffer.
1560  * @param targetCapacity    Capacity of the target, in bytes.
1561  * @param source            Pointer to the input buffer.
1562  * @param sourceLength      Length of the input text, in bytes, or -1 for NUL-terminated input.
1563  * @param pErrorCode        ICU error code in/out parameter.
1564  *                          Must fulfill U_SUCCESS before the function call.
1565  * @return Length of the complete output text in bytes, even if it exceeds the targetCapacity
1566  *         and a U_BUFFER_OVERFLOW_ERROR is set.
1567  *
1568  * @see ucnv_convertEx
1569  * @see ucnv_fromAlgorithmic
1570  * @see ucnv_toAlgorithmic
1571  * @see ucnv_fromUnicode
1572  * @see ucnv_toUnicode
1573  * @see ucnv_fromUChars
1574  * @see ucnv_toUChars
1575  * @see ucnv_getNextUChar
1576  * @stable ICU 2.0
1577  */
1578 U_CAPI int32_t U_EXPORT2
1579 ucnv_convert(const char *toConverterName,
1580              const char *fromConverterName,
1581              char *target,
1582              int32_t targetCapacity,
1583              const char *source,
1584              int32_t sourceLength,
1585              UErrorCode *pErrorCode);
1586 
1587 /**
1588  * Convert from one external charset to another.
1589  * Internally, the text is converted to and from the 16-bit Unicode "pivot"
1590  * using ucnv_convertEx(). ucnv_toAlgorithmic() works exactly like ucnv_convert()
1591  * except that the two converters need not be looked up and opened completely.
1592  *
1593  * The source-to-pivot conversion uses the cnv converter parameter.
1594  * The pivot-to-target conversion uses a purely algorithmic converter
1595  * according to the specified type, e.g., UCNV_UTF8 for a UTF-8 converter.
1596  *
1597  * Internally, the algorithmic converter is opened and closed for each
1598  * function call, which is more efficient than using the public ucnv_open()
1599  * but somewhat less efficient than only resetting an existing converter
1600  * and using ucnv_convertEx().
1601  *
1602  * This function is more convenient than ucnv_convertEx() for single-string
1603  * conversions, especially when "preflighting" is desired (returning the length
1604  * of the complete output even if it does not fit into the target buffer;
1605  * see the User Guide Strings chapter). See ucnv_convert() for details.
1606  *
1607  * @param algorithmicType   UConverterType constant identifying the desired target
1608  *                          charset as a purely algorithmic converter.
1609  *                          Those are converters for Unicode charsets like
1610  *                          UTF-8, BOCU-1, SCSU, UTF-7, IMAP-mailbox-name, etc.,
1611  *                          as well as US-ASCII and ISO-8859-1.
1612  * @param cnv               The converter that is used to convert
1613  *                          from the source to the UTF-16 pivot buffer.
1614  * @param target            Pointer to the output buffer.
1615  * @param targetCapacity    Capacity of the target, in bytes.
1616  * @param source            Pointer to the input buffer.
1617  * @param sourceLength      Length of the input text, in bytes
1618  * @param pErrorCode        ICU error code in/out parameter.
1619  *                          Must fulfill U_SUCCESS before the function call.
1620  * @return Length of the complete output text in bytes, even if it exceeds the targetCapacity
1621  *         and a U_BUFFER_OVERFLOW_ERROR is set.
1622  *
1623  * @see ucnv_fromAlgorithmic
1624  * @see ucnv_convert
1625  * @see ucnv_convertEx
1626  * @see ucnv_fromUnicode
1627  * @see ucnv_toUnicode
1628  * @see ucnv_fromUChars
1629  * @see ucnv_toUChars
1630  * @stable ICU 2.6
1631  */
1632 U_CAPI int32_t U_EXPORT2
1633 ucnv_toAlgorithmic(UConverterType algorithmicType,
1634                    UConverter *cnv,
1635                    char *target, int32_t targetCapacity,
1636                    const char *source, int32_t sourceLength,
1637                    UErrorCode *pErrorCode);
1638 
1639 /**
1640  * Convert from one external charset to another.
1641  * Internally, the text is converted to and from the 16-bit Unicode "pivot"
1642  * using ucnv_convertEx(). ucnv_fromAlgorithmic() works exactly like ucnv_convert()
1643  * except that the two converters need not be looked up and opened completely.
1644  *
1645  * The source-to-pivot conversion uses a purely algorithmic converter
1646  * according to the specified type, e.g., UCNV_UTF8 for a UTF-8 converter.
1647  * The pivot-to-target conversion uses the cnv converter parameter.
1648  *
1649  * Internally, the algorithmic converter is opened and closed for each
1650  * function call, which is more efficient than using the public ucnv_open()
1651  * but somewhat less efficient than only resetting an existing converter
1652  * and using ucnv_convertEx().
1653  *
1654  * This function is more convenient than ucnv_convertEx() for single-string
1655  * conversions, especially when "preflighting" is desired (returning the length
1656  * of the complete output even if it does not fit into the target buffer;
1657  * see the User Guide Strings chapter). See ucnv_convert() for details.
1658  *
1659  * @param cnv               The converter that is used to convert
1660  *                          from the UTF-16 pivot buffer to the target.
1661  * @param algorithmicType   UConverterType constant identifying the desired source
1662  *                          charset as a purely algorithmic converter.
1663  *                          Those are converters for Unicode charsets like
1664  *                          UTF-8, BOCU-1, SCSU, UTF-7, IMAP-mailbox-name, etc.,
1665  *                          as well as US-ASCII and ISO-8859-1.
1666  * @param target            Pointer to the output buffer.
1667  * @param targetCapacity    Capacity of the target, in bytes.
1668  * @param source            Pointer to the input buffer.
1669  * @param sourceLength      Length of the input text, in bytes
1670  * @param pErrorCode        ICU error code in/out parameter.
1671  *                          Must fulfill U_SUCCESS before the function call.
1672  * @return Length of the complete output text in bytes, even if it exceeds the targetCapacity
1673  *         and a U_BUFFER_OVERFLOW_ERROR is set.
1674  *
1675  * @see ucnv_fromAlgorithmic
1676  * @see ucnv_convert
1677  * @see ucnv_convertEx
1678  * @see ucnv_fromUnicode
1679  * @see ucnv_toUnicode
1680  * @see ucnv_fromUChars
1681  * @see ucnv_toUChars
1682  * @stable ICU 2.6
1683  */
1684 U_CAPI int32_t U_EXPORT2
1685 ucnv_fromAlgorithmic(UConverter *cnv,
1686                      UConverterType algorithmicType,
1687                      char *target, int32_t targetCapacity,
1688                      const char *source, int32_t sourceLength,
1689                      UErrorCode *pErrorCode);
1690 
1691 /**
1692  * Frees up memory occupied by unused, cached converter shared data.
1693  *
1694  * @return the number of cached converters successfully deleted
1695  * @see ucnv_close
1696  * @stable ICU 2.0
1697  */
1698 U_CAPI int32_t U_EXPORT2
1699 ucnv_flushCache(void);
1700 
1701 /**
1702  * Returns the number of available converters, as per the alias file.
1703  *
1704  * @return the number of available converters
1705  * @see ucnv_getAvailableName
1706  * @stable ICU 2.0
1707  */
1708 U_CAPI int32_t U_EXPORT2
1709 ucnv_countAvailable(void);
1710 
1711 /**
1712  * Gets the canonical converter name of the specified converter from a list of
1713  * all available converters contained in the alias file. All converters
1714  * in this list can be opened.
1715  *
1716  * @param n the index to a converter available on the system (in the range <TT>[0..ucnv_countAvailable()]</TT>)
1717  * @return a pointer a string (library owned), or <TT>NULL</TT> if the index is out of bounds.
1718  * @see ucnv_countAvailable
1719  * @stable ICU 2.0
1720  */
1721 U_CAPI const char* U_EXPORT2
1722 ucnv_getAvailableName(int32_t n);
1723 
1724 /**
1725  * Returns a UEnumeration to enumerate all of the canonical converter
1726  * names, as per the alias file, regardless of the ability to open each
1727  * converter.
1728  *
1729  * @return A UEnumeration object for getting all the recognized canonical
1730  *   converter names.
1731  * @see ucnv_getAvailableName
1732  * @see uenum_close
1733  * @see uenum_next
1734  * @stable ICU 2.4
1735  */
1736 U_CAPI UEnumeration * U_EXPORT2
1737 ucnv_openAllNames(UErrorCode *pErrorCode);
1738 
1739 /**
1740  * Gives the number of aliases for a given converter or alias name.
1741  * If the alias is ambiguous, then the preferred converter is used
1742  * and the status is set to U_AMBIGUOUS_ALIAS_WARNING.
1743  * This method only enumerates the listed entries in the alias file.
1744  * @param alias alias name
1745  * @param pErrorCode error status
1746  * @return number of names on alias list for given alias
1747  * @stable ICU 2.0
1748  */
1749 U_CAPI uint16_t U_EXPORT2
1750 ucnv_countAliases(const char *alias, UErrorCode *pErrorCode);
1751 
1752 /**
1753  * Gives the name of the alias at given index of alias list.
1754  * This method only enumerates the listed entries in the alias file.
1755  * If the alias is ambiguous, then the preferred converter is used
1756  * and the status is set to U_AMBIGUOUS_ALIAS_WARNING.
1757  * @param alias alias name
1758  * @param n index in alias list
1759  * @param pErrorCode result of operation
1760  * @return returns the name of the alias at given index
1761  * @see ucnv_countAliases
1762  * @stable ICU 2.0
1763  */
1764 U_CAPI const char * U_EXPORT2
1765 ucnv_getAlias(const char *alias, uint16_t n, UErrorCode *pErrorCode);
1766 
1767 /**
1768  * Fill-up the list of alias names for the given alias.
1769  * This method only enumerates the listed entries in the alias file.
1770  * If the alias is ambiguous, then the preferred converter is used
1771  * and the status is set to U_AMBIGUOUS_ALIAS_WARNING.
1772  * @param alias alias name
1773  * @param aliases fill-in list, aliases is a pointer to an array of
1774  *        <code>ucnv_countAliases()</code> string-pointers
1775  *        (<code>const char *</code>) that will be filled in.
1776  *        The strings themselves are owned by the library.
1777  * @param pErrorCode result of operation
1778  * @stable ICU 2.0
1779  */
1780 U_CAPI void U_EXPORT2
1781 ucnv_getAliases(const char *alias, const char **aliases, UErrorCode *pErrorCode);
1782 
1783 /**
1784  * Return a new UEnumeration object for enumerating all the
1785  * alias names for a given converter that are recognized by a standard.
1786  * This method only enumerates the listed entries in the alias file.
1787  * The convrtrs.txt file can be modified to change the results of
1788  * this function.
1789  * The first result in this list is the same result given by
1790  * <code>ucnv_getStandardName</code>, which is the default alias for
1791  * the specified standard name. The returned object must be closed with
1792  * <code>uenum_close</code> when you are done with the object.
1793  *
1794  * @param convName original converter name
1795  * @param standard name of the standard governing the names; MIME and IANA
1796  *      are such standards
1797  * @param pErrorCode The error code
1798  * @return A UEnumeration object for getting all aliases that are recognized
1799  *      by a standard. If any of the parameters are invalid, NULL
1800  *      is returned.
1801  * @see ucnv_getStandardName
1802  * @see uenum_close
1803  * @see uenum_next
1804  * @stable ICU 2.2
1805  */
1806 U_CAPI UEnumeration * U_EXPORT2
1807 ucnv_openStandardNames(const char *convName,
1808                        const char *standard,
1809                        UErrorCode *pErrorCode);
1810 
1811 /**
1812  * Gives the number of standards associated to converter names.
1813  * @return number of standards
1814  * @stable ICU 2.0
1815  */
1816 U_CAPI uint16_t U_EXPORT2
1817 ucnv_countStandards(void);
1818 
1819 /**
1820  * Gives the name of the standard at given index of standard list.
1821  * @param n index in standard list
1822  * @param pErrorCode result of operation
1823  * @return returns the name of the standard at given index. Owned by the library.
1824  * @stable ICU 2.0
1825  */
1826 U_CAPI const char * U_EXPORT2
1827 ucnv_getStandard(uint16_t n, UErrorCode *pErrorCode);
1828 
1829 /**
1830  * Returns a standard name for a given converter name.
1831  * <p>
1832  * Example alias table:<br>
1833  * conv alias1 { STANDARD1 } alias2 { STANDARD1* }
1834  * <p>
1835  * Result of ucnv_getStandardName("conv", "STANDARD1") from example
1836  * alias table:<br>
1837  * <b>"alias2"</b>
1838  *
1839  * @param name original converter name
1840  * @param standard name of the standard governing the names; MIME and IANA
1841  *        are such standards
1842  * @param pErrorCode result of operation
1843  * @return returns the standard converter name;
1844  *         if a standard converter name cannot be determined,
1845  *         then <code>NULL</code> is returned. Owned by the library.
1846  * @stable ICU 2.0
1847  */
1848 U_CAPI const char * U_EXPORT2
1849 ucnv_getStandardName(const char *name, const char *standard, UErrorCode *pErrorCode);
1850 
1851 /**
1852  * This function will return the internal canonical converter name of the
1853  * tagged alias. This is the opposite of ucnv_openStandardNames, which
1854  * returns the tagged alias given the canonical name.
1855  * <p>
1856  * Example alias table:<br>
1857  * conv alias1 { STANDARD1 } alias2 { STANDARD1* }
1858  * <p>
1859  * Result of ucnv_getStandardName("alias1", "STANDARD1") from example
1860  * alias table:<br>
1861  * <b>"conv"</b>
1862  *
1863  * @return returns the canonical converter name;
1864  *         if a standard or alias name cannot be determined,
1865  *         then <code>NULL</code> is returned. The returned string is
1866  *         owned by the library.
1867  * @see ucnv_getStandardName
1868  * @stable ICU 2.4
1869  */
1870 U_CAPI const char * U_EXPORT2
1871 ucnv_getCanonicalName(const char *alias, const char *standard, UErrorCode *pErrorCode);
1872 
1873 /**
1874  * Returns the current default converter name. If you want to open
1875  * a default converter, you do not need to use this function.
1876  * It is faster if you pass a NULL argument to ucnv_open the
1877  * default converter.
1878  *
1879  * If U_CHARSET_IS_UTF8 is defined to 1 in utypes.h then this function
1880  * always returns "UTF-8".
1881  *
1882  * @return returns the current default converter name.
1883  *         Storage owned by the library
1884  * @see ucnv_setDefaultName
1885  * @stable ICU 2.0
1886  */
1887 U_CAPI const char * U_EXPORT2
1888 ucnv_getDefaultName(void);
1889 
1890 #ifndef U_HIDE_SYSTEM_API
1891 /**
1892  * This function is not thread safe. DO NOT call this function when ANY ICU
1893  * function is being used from more than one thread! This function sets the
1894  * current default converter name. If this function needs to be called, it
1895  * should be called during application initialization. Most of the time, the
1896  * results from ucnv_getDefaultName() or ucnv_open with a NULL string argument
1897  * is sufficient for your application.
1898  *
1899  * If U_CHARSET_IS_UTF8 is defined to 1 in utypes.h then this function
1900  * does nothing.
1901  *
1902  * @param name the converter name to be the default (must be known by ICU).
1903  * @see ucnv_getDefaultName
1904  * @system
1905  * @stable ICU 2.0
1906  */
1907 U_CAPI void U_EXPORT2
1908 ucnv_setDefaultName(const char *name);
1909 #endif  /* U_HIDE_SYSTEM_API */
1910 
1911 /**
1912  * Fixes the backslash character mismapping.  For example, in SJIS, the backslash
1913  * character in the ASCII portion is also used to represent the yen currency sign.
1914  * When mapping from Unicode character 0x005C, it's unclear whether to map the
1915  * character back to yen or backslash in SJIS.  This function will take the input
1916  * buffer and replace all the yen sign characters with backslash.  This is necessary
1917  * when the user tries to open a file with the input buffer on Windows.
1918  * This function will test the converter to see whether such mapping is
1919  * required.  You can sometimes avoid using this function by using the correct version
1920  * of Shift-JIS.
1921  *
1922  * @param cnv The converter representing the target codepage.
1923  * @param source the input buffer to be fixed
1924  * @param sourceLen the length of the input buffer
1925  * @see ucnv_isAmbiguous
1926  * @stable ICU 2.0
1927  */
1928 U_CAPI void U_EXPORT2
1929 ucnv_fixFileSeparator(const UConverter *cnv, UChar *source, int32_t sourceLen);
1930 
1931 /**
1932  * Determines if the converter contains ambiguous mappings of the same
1933  * character or not.
1934  * @param cnv the converter to be tested
1935  * @return true if the converter contains ambiguous mapping of the same
1936  * character, false otherwise.
1937  * @stable ICU 2.0
1938  */
1939 U_CAPI UBool U_EXPORT2
1940 ucnv_isAmbiguous(const UConverter *cnv);
1941 
1942 /**
1943  * Sets the converter to use fallback mappings or not.
1944  * Regardless of this flag, the converter will always use
1945  * fallbacks from Unicode Private Use code points, as well as
1946  * reverse fallbacks (to Unicode).
1947  * For details see ".ucm File Format"
1948  * in the Conversion Data chapter of the ICU User Guide:
1949  * https://unicode-org.github.io/icu/userguide/conversion/data.html#ucm-file-format
1950  *
1951  * @param cnv The converter to set the fallback mapping usage on.
1952  * @param usesFallback true if the user wants the converter to take advantage of the fallback
1953  * mapping, false otherwise.
1954  * @stable ICU 2.0
1955  * @see ucnv_usesFallback
1956  */
1957 U_CAPI void U_EXPORT2
1958 ucnv_setFallback(UConverter *cnv, UBool usesFallback);
1959 
1960 /**
1961  * Determines if the converter uses fallback mappings or not.
1962  * This flag has restrictions, see ucnv_setFallback().
1963  *
1964  * @param cnv The converter to be tested
1965  * @return true if the converter uses fallback, false otherwise.
1966  * @stable ICU 2.0
1967  * @see ucnv_setFallback
1968  */
1969 U_CAPI UBool U_EXPORT2
1970 ucnv_usesFallback(const UConverter *cnv);
1971 
1972 /**
1973  * Detects Unicode signature byte sequences at the start of the byte stream
1974  * and returns the charset name of the indicated Unicode charset.
1975  * NULL is returned when no Unicode signature is recognized.
1976  * The number of bytes in the signature is output as well.
1977  *
1978  * The caller can ucnv_open() a converter using the charset name.
1979  * The first code unit (UChar) from the start of the stream will be U+FEFF
1980  * (the Unicode BOM/signature character) and can usually be ignored.
1981  *
1982  * For most Unicode charsets it is also possible to ignore the indicated
1983  * number of initial stream bytes and start converting after them.
1984  * However, there are stateful Unicode charsets (UTF-7 and BOCU-1) for which
1985  * this will not work. Therefore, it is best to ignore the first output UChar
1986  * instead of the input signature bytes.
1987  * <p>
1988  * Usage:
1989  * \snippet samples/ucnv/convsamp.cpp ucnv_detectUnicodeSignature
1990  *
1991  * @param source            The source string in which the signature should be detected.
1992  * @param sourceLength      Length of the input string, or -1 if terminated with a NUL byte.
1993  * @param signatureLength   A pointer to int32_t to receive the number of bytes that make up the signature
1994  *                          of the detected UTF. 0 if not detected.
1995  *                          Can be a NULL pointer.
1996  * @param pErrorCode        ICU error code in/out parameter.
1997  *                          Must fulfill U_SUCCESS before the function call.
1998  * @return The name of the encoding detected. NULL if encoding is not detected.
1999  * @stable ICU 2.4
2000  */
2001 U_CAPI const char* U_EXPORT2
2002 ucnv_detectUnicodeSignature(const char* source,
2003                             int32_t sourceLength,
2004                             int32_t *signatureLength,
2005                             UErrorCode *pErrorCode);
2006 
2007 /**
2008  * Returns the number of UChars held in the converter's internal state
2009  * because more input is needed for completing the conversion. This function is
2010  * useful for mapping semantics of ICU's converter interface to those of iconv,
2011  * and this information is not needed for normal conversion.
2012  * @param cnv       The converter in which the input is held
2013  * @param status    ICU error code in/out parameter.
2014  *                  Must fulfill U_SUCCESS before the function call.
2015  * @return The number of UChars in the state. -1 if an error is encountered.
2016  * @stable ICU 3.4
2017  */
2018 U_CAPI int32_t U_EXPORT2
2019 ucnv_fromUCountPending(const UConverter* cnv, UErrorCode* status);
2020 
2021 /**
2022  * Returns the number of chars held in the converter's internal state
2023  * because more input is needed for completing the conversion. This function is
2024  * useful for mapping semantics of ICU's converter interface to those of iconv,
2025  * and this information is not needed for normal conversion.
2026  * @param cnv       The converter in which the input is held as internal state
2027  * @param status    ICU error code in/out parameter.
2028  *                  Must fulfill U_SUCCESS before the function call.
2029  * @return The number of chars in the state. -1 if an error is encountered.
2030  * @stable ICU 3.4
2031  */
2032 U_CAPI int32_t U_EXPORT2
2033 ucnv_toUCountPending(const UConverter* cnv, UErrorCode* status);
2034 
2035 /**
2036  * Returns whether or not the charset of the converter has a fixed number of bytes
2037  * per charset character.
2038  * An example of this are converters that are of the type UCNV_SBCS or UCNV_DBCS.
2039  * Another example is UTF-32 which is always 4 bytes per character.
2040  * A Unicode code point may be represented by more than one UTF-8 or UTF-16 code unit
2041  * but a UTF-32 converter encodes each code point with 4 bytes.
2042  * Note: This method is not intended to be used to determine whether the charset has a
2043  * fixed ratio of bytes to Unicode codes <i>units</i> for any particular Unicode encoding form.
2044  * false is returned with the UErrorCode if error occurs or cnv is NULL.
2045  * @param cnv       The converter to be tested
2046  * @param status    ICU error code in/out parameter
2047  * @return true if the converter is fixed-width
2048  * @stable ICU 4.8
2049  */
2050 U_CAPI UBool U_EXPORT2
2051 ucnv_isFixedWidth(UConverter *cnv, UErrorCode *status);
2052 
2053 #endif
2054 
2055 #endif
2056 /*_UCNV*/