jpayne@69: // © 2016 and later: Unicode, Inc. and others. jpayne@69: // License & terms of use: http://www.unicode.org/copyright.html jpayne@69: /* jpayne@69: ********************************************************************** jpayne@69: * Copyright (C) 1999-2014, International Business Machines jpayne@69: * Corporation and others. All Rights Reserved. jpayne@69: ********************************************************************** jpayne@69: * ucnv.h: jpayne@69: * External APIs for the ICU's codeset conversion library jpayne@69: * Bertrand A. Damiba jpayne@69: * jpayne@69: * Modification History: jpayne@69: * jpayne@69: * Date Name Description jpayne@69: * 04/04/99 helena Fixed internal header inclusion. jpayne@69: * 05/11/00 helena Added setFallback and usesFallback APIs. jpayne@69: * 06/29/2000 helena Major rewrite of the callback APIs. jpayne@69: * 12/07/2000 srl Update of documentation jpayne@69: */ jpayne@69: jpayne@69: /** jpayne@69: * \file jpayne@69: * \brief C API: Character conversion jpayne@69: * jpayne@69: *

Character Conversion C API

jpayne@69: * jpayne@69: *

This API is used to convert codepage or character encoded data to and jpayne@69: * from UTF-16. You can open a converter with {@link ucnv_open() }. With that jpayne@69: * converter, you can get its properties, set options, convert your data and jpayne@69: * close the converter.

jpayne@69: * jpayne@69: *

Since many software programs recognize different converter names for jpayne@69: * different types of converters, there are other functions in this API to jpayne@69: * iterate over the converter aliases. The functions {@link ucnv_getAvailableName() }, jpayne@69: * {@link ucnv_getAlias() } and {@link ucnv_getStandardName() } are some of the jpayne@69: * more frequently used alias functions to get this information.

jpayne@69: * jpayne@69: *

When a converter encounters an illegal, irregular, invalid or unmappable character jpayne@69: * its default behavior is to use a substitution character to replace the jpayne@69: * bad byte sequence. This behavior can be changed by using {@link ucnv_setFromUCallBack() } jpayne@69: * or {@link ucnv_setToUCallBack() } on the converter. The header ucnv_err.h defines jpayne@69: * many other callback actions that can be used instead of a character substitution.

jpayne@69: * jpayne@69: *

More information about this API can be found in our jpayne@69: * User's jpayne@69: * Guide.

jpayne@69: */ jpayne@69: jpayne@69: #ifndef UCNV_H jpayne@69: #define UCNV_H jpayne@69: jpayne@69: #include "unicode/ucnv_err.h" jpayne@69: #include "unicode/uenum.h" jpayne@69: #include "unicode/localpointer.h" jpayne@69: jpayne@69: #if !defined(USET_DEFINED) && !defined(U_IN_DOXYGEN) jpayne@69: jpayne@69: #define USET_DEFINED jpayne@69: jpayne@69: /** jpayne@69: * USet is the C API type corresponding to C++ class UnicodeSet. jpayne@69: * It is forward-declared here to avoid including unicode/uset.h file if related jpayne@69: * conversion APIs are not used. jpayne@69: * jpayne@69: * @see ucnv_getUnicodeSet jpayne@69: * @stable ICU 2.4 jpayne@69: */ jpayne@69: typedef struct USet USet; jpayne@69: jpayne@69: #endif jpayne@69: jpayne@69: #if !UCONFIG_NO_CONVERSION jpayne@69: jpayne@69: U_CDECL_BEGIN jpayne@69: jpayne@69: /** Maximum length of a converter name including the terminating NULL @stable ICU 2.0 */ jpayne@69: #define UCNV_MAX_CONVERTER_NAME_LENGTH 60 jpayne@69: /** Maximum length of a converter name including path and terminating NULL @stable ICU 2.0 */ jpayne@69: #define UCNV_MAX_FULL_FILE_NAME_LENGTH (600+UCNV_MAX_CONVERTER_NAME_LENGTH) jpayne@69: jpayne@69: /** Shift in for EBDCDIC_STATEFUL and iso2022 states @stable ICU 2.0 */ jpayne@69: #define UCNV_SI 0x0F jpayne@69: /** Shift out for EBDCDIC_STATEFUL and iso2022 states @stable ICU 2.0 */ jpayne@69: #define UCNV_SO 0x0E jpayne@69: jpayne@69: /** jpayne@69: * Enum for specifying basic types of converters jpayne@69: * @see ucnv_getType jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: typedef enum { jpayne@69: /** @stable ICU 2.0 */ jpayne@69: UCNV_UNSUPPORTED_CONVERTER = -1, jpayne@69: /** @stable ICU 2.0 */ jpayne@69: UCNV_SBCS = 0, jpayne@69: /** @stable ICU 2.0 */ jpayne@69: UCNV_DBCS = 1, jpayne@69: /** @stable ICU 2.0 */ jpayne@69: UCNV_MBCS = 2, jpayne@69: /** @stable ICU 2.0 */ jpayne@69: UCNV_LATIN_1 = 3, jpayne@69: /** @stable ICU 2.0 */ jpayne@69: UCNV_UTF8 = 4, jpayne@69: /** @stable ICU 2.0 */ jpayne@69: UCNV_UTF16_BigEndian = 5, jpayne@69: /** @stable ICU 2.0 */ jpayne@69: UCNV_UTF16_LittleEndian = 6, jpayne@69: /** @stable ICU 2.0 */ jpayne@69: UCNV_UTF32_BigEndian = 7, jpayne@69: /** @stable ICU 2.0 */ jpayne@69: UCNV_UTF32_LittleEndian = 8, jpayne@69: /** @stable ICU 2.0 */ jpayne@69: UCNV_EBCDIC_STATEFUL = 9, jpayne@69: /** @stable ICU 2.0 */ jpayne@69: UCNV_ISO_2022 = 10, jpayne@69: jpayne@69: /** @stable ICU 2.0 */ jpayne@69: UCNV_LMBCS_1 = 11, jpayne@69: /** @stable ICU 2.0 */ jpayne@69: UCNV_LMBCS_2, jpayne@69: /** @stable ICU 2.0 */ jpayne@69: UCNV_LMBCS_3, jpayne@69: /** @stable ICU 2.0 */ jpayne@69: UCNV_LMBCS_4, jpayne@69: /** @stable ICU 2.0 */ jpayne@69: UCNV_LMBCS_5, jpayne@69: /** @stable ICU 2.0 */ jpayne@69: UCNV_LMBCS_6, jpayne@69: /** @stable ICU 2.0 */ jpayne@69: UCNV_LMBCS_8, jpayne@69: /** @stable ICU 2.0 */ jpayne@69: UCNV_LMBCS_11, jpayne@69: /** @stable ICU 2.0 */ jpayne@69: UCNV_LMBCS_16, jpayne@69: /** @stable ICU 2.0 */ jpayne@69: UCNV_LMBCS_17, jpayne@69: /** @stable ICU 2.0 */ jpayne@69: UCNV_LMBCS_18, jpayne@69: /** @stable ICU 2.0 */ jpayne@69: UCNV_LMBCS_19, jpayne@69: /** @stable ICU 2.0 */ jpayne@69: UCNV_LMBCS_LAST = UCNV_LMBCS_19, jpayne@69: /** @stable ICU 2.0 */ jpayne@69: UCNV_HZ, jpayne@69: /** @stable ICU 2.0 */ jpayne@69: UCNV_SCSU, jpayne@69: /** @stable ICU 2.0 */ jpayne@69: UCNV_ISCII, jpayne@69: /** @stable ICU 2.0 */ jpayne@69: UCNV_US_ASCII, jpayne@69: /** @stable ICU 2.0 */ jpayne@69: UCNV_UTF7, jpayne@69: /** @stable ICU 2.2 */ jpayne@69: UCNV_BOCU1, jpayne@69: /** @stable ICU 2.2 */ jpayne@69: UCNV_UTF16, jpayne@69: /** @stable ICU 2.2 */ jpayne@69: UCNV_UTF32, jpayne@69: /** @stable ICU 2.2 */ jpayne@69: UCNV_CESU8, jpayne@69: /** @stable ICU 2.4 */ jpayne@69: UCNV_IMAP_MAILBOX, jpayne@69: /** @stable ICU 4.8 */ jpayne@69: UCNV_COMPOUND_TEXT, jpayne@69: jpayne@69: /* Number of converter types for which we have conversion routines. */ jpayne@69: UCNV_NUMBER_OF_SUPPORTED_CONVERTER_TYPES jpayne@69: } UConverterType; jpayne@69: jpayne@69: /** jpayne@69: * Enum for specifying which platform a converter ID refers to. jpayne@69: * The use of platform/CCSID is not recommended. See ucnv_openCCSID(). jpayne@69: * jpayne@69: * @see ucnv_getPlatform jpayne@69: * @see ucnv_openCCSID jpayne@69: * @see ucnv_getCCSID jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: typedef enum { jpayne@69: UCNV_UNKNOWN = -1, jpayne@69: UCNV_IBM = 0 jpayne@69: } UConverterPlatform; jpayne@69: jpayne@69: /** jpayne@69: * Function pointer for error callback in the codepage to unicode direction. jpayne@69: * Called when an error has occurred in conversion to unicode, or on open/close of the callback (see reason). jpayne@69: * @param context Pointer to the callback's private data jpayne@69: * @param args Information about the conversion in progress jpayne@69: * @param codeUnits Points to 'length' bytes of the concerned codepage sequence jpayne@69: * @param length Size (in bytes) of the concerned codepage sequence jpayne@69: * @param reason Defines the reason the callback was invoked jpayne@69: * @param pErrorCode ICU error code in/out parameter. jpayne@69: * For converter callback functions, set to a conversion error jpayne@69: * before the call, and the callback may reset it to U_ZERO_ERROR. jpayne@69: * @see ucnv_setToUCallBack jpayne@69: * @see UConverterToUnicodeArgs jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: typedef void (U_EXPORT2 *UConverterToUCallback) ( jpayne@69: const void* context, jpayne@69: UConverterToUnicodeArgs *args, jpayne@69: const char *codeUnits, jpayne@69: int32_t length, jpayne@69: UConverterCallbackReason reason, jpayne@69: UErrorCode *pErrorCode); jpayne@69: jpayne@69: /** jpayne@69: * Function pointer for error callback in the unicode to codepage direction. jpayne@69: * Called when an error has occurred in conversion from unicode, or on open/close of the callback (see reason). jpayne@69: * @param context Pointer to the callback's private data jpayne@69: * @param args Information about the conversion in progress jpayne@69: * @param codeUnits Points to 'length' UChars of the concerned Unicode sequence jpayne@69: * @param length Size (in bytes) of the concerned codepage sequence jpayne@69: * @param codePoint Single UChar32 (UTF-32) containing the concerend Unicode codepoint. jpayne@69: * @param reason Defines the reason the callback was invoked jpayne@69: * @param pErrorCode ICU error code in/out parameter. jpayne@69: * For converter callback functions, set to a conversion error jpayne@69: * before the call, and the callback may reset it to U_ZERO_ERROR. jpayne@69: * @see ucnv_setFromUCallBack jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: typedef void (U_EXPORT2 *UConverterFromUCallback) ( jpayne@69: const void* context, jpayne@69: UConverterFromUnicodeArgs *args, jpayne@69: const UChar* codeUnits, jpayne@69: int32_t length, jpayne@69: UChar32 codePoint, jpayne@69: UConverterCallbackReason reason, jpayne@69: UErrorCode *pErrorCode); jpayne@69: jpayne@69: U_CDECL_END jpayne@69: jpayne@69: /** jpayne@69: * Character that separates converter names from options and options from each other. jpayne@69: * @see ucnv_open jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: #define UCNV_OPTION_SEP_CHAR ',' jpayne@69: jpayne@69: /** jpayne@69: * String version of UCNV_OPTION_SEP_CHAR. jpayne@69: * @see ucnv_open jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: #define UCNV_OPTION_SEP_STRING "," jpayne@69: jpayne@69: /** jpayne@69: * Character that separates a converter option from its value. jpayne@69: * @see ucnv_open jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: #define UCNV_VALUE_SEP_CHAR '=' jpayne@69: jpayne@69: /** jpayne@69: * String version of UCNV_VALUE_SEP_CHAR. jpayne@69: * @see ucnv_open jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: #define UCNV_VALUE_SEP_STRING "=" jpayne@69: jpayne@69: /** jpayne@69: * Converter option for specifying a locale. jpayne@69: * For example, ucnv_open("SCSU,locale=ja", &errorCode); jpayne@69: * See convrtrs.txt. jpayne@69: * jpayne@69: * @see ucnv_open jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: #define UCNV_LOCALE_OPTION_STRING ",locale=" jpayne@69: jpayne@69: /** jpayne@69: * Converter option for specifying a version selector (0..9) for some converters. jpayne@69: * For example, jpayne@69: * \code jpayne@69: * ucnv_open("UTF-7,version=1", &errorCode); jpayne@69: * \endcode jpayne@69: * See convrtrs.txt. jpayne@69: * jpayne@69: * @see ucnv_open jpayne@69: * @stable ICU 2.4 jpayne@69: */ jpayne@69: #define UCNV_VERSION_OPTION_STRING ",version=" jpayne@69: jpayne@69: /** jpayne@69: * Converter option for EBCDIC SBCS or mixed-SBCS/DBCS (stateful) codepages. jpayne@69: * Swaps Unicode mappings for EBCDIC LF and NL codes, as used on jpayne@69: * S/390 (z/OS) Unix System Services (Open Edition). jpayne@69: * For example, ucnv_open("ibm-1047,swaplfnl", &errorCode); jpayne@69: * See convrtrs.txt. jpayne@69: * jpayne@69: * @see ucnv_open jpayne@69: * @stable ICU 2.4 jpayne@69: */ jpayne@69: #define UCNV_SWAP_LFNL_OPTION_STRING ",swaplfnl" jpayne@69: jpayne@69: /** jpayne@69: * Do a fuzzy compare of two converter/alias names. jpayne@69: * The comparison is case-insensitive, ignores leading zeroes if they are not jpayne@69: * followed by further digits, and ignores all but letters and digits. jpayne@69: * Thus the strings "UTF-8", "utf_8", "u*T@f08" and "Utf 8" are exactly equivalent. jpayne@69: * See section 1.4, Charset Alias Matching in Unicode Technical Standard #22 jpayne@69: * at http://www.unicode.org/reports/tr22/ jpayne@69: * jpayne@69: * @param name1 a converter name or alias, zero-terminated jpayne@69: * @param name2 a converter name or alias, zero-terminated jpayne@69: * @return 0 if the names match, or a negative value if the name1 jpayne@69: * lexically precedes name2, or a positive value if the name1 jpayne@69: * lexically follows name2. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE int U_EXPORT2 jpayne@69: ucnv_compareNames(const char *name1, const char *name2); jpayne@69: jpayne@69: jpayne@69: /** jpayne@69: * Creates a UConverter object with the name of a coded character set specified as a C string. jpayne@69: * The actual name will be resolved with the alias file jpayne@69: * using a case-insensitive string comparison that ignores jpayne@69: * leading zeroes and all non-alphanumeric characters. jpayne@69: * E.g., the names "UTF8", "utf-8", "u*T@f08" and "Utf 8" are all equivalent. jpayne@69: * (See also ucnv_compareNames().) jpayne@69: * If NULL is passed for the converter name, it will create one with the jpayne@69: * getDefaultName return value. jpayne@69: * jpayne@69: *

A converter name for ICU 1.5 and above may contain options jpayne@69: * like a locale specification to control the specific behavior of jpayne@69: * the newly instantiated converter. jpayne@69: * The meaning of the options depends on the particular converter. jpayne@69: * If an option is not defined for or recognized by a given converter, then it is ignored.

jpayne@69: * jpayne@69: *

Options are appended to the converter name string, with a jpayne@69: * UCNV_OPTION_SEP_CHAR between the name and the first option and jpayne@69: * also between adjacent options.

jpayne@69: * jpayne@69: *

If the alias is ambiguous, then the preferred converter is used jpayne@69: * and the status is set to U_AMBIGUOUS_ALIAS_WARNING.

jpayne@69: * jpayne@69: *

The conversion behavior and names can vary between platforms. ICU may jpayne@69: * convert some characters differently from other platforms. Details on this topic jpayne@69: * are in the User's jpayne@69: * Guide. Aliases starting with a "cp" prefix have no specific meaning jpayne@69: * other than its an alias starting with the letters "cp". Please do not jpayne@69: * associate any meaning to these aliases.

jpayne@69: * jpayne@69: * \snippet samples/ucnv/convsamp.cpp ucnv_open jpayne@69: * jpayne@69: * @param converterName Name of the coded character set table. jpayne@69: * This may have options appended to the string. jpayne@69: * IANA alias character set names, IBM CCSIDs starting with "ibm-", jpayne@69: * Windows codepage numbers starting with "windows-" are frequently jpayne@69: * used for this parameter. See ucnv_getAvailableName and jpayne@69: * ucnv_getAlias for a complete list that is available. jpayne@69: * If this parameter is NULL, the default converter will be used. jpayne@69: * @param err outgoing error status U_MEMORY_ALLOCATION_ERROR, U_FILE_ACCESS_ERROR jpayne@69: * @return the created Unicode converter object, or NULL if an error occurred jpayne@69: * @see ucnv_openU jpayne@69: * @see ucnv_openCCSID jpayne@69: * @see ucnv_getAvailableName jpayne@69: * @see ucnv_getAlias jpayne@69: * @see ucnv_getDefaultName jpayne@69: * @see ucnv_close jpayne@69: * @see ucnv_compareNames jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE UConverter* U_EXPORT2 jpayne@69: ucnv_open(const char *converterName, UErrorCode *err); jpayne@69: jpayne@69: jpayne@69: /** jpayne@69: * Creates a Unicode converter with the names specified as unicode string. jpayne@69: * The name should be limited to the ASCII-7 alphanumerics range. jpayne@69: * The actual name will be resolved with the alias file jpayne@69: * using a case-insensitive string comparison that ignores jpayne@69: * leading zeroes and all non-alphanumeric characters. jpayne@69: * E.g., the names "UTF8", "utf-8", "u*T@f08" and "Utf 8" are all equivalent. jpayne@69: * (See also ucnv_compareNames().) jpayne@69: * If NULL is passed for the converter name, it will create jpayne@69: * one with the ucnv_getDefaultName() return value. jpayne@69: * If the alias is ambiguous, then the preferred converter is used jpayne@69: * and the status is set to U_AMBIGUOUS_ALIAS_WARNING. jpayne@69: * jpayne@69: *

See ucnv_open for the complete details

jpayne@69: * @param name Name of the UConverter table in a zero terminated jpayne@69: * Unicode string jpayne@69: * @param err outgoing error status U_MEMORY_ALLOCATION_ERROR, jpayne@69: * U_FILE_ACCESS_ERROR jpayne@69: * @return the created Unicode converter object, or NULL if an jpayne@69: * error occurred jpayne@69: * @see ucnv_open jpayne@69: * @see ucnv_openCCSID jpayne@69: * @see ucnv_close jpayne@69: * @see ucnv_compareNames jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE UConverter* U_EXPORT2 jpayne@69: ucnv_openU(const UChar *name, jpayne@69: UErrorCode *err); jpayne@69: jpayne@69: /** jpayne@69: * Creates a UConverter object from a CCSID number and platform pair. jpayne@69: * Note that the usefulness of this function is limited to platforms with numeric jpayne@69: * encoding IDs. Only IBM and Microsoft platforms use numeric (16-bit) identifiers for jpayne@69: * encodings. jpayne@69: * jpayne@69: * In addition, IBM CCSIDs and Unicode conversion tables are not 1:1 related. jpayne@69: * For many IBM CCSIDs there are multiple (up to six) Unicode conversion tables, and jpayne@69: * for some Unicode conversion tables there are multiple CCSIDs. jpayne@69: * Some "alternate" Unicode conversion tables are provided by the jpayne@69: * IBM CDRA conversion table registry. jpayne@69: * The most prominent example of a systematic modification of conversion tables that is jpayne@69: * not provided in the form of conversion table files in the repository is jpayne@69: * that S/390 Unix System Services swaps the codes for Line Feed and New Line in all jpayne@69: * EBCDIC codepages, which requires such a swap in the Unicode conversion tables as well. jpayne@69: * jpayne@69: * Only IBM default conversion tables are accessible with ucnv_openCCSID(). jpayne@69: * ucnv_getCCSID() will return the same CCSID for all conversion tables that are associated jpayne@69: * with that CCSID. jpayne@69: * jpayne@69: * Currently, the only "platform" supported in the ICU converter API is UCNV_IBM. jpayne@69: * jpayne@69: * In summary, the use of CCSIDs and the associated API functions is not recommended. jpayne@69: * jpayne@69: * In order to open a converter with the default IBM CDRA Unicode conversion table, jpayne@69: * you can use this function or use the prefix "ibm-": jpayne@69: * \code jpayne@69: * char name[20]; jpayne@69: * sprintf(name, "ibm-%hu", ccsid); jpayne@69: * cnv=ucnv_open(name, &errorCode); jpayne@69: * \endcode jpayne@69: * jpayne@69: * In order to open a converter with the IBM S/390 Unix System Services variant jpayne@69: * of a Unicode/EBCDIC conversion table, jpayne@69: * you can use the prefix "ibm-" together with the option string UCNV_SWAP_LFNL_OPTION_STRING: jpayne@69: * \code jpayne@69: * char name[20]; jpayne@69: * sprintf(name, "ibm-%hu" UCNV_SWAP_LFNL_OPTION_STRING, ccsid); jpayne@69: * cnv=ucnv_open(name, &errorCode); jpayne@69: * \endcode jpayne@69: * jpayne@69: * In order to open a converter from a Microsoft codepage number, use the prefix "cp": jpayne@69: * \code jpayne@69: * char name[20]; jpayne@69: * sprintf(name, "cp%hu", codepageID); jpayne@69: * cnv=ucnv_open(name, &errorCode); jpayne@69: * \endcode jpayne@69: * jpayne@69: * If the alias is ambiguous, then the preferred converter is used jpayne@69: * and the status is set to U_AMBIGUOUS_ALIAS_WARNING. jpayne@69: * jpayne@69: * @param codepage codepage number to create jpayne@69: * @param platform the platform in which the codepage number exists jpayne@69: * @param err error status U_MEMORY_ALLOCATION_ERROR, U_FILE_ACCESS_ERROR jpayne@69: * @return the created Unicode converter object, or NULL if an error jpayne@69: * occurred. jpayne@69: * @see ucnv_open jpayne@69: * @see ucnv_openU jpayne@69: * @see ucnv_close jpayne@69: * @see ucnv_getCCSID jpayne@69: * @see ucnv_getPlatform jpayne@69: * @see UConverterPlatform jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE UConverter* U_EXPORT2 jpayne@69: ucnv_openCCSID(int32_t codepage, jpayne@69: UConverterPlatform platform, jpayne@69: UErrorCode * err); jpayne@69: jpayne@69: /** jpayne@69: *

Creates a UConverter object specified from a packageName and a converterName.

jpayne@69: * jpayne@69: *

The packageName and converterName must point to an ICU udata object, as defined by jpayne@69: * udata_open( packageName, "cnv", converterName, err) or equivalent. jpayne@69: * Typically, packageName will refer to a (.dat) file, or to a package registered with jpayne@69: * udata_setAppData(). Using a full file or directory pathname for packageName is deprecated.

jpayne@69: * jpayne@69: *

The name will NOT be looked up in the alias mechanism, nor will the converter be jpayne@69: * stored in the converter cache or the alias table. The only way to open further converters jpayne@69: * is call this function multiple times, or use the ucnv_safeClone() function to clone a jpayne@69: * 'master' converter.

jpayne@69: * jpayne@69: *

A future version of ICU may add alias table lookups and/or caching jpayne@69: * to this function.

jpayne@69: * jpayne@69: *

Example Use: jpayne@69: * cnv = ucnv_openPackage("myapp", "myconverter", &err); jpayne@69: *

jpayne@69: * jpayne@69: * @param packageName name of the package (equivalent to 'path' in udata_open() call) jpayne@69: * @param converterName name of the data item to be used, without suffix. jpayne@69: * @param err outgoing error status U_MEMORY_ALLOCATION_ERROR, U_FILE_ACCESS_ERROR jpayne@69: * @return the created Unicode converter object, or NULL if an error occurred jpayne@69: * @see udata_open jpayne@69: * @see ucnv_open jpayne@69: * @see ucnv_safeClone jpayne@69: * @see ucnv_close jpayne@69: * @stable ICU 2.2 jpayne@69: */ jpayne@69: U_STABLE UConverter* U_EXPORT2 jpayne@69: ucnv_openPackage(const char *packageName, const char *converterName, UErrorCode *err); jpayne@69: jpayne@69: /** jpayne@69: * Thread safe converter cloning operation. jpayne@69: * For most efficient operation, pass in a stackBuffer (and a *pBufferSize) jpayne@69: * with at least U_CNV_SAFECLONE_BUFFERSIZE bytes of space. jpayne@69: * If the buffer size is sufficient, then the clone will use the stack buffer; jpayne@69: * otherwise, it will be allocated, and *pBufferSize will indicate jpayne@69: * the actual size. (This should not occur with U_CNV_SAFECLONE_BUFFERSIZE.) jpayne@69: * jpayne@69: * You must ucnv_close() the clone in any case. jpayne@69: * jpayne@69: * If *pBufferSize==0, (regardless of whether stackBuffer==NULL or not) jpayne@69: * then *pBufferSize will be changed to a sufficient size jpayne@69: * for cloning this converter, jpayne@69: * without actually cloning the converter ("pure pre-flighting"). jpayne@69: * jpayne@69: * If *pBufferSize is greater than zero but not large enough for a stack-based jpayne@69: * clone, then the converter is cloned using newly allocated memory jpayne@69: * and *pBufferSize is changed to the necessary size. jpayne@69: * jpayne@69: * If the converter clone fits into the stack buffer but the stack buffer is not jpayne@69: * sufficiently aligned for the clone, then the clone will use an jpayne@69: * adjusted pointer and use an accordingly smaller buffer size. jpayne@69: * jpayne@69: * @param cnv converter to be cloned jpayne@69: * @param stackBuffer Deprecated functionality as of ICU 52, use NULL.
jpayne@69: * user allocated space for the new clone. If NULL new memory will be allocated. jpayne@69: * If buffer is not large enough, new memory will be allocated. jpayne@69: * Clients can use the U_CNV_SAFECLONE_BUFFERSIZE. This will probably be enough to avoid memory allocations. jpayne@69: * @param pBufferSize Deprecated functionality as of ICU 52, use NULL or 1.
jpayne@69: * pointer to size of allocated space. jpayne@69: * @param status to indicate whether the operation went on smoothly or there were errors jpayne@69: * An informational status value, U_SAFECLONE_ALLOCATED_WARNING, jpayne@69: * is used if any allocations were necessary. jpayne@69: * However, it is better to check if *pBufferSize grew for checking for jpayne@69: * allocations because warning codes can be overridden by subsequent jpayne@69: * function calls. jpayne@69: * @return pointer to the new clone jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE UConverter * U_EXPORT2 jpayne@69: ucnv_safeClone(const UConverter *cnv, jpayne@69: void *stackBuffer, jpayne@69: int32_t *pBufferSize, jpayne@69: UErrorCode *status); jpayne@69: jpayne@69: #ifndef U_HIDE_DEPRECATED_API jpayne@69: jpayne@69: /** jpayne@69: * \def U_CNV_SAFECLONE_BUFFERSIZE jpayne@69: * Definition of a buffer size that is designed to be large enough for jpayne@69: * converters to be cloned with ucnv_safeClone(). jpayne@69: * @deprecated ICU 52. Do not rely on ucnv_safeClone() cloning into any provided buffer. jpayne@69: */ jpayne@69: #define U_CNV_SAFECLONE_BUFFERSIZE 1024 jpayne@69: jpayne@69: #endif /* U_HIDE_DEPRECATED_API */ jpayne@69: jpayne@69: /** jpayne@69: * Deletes the unicode converter and releases resources associated jpayne@69: * with just this instance. jpayne@69: * Does not free up shared converter tables. jpayne@69: * jpayne@69: * @param converter the converter object to be deleted jpayne@69: * @see ucnv_open jpayne@69: * @see ucnv_openU jpayne@69: * @see ucnv_openCCSID jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE void U_EXPORT2 jpayne@69: ucnv_close(UConverter * converter); jpayne@69: jpayne@69: #if U_SHOW_CPLUSPLUS_API jpayne@69: jpayne@69: U_NAMESPACE_BEGIN jpayne@69: jpayne@69: /** jpayne@69: * \class LocalUConverterPointer jpayne@69: * "Smart pointer" class, closes a UConverter via ucnv_close(). jpayne@69: * For most methods see the LocalPointerBase base class. jpayne@69: * jpayne@69: * @see LocalPointerBase jpayne@69: * @see LocalPointer jpayne@69: * @stable ICU 4.4 jpayne@69: */ jpayne@69: U_DEFINE_LOCAL_OPEN_POINTER(LocalUConverterPointer, UConverter, ucnv_close); jpayne@69: jpayne@69: U_NAMESPACE_END jpayne@69: jpayne@69: #endif jpayne@69: jpayne@69: /** jpayne@69: * Fills in the output parameter, subChars, with the substitution characters jpayne@69: * as multiple bytes. jpayne@69: * If ucnv_setSubstString() set a Unicode string because the converter is jpayne@69: * stateful, then subChars will be an empty string. jpayne@69: * jpayne@69: * @param converter the Unicode converter jpayne@69: * @param subChars the substitution characters jpayne@69: * @param len on input the capacity of subChars, on output the number jpayne@69: * of bytes copied to it jpayne@69: * @param err the outgoing error status code. jpayne@69: * If the substitution character array is too small, an jpayne@69: * U_INDEX_OUTOFBOUNDS_ERROR will be returned. jpayne@69: * @see ucnv_setSubstString jpayne@69: * @see ucnv_setSubstChars jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE void U_EXPORT2 jpayne@69: ucnv_getSubstChars(const UConverter *converter, jpayne@69: char *subChars, jpayne@69: int8_t *len, jpayne@69: UErrorCode *err); jpayne@69: jpayne@69: /** jpayne@69: * Sets the substitution chars when converting from unicode to a codepage. The jpayne@69: * substitution is specified as a string of 1-4 bytes, and may contain jpayne@69: * NULL bytes. jpayne@69: * The subChars must represent a single character. The caller needs to know the jpayne@69: * byte sequence of a valid character in the converter's charset. jpayne@69: * For some converters, for example some ISO 2022 variants, only single-byte jpayne@69: * substitution characters may be supported. jpayne@69: * The newer ucnv_setSubstString() function relaxes these limitations. jpayne@69: * jpayne@69: * @param converter the Unicode converter jpayne@69: * @param subChars the substitution character byte sequence we want set jpayne@69: * @param len the number of bytes in subChars jpayne@69: * @param err the error status code. U_INDEX_OUTOFBOUNDS_ERROR if jpayne@69: * len is bigger than the maximum number of bytes allowed in subchars jpayne@69: * @see ucnv_setSubstString jpayne@69: * @see ucnv_getSubstChars jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE void U_EXPORT2 jpayne@69: ucnv_setSubstChars(UConverter *converter, jpayne@69: const char *subChars, jpayne@69: int8_t len, jpayne@69: UErrorCode *err); jpayne@69: jpayne@69: /** jpayne@69: * Set a substitution string for converting from Unicode to a charset. jpayne@69: * The caller need not know the charset byte sequence for each charset. jpayne@69: * jpayne@69: * Unlike ucnv_setSubstChars() which is designed to set a charset byte sequence jpayne@69: * for a single character, this function takes a Unicode string with jpayne@69: * zero, one or more characters, and immediately verifies that the string can be jpayne@69: * converted to the charset. jpayne@69: * If not, or if the result is too long (more than 32 bytes as of ICU 3.6), jpayne@69: * then the function returns with an error accordingly. jpayne@69: * jpayne@69: * Also unlike ucnv_setSubstChars(), this function works for stateful charsets jpayne@69: * by converting on the fly at the point of substitution rather than setting jpayne@69: * a fixed byte sequence. jpayne@69: * jpayne@69: * @param cnv The UConverter object. jpayne@69: * @param s The Unicode string. jpayne@69: * @param length The number of UChars in s, or -1 for a NUL-terminated string. jpayne@69: * @param err Pointer to a standard ICU error code. Its input value must jpayne@69: * pass the U_SUCCESS() test, or else the function returns jpayne@69: * immediately. Check for U_FAILURE() on output or use with jpayne@69: * function chaining. (See User Guide for details.) jpayne@69: * jpayne@69: * @see ucnv_setSubstChars jpayne@69: * @see ucnv_getSubstChars jpayne@69: * @stable ICU 3.6 jpayne@69: */ jpayne@69: U_STABLE void U_EXPORT2 jpayne@69: ucnv_setSubstString(UConverter *cnv, jpayne@69: const UChar *s, jpayne@69: int32_t length, jpayne@69: UErrorCode *err); jpayne@69: jpayne@69: /** jpayne@69: * Fills in the output parameter, errBytes, with the error characters from the jpayne@69: * last failing conversion. jpayne@69: * jpayne@69: * @param converter the Unicode converter jpayne@69: * @param errBytes the codepage bytes which were in error jpayne@69: * @param len on input the capacity of errBytes, on output the number of jpayne@69: * bytes which were copied to it jpayne@69: * @param err the error status code. jpayne@69: * If the substitution character array is too small, an jpayne@69: * U_INDEX_OUTOFBOUNDS_ERROR will be returned. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE void U_EXPORT2 jpayne@69: ucnv_getInvalidChars(const UConverter *converter, jpayne@69: char *errBytes, jpayne@69: int8_t *len, jpayne@69: UErrorCode *err); jpayne@69: jpayne@69: /** jpayne@69: * Fills in the output parameter, errChars, with the error characters from the jpayne@69: * last failing conversion. jpayne@69: * jpayne@69: * @param converter the Unicode converter jpayne@69: * @param errUChars the UChars which were in error jpayne@69: * @param len on input the capacity of errUChars, on output the number of jpayne@69: * UChars which were copied to it jpayne@69: * @param err the error status code. jpayne@69: * If the substitution character array is too small, an jpayne@69: * U_INDEX_OUTOFBOUNDS_ERROR will be returned. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE void U_EXPORT2 jpayne@69: ucnv_getInvalidUChars(const UConverter *converter, jpayne@69: UChar *errUChars, jpayne@69: int8_t *len, jpayne@69: UErrorCode *err); jpayne@69: jpayne@69: /** jpayne@69: * Resets the state of a converter to the default state. This is used jpayne@69: * in the case of an error, to restart a conversion from a known default state. jpayne@69: * It will also empty the internal output buffers. jpayne@69: * @param converter the Unicode converter jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE void U_EXPORT2 jpayne@69: ucnv_reset(UConverter *converter); jpayne@69: jpayne@69: /** jpayne@69: * Resets the to-Unicode part of a converter state to the default state. jpayne@69: * This is used in the case of an error to restart a conversion to jpayne@69: * Unicode to a known default state. It will also empty the internal jpayne@69: * output buffers used for the conversion to Unicode codepoints. jpayne@69: * @param converter the Unicode converter jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE void U_EXPORT2 jpayne@69: ucnv_resetToUnicode(UConverter *converter); jpayne@69: jpayne@69: /** jpayne@69: * Resets the from-Unicode part of a converter state to the default state. jpayne@69: * This is used in the case of an error to restart a conversion from jpayne@69: * Unicode to a known default state. It will also empty the internal output jpayne@69: * buffers used for the conversion from Unicode codepoints. jpayne@69: * @param converter the Unicode converter jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE void U_EXPORT2 jpayne@69: ucnv_resetFromUnicode(UConverter *converter); jpayne@69: jpayne@69: /** jpayne@69: * Returns the maximum number of bytes that are output per UChar in conversion jpayne@69: * from Unicode using this converter. jpayne@69: * The returned number can be used with UCNV_GET_MAX_BYTES_FOR_STRING jpayne@69: * to calculate the size of a target buffer for conversion from Unicode. jpayne@69: * jpayne@69: * Note: Before ICU 2.8, this function did not return reliable numbers for jpayne@69: * some stateful converters (EBCDIC_STATEFUL, ISO-2022) and LMBCS. jpayne@69: * jpayne@69: * This number may not be the same as the maximum number of bytes per jpayne@69: * "conversion unit". In other words, it may not be the intuitively expected jpayne@69: * number of bytes per character that would be published for a charset, jpayne@69: * and may not fulfill any other purpose than the allocation of an output jpayne@69: * buffer of guaranteed sufficient size for a given input length and converter. jpayne@69: * jpayne@69: * Examples for special cases that are taken into account: jpayne@69: * - Supplementary code points may convert to more bytes than BMP code points. jpayne@69: * This function returns bytes per UChar (UTF-16 code unit), not per jpayne@69: * Unicode code point, for efficient buffer allocation. jpayne@69: * - State-shifting output (SI/SO, escapes, etc.) from stateful converters. jpayne@69: * - When m input UChars are converted to n output bytes, then the maximum m/n jpayne@69: * is taken into account. jpayne@69: * jpayne@69: * The number returned here does not take into account jpayne@69: * (see UCNV_GET_MAX_BYTES_FOR_STRING): jpayne@69: * - callbacks which output more than one charset character sequence per call, jpayne@69: * like escape callbacks jpayne@69: * - initial and final non-character bytes that are output by some converters jpayne@69: * (automatic BOMs, initial escape sequence, final SI, etc.) jpayne@69: * jpayne@69: * Examples for returned values: jpayne@69: * - SBCS charsets: 1 jpayne@69: * - Shift-JIS: 2 jpayne@69: * - UTF-16: 2 (2 per BMP, 4 per surrogate _pair_, BOM not counted) jpayne@69: * - UTF-8: 3 (3 per BMP, 4 per surrogate _pair_) jpayne@69: * - EBCDIC_STATEFUL (EBCDIC mixed SBCS/DBCS): 3 (SO + DBCS) jpayne@69: * - ISO-2022: 3 (always outputs UTF-8) jpayne@69: * - ISO-2022-JP: 6 (4-byte escape sequences + DBCS) jpayne@69: * - ISO-2022-CN: 8 (4-byte designator sequences + 2-byte SS2/SS3 + DBCS) jpayne@69: * jpayne@69: * @param converter The Unicode converter. jpayne@69: * @return The maximum number of bytes per UChar (16 bit code unit) jpayne@69: * that are output by ucnv_fromUnicode(), jpayne@69: * to be used together with UCNV_GET_MAX_BYTES_FOR_STRING jpayne@69: * for buffer allocation. jpayne@69: * jpayne@69: * @see UCNV_GET_MAX_BYTES_FOR_STRING jpayne@69: * @see ucnv_getMinCharSize jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE int8_t U_EXPORT2 jpayne@69: ucnv_getMaxCharSize(const UConverter *converter); jpayne@69: jpayne@69: /** jpayne@69: * Calculates the size of a buffer for conversion from Unicode to a charset. jpayne@69: * The calculated size is guaranteed to be sufficient for this conversion. jpayne@69: * jpayne@69: * It takes into account initial and final non-character bytes that are output jpayne@69: * by some converters. jpayne@69: * It does not take into account callbacks which output more than one charset jpayne@69: * character sequence per call, like escape callbacks. jpayne@69: * The default (substitution) callback only outputs one charset character sequence. jpayne@69: * jpayne@69: * @param length Number of UChars to be converted. jpayne@69: * @param maxCharSize Return value from ucnv_getMaxCharSize() for the converter jpayne@69: * that will be used. jpayne@69: * @return Size of a buffer that will be large enough to hold the output bytes of jpayne@69: * converting length UChars with the converter that returned the maxCharSize. jpayne@69: * jpayne@69: * @see ucnv_getMaxCharSize jpayne@69: * @stable ICU 2.8 jpayne@69: */ jpayne@69: #define UCNV_GET_MAX_BYTES_FOR_STRING(length, maxCharSize) \ jpayne@69: (((int32_t)(length)+10)*(int32_t)(maxCharSize)) jpayne@69: jpayne@69: /** jpayne@69: * Returns the minimum byte length (per codepoint) for characters in this codepage. jpayne@69: * This is usually either 1 or 2. jpayne@69: * @param converter the Unicode converter jpayne@69: * @return the minimum number of bytes per codepoint allowed by this particular converter jpayne@69: * @see ucnv_getMaxCharSize jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE int8_t U_EXPORT2 jpayne@69: ucnv_getMinCharSize(const UConverter *converter); jpayne@69: jpayne@69: /** jpayne@69: * Returns the display name of the converter passed in based on the Locale jpayne@69: * passed in. If the locale contains no display name, the internal ASCII jpayne@69: * name will be filled in. jpayne@69: * jpayne@69: * @param converter the Unicode converter. jpayne@69: * @param displayLocale is the specific Locale we want to localized for jpayne@69: * @param displayName user provided buffer to be filled in jpayne@69: * @param displayNameCapacity size of displayName Buffer jpayne@69: * @param err error status code jpayne@69: * @return displayNameLength number of UChar needed in displayName jpayne@69: * @see ucnv_getName jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: ucnv_getDisplayName(const UConverter *converter, jpayne@69: const char *displayLocale, jpayne@69: UChar *displayName, jpayne@69: int32_t displayNameCapacity, jpayne@69: UErrorCode *err); jpayne@69: jpayne@69: /** jpayne@69: * Gets the internal, canonical name of the converter (zero-terminated). jpayne@69: * The lifetime of the returned string will be that of the converter jpayne@69: * passed to this function. jpayne@69: * @param converter the Unicode converter jpayne@69: * @param err UErrorCode status jpayne@69: * @return the internal name of the converter jpayne@69: * @see ucnv_getDisplayName jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE const char * U_EXPORT2 jpayne@69: ucnv_getName(const UConverter *converter, UErrorCode *err); jpayne@69: jpayne@69: /** jpayne@69: * Gets a codepage number associated with the converter. This is not guaranteed jpayne@69: * to be the one used to create the converter. Some converters do not represent jpayne@69: * platform registered codepages and return zero for the codepage number. jpayne@69: * The error code fill-in parameter indicates if the codepage number jpayne@69: * is available. jpayne@69: * Does not check if the converter is NULL or if converter's data jpayne@69: * table is NULL. jpayne@69: * jpayne@69: * Important: The use of CCSIDs is not recommended because it is limited jpayne@69: * to only two platforms in principle and only one (UCNV_IBM) in the current jpayne@69: * ICU converter API. jpayne@69: * Also, CCSIDs are insufficient to identify IBM Unicode conversion tables precisely. jpayne@69: * For more details see ucnv_openCCSID(). jpayne@69: * jpayne@69: * @param converter the Unicode converter jpayne@69: * @param err the error status code. jpayne@69: * @return If any error occurs, -1 will be returned otherwise, the codepage number jpayne@69: * will be returned jpayne@69: * @see ucnv_openCCSID jpayne@69: * @see ucnv_getPlatform jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: ucnv_getCCSID(const UConverter *converter, jpayne@69: UErrorCode *err); jpayne@69: jpayne@69: /** jpayne@69: * Gets a codepage platform associated with the converter. Currently, jpayne@69: * only UCNV_IBM will be returned. jpayne@69: * Does not test if the converter is NULL or if converter's data jpayne@69: * table is NULL. jpayne@69: * @param converter the Unicode converter jpayne@69: * @param err the error status code. jpayne@69: * @return The codepage platform jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE UConverterPlatform U_EXPORT2 jpayne@69: ucnv_getPlatform(const UConverter *converter, jpayne@69: UErrorCode *err); jpayne@69: jpayne@69: /** jpayne@69: * Gets the type of the converter jpayne@69: * e.g. SBCS, MBCS, DBCS, UTF8, UTF16_BE, UTF16_LE, ISO_2022, jpayne@69: * EBCDIC_STATEFUL, LATIN_1 jpayne@69: * @param converter a valid, opened converter jpayne@69: * @return the type of the converter jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE UConverterType U_EXPORT2 jpayne@69: ucnv_getType(const UConverter * converter); jpayne@69: jpayne@69: /** jpayne@69: * Gets the "starter" (lead) bytes for converters of type MBCS. jpayne@69: * Will fill in an U_ILLEGAL_ARGUMENT_ERROR if converter passed in jpayne@69: * is not MBCS. Fills in an array of type UBool, with the value of the byte jpayne@69: * as offset to the array. For example, if (starters[0x20] == TRUE) at return, jpayne@69: * it means that the byte 0x20 is a starter byte in this converter. jpayne@69: * Context pointers are always owned by the caller. jpayne@69: * jpayne@69: * @param converter a valid, opened converter of type MBCS jpayne@69: * @param starters an array of size 256 to be filled in jpayne@69: * @param err error status, U_ILLEGAL_ARGUMENT_ERROR if the jpayne@69: * converter is not a type which can return starters. jpayne@69: * @see ucnv_getType jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE void U_EXPORT2 jpayne@69: ucnv_getStarters(const UConverter* converter, jpayne@69: UBool starters[256], jpayne@69: UErrorCode* err); jpayne@69: jpayne@69: jpayne@69: /** jpayne@69: * Selectors for Unicode sets that can be returned by ucnv_getUnicodeSet(). jpayne@69: * @see ucnv_getUnicodeSet jpayne@69: * @stable ICU 2.6 jpayne@69: */ jpayne@69: typedef enum UConverterUnicodeSet { jpayne@69: /** Select the set of roundtrippable Unicode code points. @stable ICU 2.6 */ jpayne@69: UCNV_ROUNDTRIP_SET, jpayne@69: /** Select the set of Unicode code points with roundtrip or fallback mappings. @stable ICU 4.0 */ jpayne@69: UCNV_ROUNDTRIP_AND_FALLBACK_SET, jpayne@69: #ifndef U_HIDE_DEPRECATED_API jpayne@69: /** jpayne@69: * Number of UConverterUnicodeSet selectors. jpayne@69: * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420. jpayne@69: */ jpayne@69: UCNV_SET_COUNT jpayne@69: #endif // U_HIDE_DEPRECATED_API jpayne@69: } UConverterUnicodeSet; jpayne@69: jpayne@69: jpayne@69: /** jpayne@69: * Returns the set of Unicode code points that can be converted by an ICU converter. jpayne@69: * jpayne@69: * Returns one of several kinds of set: jpayne@69: * jpayne@69: * 1. UCNV_ROUNDTRIP_SET jpayne@69: * jpayne@69: * The set of all Unicode code points that can be roundtrip-converted jpayne@69: * (converted without any data loss) with the converter (ucnv_fromUnicode()). jpayne@69: * This set will not include code points that have fallback mappings jpayne@69: * or are only the result of reverse fallback mappings. jpayne@69: * This set will also not include PUA code points with fallbacks, although jpayne@69: * ucnv_fromUnicode() will always uses those mappings despite ucnv_setFallback(). jpayne@69: * See UTR #22 "Character Mapping Markup Language" jpayne@69: * at http://www.unicode.org/reports/tr22/ jpayne@69: * jpayne@69: * This is useful for example for jpayne@69: * - checking that a string or document can be roundtrip-converted with a converter, jpayne@69: * without/before actually performing the conversion jpayne@69: * - testing if a converter can be used for text for typical text for a certain locale, jpayne@69: * by comparing its roundtrip set with the set of ExemplarCharacters from jpayne@69: * ICU's locale data or other sources jpayne@69: * jpayne@69: * 2. UCNV_ROUNDTRIP_AND_FALLBACK_SET jpayne@69: * jpayne@69: * The set of all Unicode code points that can be converted with the converter (ucnv_fromUnicode()) jpayne@69: * when fallbacks are turned on (see ucnv_setFallback()). jpayne@69: * This set includes all code points with roundtrips and fallbacks (but not reverse fallbacks). jpayne@69: * jpayne@69: * In the future, there may be more UConverterUnicodeSet choices to select jpayne@69: * sets with different properties. jpayne@69: * jpayne@69: * @param cnv The converter for which a set is requested. jpayne@69: * @param setFillIn A valid USet *. It will be cleared by this function before jpayne@69: * the converter's specific set is filled into the USet. jpayne@69: * @param whichSet A UConverterUnicodeSet selector; jpayne@69: * currently UCNV_ROUNDTRIP_SET is the only supported value. jpayne@69: * @param pErrorCode ICU error code in/out parameter. jpayne@69: * Must fulfill U_SUCCESS before the function call. jpayne@69: * jpayne@69: * @see UConverterUnicodeSet jpayne@69: * @see uset_open jpayne@69: * @see uset_close jpayne@69: * @stable ICU 2.6 jpayne@69: */ jpayne@69: U_STABLE void U_EXPORT2 jpayne@69: ucnv_getUnicodeSet(const UConverter *cnv, jpayne@69: USet *setFillIn, jpayne@69: UConverterUnicodeSet whichSet, jpayne@69: UErrorCode *pErrorCode); jpayne@69: jpayne@69: /** jpayne@69: * Gets the current calback function used by the converter when an illegal jpayne@69: * or invalid codepage sequence is found. jpayne@69: * Context pointers are always owned by the caller. jpayne@69: * jpayne@69: * @param converter the unicode converter jpayne@69: * @param action fillin: returns the callback function pointer jpayne@69: * @param context fillin: returns the callback's private void* context jpayne@69: * @see ucnv_setToUCallBack jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE void U_EXPORT2 jpayne@69: ucnv_getToUCallBack (const UConverter * converter, jpayne@69: UConverterToUCallback *action, jpayne@69: const void **context); jpayne@69: jpayne@69: /** jpayne@69: * Gets the current callback function used by the converter when illegal jpayne@69: * or invalid Unicode sequence is found. jpayne@69: * Context pointers are always owned by the caller. jpayne@69: * jpayne@69: * @param converter the unicode converter jpayne@69: * @param action fillin: returns the callback function pointer jpayne@69: * @param context fillin: returns the callback's private void* context jpayne@69: * @see ucnv_setFromUCallBack jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE void U_EXPORT2 jpayne@69: ucnv_getFromUCallBack (const UConverter * converter, jpayne@69: UConverterFromUCallback *action, jpayne@69: const void **context); jpayne@69: jpayne@69: /** jpayne@69: * Changes the callback function used by the converter when jpayne@69: * an illegal or invalid sequence is found. jpayne@69: * Context pointers are always owned by the caller. jpayne@69: * Predefined actions and contexts can be found in the ucnv_err.h header. jpayne@69: * jpayne@69: * @param converter the unicode converter jpayne@69: * @param newAction the new callback function jpayne@69: * @param newContext the new toUnicode callback context pointer. This can be NULL. jpayne@69: * @param oldAction fillin: returns the old callback function pointer. This can be NULL. jpayne@69: * @param oldContext fillin: returns the old callback's private void* context. This can be NULL. jpayne@69: * @param err The error code status jpayne@69: * @see ucnv_getToUCallBack jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE void U_EXPORT2 jpayne@69: ucnv_setToUCallBack (UConverter * converter, jpayne@69: UConverterToUCallback newAction, jpayne@69: const void* newContext, jpayne@69: UConverterToUCallback *oldAction, jpayne@69: const void** oldContext, jpayne@69: UErrorCode * err); jpayne@69: jpayne@69: /** jpayne@69: * Changes the current callback function used by the converter when jpayne@69: * an illegal or invalid sequence is found. jpayne@69: * Context pointers are always owned by the caller. jpayne@69: * Predefined actions and contexts can be found in the ucnv_err.h header. jpayne@69: * jpayne@69: * @param converter the unicode converter jpayne@69: * @param newAction the new callback function jpayne@69: * @param newContext the new fromUnicode callback context pointer. This can be NULL. jpayne@69: * @param oldAction fillin: returns the old callback function pointer. This can be NULL. jpayne@69: * @param oldContext fillin: returns the old callback's private void* context. This can be NULL. jpayne@69: * @param err The error code status jpayne@69: * @see ucnv_getFromUCallBack jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE void U_EXPORT2 jpayne@69: ucnv_setFromUCallBack (UConverter * converter, jpayne@69: UConverterFromUCallback newAction, jpayne@69: const void *newContext, jpayne@69: UConverterFromUCallback *oldAction, jpayne@69: const void **oldContext, jpayne@69: UErrorCode * err); jpayne@69: jpayne@69: /** jpayne@69: * Converts an array of unicode characters to an array of codepage jpayne@69: * characters. This function is optimized for converting a continuous jpayne@69: * stream of data in buffer-sized chunks, where the entire source and jpayne@69: * target does not fit in available buffers. jpayne@69: * jpayne@69: * The source pointer is an in/out parameter. It starts out pointing where the jpayne@69: * conversion is to begin, and ends up pointing after the last UChar consumed. jpayne@69: * jpayne@69: * Target similarly starts out pointer at the first available byte in the output jpayne@69: * buffer, and ends up pointing after the last byte written to the output. jpayne@69: * jpayne@69: * The converter always attempts to consume the entire source buffer, unless jpayne@69: * (1.) the target buffer is full, or (2.) a failing error is returned from the jpayne@69: * current callback function. When a successful error status has been jpayne@69: * returned, it means that all of the source buffer has been jpayne@69: * consumed. At that point, the caller should reset the source and jpayne@69: * sourceLimit pointers to point to the next chunk. jpayne@69: * jpayne@69: * At the end of the stream (flush==TRUE), the input is completely consumed jpayne@69: * when *source==sourceLimit and no error code is set. jpayne@69: * The converter object is then automatically reset by this function. jpayne@69: * (This means that a converter need not be reset explicitly between data jpayne@69: * streams if it finishes the previous stream without errors.) jpayne@69: * jpayne@69: * This is a stateful conversion. Additionally, even when all source data has jpayne@69: * been consumed, some data may be in the converters' internal state. jpayne@69: * Call this function repeatedly, updating the target pointers with jpayne@69: * the next empty chunk of target in case of a jpayne@69: * U_BUFFER_OVERFLOW_ERROR, and updating the source pointers jpayne@69: * with the next chunk of source when a successful error status is jpayne@69: * returned, until there are no more chunks of source data. jpayne@69: * @param converter the Unicode converter jpayne@69: * @param target I/O parameter. Input : Points to the beginning of the buffer to copy jpayne@69: * codepage characters to. Output : points to after the last codepage character copied jpayne@69: * to target. jpayne@69: * @param targetLimit the pointer just after last of the target buffer jpayne@69: * @param source I/O parameter, pointer to pointer to the source Unicode character buffer. jpayne@69: * @param sourceLimit the pointer just after the last of the source buffer jpayne@69: * @param offsets if NULL is passed, nothing will happen to it, otherwise it needs to have the same number jpayne@69: * of allocated cells as target. Will fill in offsets from target to source pointer jpayne@69: * e.g: offsets[3] is equal to 6, it means that the target[3] was a result of transcoding source[6] jpayne@69: * For output data carried across calls, and other data without a specific source character jpayne@69: * (such as from escape sequences or callbacks) -1 will be placed for offsets. jpayne@69: * @param flush set to TRUE if the current source buffer is the last available jpayne@69: * chunk of the source, FALSE otherwise. Note that if a failing status is returned, jpayne@69: * this function may have to be called multiple times with flush set to TRUE until jpayne@69: * the source buffer is consumed. jpayne@69: * @param err the error status. U_ILLEGAL_ARGUMENT_ERROR will be set if the jpayne@69: * converter is NULL. jpayne@69: * U_BUFFER_OVERFLOW_ERROR will be set if the target is full and there is jpayne@69: * still data to be written to the target. jpayne@69: * @see ucnv_fromUChars jpayne@69: * @see ucnv_convert jpayne@69: * @see ucnv_getMinCharSize jpayne@69: * @see ucnv_setToUCallBack jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE void U_EXPORT2 jpayne@69: ucnv_fromUnicode (UConverter * converter, jpayne@69: char **target, jpayne@69: const char *targetLimit, jpayne@69: const UChar ** source, jpayne@69: const UChar * sourceLimit, jpayne@69: int32_t* offsets, jpayne@69: UBool flush, jpayne@69: UErrorCode * err); jpayne@69: jpayne@69: /** jpayne@69: * Converts a buffer of codepage bytes into an array of unicode UChars jpayne@69: * characters. This function is optimized for converting a continuous jpayne@69: * stream of data in buffer-sized chunks, where the entire source and jpayne@69: * target does not fit in available buffers. jpayne@69: * jpayne@69: * The source pointer is an in/out parameter. It starts out pointing where the jpayne@69: * conversion is to begin, and ends up pointing after the last byte of source consumed. jpayne@69: * jpayne@69: * Target similarly starts out pointer at the first available UChar in the output jpayne@69: * buffer, and ends up pointing after the last UChar written to the output. jpayne@69: * It does NOT necessarily keep UChar sequences together. jpayne@69: * jpayne@69: * The converter always attempts to consume the entire source buffer, unless jpayne@69: * (1.) the target buffer is full, or (2.) a failing error is returned from the jpayne@69: * current callback function. When a successful error status has been jpayne@69: * returned, it means that all of the source buffer has been jpayne@69: * consumed. At that point, the caller should reset the source and jpayne@69: * sourceLimit pointers to point to the next chunk. jpayne@69: * jpayne@69: * At the end of the stream (flush==TRUE), the input is completely consumed jpayne@69: * when *source==sourceLimit and no error code is set jpayne@69: * The converter object is then automatically reset by this function. jpayne@69: * (This means that a converter need not be reset explicitly between data jpayne@69: * streams if it finishes the previous stream without errors.) jpayne@69: * jpayne@69: * This is a stateful conversion. Additionally, even when all source data has jpayne@69: * been consumed, some data may be in the converters' internal state. jpayne@69: * Call this function repeatedly, updating the target pointers with jpayne@69: * the next empty chunk of target in case of a jpayne@69: * U_BUFFER_OVERFLOW_ERROR, and updating the source pointers jpayne@69: * with the next chunk of source when a successful error status is jpayne@69: * returned, until there are no more chunks of source data. jpayne@69: * @param converter the Unicode converter jpayne@69: * @param target I/O parameter. Input : Points to the beginning of the buffer to copy jpayne@69: * UChars into. Output : points to after the last UChar copied. jpayne@69: * @param targetLimit the pointer just after the end of the target buffer jpayne@69: * @param source I/O parameter, pointer to pointer to the source codepage buffer. jpayne@69: * @param sourceLimit the pointer to the byte after the end of the source buffer jpayne@69: * @param offsets if NULL is passed, nothing will happen to it, otherwise it needs to have the same number jpayne@69: * of allocated cells as target. Will fill in offsets from target to source pointer jpayne@69: * e.g: offsets[3] is equal to 6, it means that the target[3] was a result of transcoding source[6] jpayne@69: * For output data carried across calls, and other data without a specific source character jpayne@69: * (such as from escape sequences or callbacks) -1 will be placed for offsets. jpayne@69: * @param flush set to TRUE if the current source buffer is the last available jpayne@69: * chunk of the source, FALSE otherwise. Note that if a failing status is returned, jpayne@69: * this function may have to be called multiple times with flush set to TRUE until jpayne@69: * the source buffer is consumed. jpayne@69: * @param err the error status. U_ILLEGAL_ARGUMENT_ERROR will be set if the jpayne@69: * converter is NULL. jpayne@69: * U_BUFFER_OVERFLOW_ERROR will be set if the target is full and there is jpayne@69: * still data to be written to the target. jpayne@69: * @see ucnv_fromUChars jpayne@69: * @see ucnv_convert jpayne@69: * @see ucnv_getMinCharSize jpayne@69: * @see ucnv_setFromUCallBack jpayne@69: * @see ucnv_getNextUChar jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE void U_EXPORT2 jpayne@69: ucnv_toUnicode(UConverter *converter, jpayne@69: UChar **target, jpayne@69: const UChar *targetLimit, jpayne@69: const char **source, jpayne@69: const char *sourceLimit, jpayne@69: int32_t *offsets, jpayne@69: UBool flush, jpayne@69: UErrorCode *err); jpayne@69: jpayne@69: /** jpayne@69: * Convert the Unicode string into a codepage string using an existing UConverter. jpayne@69: * The output string is NUL-terminated if possible. jpayne@69: * jpayne@69: * This function is a more convenient but less powerful version of ucnv_fromUnicode(). jpayne@69: * It is only useful for whole strings, not for streaming conversion. jpayne@69: * jpayne@69: * The maximum output buffer capacity required (barring output from callbacks) will be jpayne@69: * UCNV_GET_MAX_BYTES_FOR_STRING(srcLength, ucnv_getMaxCharSize(cnv)). jpayne@69: * jpayne@69: * @param cnv the converter object to be used (ucnv_resetFromUnicode() will be called) jpayne@69: * @param src the input Unicode string jpayne@69: * @param srcLength the input string length, or -1 if NUL-terminated jpayne@69: * @param dest destination string buffer, can be NULL if destCapacity==0 jpayne@69: * @param destCapacity the number of chars available at dest jpayne@69: * @param pErrorCode normal ICU error code; jpayne@69: * common error codes that may be set by this function include jpayne@69: * U_BUFFER_OVERFLOW_ERROR, U_STRING_NOT_TERMINATED_WARNING, jpayne@69: * U_ILLEGAL_ARGUMENT_ERROR, and conversion errors jpayne@69: * @return the length of the output string, not counting the terminating NUL; jpayne@69: * if the length is greater than destCapacity, then the string will not fit jpayne@69: * and a buffer of the indicated length would need to be passed in jpayne@69: * @see ucnv_fromUnicode jpayne@69: * @see ucnv_convert jpayne@69: * @see UCNV_GET_MAX_BYTES_FOR_STRING jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: ucnv_fromUChars(UConverter *cnv, jpayne@69: char *dest, int32_t destCapacity, jpayne@69: const UChar *src, int32_t srcLength, jpayne@69: UErrorCode *pErrorCode); jpayne@69: jpayne@69: /** jpayne@69: * Convert the codepage string into a Unicode string using an existing UConverter. jpayne@69: * The output string is NUL-terminated if possible. jpayne@69: * jpayne@69: * This function is a more convenient but less powerful version of ucnv_toUnicode(). jpayne@69: * It is only useful for whole strings, not for streaming conversion. jpayne@69: * jpayne@69: * The maximum output buffer capacity required (barring output from callbacks) will be jpayne@69: * 2*srcLength (each char may be converted into a surrogate pair). jpayne@69: * jpayne@69: * @param cnv the converter object to be used (ucnv_resetToUnicode() will be called) jpayne@69: * @param src the input codepage string jpayne@69: * @param srcLength the input string length, or -1 if NUL-terminated jpayne@69: * @param dest destination string buffer, can be NULL if destCapacity==0 jpayne@69: * @param destCapacity the number of UChars available at dest jpayne@69: * @param pErrorCode normal ICU error code; jpayne@69: * common error codes that may be set by this function include jpayne@69: * U_BUFFER_OVERFLOW_ERROR, U_STRING_NOT_TERMINATED_WARNING, jpayne@69: * U_ILLEGAL_ARGUMENT_ERROR, and conversion errors jpayne@69: * @return the length of the output string, not counting the terminating NUL; jpayne@69: * if the length is greater than destCapacity, then the string will not fit jpayne@69: * and a buffer of the indicated length would need to be passed in jpayne@69: * @see ucnv_toUnicode jpayne@69: * @see ucnv_convert jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: ucnv_toUChars(UConverter *cnv, jpayne@69: UChar *dest, int32_t destCapacity, jpayne@69: const char *src, int32_t srcLength, jpayne@69: UErrorCode *pErrorCode); jpayne@69: jpayne@69: /** jpayne@69: * Convert a codepage buffer into Unicode one character at a time. jpayne@69: * The input is completely consumed when the U_INDEX_OUTOFBOUNDS_ERROR is set. jpayne@69: * jpayne@69: * Advantage compared to ucnv_toUnicode() or ucnv_toUChars(): jpayne@69: * - Faster for small amounts of data, for most converters, e.g., jpayne@69: * US-ASCII, ISO-8859-1, UTF-8/16/32, and most "normal" charsets. jpayne@69: * (For complex converters, e.g., SCSU, UTF-7 and ISO 2022 variants, jpayne@69: * it uses ucnv_toUnicode() internally.) jpayne@69: * - Convenient. jpayne@69: * jpayne@69: * Limitations compared to ucnv_toUnicode(): jpayne@69: * - Always assumes flush=TRUE. jpayne@69: * This makes ucnv_getNextUChar() unsuitable for "streaming" conversion, jpayne@69: * that is, for where the input is supplied in multiple buffers, jpayne@69: * because ucnv_getNextUChar() will assume the end of the input at the end jpayne@69: * of the first buffer. jpayne@69: * - Does not provide offset output. jpayne@69: * jpayne@69: * It is possible to "mix" ucnv_getNextUChar() and ucnv_toUnicode() because jpayne@69: * ucnv_getNextUChar() uses the current state of the converter jpayne@69: * (unlike ucnv_toUChars() which always resets first). jpayne@69: * However, if ucnv_getNextUChar() is called after ucnv_toUnicode() jpayne@69: * stopped in the middle of a character sequence (with flush=FALSE), jpayne@69: * then ucnv_getNextUChar() will always use the slower ucnv_toUnicode() jpayne@69: * internally until the next character boundary. jpayne@69: * (This is new in ICU 2.6. In earlier releases, ucnv_getNextUChar() had to jpayne@69: * start at a character boundary.) jpayne@69: * jpayne@69: * Instead of using ucnv_getNextUChar(), it is recommended jpayne@69: * to convert using ucnv_toUnicode() or ucnv_toUChars() jpayne@69: * and then iterate over the text using U16_NEXT() or a UCharIterator (uiter.h) jpayne@69: * or a C++ CharacterIterator or similar. jpayne@69: * This allows streaming conversion and offset output, for example. jpayne@69: * jpayne@69: *

Handling of surrogate pairs and supplementary-plane code points:
jpayne@69: * There are two different kinds of codepages that provide mappings for surrogate characters: jpayne@69: *

jpayne@69: * jpayne@69: * @param converter an open UConverter jpayne@69: * @param source the address of a pointer to the codepage buffer, will be jpayne@69: * updated to point after the bytes consumed in the conversion call. jpayne@69: * @param sourceLimit points to the end of the input buffer jpayne@69: * @param err fills in error status (see ucnv_toUnicode) jpayne@69: * U_INDEX_OUTOFBOUNDS_ERROR will be set if the input jpayne@69: * is empty or does not convert to any output (e.g.: pure state-change jpayne@69: * codes SI/SO, escape sequences for ISO 2022, jpayne@69: * or if the callback did not output anything, ...). jpayne@69: * This function will not set a U_BUFFER_OVERFLOW_ERROR because jpayne@69: * the "buffer" is the return code. However, there might be subsequent output jpayne@69: * stored in the converter object jpayne@69: * that will be returned in following calls to this function. jpayne@69: * @return a UChar32 resulting from the partial conversion of source jpayne@69: * @see ucnv_toUnicode jpayne@69: * @see ucnv_toUChars jpayne@69: * @see ucnv_convert jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE UChar32 U_EXPORT2 jpayne@69: ucnv_getNextUChar(UConverter * converter, jpayne@69: const char **source, jpayne@69: const char * sourceLimit, jpayne@69: UErrorCode * err); jpayne@69: jpayne@69: /** jpayne@69: * Convert from one external charset to another using two existing UConverters. jpayne@69: * Internally, two conversions - ucnv_toUnicode() and ucnv_fromUnicode() - jpayne@69: * are used, "pivoting" through 16-bit Unicode. jpayne@69: * jpayne@69: * Important: For streaming conversion (multiple function calls for successive jpayne@69: * parts of a text stream), the caller must provide a pivot buffer explicitly, jpayne@69: * and must preserve the pivot buffer and associated pointers from one jpayne@69: * call to another. (The buffer may be moved if its contents and the relative jpayne@69: * pointer positions are preserved.) jpayne@69: * jpayne@69: * There is a similar function, ucnv_convert(), jpayne@69: * which has the following limitations: jpayne@69: * - it takes charset names, not converter objects, so that jpayne@69: * - two converters are opened for each call jpayne@69: * - only single-string conversion is possible, not streaming operation jpayne@69: * - it does not provide enough information to find out, jpayne@69: * in case of failure, whether the toUnicode or jpayne@69: * the fromUnicode conversion failed jpayne@69: * jpayne@69: * By contrast, ucnv_convertEx() jpayne@69: * - takes UConverter parameters instead of charset names jpayne@69: * - fully exposes the pivot buffer for streaming conversion and complete error handling jpayne@69: * jpayne@69: * ucnv_convertEx() also provides further convenience: jpayne@69: * - an option to reset the converters at the beginning jpayne@69: * (if reset==TRUE, see parameters; jpayne@69: * also sets *pivotTarget=*pivotSource=pivotStart) jpayne@69: * - allow NUL-terminated input jpayne@69: * (only a single NUL byte, will not work for charsets with multi-byte NULs) jpayne@69: * (if sourceLimit==NULL, see parameters) jpayne@69: * - terminate with a NUL on output jpayne@69: * (only a single NUL byte, not useful for charsets with multi-byte NULs), jpayne@69: * or set U_STRING_NOT_TERMINATED_WARNING if the output exactly fills jpayne@69: * the target buffer jpayne@69: * - the pivot buffer can be provided internally; jpayne@69: * possible only for whole-string conversion, not streaming conversion; jpayne@69: * in this case, the caller will not be able to get details about where an jpayne@69: * error occurred jpayne@69: * (if pivotStart==NULL, see below) jpayne@69: * jpayne@69: * The function returns when one of the following is true: jpayne@69: * - the entire source text has been converted successfully to the target buffer jpayne@69: * - a target buffer overflow occurred (U_BUFFER_OVERFLOW_ERROR) jpayne@69: * - a conversion error occurred jpayne@69: * (other U_FAILURE(), see description of pErrorCode) jpayne@69: * jpayne@69: * Limitation compared to the direct use of jpayne@69: * ucnv_fromUnicode() and ucnv_toUnicode(): jpayne@69: * ucnv_convertEx() does not provide offset information. jpayne@69: * jpayne@69: * Limitation compared to ucnv_fromUChars() and ucnv_toUChars(): jpayne@69: * ucnv_convertEx() does not support preflighting directly. jpayne@69: * jpayne@69: * Sample code for converting a single string from jpayne@69: * one external charset to UTF-8, ignoring the location of errors: jpayne@69: * jpayne@69: * \code jpayne@69: * int32_t jpayne@69: * myToUTF8(UConverter *cnv, jpayne@69: * const char *s, int32_t length, jpayne@69: * char *u8, int32_t capacity, jpayne@69: * UErrorCode *pErrorCode) { jpayne@69: * UConverter *utf8Cnv; jpayne@69: * char *target; jpayne@69: * jpayne@69: * if(U_FAILURE(*pErrorCode)) { jpayne@69: * return 0; jpayne@69: * } jpayne@69: * jpayne@69: * utf8Cnv=myGetCachedUTF8Converter(pErrorCode); jpayne@69: * if(U_FAILURE(*pErrorCode)) { jpayne@69: * return 0; jpayne@69: * } jpayne@69: * jpayne@69: * if(length<0) { jpayne@69: * length=strlen(s); jpayne@69: * } jpayne@69: * target=u8; jpayne@69: * ucnv_convertEx(utf8Cnv, cnv, jpayne@69: * &target, u8+capacity, jpayne@69: * &s, s+length, jpayne@69: * NULL, NULL, NULL, NULL, jpayne@69: * TRUE, TRUE, jpayne@69: * pErrorCode); jpayne@69: * jpayne@69: * myReleaseCachedUTF8Converter(utf8Cnv); jpayne@69: * jpayne@69: * // return the output string length, but without preflighting jpayne@69: * return (int32_t)(target-u8); jpayne@69: * } jpayne@69: * \endcode jpayne@69: * jpayne@69: * @param targetCnv Output converter, used to convert from the UTF-16 pivot jpayne@69: * to the target using ucnv_fromUnicode(). jpayne@69: * @param sourceCnv Input converter, used to convert from the source to jpayne@69: * the UTF-16 pivot using ucnv_toUnicode(). jpayne@69: * @param target I/O parameter, same as for ucnv_fromUChars(). jpayne@69: * Input: *target points to the beginning of the target buffer. jpayne@69: * Output: *target points to the first unit after the last char written. jpayne@69: * @param targetLimit Pointer to the first unit after the target buffer. jpayne@69: * @param source I/O parameter, same as for ucnv_toUChars(). jpayne@69: * Input: *source points to the beginning of the source buffer. jpayne@69: * Output: *source points to the first unit after the last char read. jpayne@69: * @param sourceLimit Pointer to the first unit after the source buffer. jpayne@69: * @param pivotStart Pointer to the UTF-16 pivot buffer. If pivotStart==NULL, jpayne@69: * then an internal buffer is used and the other pivot jpayne@69: * arguments are ignored and can be NULL as well. jpayne@69: * @param pivotSource I/O parameter, same as source in ucnv_fromUChars() for jpayne@69: * conversion from the pivot buffer to the target buffer. jpayne@69: * @param pivotTarget I/O parameter, same as target in ucnv_toUChars() for jpayne@69: * conversion from the source buffer to the pivot buffer. jpayne@69: * It must be pivotStart<=*pivotSource<=*pivotTarget<=pivotLimit jpayne@69: * and pivotStart[0..ucnv_countAvaiable()]) jpayne@69: * @return a pointer a string (library owned), or NULL if the index is out of bounds. jpayne@69: * @see ucnv_countAvailable jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE const char* U_EXPORT2 jpayne@69: ucnv_getAvailableName(int32_t n); jpayne@69: jpayne@69: /** jpayne@69: * Returns a UEnumeration to enumerate all of the canonical converter jpayne@69: * names, as per the alias file, regardless of the ability to open each jpayne@69: * converter. jpayne@69: * jpayne@69: * @return A UEnumeration object for getting all the recognized canonical jpayne@69: * converter names. jpayne@69: * @see ucnv_getAvailableName jpayne@69: * @see uenum_close jpayne@69: * @see uenum_next jpayne@69: * @stable ICU 2.4 jpayne@69: */ jpayne@69: U_STABLE UEnumeration * U_EXPORT2 jpayne@69: ucnv_openAllNames(UErrorCode *pErrorCode); jpayne@69: jpayne@69: /** jpayne@69: * Gives the number of aliases for a given converter or alias name. jpayne@69: * If the alias is ambiguous, then the preferred converter is used jpayne@69: * and the status is set to U_AMBIGUOUS_ALIAS_WARNING. jpayne@69: * This method only enumerates the listed entries in the alias file. jpayne@69: * @param alias alias name jpayne@69: * @param pErrorCode error status jpayne@69: * @return number of names on alias list for given alias jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE uint16_t U_EXPORT2 jpayne@69: ucnv_countAliases(const char *alias, UErrorCode *pErrorCode); jpayne@69: jpayne@69: /** jpayne@69: * Gives the name of the alias at given index of alias list. jpayne@69: * This method only enumerates the listed entries in the alias file. jpayne@69: * If the alias is ambiguous, then the preferred converter is used jpayne@69: * and the status is set to U_AMBIGUOUS_ALIAS_WARNING. jpayne@69: * @param alias alias name jpayne@69: * @param n index in alias list jpayne@69: * @param pErrorCode result of operation jpayne@69: * @return returns the name of the alias at given index jpayne@69: * @see ucnv_countAliases jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE const char * U_EXPORT2 jpayne@69: ucnv_getAlias(const char *alias, uint16_t n, UErrorCode *pErrorCode); jpayne@69: jpayne@69: /** jpayne@69: * Fill-up the list of alias names for the given alias. jpayne@69: * This method only enumerates the listed entries in the alias file. jpayne@69: * If the alias is ambiguous, then the preferred converter is used jpayne@69: * and the status is set to U_AMBIGUOUS_ALIAS_WARNING. jpayne@69: * @param alias alias name jpayne@69: * @param aliases fill-in list, aliases is a pointer to an array of jpayne@69: * ucnv_countAliases() string-pointers jpayne@69: * (const char *) that will be filled in. jpayne@69: * The strings themselves are owned by the library. jpayne@69: * @param pErrorCode result of operation jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE void U_EXPORT2 jpayne@69: ucnv_getAliases(const char *alias, const char **aliases, UErrorCode *pErrorCode); jpayne@69: jpayne@69: /** jpayne@69: * Return a new UEnumeration object for enumerating all the jpayne@69: * alias names for a given converter that are recognized by a standard. jpayne@69: * This method only enumerates the listed entries in the alias file. jpayne@69: * The convrtrs.txt file can be modified to change the results of jpayne@69: * this function. jpayne@69: * The first result in this list is the same result given by jpayne@69: * ucnv_getStandardName, which is the default alias for jpayne@69: * the specified standard name. The returned object must be closed with jpayne@69: * uenum_close when you are done with the object. jpayne@69: * jpayne@69: * @param convName original converter name jpayne@69: * @param standard name of the standard governing the names; MIME and IANA jpayne@69: * are such standards jpayne@69: * @param pErrorCode The error code jpayne@69: * @return A UEnumeration object for getting all aliases that are recognized jpayne@69: * by a standard. If any of the parameters are invalid, NULL jpayne@69: * is returned. jpayne@69: * @see ucnv_getStandardName jpayne@69: * @see uenum_close jpayne@69: * @see uenum_next jpayne@69: * @stable ICU 2.2 jpayne@69: */ jpayne@69: U_STABLE UEnumeration * U_EXPORT2 jpayne@69: ucnv_openStandardNames(const char *convName, jpayne@69: const char *standard, jpayne@69: UErrorCode *pErrorCode); jpayne@69: jpayne@69: /** jpayne@69: * Gives the number of standards associated to converter names. jpayne@69: * @return number of standards jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE uint16_t U_EXPORT2 jpayne@69: ucnv_countStandards(void); jpayne@69: jpayne@69: /** jpayne@69: * Gives the name of the standard at given index of standard list. jpayne@69: * @param n index in standard list jpayne@69: * @param pErrorCode result of operation jpayne@69: * @return returns the name of the standard at given index. Owned by the library. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE const char * U_EXPORT2 jpayne@69: ucnv_getStandard(uint16_t n, UErrorCode *pErrorCode); jpayne@69: jpayne@69: /** jpayne@69: * Returns a standard name for a given converter name. jpayne@69: *

jpayne@69: * Example alias table:
jpayne@69: * conv alias1 { STANDARD1 } alias2 { STANDARD1* } jpayne@69: *

jpayne@69: * Result of ucnv_getStandardName("conv", "STANDARD1") from example jpayne@69: * alias table:
jpayne@69: * "alias2" jpayne@69: * jpayne@69: * @param name original converter name jpayne@69: * @param standard name of the standard governing the names; MIME and IANA jpayne@69: * are such standards jpayne@69: * @param pErrorCode result of operation jpayne@69: * @return returns the standard converter name; jpayne@69: * if a standard converter name cannot be determined, jpayne@69: * then NULL is returned. Owned by the library. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE const char * U_EXPORT2 jpayne@69: ucnv_getStandardName(const char *name, const char *standard, UErrorCode *pErrorCode); jpayne@69: jpayne@69: /** jpayne@69: * This function will return the internal canonical converter name of the jpayne@69: * tagged alias. This is the opposite of ucnv_openStandardNames, which jpayne@69: * returns the tagged alias given the canonical name. jpayne@69: *

jpayne@69: * Example alias table:
jpayne@69: * conv alias1 { STANDARD1 } alias2 { STANDARD1* } jpayne@69: *

jpayne@69: * Result of ucnv_getStandardName("alias1", "STANDARD1") from example jpayne@69: * alias table:
jpayne@69: * "conv" jpayne@69: * jpayne@69: * @return returns the canonical converter name; jpayne@69: * if a standard or alias name cannot be determined, jpayne@69: * then NULL is returned. The returned string is jpayne@69: * owned by the library. jpayne@69: * @see ucnv_getStandardName jpayne@69: * @stable ICU 2.4 jpayne@69: */ jpayne@69: U_STABLE const char * U_EXPORT2 jpayne@69: ucnv_getCanonicalName(const char *alias, const char *standard, UErrorCode *pErrorCode); jpayne@69: jpayne@69: /** jpayne@69: * Returns the current default converter name. If you want to open jpayne@69: * a default converter, you do not need to use this function. jpayne@69: * It is faster if you pass a NULL argument to ucnv_open the jpayne@69: * default converter. jpayne@69: * jpayne@69: * If U_CHARSET_IS_UTF8 is defined to 1 in utypes.h then this function jpayne@69: * always returns "UTF-8". jpayne@69: * jpayne@69: * @return returns the current default converter name. jpayne@69: * Storage owned by the library jpayne@69: * @see ucnv_setDefaultName jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE const char * U_EXPORT2 jpayne@69: ucnv_getDefaultName(void); jpayne@69: jpayne@69: #ifndef U_HIDE_SYSTEM_API jpayne@69: /** jpayne@69: * This function is not thread safe. DO NOT call this function when ANY ICU jpayne@69: * function is being used from more than one thread! This function sets the jpayne@69: * current default converter name. If this function needs to be called, it jpayne@69: * should be called during application initialization. Most of the time, the jpayne@69: * results from ucnv_getDefaultName() or ucnv_open with a NULL string argument jpayne@69: * is sufficient for your application. jpayne@69: * jpayne@69: * If U_CHARSET_IS_UTF8 is defined to 1 in utypes.h then this function jpayne@69: * does nothing. jpayne@69: * jpayne@69: * @param name the converter name to be the default (must be known by ICU). jpayne@69: * @see ucnv_getDefaultName jpayne@69: * @system jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE void U_EXPORT2 jpayne@69: ucnv_setDefaultName(const char *name); jpayne@69: #endif /* U_HIDE_SYSTEM_API */ jpayne@69: jpayne@69: /** jpayne@69: * Fixes the backslash character mismapping. For example, in SJIS, the backslash jpayne@69: * character in the ASCII portion is also used to represent the yen currency sign. jpayne@69: * When mapping from Unicode character 0x005C, it's unclear whether to map the jpayne@69: * character back to yen or backslash in SJIS. This function will take the input jpayne@69: * buffer and replace all the yen sign characters with backslash. This is necessary jpayne@69: * when the user tries to open a file with the input buffer on Windows. jpayne@69: * This function will test the converter to see whether such mapping is jpayne@69: * required. You can sometimes avoid using this function by using the correct version jpayne@69: * of Shift-JIS. jpayne@69: * jpayne@69: * @param cnv The converter representing the target codepage. jpayne@69: * @param source the input buffer to be fixed jpayne@69: * @param sourceLen the length of the input buffer jpayne@69: * @see ucnv_isAmbiguous jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE void U_EXPORT2 jpayne@69: ucnv_fixFileSeparator(const UConverter *cnv, UChar *source, int32_t sourceLen); jpayne@69: jpayne@69: /** jpayne@69: * Determines if the converter contains ambiguous mappings of the same jpayne@69: * character or not. jpayne@69: * @param cnv the converter to be tested jpayne@69: * @return TRUE if the converter contains ambiguous mapping of the same jpayne@69: * character, FALSE otherwise. jpayne@69: * @stable ICU 2.0 jpayne@69: */ jpayne@69: U_STABLE UBool U_EXPORT2 jpayne@69: ucnv_isAmbiguous(const UConverter *cnv); jpayne@69: jpayne@69: /** jpayne@69: * Sets the converter to use fallback mappings or not. jpayne@69: * Regardless of this flag, the converter will always use jpayne@69: * fallbacks from Unicode Private Use code points, as well as jpayne@69: * reverse fallbacks (to Unicode). jpayne@69: * For details see ".ucm File Format" jpayne@69: * in the Conversion Data chapter of the ICU User Guide: jpayne@69: * http://www.icu-project.org/userguide/conversion-data.html#ucmformat jpayne@69: * jpayne@69: * @param cnv The converter to set the fallback mapping usage on. jpayne@69: * @param usesFallback TRUE if the user wants the converter to take advantage of the fallback jpayne@69: * mapping, FALSE otherwise. jpayne@69: * @stable ICU 2.0 jpayne@69: * @see ucnv_usesFallback jpayne@69: */ jpayne@69: U_STABLE void U_EXPORT2 jpayne@69: ucnv_setFallback(UConverter *cnv, UBool usesFallback); jpayne@69: jpayne@69: /** jpayne@69: * Determines if the converter uses fallback mappings or not. jpayne@69: * This flag has restrictions, see ucnv_setFallback(). jpayne@69: * jpayne@69: * @param cnv The converter to be tested jpayne@69: * @return TRUE if the converter uses fallback, FALSE otherwise. jpayne@69: * @stable ICU 2.0 jpayne@69: * @see ucnv_setFallback jpayne@69: */ jpayne@69: U_STABLE UBool U_EXPORT2 jpayne@69: ucnv_usesFallback(const UConverter *cnv); jpayne@69: jpayne@69: /** jpayne@69: * Detects Unicode signature byte sequences at the start of the byte stream jpayne@69: * and returns the charset name of the indicated Unicode charset. jpayne@69: * NULL is returned when no Unicode signature is recognized. jpayne@69: * The number of bytes in the signature is output as well. jpayne@69: * jpayne@69: * The caller can ucnv_open() a converter using the charset name. jpayne@69: * The first code unit (UChar) from the start of the stream will be U+FEFF jpayne@69: * (the Unicode BOM/signature character) and can usually be ignored. jpayne@69: * jpayne@69: * For most Unicode charsets it is also possible to ignore the indicated jpayne@69: * number of initial stream bytes and start converting after them. jpayne@69: * However, there are stateful Unicode charsets (UTF-7 and BOCU-1) for which jpayne@69: * this will not work. Therefore, it is best to ignore the first output UChar jpayne@69: * instead of the input signature bytes. jpayne@69: *

jpayne@69: * Usage: jpayne@69: * \snippet samples/ucnv/convsamp.cpp ucnv_detectUnicodeSignature jpayne@69: * jpayne@69: * @param source The source string in which the signature should be detected. jpayne@69: * @param sourceLength Length of the input string, or -1 if terminated with a NUL byte. jpayne@69: * @param signatureLength A pointer to int32_t to receive the number of bytes that make up the signature jpayne@69: * of the detected UTF. 0 if not detected. jpayne@69: * Can be a NULL pointer. jpayne@69: * @param pErrorCode ICU error code in/out parameter. jpayne@69: * Must fulfill U_SUCCESS before the function call. jpayne@69: * @return The name of the encoding detected. NULL if encoding is not detected. jpayne@69: * @stable ICU 2.4 jpayne@69: */ jpayne@69: U_STABLE const char* U_EXPORT2 jpayne@69: ucnv_detectUnicodeSignature(const char* source, jpayne@69: int32_t sourceLength, jpayne@69: int32_t *signatureLength, jpayne@69: UErrorCode *pErrorCode); jpayne@69: jpayne@69: /** jpayne@69: * Returns the number of UChars held in the converter's internal state jpayne@69: * because more input is needed for completing the conversion. This function is jpayne@69: * useful for mapping semantics of ICU's converter interface to those of iconv, jpayne@69: * and this information is not needed for normal conversion. jpayne@69: * @param cnv The converter in which the input is held jpayne@69: * @param status ICU error code in/out parameter. jpayne@69: * Must fulfill U_SUCCESS before the function call. jpayne@69: * @return The number of UChars in the state. -1 if an error is encountered. jpayne@69: * @stable ICU 3.4 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: ucnv_fromUCountPending(const UConverter* cnv, UErrorCode* status); jpayne@69: jpayne@69: /** jpayne@69: * Returns the number of chars held in the converter's internal state jpayne@69: * because more input is needed for completing the conversion. This function is jpayne@69: * useful for mapping semantics of ICU's converter interface to those of iconv, jpayne@69: * and this information is not needed for normal conversion. jpayne@69: * @param cnv The converter in which the input is held as internal state jpayne@69: * @param status ICU error code in/out parameter. jpayne@69: * Must fulfill U_SUCCESS before the function call. jpayne@69: * @return The number of chars in the state. -1 if an error is encountered. jpayne@69: * @stable ICU 3.4 jpayne@69: */ jpayne@69: U_STABLE int32_t U_EXPORT2 jpayne@69: ucnv_toUCountPending(const UConverter* cnv, UErrorCode* status); jpayne@69: jpayne@69: /** jpayne@69: * Returns whether or not the charset of the converter has a fixed number of bytes jpayne@69: * per charset character. jpayne@69: * An example of this are converters that are of the type UCNV_SBCS or UCNV_DBCS. jpayne@69: * Another example is UTF-32 which is always 4 bytes per character. jpayne@69: * A Unicode code point may be represented by more than one UTF-8 or UTF-16 code unit jpayne@69: * but a UTF-32 converter encodes each code point with 4 bytes. jpayne@69: * Note: This method is not intended to be used to determine whether the charset has a jpayne@69: * fixed ratio of bytes to Unicode codes units for any particular Unicode encoding form. jpayne@69: * FALSE is returned with the UErrorCode if error occurs or cnv is NULL. jpayne@69: * @param cnv The converter to be tested jpayne@69: * @param status ICU error code in/out paramter jpayne@69: * @return TRUE if the converter is fixed-width jpayne@69: * @stable ICU 4.8 jpayne@69: */ jpayne@69: U_STABLE UBool U_EXPORT2 jpayne@69: ucnv_isFixedWidth(UConverter *cnv, UErrorCode *status); jpayne@69: jpayne@69: #endif jpayne@69: jpayne@69: #endif jpayne@69: /*_UCNV*/