michael@0: /* michael@0: ********************************************************************** michael@0: * Copyright (C) 1999-2013, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: ********************************************************************** michael@0: * ucnv.h: michael@0: * External APIs for the ICU's codeset conversion library michael@0: * Bertrand A. Damiba michael@0: * michael@0: * Modification History: michael@0: * michael@0: * Date Name Description michael@0: * 04/04/99 helena Fixed internal header inclusion. michael@0: * 05/11/00 helena Added setFallback and usesFallback APIs. michael@0: * 06/29/2000 helena Major rewrite of the callback APIs. michael@0: * 12/07/2000 srl Update of documentation michael@0: */ michael@0: michael@0: /** michael@0: * \file michael@0: * \brief C API: Character conversion michael@0: * michael@0: *
This API is used to convert codepage or character encoded data to and michael@0: * from UTF-16. You can open a converter with {@link ucnv_open() }. With that michael@0: * converter, you can get its properties, set options, convert your data and michael@0: * close the converter.
michael@0: * michael@0: *Since many software programs recogize different converter names for michael@0: * different types of converters, there are other functions in this API to michael@0: * iterate over the converter aliases. The functions {@link ucnv_getAvailableName() }, michael@0: * {@link ucnv_getAlias() } and {@link ucnv_getStandardName() } are some of the michael@0: * more frequently used alias functions to get this information.
michael@0: * michael@0: *When a converter encounters an illegal, irregular, invalid or unmappable character michael@0: * its default behavior is to use a substitution character to replace the michael@0: * bad byte sequence. This behavior can be changed by using {@link ucnv_setFromUCallBack() } michael@0: * or {@link ucnv_setToUCallBack() } on the converter. The header ucnv_err.h defines michael@0: * many other callback actions that can be used instead of a character substitution.
michael@0: * michael@0: *More information about this API can be found in our michael@0: * User's michael@0: * Guide.
michael@0: */ michael@0: michael@0: #ifndef UCNV_H michael@0: #define UCNV_H michael@0: michael@0: #include "unicode/ucnv_err.h" michael@0: #include "unicode/uenum.h" michael@0: #include "unicode/localpointer.h" michael@0: michael@0: #ifndef __USET_H__ michael@0: michael@0: /** michael@0: * USet is the C API type for Unicode sets. michael@0: * It is forward-declared here to avoid including the header file if related michael@0: * conversion APIs are not used. michael@0: * See unicode/uset.h michael@0: * michael@0: * @see ucnv_getUnicodeSet michael@0: * @stable ICU 2.6 michael@0: */ michael@0: struct USet; michael@0: /** @stable ICU 2.6 */ michael@0: typedef struct USet USet; michael@0: michael@0: #endif michael@0: michael@0: #if !UCONFIG_NO_CONVERSION michael@0: michael@0: U_CDECL_BEGIN michael@0: michael@0: /** Maximum length of a converter name including the terminating NULL @stable ICU 2.0 */ michael@0: #define UCNV_MAX_CONVERTER_NAME_LENGTH 60 michael@0: /** Maximum length of a converter name including path and terminating NULL @stable ICU 2.0 */ michael@0: #define UCNV_MAX_FULL_FILE_NAME_LENGTH (600+UCNV_MAX_CONVERTER_NAME_LENGTH) michael@0: michael@0: /** Shift in for EBDCDIC_STATEFUL and iso2022 states @stable ICU 2.0 */ michael@0: #define UCNV_SI 0x0F michael@0: /** Shift out for EBDCDIC_STATEFUL and iso2022 states @stable ICU 2.0 */ michael@0: #define UCNV_SO 0x0E michael@0: michael@0: /** michael@0: * Enum for specifying basic types of converters michael@0: * @see ucnv_getType michael@0: * @stable ICU 2.0 michael@0: */ michael@0: typedef enum { michael@0: /** @stable ICU 2.0 */ michael@0: UCNV_UNSUPPORTED_CONVERTER = -1, michael@0: /** @stable ICU 2.0 */ michael@0: UCNV_SBCS = 0, michael@0: /** @stable ICU 2.0 */ michael@0: UCNV_DBCS = 1, michael@0: /** @stable ICU 2.0 */ michael@0: UCNV_MBCS = 2, michael@0: /** @stable ICU 2.0 */ michael@0: UCNV_LATIN_1 = 3, michael@0: /** @stable ICU 2.0 */ michael@0: UCNV_UTF8 = 4, michael@0: /** @stable ICU 2.0 */ michael@0: UCNV_UTF16_BigEndian = 5, michael@0: /** @stable ICU 2.0 */ michael@0: UCNV_UTF16_LittleEndian = 6, michael@0: /** @stable ICU 2.0 */ michael@0: UCNV_UTF32_BigEndian = 7, michael@0: /** @stable ICU 2.0 */ michael@0: UCNV_UTF32_LittleEndian = 8, michael@0: /** @stable ICU 2.0 */ michael@0: UCNV_EBCDIC_STATEFUL = 9, michael@0: /** @stable ICU 2.0 */ michael@0: UCNV_ISO_2022 = 10, michael@0: michael@0: /** @stable ICU 2.0 */ michael@0: UCNV_LMBCS_1 = 11, michael@0: /** @stable ICU 2.0 */ michael@0: UCNV_LMBCS_2, michael@0: /** @stable ICU 2.0 */ michael@0: UCNV_LMBCS_3, michael@0: /** @stable ICU 2.0 */ michael@0: UCNV_LMBCS_4, michael@0: /** @stable ICU 2.0 */ michael@0: UCNV_LMBCS_5, michael@0: /** @stable ICU 2.0 */ michael@0: UCNV_LMBCS_6, michael@0: /** @stable ICU 2.0 */ michael@0: UCNV_LMBCS_8, michael@0: /** @stable ICU 2.0 */ michael@0: UCNV_LMBCS_11, michael@0: /** @stable ICU 2.0 */ michael@0: UCNV_LMBCS_16, michael@0: /** @stable ICU 2.0 */ michael@0: UCNV_LMBCS_17, michael@0: /** @stable ICU 2.0 */ michael@0: UCNV_LMBCS_18, michael@0: /** @stable ICU 2.0 */ michael@0: UCNV_LMBCS_19, michael@0: /** @stable ICU 2.0 */ michael@0: UCNV_LMBCS_LAST = UCNV_LMBCS_19, michael@0: /** @stable ICU 2.0 */ michael@0: UCNV_HZ, michael@0: /** @stable ICU 2.0 */ michael@0: UCNV_SCSU, michael@0: /** @stable ICU 2.0 */ michael@0: UCNV_ISCII, michael@0: /** @stable ICU 2.0 */ michael@0: UCNV_US_ASCII, michael@0: /** @stable ICU 2.0 */ michael@0: UCNV_UTF7, michael@0: /** @stable ICU 2.2 */ michael@0: UCNV_BOCU1, michael@0: /** @stable ICU 2.2 */ michael@0: UCNV_UTF16, michael@0: /** @stable ICU 2.2 */ michael@0: UCNV_UTF32, michael@0: /** @stable ICU 2.2 */ michael@0: UCNV_CESU8, michael@0: /** @stable ICU 2.4 */ michael@0: UCNV_IMAP_MAILBOX, michael@0: /** @stable ICU 4.8 */ michael@0: UCNV_COMPOUND_TEXT, michael@0: michael@0: /* Number of converter types for which we have conversion routines. */ michael@0: UCNV_NUMBER_OF_SUPPORTED_CONVERTER_TYPES michael@0: } UConverterType; michael@0: michael@0: /** michael@0: * Enum for specifying which platform a converter ID refers to. michael@0: * The use of platform/CCSID is not recommended. See ucnv_openCCSID(). michael@0: * michael@0: * @see ucnv_getPlatform michael@0: * @see ucnv_openCCSID michael@0: * @see ucnv_getCCSID michael@0: * @stable ICU 2.0 michael@0: */ michael@0: typedef enum { michael@0: UCNV_UNKNOWN = -1, michael@0: UCNV_IBM = 0 michael@0: } UConverterPlatform; michael@0: michael@0: /** michael@0: * Function pointer for error callback in the codepage to unicode direction. michael@0: * Called when an error has occured in conversion to unicode, or on open/close of the callback (see reason). michael@0: * @param context Pointer to the callback's private data michael@0: * @param args Information about the conversion in progress michael@0: * @param codeUnits Points to 'length' bytes of the concerned codepage sequence michael@0: * @param length Size (in bytes) of the concerned codepage sequence michael@0: * @param reason Defines the reason the callback was invoked michael@0: * @param pErrorCode ICU error code in/out parameter. michael@0: * For converter callback functions, set to a conversion error michael@0: * before the call, and the callback may reset it to U_ZERO_ERROR. michael@0: * @see ucnv_setToUCallBack michael@0: * @see UConverterToUnicodeArgs michael@0: * @stable ICU 2.0 michael@0: */ michael@0: typedef void (U_EXPORT2 *UConverterToUCallback) ( michael@0: const void* context, michael@0: UConverterToUnicodeArgs *args, michael@0: const char *codeUnits, michael@0: int32_t length, michael@0: UConverterCallbackReason reason, michael@0: UErrorCode *pErrorCode); michael@0: michael@0: /** michael@0: * Function pointer for error callback in the unicode to codepage direction. michael@0: * Called when an error has occured in conversion from unicode, or on open/close of the callback (see reason). michael@0: * @param context Pointer to the callback's private data michael@0: * @param args Information about the conversion in progress michael@0: * @param codeUnits Points to 'length' UChars of the concerned Unicode sequence michael@0: * @param length Size (in bytes) of the concerned codepage sequence michael@0: * @param codePoint Single UChar32 (UTF-32) containing the concerend Unicode codepoint. michael@0: * @param reason Defines the reason the callback was invoked michael@0: * @param pErrorCode ICU error code in/out parameter. michael@0: * For converter callback functions, set to a conversion error michael@0: * before the call, and the callback may reset it to U_ZERO_ERROR. michael@0: * @see ucnv_setFromUCallBack michael@0: * @stable ICU 2.0 michael@0: */ michael@0: typedef void (U_EXPORT2 *UConverterFromUCallback) ( michael@0: const void* context, michael@0: UConverterFromUnicodeArgs *args, michael@0: const UChar* codeUnits, michael@0: int32_t length, michael@0: UChar32 codePoint, michael@0: UConverterCallbackReason reason, michael@0: UErrorCode *pErrorCode); michael@0: michael@0: U_CDECL_END michael@0: michael@0: /** michael@0: * Character that separates converter names from options and options from each other. michael@0: * @see ucnv_open michael@0: * @stable ICU 2.0 michael@0: */ michael@0: #define UCNV_OPTION_SEP_CHAR ',' michael@0: michael@0: /** michael@0: * String version of UCNV_OPTION_SEP_CHAR. michael@0: * @see ucnv_open michael@0: * @stable ICU 2.0 michael@0: */ michael@0: #define UCNV_OPTION_SEP_STRING "," michael@0: michael@0: /** michael@0: * Character that separates a converter option from its value. michael@0: * @see ucnv_open michael@0: * @stable ICU 2.0 michael@0: */ michael@0: #define UCNV_VALUE_SEP_CHAR '=' michael@0: michael@0: /** michael@0: * String version of UCNV_VALUE_SEP_CHAR. michael@0: * @see ucnv_open michael@0: * @stable ICU 2.0 michael@0: */ michael@0: #define UCNV_VALUE_SEP_STRING "=" michael@0: michael@0: /** michael@0: * Converter option for specifying a locale. michael@0: * For example, ucnv_open("SCSU,locale=ja", &errorCode); michael@0: * See convrtrs.txt. michael@0: * michael@0: * @see ucnv_open michael@0: * @stable ICU 2.0 michael@0: */ michael@0: #define UCNV_LOCALE_OPTION_STRING ",locale=" michael@0: michael@0: /** michael@0: * Converter option for specifying a version selector (0..9) for some converters. michael@0: * For example, michael@0: * \code michael@0: * ucnv_open("UTF-7,version=1", &errorCode); michael@0: * \endcode michael@0: * See convrtrs.txt. michael@0: * michael@0: * @see ucnv_open michael@0: * @stable ICU 2.4 michael@0: */ michael@0: #define UCNV_VERSION_OPTION_STRING ",version=" michael@0: michael@0: /** michael@0: * Converter option for EBCDIC SBCS or mixed-SBCS/DBCS (stateful) codepages. michael@0: * Swaps Unicode mappings for EBCDIC LF and NL codes, as used on michael@0: * S/390 (z/OS) Unix System Services (Open Edition). michael@0: * For example, ucnv_open("ibm-1047,swaplfnl", &errorCode); michael@0: * See convrtrs.txt. michael@0: * michael@0: * @see ucnv_open michael@0: * @stable ICU 2.4 michael@0: */ michael@0: #define UCNV_SWAP_LFNL_OPTION_STRING ",swaplfnl" michael@0: michael@0: /** michael@0: * Do a fuzzy compare of two converter/alias names. michael@0: * The comparison is case-insensitive, ignores leading zeroes if they are not michael@0: * followed by further digits, and ignores all but letters and digits. michael@0: * Thus the strings "UTF-8", "utf_8", "u*T@f08" and "Utf 8" are exactly equivalent. michael@0: * See section 1.4, Charset Alias Matching in Unicode Technical Standard #22 michael@0: * at http://www.unicode.org/reports/tr22/ michael@0: * michael@0: * @param name1 a converter name or alias, zero-terminated michael@0: * @param name2 a converter name or alias, zero-terminated michael@0: * @return 0 if the names match, or a negative value if the name1 michael@0: * lexically precedes name2, or a positive value if the name1 michael@0: * lexically follows name2. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: U_STABLE int U_EXPORT2 michael@0: ucnv_compareNames(const char *name1, const char *name2); michael@0: michael@0: michael@0: /** michael@0: * Creates a UConverter object with the name of a coded character set specified as a C string. michael@0: * The actual name will be resolved with the alias file michael@0: * using a case-insensitive string comparison that ignores michael@0: * leading zeroes and all non-alphanumeric characters. michael@0: * E.g., the names "UTF8", "utf-8", "u*T@f08" and "Utf 8" are all equivalent. michael@0: * (See also ucnv_compareNames().) michael@0: * IfNULL
is passed for the converter name, it will create one with the
michael@0: * getDefaultName return value.
michael@0: *
michael@0: * A converter name for ICU 1.5 and above may contain options michael@0: * like a locale specification to control the specific behavior of michael@0: * the newly instantiated converter. michael@0: * The meaning of the options depends on the particular converter. michael@0: * If an option is not defined for or recognized by a given converter, then it is ignored.
michael@0: * michael@0: *Options are appended to the converter name string, with a
michael@0: * UCNV_OPTION_SEP_CHAR
between the name and the first option and
michael@0: * also between adjacent options.
If the alias is ambiguous, then the preferred converter is used michael@0: * and the status is set to U_AMBIGUOUS_ALIAS_WARNING.
michael@0: * michael@0: *The conversion behavior and names can vary between platforms. ICU may michael@0: * convert some characters differently from other platforms. Details on this topic michael@0: * are in the User's michael@0: * Guide. Aliases starting with a "cp" prefix have no specific meaning michael@0: * other than its an alias starting with the letters "cp". Please do not michael@0: * associate any meaning to these aliases.
michael@0: * michael@0: * \snippet samples/ucnv/convsamp.cpp ucnv_open michael@0: * michael@0: * @param converterName Name of the coded character set table. michael@0: * This may have options appended to the string. michael@0: * IANA alias character set names, IBM CCSIDs starting with "ibm-", michael@0: * Windows codepage numbers starting with "windows-" are frequently michael@0: * used for this parameter. See ucnv_getAvailableName and michael@0: * ucnv_getAlias for a complete list that is available. michael@0: * If this parameter is NULL, the default converter will be used. michael@0: * @param err outgoing error status U_MEMORY_ALLOCATION_ERROR, U_FILE_ACCESS_ERROR michael@0: * @return the created Unicode converter object, or NULL if an error occured michael@0: * @see ucnv_openU michael@0: * @see ucnv_openCCSID michael@0: * @see ucnv_getAvailableName michael@0: * @see ucnv_getAlias michael@0: * @see ucnv_getDefaultName michael@0: * @see ucnv_close michael@0: * @see ucnv_compareNames michael@0: * @stable ICU 2.0 michael@0: */ michael@0: U_STABLE UConverter* U_EXPORT2 michael@0: ucnv_open(const char *converterName, UErrorCode *err); michael@0: michael@0: michael@0: /** michael@0: * Creates a Unicode converter with the names specified as unicode string. michael@0: * The name should be limited to the ASCII-7 alphanumerics range. michael@0: * The actual name will be resolved with the alias file michael@0: * using a case-insensitive string comparison that ignores michael@0: * leading zeroes and all non-alphanumeric characters. michael@0: * E.g., the names "UTF8", "utf-8", "u*T@f08" and "Utf 8" are all equivalent. michael@0: * (See also ucnv_compareNames().) michael@0: * If NULL is passed for the converter name, it will create michael@0: * one with the ucnv_getDefaultName() return value. michael@0: * If the alias is ambiguous, then the preferred converter is used michael@0: * and the status is set to U_AMBIGUOUS_ALIAS_WARNING. michael@0: * michael@0: *See ucnv_open for the complete details
michael@0: * @param name Name of the UConverter table in a zero terminated michael@0: * Unicode string michael@0: * @param err outgoing error status U_MEMORY_ALLOCATION_ERROR, michael@0: * U_FILE_ACCESS_ERROR michael@0: * @return the created Unicode converter object, or NULL if an michael@0: * error occured michael@0: * @see ucnv_open michael@0: * @see ucnv_openCCSID michael@0: * @see ucnv_close michael@0: * @see ucnv_compareNames michael@0: * @stable ICU 2.0 michael@0: */ michael@0: U_STABLE UConverter* U_EXPORT2 michael@0: ucnv_openU(const UChar *name, michael@0: UErrorCode *err); michael@0: michael@0: /** michael@0: * Creates a UConverter object from a CCSID number and platform pair. michael@0: * Note that the usefulness of this function is limited to platforms with numeric michael@0: * encoding IDs. Only IBM and Microsoft platforms use numeric (16-bit) identifiers for michael@0: * encodings. michael@0: * michael@0: * In addition, IBM CCSIDs and Unicode conversion tables are not 1:1 related. michael@0: * For many IBM CCSIDs there are multiple (up to six) Unicode conversion tables, and michael@0: * for some Unicode conversion tables there are multiple CCSIDs. michael@0: * Some "alternate" Unicode conversion tables are provided by the michael@0: * IBM CDRA conversion table registry. michael@0: * The most prominent example of a systematic modification of conversion tables that is michael@0: * not provided in the form of conversion table files in the repository is michael@0: * that S/390 Unix System Services swaps the codes for Line Feed and New Line in all michael@0: * EBCDIC codepages, which requires such a swap in the Unicode conversion tables as well. michael@0: * michael@0: * Only IBM default conversion tables are accessible with ucnv_openCCSID(). michael@0: * ucnv_getCCSID() will return the same CCSID for all conversion tables that are associated michael@0: * with that CCSID. michael@0: * michael@0: * Currently, the only "platform" supported in the ICU converter API is UCNV_IBM. michael@0: * michael@0: * In summary, the use of CCSIDs and the associated API functions is not recommended. michael@0: * michael@0: * In order to open a converter with the default IBM CDRA Unicode conversion table, michael@0: * you can use this function or use the prefix "ibm-": michael@0: * \code michael@0: * char name[20]; michael@0: * sprintf(name, "ibm-%hu", ccsid); michael@0: * cnv=ucnv_open(name, &errorCode); michael@0: * \endcode michael@0: * michael@0: * In order to open a converter with the IBM S/390 Unix System Services variant michael@0: * of a Unicode/EBCDIC conversion table, michael@0: * you can use the prefix "ibm-" together with the option string UCNV_SWAP_LFNL_OPTION_STRING: michael@0: * \code michael@0: * char name[20]; michael@0: * sprintf(name, "ibm-%hu" UCNV_SWAP_LFNL_OPTION_STRING, ccsid); michael@0: * cnv=ucnv_open(name, &errorCode); michael@0: * \endcode michael@0: * michael@0: * In order to open a converter from a Microsoft codepage number, use the prefix "cp": michael@0: * \code michael@0: * char name[20]; michael@0: * sprintf(name, "cp%hu", codepageID); michael@0: * cnv=ucnv_open(name, &errorCode); michael@0: * \endcode michael@0: * michael@0: * If the alias is ambiguous, then the preferred converter is used michael@0: * and the status is set to U_AMBIGUOUS_ALIAS_WARNING. michael@0: * michael@0: * @param codepage codepage number to create michael@0: * @param platform the platform in which the codepage number exists michael@0: * @param err error status U_MEMORY_ALLOCATION_ERROR, U_FILE_ACCESS_ERROR michael@0: * @return the created Unicode converter object, or NULL if an error michael@0: * occured. michael@0: * @see ucnv_open michael@0: * @see ucnv_openU michael@0: * @see ucnv_close michael@0: * @see ucnv_getCCSID michael@0: * @see ucnv_getPlatform michael@0: * @see UConverterPlatform michael@0: * @stable ICU 2.0 michael@0: */ michael@0: U_STABLE UConverter* U_EXPORT2 michael@0: ucnv_openCCSID(int32_t codepage, michael@0: UConverterPlatform platform, michael@0: UErrorCode * err); michael@0: michael@0: /** michael@0: *Creates a UConverter object specified from a packageName and a converterName.
michael@0: * michael@0: *The packageName and converterName must point to an ICU udata object, as defined by
michael@0: * udata_open( packageName, "cnv", converterName, err)
or equivalent.
michael@0: * Typically, packageName will refer to a (.dat) file, or to a package registered with
michael@0: * udata_setAppData(). Using a full file or directory pathname for packageName is deprecated.
The name will NOT be looked up in the alias mechanism, nor will the converter be michael@0: * stored in the converter cache or the alias table. The only way to open further converters michael@0: * is call this function multiple times, or use the ucnv_safeClone() function to clone a michael@0: * 'master' converter.
michael@0: * michael@0: *A future version of ICU may add alias table lookups and/or caching michael@0: * to this function.
michael@0: * michael@0: *Example Use:
michael@0: * cnv = ucnv_openPackage("myapp", "myconverter", &err);
michael@0: *
U_BUFFER_OVERFLOW_ERROR
will be set if the target is full and there is
michael@0: * still data to be written to the target.
michael@0: * @see ucnv_fromUChars
michael@0: * @see ucnv_convert
michael@0: * @see ucnv_getMinCharSize
michael@0: * @see ucnv_setToUCallBack
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE void U_EXPORT2
michael@0: ucnv_fromUnicode (UConverter * converter,
michael@0: char **target,
michael@0: const char *targetLimit,
michael@0: const UChar ** source,
michael@0: const UChar * sourceLimit,
michael@0: int32_t* offsets,
michael@0: UBool flush,
michael@0: UErrorCode * err);
michael@0:
michael@0: /**
michael@0: * Converts a buffer of codepage bytes into an array of unicode UChars
michael@0: * characters. This function is optimized for converting a continuous
michael@0: * stream of data in buffer-sized chunks, where the entire source and
michael@0: * target does not fit in available buffers.
michael@0: *
michael@0: * The source pointer is an in/out parameter. It starts out pointing where the
michael@0: * conversion is to begin, and ends up pointing after the last byte of source consumed.
michael@0: *
michael@0: * Target similarly starts out pointer at the first available UChar in the output
michael@0: * buffer, and ends up pointing after the last UChar written to the output.
michael@0: * It does NOT necessarily keep UChar sequences together.
michael@0: *
michael@0: * The converter always attempts to consume the entire source buffer, unless
michael@0: * (1.) the target buffer is full, or (2.) a failing error is returned from the
michael@0: * current callback function. When a successful error status has been
michael@0: * returned, it means that all of the source buffer has been
michael@0: * consumed. At that point, the caller should reset the source and
michael@0: * sourceLimit pointers to point to the next chunk.
michael@0: *
michael@0: * At the end of the stream (flush==TRUE), the input is completely consumed
michael@0: * when *source==sourceLimit and no error code is set
michael@0: * The converter object is then automatically reset by this function.
michael@0: * (This means that a converter need not be reset explicitly between data
michael@0: * streams if it finishes the previous stream without errors.)
michael@0: *
michael@0: * This is a stateful conversion. Additionally, even when all source data has
michael@0: * been consumed, some data may be in the converters' internal state.
michael@0: * Call this function repeatedly, updating the target pointers with
michael@0: * the next empty chunk of target in case of a
michael@0: * U_BUFFER_OVERFLOW_ERROR, and updating the source pointers
michael@0: * with the next chunk of source when a successful error status is
michael@0: * returned, until there are no more chunks of source data.
michael@0: * @param converter the Unicode converter
michael@0: * @param target I/O parameter. Input : Points to the beginning of the buffer to copy
michael@0: * UChars into. Output : points to after the last UChar copied.
michael@0: * @param targetLimit the pointer just after the end of the target buffer
michael@0: * @param source I/O parameter, pointer to pointer to the source codepage buffer.
michael@0: * @param sourceLimit the pointer to the byte after the end of the source buffer
michael@0: * @param offsets if NULL is passed, nothing will happen to it, otherwise it needs to have the same number
michael@0: * of allocated cells as target. Will fill in offsets from target to source pointer
michael@0: * e.g: offsets[3] is equal to 6, it means that the target[3] was a result of transcoding source[6]
michael@0: * For output data carried across calls, and other data without a specific source character
michael@0: * (such as from escape sequences or callbacks) -1 will be placed for offsets.
michael@0: * @param flush set to TRUE if the current source buffer is the last available
michael@0: * chunk of the source, FALSE otherwise. Note that if a failing status is returned,
michael@0: * this function may have to be called multiple times with flush set to TRUE until
michael@0: * the source buffer is consumed.
michael@0: * @param err the error status. U_ILLEGAL_ARGUMENT_ERROR will be set if the
michael@0: * converter is NULL.
michael@0: * U_BUFFER_OVERFLOW_ERROR
will be set if the target is full and there is
michael@0: * still data to be written to the target.
michael@0: * @see ucnv_fromUChars
michael@0: * @see ucnv_convert
michael@0: * @see ucnv_getMinCharSize
michael@0: * @see ucnv_setFromUCallBack
michael@0: * @see ucnv_getNextUChar
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE void U_EXPORT2
michael@0: ucnv_toUnicode(UConverter *converter,
michael@0: UChar **target,
michael@0: const UChar *targetLimit,
michael@0: const char **source,
michael@0: const char *sourceLimit,
michael@0: int32_t *offsets,
michael@0: UBool flush,
michael@0: UErrorCode *err);
michael@0:
michael@0: /**
michael@0: * Convert the Unicode string into a codepage string using an existing UConverter.
michael@0: * The output string is NUL-terminated if possible.
michael@0: *
michael@0: * This function is a more convenient but less powerful version of ucnv_fromUnicode().
michael@0: * It is only useful for whole strings, not for streaming conversion.
michael@0: *
michael@0: * The maximum output buffer capacity required (barring output from callbacks) will be
michael@0: * UCNV_GET_MAX_BYTES_FOR_STRING(srcLength, ucnv_getMaxCharSize(cnv)).
michael@0: *
michael@0: * @param cnv the converter object to be used (ucnv_resetFromUnicode() will be called)
michael@0: * @param src the input Unicode string
michael@0: * @param srcLength the input string length, or -1 if NUL-terminated
michael@0: * @param dest destination string buffer, can be NULL if destCapacity==0
michael@0: * @param destCapacity the number of chars available at dest
michael@0: * @param pErrorCode normal ICU error code;
michael@0: * common error codes that may be set by this function include
michael@0: * U_BUFFER_OVERFLOW_ERROR, U_STRING_NOT_TERMINATED_WARNING,
michael@0: * U_ILLEGAL_ARGUMENT_ERROR, and conversion errors
michael@0: * @return the length of the output string, not counting the terminating NUL;
michael@0: * if the length is greater than destCapacity, then the string will not fit
michael@0: * and a buffer of the indicated length would need to be passed in
michael@0: * @see ucnv_fromUnicode
michael@0: * @see ucnv_convert
michael@0: * @see UCNV_GET_MAX_BYTES_FOR_STRING
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE int32_t U_EXPORT2
michael@0: ucnv_fromUChars(UConverter *cnv,
michael@0: char *dest, int32_t destCapacity,
michael@0: const UChar *src, int32_t srcLength,
michael@0: UErrorCode *pErrorCode);
michael@0:
michael@0: /**
michael@0: * Convert the codepage string into a Unicode string using an existing UConverter.
michael@0: * The output string is NUL-terminated if possible.
michael@0: *
michael@0: * This function is a more convenient but less powerful version of ucnv_toUnicode().
michael@0: * It is only useful for whole strings, not for streaming conversion.
michael@0: *
michael@0: * The maximum output buffer capacity required (barring output from callbacks) will be
michael@0: * 2*srcLength (each char may be converted into a surrogate pair).
michael@0: *
michael@0: * @param cnv the converter object to be used (ucnv_resetToUnicode() will be called)
michael@0: * @param src the input codepage string
michael@0: * @param srcLength the input string length, or -1 if NUL-terminated
michael@0: * @param dest destination string buffer, can be NULL if destCapacity==0
michael@0: * @param destCapacity the number of UChars available at dest
michael@0: * @param pErrorCode normal ICU error code;
michael@0: * common error codes that may be set by this function include
michael@0: * U_BUFFER_OVERFLOW_ERROR, U_STRING_NOT_TERMINATED_WARNING,
michael@0: * U_ILLEGAL_ARGUMENT_ERROR, and conversion errors
michael@0: * @return the length of the output string, not counting the terminating NUL;
michael@0: * if the length is greater than destCapacity, then the string will not fit
michael@0: * and a buffer of the indicated length would need to be passed in
michael@0: * @see ucnv_toUnicode
michael@0: * @see ucnv_convert
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE int32_t U_EXPORT2
michael@0: ucnv_toUChars(UConverter *cnv,
michael@0: UChar *dest, int32_t destCapacity,
michael@0: const char *src, int32_t srcLength,
michael@0: UErrorCode *pErrorCode);
michael@0:
michael@0: /**
michael@0: * Convert a codepage buffer into Unicode one character at a time.
michael@0: * The input is completely consumed when the U_INDEX_OUTOFBOUNDS_ERROR is set.
michael@0: *
michael@0: * Advantage compared to ucnv_toUnicode() or ucnv_toUChars():
michael@0: * - Faster for small amounts of data, for most converters, e.g.,
michael@0: * US-ASCII, ISO-8859-1, UTF-8/16/32, and most "normal" charsets.
michael@0: * (For complex converters, e.g., SCSU, UTF-7 and ISO 2022 variants,
michael@0: * it uses ucnv_toUnicode() internally.)
michael@0: * - Convenient.
michael@0: *
michael@0: * Limitations compared to ucnv_toUnicode():
michael@0: * - Always assumes flush=TRUE.
michael@0: * This makes ucnv_getNextUChar() unsuitable for "streaming" conversion,
michael@0: * that is, for where the input is supplied in multiple buffers,
michael@0: * because ucnv_getNextUChar() will assume the end of the input at the end
michael@0: * of the first buffer.
michael@0: * - Does not provide offset output.
michael@0: *
michael@0: * It is possible to "mix" ucnv_getNextUChar() and ucnv_toUnicode() because
michael@0: * ucnv_getNextUChar() uses the current state of the converter
michael@0: * (unlike ucnv_toUChars() which always resets first).
michael@0: * However, if ucnv_getNextUChar() is called after ucnv_toUnicode()
michael@0: * stopped in the middle of a character sequence (with flush=FALSE),
michael@0: * then ucnv_getNextUChar() will always use the slower ucnv_toUnicode()
michael@0: * internally until the next character boundary.
michael@0: * (This is new in ICU 2.6. In earlier releases, ucnv_getNextUChar() had to
michael@0: * start at a character boundary.)
michael@0: *
michael@0: * Instead of using ucnv_getNextUChar(), it is recommended
michael@0: * to convert using ucnv_toUnicode() or ucnv_toUChars()
michael@0: * and then iterate over the text using U16_NEXT() or a UCharIterator (uiter.h)
michael@0: * or a C++ CharacterIterator or similar.
michael@0: * This allows streaming conversion and offset output, for example.
michael@0: *
michael@0: * Handling of surrogate pairs and supplementary-plane code points:
michael@0: * There are two different kinds of codepages that provide mappings for surrogate characters:
michael@0: *
U_INDEX_OUTOFBOUNDS_ERROR
will be set if the input
michael@0: * is empty or does not convert to any output (e.g.: pure state-change
michael@0: * codes SI/SO, escape sequences for ISO 2022,
michael@0: * or if the callback did not output anything, ...).
michael@0: * This function will not set a U_BUFFER_OVERFLOW_ERROR
because
michael@0: * the "buffer" is the return code. However, there might be subsequent output
michael@0: * stored in the converter object
michael@0: * that will be returned in following calls to this function.
michael@0: * @return a UChar32 resulting from the partial conversion of source
michael@0: * @see ucnv_toUnicode
michael@0: * @see ucnv_toUChars
michael@0: * @see ucnv_convert
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE UChar32 U_EXPORT2
michael@0: ucnv_getNextUChar(UConverter * converter,
michael@0: const char **source,
michael@0: const char * sourceLimit,
michael@0: UErrorCode * err);
michael@0:
michael@0: /**
michael@0: * Convert from one external charset to another using two existing UConverters.
michael@0: * Internally, two conversions - ucnv_toUnicode() and ucnv_fromUnicode() -
michael@0: * are used, "pivoting" through 16-bit Unicode.
michael@0: *
michael@0: * Important: For streaming conversion (multiple function calls for successive
michael@0: * parts of a text stream), the caller must provide a pivot buffer explicitly,
michael@0: * and must preserve the pivot buffer and associated pointers from one
michael@0: * call to another. (The buffer may be moved if its contents and the relative
michael@0: * pointer positions are preserved.)
michael@0: *
michael@0: * There is a similar function, ucnv_convert(),
michael@0: * which has the following limitations:
michael@0: * - it takes charset names, not converter objects, so that
michael@0: * - two converters are opened for each call
michael@0: * - only single-string conversion is possible, not streaming operation
michael@0: * - it does not provide enough information to find out,
michael@0: * in case of failure, whether the toUnicode or
michael@0: * the fromUnicode conversion failed
michael@0: *
michael@0: * By contrast, ucnv_convertEx()
michael@0: * - takes UConverter parameters instead of charset names
michael@0: * - fully exposes the pivot buffer for streaming conversion and complete error handling
michael@0: *
michael@0: * ucnv_convertEx() also provides further convenience:
michael@0: * - an option to reset the converters at the beginning
michael@0: * (if reset==TRUE, see parameters;
michael@0: * also sets *pivotTarget=*pivotSource=pivotStart)
michael@0: * - allow NUL-terminated input
michael@0: * (only a single NUL byte, will not work for charsets with multi-byte NULs)
michael@0: * (if sourceLimit==NULL, see parameters)
michael@0: * - terminate with a NUL on output
michael@0: * (only a single NUL byte, not useful for charsets with multi-byte NULs),
michael@0: * or set U_STRING_NOT_TERMINATED_WARNING if the output exactly fills
michael@0: * the target buffer
michael@0: * - the pivot buffer can be provided internally;
michael@0: * possible only for whole-string conversion, not streaming conversion;
michael@0: * in this case, the caller will not be able to get details about where an
michael@0: * error occurred
michael@0: * (if pivotStart==NULL, see below)
michael@0: *
michael@0: * The function returns when one of the following is true:
michael@0: * - the entire source text has been converted successfully to the target buffer
michael@0: * - a target buffer overflow occurred (U_BUFFER_OVERFLOW_ERROR)
michael@0: * - a conversion error occurred
michael@0: * (other U_FAILURE(), see description of pErrorCode)
michael@0: *
michael@0: * Limitation compared to the direct use of
michael@0: * ucnv_fromUnicode() and ucnv_toUnicode():
michael@0: * ucnv_convertEx() does not provide offset information.
michael@0: *
michael@0: * Limitation compared to ucnv_fromUChars() and ucnv_toUChars():
michael@0: * ucnv_convertEx() does not support preflighting directly.
michael@0: *
michael@0: * Sample code for converting a single string from
michael@0: * one external charset to UTF-8, ignoring the location of errors:
michael@0: *
michael@0: * \code
michael@0: * int32_t
michael@0: * myToUTF8(UConverter *cnv,
michael@0: * const char *s, int32_t length,
michael@0: * char *u8, int32_t capacity,
michael@0: * UErrorCode *pErrorCode) {
michael@0: * UConverter *utf8Cnv;
michael@0: * char *target;
michael@0: *
michael@0: * if(U_FAILURE(*pErrorCode)) {
michael@0: * return 0;
michael@0: * }
michael@0: *
michael@0: * utf8Cnv=myGetCachedUTF8Converter(pErrorCode);
michael@0: * if(U_FAILURE(*pErrorCode)) {
michael@0: * return 0;
michael@0: * }
michael@0: *
michael@0: * if(length<0) {
michael@0: * length=strlen(s);
michael@0: * }
michael@0: * target=u8;
michael@0: * ucnv_convertEx(utf8Cnv, cnv,
michael@0: * &target, u8+capacity,
michael@0: * &s, s+length,
michael@0: * NULL, NULL, NULL, NULL,
michael@0: * TRUE, TRUE,
michael@0: * pErrorCode);
michael@0: *
michael@0: * myReleaseCachedUTF8Converter(utf8Cnv);
michael@0: *
michael@0: * // return the output string length, but without preflighting
michael@0: * return (int32_t)(target-u8);
michael@0: * }
michael@0: * \endcode
michael@0: *
michael@0: * @param targetCnv Output converter, used to convert from the UTF-16 pivot
michael@0: * to the target using ucnv_fromUnicode().
michael@0: * @param sourceCnv Input converter, used to convert from the source to
michael@0: * the UTF-16 pivot using ucnv_toUnicode().
michael@0: * @param target I/O parameter, same as for ucnv_fromUChars().
michael@0: * Input: *target points to the beginning of the target buffer.
michael@0: * Output: *target points to the first unit after the last char written.
michael@0: * @param targetLimit Pointer to the first unit after the target buffer.
michael@0: * @param source I/O parameter, same as for ucnv_toUChars().
michael@0: * Input: *source points to the beginning of the source buffer.
michael@0: * Output: *source points to the first unit after the last char read.
michael@0: * @param sourceLimit Pointer to the first unit after the source buffer.
michael@0: * @param pivotStart Pointer to the UTF-16 pivot buffer. If pivotStart==NULL,
michael@0: * then an internal buffer is used and the other pivot
michael@0: * arguments are ignored and can be NULL as well.
michael@0: * @param pivotSource I/O parameter, same as source in ucnv_fromUChars() for
michael@0: * conversion from the pivot buffer to the target buffer.
michael@0: * @param pivotTarget I/O parameter, same as target in ucnv_toUChars() for
michael@0: * conversion from the source buffer to the pivot buffer.
michael@0: * It must be pivotStart<=*pivotSource<=*pivotTarget<=pivotLimit
michael@0: * and pivotStartucnv_countAliases()
string-pointers
michael@0: * (const char *
) that will be filled in.
michael@0: * The strings themselves are owned by the library.
michael@0: * @param pErrorCode result of operation
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE void U_EXPORT2
michael@0: ucnv_getAliases(const char *alias, const char **aliases, UErrorCode *pErrorCode);
michael@0:
michael@0: /**
michael@0: * Return a new UEnumeration object for enumerating all the
michael@0: * alias names for a given converter that are recognized by a standard.
michael@0: * This method only enumerates the listed entries in the alias file.
michael@0: * The convrtrs.txt file can be modified to change the results of
michael@0: * this function.
michael@0: * The first result in this list is the same result given by
michael@0: * ucnv_getStandardName
, which is the default alias for
michael@0: * the specified standard name. The returned object must be closed with
michael@0: * uenum_close
when you are done with the object.
michael@0: *
michael@0: * @param convName original converter name
michael@0: * @param standard name of the standard governing the names; MIME and IANA
michael@0: * are such standards
michael@0: * @param pErrorCode The error code
michael@0: * @return A UEnumeration object for getting all aliases that are recognized
michael@0: * by a standard. If any of the parameters are invalid, NULL
michael@0: * is returned.
michael@0: * @see ucnv_getStandardName
michael@0: * @see uenum_close
michael@0: * @see uenum_next
michael@0: * @stable ICU 2.2
michael@0: */
michael@0: U_STABLE UEnumeration * U_EXPORT2
michael@0: ucnv_openStandardNames(const char *convName,
michael@0: const char *standard,
michael@0: UErrorCode *pErrorCode);
michael@0:
michael@0: /**
michael@0: * Gives the number of standards associated to converter names.
michael@0: * @return number of standards
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE uint16_t U_EXPORT2
michael@0: ucnv_countStandards(void);
michael@0:
michael@0: /**
michael@0: * Gives the name of the standard at given index of standard list.
michael@0: * @param n index in standard list
michael@0: * @param pErrorCode result of operation
michael@0: * @return returns the name of the standard at given index. Owned by the library.
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE const char * U_EXPORT2
michael@0: ucnv_getStandard(uint16_t n, UErrorCode *pErrorCode);
michael@0:
michael@0: /**
michael@0: * Returns a standard name for a given converter name.
michael@0: *
michael@0: * Example alias table:
michael@0: * conv alias1 { STANDARD1 } alias2 { STANDARD1* }
michael@0: *
michael@0: * Result of ucnv_getStandardName("conv", "STANDARD1") from example
michael@0: * alias table:
michael@0: * "alias2"
michael@0: *
michael@0: * @param name original converter name
michael@0: * @param standard name of the standard governing the names; MIME and IANA
michael@0: * are such standards
michael@0: * @param pErrorCode result of operation
michael@0: * @return returns the standard converter name;
michael@0: * if a standard converter name cannot be determined,
michael@0: * then NULL
is returned. Owned by the library.
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE const char * U_EXPORT2
michael@0: ucnv_getStandardName(const char *name, const char *standard, UErrorCode *pErrorCode);
michael@0:
michael@0: /**
michael@0: * This function will return the internal canonical converter name of the
michael@0: * tagged alias. This is the opposite of ucnv_openStandardNames, which
michael@0: * returns the tagged alias given the canonical name.
michael@0: *
michael@0: * Example alias table:
michael@0: * conv alias1 { STANDARD1 } alias2 { STANDARD1* }
michael@0: *
michael@0: * Result of ucnv_getStandardName("alias1", "STANDARD1") from example
michael@0: * alias table:
michael@0: * "conv"
michael@0: *
michael@0: * @return returns the canonical converter name;
michael@0: * if a standard or alias name cannot be determined,
michael@0: * then NULL
is returned. The returned string is
michael@0: * owned by the library.
michael@0: * @see ucnv_getStandardName
michael@0: * @stable ICU 2.4
michael@0: */
michael@0: U_STABLE const char * U_EXPORT2
michael@0: ucnv_getCanonicalName(const char *alias, const char *standard, UErrorCode *pErrorCode);
michael@0:
michael@0: /**
michael@0: * Returns the current default converter name. If you want to open
michael@0: * a default converter, you do not need to use this function.
michael@0: * It is faster if you pass a NULL argument to ucnv_open the
michael@0: * default converter.
michael@0: *
michael@0: * If U_CHARSET_IS_UTF8 is defined to 1 in utypes.h then this function
michael@0: * always returns "UTF-8".
michael@0: *
michael@0: * @return returns the current default converter name.
michael@0: * Storage owned by the library
michael@0: * @see ucnv_setDefaultName
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE const char * U_EXPORT2
michael@0: ucnv_getDefaultName(void);
michael@0:
michael@0: #ifndef U_HIDE_SYSTEM_API
michael@0: /**
michael@0: * This function is not thread safe. DO NOT call this function when ANY ICU
michael@0: * function is being used from more than one thread! This function sets the
michael@0: * current default converter name. If this function needs to be called, it
michael@0: * should be called during application initialization. Most of the time, the
michael@0: * results from ucnv_getDefaultName() or ucnv_open with a NULL string argument
michael@0: * is sufficient for your application.
michael@0: *
michael@0: * If U_CHARSET_IS_UTF8 is defined to 1 in utypes.h then this function
michael@0: * does nothing.
michael@0: *
michael@0: * @param name the converter name to be the default (must be known by ICU).
michael@0: * @see ucnv_getDefaultName
michael@0: * @system
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE void U_EXPORT2
michael@0: ucnv_setDefaultName(const char *name);
michael@0: #endif /* U_HIDE_SYSTEM_API */
michael@0:
michael@0: /**
michael@0: * Fixes the backslash character mismapping. For example, in SJIS, the backslash
michael@0: * character in the ASCII portion is also used to represent the yen currency sign.
michael@0: * When mapping from Unicode character 0x005C, it's unclear whether to map the
michael@0: * character back to yen or backslash in SJIS. This function will take the input
michael@0: * buffer and replace all the yen sign characters with backslash. This is necessary
michael@0: * when the user tries to open a file with the input buffer on Windows.
michael@0: * This function will test the converter to see whether such mapping is
michael@0: * required. You can sometimes avoid using this function by using the correct version
michael@0: * of Shift-JIS.
michael@0: *
michael@0: * @param cnv The converter representing the target codepage.
michael@0: * @param source the input buffer to be fixed
michael@0: * @param sourceLen the length of the input buffer
michael@0: * @see ucnv_isAmbiguous
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE void U_EXPORT2
michael@0: ucnv_fixFileSeparator(const UConverter *cnv, UChar *source, int32_t sourceLen);
michael@0:
michael@0: /**
michael@0: * Determines if the converter contains ambiguous mappings of the same
michael@0: * character or not.
michael@0: * @param cnv the converter to be tested
michael@0: * @return TRUE if the converter contains ambiguous mapping of the same
michael@0: * character, FALSE otherwise.
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE UBool U_EXPORT2
michael@0: ucnv_isAmbiguous(const UConverter *cnv);
michael@0:
michael@0: /**
michael@0: * Sets the converter to use fallback mappings or not.
michael@0: * Regardless of this flag, the converter will always use
michael@0: * fallbacks from Unicode Private Use code points, as well as
michael@0: * reverse fallbacks (to Unicode).
michael@0: * For details see ".ucm File Format"
michael@0: * in the Conversion Data chapter of the ICU User Guide:
michael@0: * http://www.icu-project.org/userguide/conversion-data.html#ucmformat
michael@0: *
michael@0: * @param cnv The converter to set the fallback mapping usage on.
michael@0: * @param usesFallback TRUE if the user wants the converter to take advantage of the fallback
michael@0: * mapping, FALSE otherwise.
michael@0: * @stable ICU 2.0
michael@0: * @see ucnv_usesFallback
michael@0: */
michael@0: U_STABLE void U_EXPORT2
michael@0: ucnv_setFallback(UConverter *cnv, UBool usesFallback);
michael@0:
michael@0: /**
michael@0: * Determines if the converter uses fallback mappings or not.
michael@0: * This flag has restrictions, see ucnv_setFallback().
michael@0: *
michael@0: * @param cnv The converter to be tested
michael@0: * @return TRUE if the converter uses fallback, FALSE otherwise.
michael@0: * @stable ICU 2.0
michael@0: * @see ucnv_setFallback
michael@0: */
michael@0: U_STABLE UBool U_EXPORT2
michael@0: ucnv_usesFallback(const UConverter *cnv);
michael@0:
michael@0: /**
michael@0: * Detects Unicode signature byte sequences at the start of the byte stream
michael@0: * and returns the charset name of the indicated Unicode charset.
michael@0: * NULL is returned when no Unicode signature is recognized.
michael@0: * The number of bytes in the signature is output as well.
michael@0: *
michael@0: * The caller can ucnv_open() a converter using the charset name.
michael@0: * The first code unit (UChar) from the start of the stream will be U+FEFF
michael@0: * (the Unicode BOM/signature character) and can usually be ignored.
michael@0: *
michael@0: * For most Unicode charsets it is also possible to ignore the indicated
michael@0: * number of initial stream bytes and start converting after them.
michael@0: * However, there are stateful Unicode charsets (UTF-7 and BOCU-1) for which
michael@0: * this will not work. Therefore, it is best to ignore the first output UChar
michael@0: * instead of the input signature bytes.
michael@0: *
michael@0: * Usage: michael@0: * \snippet samples/ucnv/convsamp.cpp ucnv_detectUnicodeSignature michael@0: * michael@0: * @param source The source string in which the signature should be detected. michael@0: * @param sourceLength Length of the input string, or -1 if terminated with a NUL byte. michael@0: * @param signatureLength A pointer to int32_t to receive the number of bytes that make up the signature michael@0: * of the detected UTF. 0 if not detected. michael@0: * Can be a NULL pointer. michael@0: * @param pErrorCode ICU error code in/out parameter. michael@0: * Must fulfill U_SUCCESS before the function call. michael@0: * @return The name of the encoding detected. NULL if encoding is not detected. michael@0: * @stable ICU 2.4 michael@0: */ michael@0: U_STABLE const char* U_EXPORT2 michael@0: ucnv_detectUnicodeSignature(const char* source, michael@0: int32_t sourceLength, michael@0: int32_t *signatureLength, michael@0: UErrorCode *pErrorCode); michael@0: michael@0: /** michael@0: * Returns the number of UChars held in the converter's internal state michael@0: * because more input is needed for completing the conversion. This function is michael@0: * useful for mapping semantics of ICU's converter interface to those of iconv, michael@0: * and this information is not needed for normal conversion. michael@0: * @param cnv The converter in which the input is held michael@0: * @param status ICU error code in/out parameter. michael@0: * Must fulfill U_SUCCESS before the function call. michael@0: * @return The number of UChars in the state. -1 if an error is encountered. michael@0: * @stable ICU 3.4 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: ucnv_fromUCountPending(const UConverter* cnv, UErrorCode* status); michael@0: michael@0: /** michael@0: * Returns the number of chars held in the converter's internal state michael@0: * because more input is needed for completing the conversion. This function is michael@0: * useful for mapping semantics of ICU's converter interface to those of iconv, michael@0: * and this information is not needed for normal conversion. michael@0: * @param cnv The converter in which the input is held as internal state michael@0: * @param status ICU error code in/out parameter. michael@0: * Must fulfill U_SUCCESS before the function call. michael@0: * @return The number of chars in the state. -1 if an error is encountered. michael@0: * @stable ICU 3.4 michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: ucnv_toUCountPending(const UConverter* cnv, UErrorCode* status); michael@0: michael@0: /** michael@0: * Returns whether or not the charset of the converter has a fixed number of bytes michael@0: * per charset character. michael@0: * An example of this are converters that are of the type UCNV_SBCS or UCNV_DBCS. michael@0: * Another example is UTF-32 which is always 4 bytes per character. michael@0: * A Unicode code point may be represented by more than one UTF-8 or UTF-16 code unit michael@0: * but a UTF-32 converter encodes each code point with 4 bytes. michael@0: * Note: This method is not intended to be used to determine whether the charset has a michael@0: * fixed ratio of bytes to Unicode codes units for any particular Unicode encoding form. michael@0: * FALSE is returned with the UErrorCode if error occurs or cnv is NULL. michael@0: * @param cnv The converter to be tested michael@0: * @param status ICU error code in/out paramter michael@0: * @return TRUE if the converter is fixed-width michael@0: * @stable ICU 4.8 michael@0: */ michael@0: U_STABLE UBool U_EXPORT2 michael@0: ucnv_isFixedWidth(UConverter *cnv, UErrorCode *status); michael@0: michael@0: #endif michael@0: michael@0: #endif michael@0: /*_UCNV*/