17777dab0Sopenharmony_ci// © 2016 and later: Unicode, Inc. and others. 27777dab0Sopenharmony_ci// License & terms of use: http://www.unicode.org/copyright.html 37777dab0Sopenharmony_ci/* 47777dab0Sopenharmony_ci********************************************************************** 57777dab0Sopenharmony_ci* Copyright (C) 1999-2014, International Business Machines 67777dab0Sopenharmony_ci* Corporation and others. All Rights Reserved. 77777dab0Sopenharmony_ci********************************************************************** 87777dab0Sopenharmony_ci * ucnv.h: 97777dab0Sopenharmony_ci * External APIs for the ICU's codeset conversion library 107777dab0Sopenharmony_ci * Bertrand A. Damiba 117777dab0Sopenharmony_ci * 127777dab0Sopenharmony_ci * Modification History: 137777dab0Sopenharmony_ci * 147777dab0Sopenharmony_ci * Date Name Description 157777dab0Sopenharmony_ci * 04/04/99 helena Fixed internal header inclusion. 167777dab0Sopenharmony_ci * 05/11/00 helena Added setFallback and usesFallback APIs. 177777dab0Sopenharmony_ci * 06/29/2000 helena Major rewrite of the callback APIs. 187777dab0Sopenharmony_ci * 12/07/2000 srl Update of documentation 197777dab0Sopenharmony_ci */ 207777dab0Sopenharmony_ci 217777dab0Sopenharmony_ci/** 227777dab0Sopenharmony_ci * \file 237777dab0Sopenharmony_ci * \brief C API: Character conversion 247777dab0Sopenharmony_ci * 257777dab0Sopenharmony_ci * <h2>Character Conversion C API</h2> 267777dab0Sopenharmony_ci * 277777dab0Sopenharmony_ci * <p>This API is used to convert codepage or character encoded data to and 287777dab0Sopenharmony_ci * from UTF-16. You can open a converter with {@link ucnv_open() }. With that 297777dab0Sopenharmony_ci * converter, you can get its properties, set options, convert your data and 307777dab0Sopenharmony_ci * close the converter.</p> 317777dab0Sopenharmony_ci * 327777dab0Sopenharmony_ci * <p>Since many software programs recognize different converter names for 337777dab0Sopenharmony_ci * different types of converters, there are other functions in this API to 347777dab0Sopenharmony_ci * iterate over the converter aliases. The functions {@link ucnv_getAvailableName() }, 357777dab0Sopenharmony_ci * {@link ucnv_getAlias() } and {@link ucnv_getStandardName() } are some of the 367777dab0Sopenharmony_ci * more frequently used alias functions to get this information.</p> 377777dab0Sopenharmony_ci * 387777dab0Sopenharmony_ci * <p>When a converter encounters an illegal, irregular, invalid or unmappable character 397777dab0Sopenharmony_ci * its default behavior is to use a substitution character to replace the 407777dab0Sopenharmony_ci * bad byte sequence. This behavior can be changed by using {@link ucnv_setFromUCallBack() } 417777dab0Sopenharmony_ci * or {@link ucnv_setToUCallBack() } on the converter. The header ucnv_err.h defines 427777dab0Sopenharmony_ci * many other callback actions that can be used instead of a character substitution.</p> 437777dab0Sopenharmony_ci * 447777dab0Sopenharmony_ci * <p>More information about this API can be found in our 457777dab0Sopenharmony_ci * <a href="https://unicode-org.github.io/icu/userguide/conversion/">User Guide</a>.</p> 467777dab0Sopenharmony_ci */ 477777dab0Sopenharmony_ci 487777dab0Sopenharmony_ci#ifndef UCNV_H 497777dab0Sopenharmony_ci#define UCNV_H 507777dab0Sopenharmony_ci 517777dab0Sopenharmony_ci#include "unicode/ucnv_err.h" 527777dab0Sopenharmony_ci#include "unicode/uenum.h" 537777dab0Sopenharmony_ci 547777dab0Sopenharmony_ci#if U_SHOW_CPLUSPLUS_API 557777dab0Sopenharmony_ci#include "unicode/localpointer.h" 567777dab0Sopenharmony_ci#endif // U_SHOW_CPLUSPLUS_API 577777dab0Sopenharmony_ci 587777dab0Sopenharmony_ci#if !defined(USET_DEFINED) && !defined(U_IN_DOXYGEN) 597777dab0Sopenharmony_ci 607777dab0Sopenharmony_ci#define USET_DEFINED 617777dab0Sopenharmony_ci 627777dab0Sopenharmony_ci/** 637777dab0Sopenharmony_ci * USet is the C API type corresponding to C++ class UnicodeSet. 647777dab0Sopenharmony_ci * It is forward-declared here to avoid including unicode/uset.h file if related 657777dab0Sopenharmony_ci * conversion APIs are not used. 667777dab0Sopenharmony_ci * 677777dab0Sopenharmony_ci * @see ucnv_getUnicodeSet 687777dab0Sopenharmony_ci * @stable ICU 2.4 697777dab0Sopenharmony_ci */ 707777dab0Sopenharmony_citypedef struct USet USet; 717777dab0Sopenharmony_ci 727777dab0Sopenharmony_ci#endif 737777dab0Sopenharmony_ci 747777dab0Sopenharmony_ci#if !UCONFIG_NO_CONVERSION 757777dab0Sopenharmony_ci 767777dab0Sopenharmony_ciU_CDECL_BEGIN 777777dab0Sopenharmony_ci 787777dab0Sopenharmony_ci/** Maximum length of a converter name including the terminating NULL @stable ICU 2.0 */ 797777dab0Sopenharmony_ci#define UCNV_MAX_CONVERTER_NAME_LENGTH 60 807777dab0Sopenharmony_ci/** Maximum length of a converter name including path and terminating NULL @stable ICU 2.0 */ 817777dab0Sopenharmony_ci#define UCNV_MAX_FULL_FILE_NAME_LENGTH (600+UCNV_MAX_CONVERTER_NAME_LENGTH) 827777dab0Sopenharmony_ci 837777dab0Sopenharmony_ci/** Shift in for EBDCDIC_STATEFUL and iso2022 states @stable ICU 2.0 */ 847777dab0Sopenharmony_ci#define UCNV_SI 0x0F 857777dab0Sopenharmony_ci/** Shift out for EBDCDIC_STATEFUL and iso2022 states @stable ICU 2.0 */ 867777dab0Sopenharmony_ci#define UCNV_SO 0x0E 877777dab0Sopenharmony_ci 887777dab0Sopenharmony_ci/** 897777dab0Sopenharmony_ci * Enum for specifying basic types of converters 907777dab0Sopenharmony_ci * @see ucnv_getType 917777dab0Sopenharmony_ci * @stable ICU 2.0 927777dab0Sopenharmony_ci */ 937777dab0Sopenharmony_citypedef enum { 947777dab0Sopenharmony_ci /** @stable ICU 2.0 */ 957777dab0Sopenharmony_ci UCNV_UNSUPPORTED_CONVERTER = -1, 967777dab0Sopenharmony_ci /** @stable ICU 2.0 */ 977777dab0Sopenharmony_ci UCNV_SBCS = 0, 987777dab0Sopenharmony_ci /** @stable ICU 2.0 */ 997777dab0Sopenharmony_ci UCNV_DBCS = 1, 1007777dab0Sopenharmony_ci /** @stable ICU 2.0 */ 1017777dab0Sopenharmony_ci UCNV_MBCS = 2, 1027777dab0Sopenharmony_ci /** @stable ICU 2.0 */ 1037777dab0Sopenharmony_ci UCNV_LATIN_1 = 3, 1047777dab0Sopenharmony_ci /** @stable ICU 2.0 */ 1057777dab0Sopenharmony_ci UCNV_UTF8 = 4, 1067777dab0Sopenharmony_ci /** @stable ICU 2.0 */ 1077777dab0Sopenharmony_ci UCNV_UTF16_BigEndian = 5, 1087777dab0Sopenharmony_ci /** @stable ICU 2.0 */ 1097777dab0Sopenharmony_ci UCNV_UTF16_LittleEndian = 6, 1107777dab0Sopenharmony_ci /** @stable ICU 2.0 */ 1117777dab0Sopenharmony_ci UCNV_UTF32_BigEndian = 7, 1127777dab0Sopenharmony_ci /** @stable ICU 2.0 */ 1137777dab0Sopenharmony_ci UCNV_UTF32_LittleEndian = 8, 1147777dab0Sopenharmony_ci /** @stable ICU 2.0 */ 1157777dab0Sopenharmony_ci UCNV_EBCDIC_STATEFUL = 9, 1167777dab0Sopenharmony_ci /** @stable ICU 2.0 */ 1177777dab0Sopenharmony_ci UCNV_ISO_2022 = 10, 1187777dab0Sopenharmony_ci 1197777dab0Sopenharmony_ci /** @stable ICU 2.0 */ 1207777dab0Sopenharmony_ci UCNV_LMBCS_1 = 11, 1217777dab0Sopenharmony_ci /** @stable ICU 2.0 */ 1227777dab0Sopenharmony_ci UCNV_LMBCS_2, 1237777dab0Sopenharmony_ci /** @stable ICU 2.0 */ 1247777dab0Sopenharmony_ci UCNV_LMBCS_3, 1257777dab0Sopenharmony_ci /** @stable ICU 2.0 */ 1267777dab0Sopenharmony_ci UCNV_LMBCS_4, 1277777dab0Sopenharmony_ci /** @stable ICU 2.0 */ 1287777dab0Sopenharmony_ci UCNV_LMBCS_5, 1297777dab0Sopenharmony_ci /** @stable ICU 2.0 */ 1307777dab0Sopenharmony_ci UCNV_LMBCS_6, 1317777dab0Sopenharmony_ci /** @stable ICU 2.0 */ 1327777dab0Sopenharmony_ci UCNV_LMBCS_8, 1337777dab0Sopenharmony_ci /** @stable ICU 2.0 */ 1347777dab0Sopenharmony_ci UCNV_LMBCS_11, 1357777dab0Sopenharmony_ci /** @stable ICU 2.0 */ 1367777dab0Sopenharmony_ci UCNV_LMBCS_16, 1377777dab0Sopenharmony_ci /** @stable ICU 2.0 */ 1387777dab0Sopenharmony_ci UCNV_LMBCS_17, 1397777dab0Sopenharmony_ci /** @stable ICU 2.0 */ 1407777dab0Sopenharmony_ci UCNV_LMBCS_18, 1417777dab0Sopenharmony_ci /** @stable ICU 2.0 */ 1427777dab0Sopenharmony_ci UCNV_LMBCS_19, 1437777dab0Sopenharmony_ci /** @stable ICU 2.0 */ 1447777dab0Sopenharmony_ci UCNV_LMBCS_LAST = UCNV_LMBCS_19, 1457777dab0Sopenharmony_ci /** @stable ICU 2.0 */ 1467777dab0Sopenharmony_ci UCNV_HZ, 1477777dab0Sopenharmony_ci /** @stable ICU 2.0 */ 1487777dab0Sopenharmony_ci UCNV_SCSU, 1497777dab0Sopenharmony_ci /** @stable ICU 2.0 */ 1507777dab0Sopenharmony_ci UCNV_ISCII, 1517777dab0Sopenharmony_ci /** @stable ICU 2.0 */ 1527777dab0Sopenharmony_ci UCNV_US_ASCII, 1537777dab0Sopenharmony_ci /** @stable ICU 2.0 */ 1547777dab0Sopenharmony_ci UCNV_UTF7, 1557777dab0Sopenharmony_ci /** @stable ICU 2.2 */ 1567777dab0Sopenharmony_ci UCNV_BOCU1, 1577777dab0Sopenharmony_ci /** @stable ICU 2.2 */ 1587777dab0Sopenharmony_ci UCNV_UTF16, 1597777dab0Sopenharmony_ci /** @stable ICU 2.2 */ 1607777dab0Sopenharmony_ci UCNV_UTF32, 1617777dab0Sopenharmony_ci /** @stable ICU 2.2 */ 1627777dab0Sopenharmony_ci UCNV_CESU8, 1637777dab0Sopenharmony_ci /** @stable ICU 2.4 */ 1647777dab0Sopenharmony_ci UCNV_IMAP_MAILBOX, 1657777dab0Sopenharmony_ci /** @stable ICU 4.8 */ 1667777dab0Sopenharmony_ci UCNV_COMPOUND_TEXT, 1677777dab0Sopenharmony_ci 1687777dab0Sopenharmony_ci /* Number of converter types for which we have conversion routines. */ 1697777dab0Sopenharmony_ci UCNV_NUMBER_OF_SUPPORTED_CONVERTER_TYPES 1707777dab0Sopenharmony_ci} UConverterType; 1717777dab0Sopenharmony_ci 1727777dab0Sopenharmony_ci/** 1737777dab0Sopenharmony_ci * Enum for specifying which platform a converter ID refers to. 1747777dab0Sopenharmony_ci * The use of platform/CCSID is not recommended. See ucnv_openCCSID(). 1757777dab0Sopenharmony_ci * 1767777dab0Sopenharmony_ci * @see ucnv_getPlatform 1777777dab0Sopenharmony_ci * @see ucnv_openCCSID 1787777dab0Sopenharmony_ci * @see ucnv_getCCSID 1797777dab0Sopenharmony_ci * @stable ICU 2.0 1807777dab0Sopenharmony_ci */ 1817777dab0Sopenharmony_citypedef enum { 1827777dab0Sopenharmony_ci UCNV_UNKNOWN = -1, 1837777dab0Sopenharmony_ci UCNV_IBM = 0 1847777dab0Sopenharmony_ci} UConverterPlatform; 1857777dab0Sopenharmony_ci 1867777dab0Sopenharmony_ci/** 1877777dab0Sopenharmony_ci * Function pointer for error callback in the codepage to unicode direction. 1887777dab0Sopenharmony_ci * Called when an error has occurred in conversion to unicode, or on open/close of the callback (see reason). 1897777dab0Sopenharmony_ci * @param context Pointer to the callback's private data 1907777dab0Sopenharmony_ci * @param args Information about the conversion in progress 1917777dab0Sopenharmony_ci * @param codeUnits Points to 'length' bytes of the concerned codepage sequence 1927777dab0Sopenharmony_ci * @param length Size (in bytes) of the concerned codepage sequence 1937777dab0Sopenharmony_ci * @param reason Defines the reason the callback was invoked 1947777dab0Sopenharmony_ci * @param pErrorCode ICU error code in/out parameter. 1957777dab0Sopenharmony_ci * For converter callback functions, set to a conversion error 1967777dab0Sopenharmony_ci * before the call, and the callback may reset it to U_ZERO_ERROR. 1977777dab0Sopenharmony_ci * @see ucnv_setToUCallBack 1987777dab0Sopenharmony_ci * @see UConverterToUnicodeArgs 1997777dab0Sopenharmony_ci * @stable ICU 2.0 2007777dab0Sopenharmony_ci */ 2017777dab0Sopenharmony_citypedef void (U_EXPORT2 *UConverterToUCallback) ( 2027777dab0Sopenharmony_ci const void* context, 2037777dab0Sopenharmony_ci UConverterToUnicodeArgs *args, 2047777dab0Sopenharmony_ci const char *codeUnits, 2057777dab0Sopenharmony_ci int32_t length, 2067777dab0Sopenharmony_ci UConverterCallbackReason reason, 2077777dab0Sopenharmony_ci UErrorCode *pErrorCode); 2087777dab0Sopenharmony_ci 2097777dab0Sopenharmony_ci/** 2107777dab0Sopenharmony_ci * Function pointer for error callback in the unicode to codepage direction. 2117777dab0Sopenharmony_ci * Called when an error has occurred in conversion from unicode, or on open/close of the callback (see reason). 2127777dab0Sopenharmony_ci * @param context Pointer to the callback's private data 2137777dab0Sopenharmony_ci * @param args Information about the conversion in progress 2147777dab0Sopenharmony_ci * @param codeUnits Points to 'length' UChars of the concerned Unicode sequence 2157777dab0Sopenharmony_ci * @param length Size (in bytes) of the concerned codepage sequence 2167777dab0Sopenharmony_ci * @param codePoint Single UChar32 (UTF-32) containing the concerend Unicode codepoint. 2177777dab0Sopenharmony_ci * @param reason Defines the reason the callback was invoked 2187777dab0Sopenharmony_ci * @param pErrorCode ICU error code in/out parameter. 2197777dab0Sopenharmony_ci * For converter callback functions, set to a conversion error 2207777dab0Sopenharmony_ci * before the call, and the callback may reset it to U_ZERO_ERROR. 2217777dab0Sopenharmony_ci * @see ucnv_setFromUCallBack 2227777dab0Sopenharmony_ci * @stable ICU 2.0 2237777dab0Sopenharmony_ci */ 2247777dab0Sopenharmony_citypedef void (U_EXPORT2 *UConverterFromUCallback) ( 2257777dab0Sopenharmony_ci const void* context, 2267777dab0Sopenharmony_ci UConverterFromUnicodeArgs *args, 2277777dab0Sopenharmony_ci const UChar* codeUnits, 2287777dab0Sopenharmony_ci int32_t length, 2297777dab0Sopenharmony_ci UChar32 codePoint, 2307777dab0Sopenharmony_ci UConverterCallbackReason reason, 2317777dab0Sopenharmony_ci UErrorCode *pErrorCode); 2327777dab0Sopenharmony_ci 2337777dab0Sopenharmony_ciU_CDECL_END 2347777dab0Sopenharmony_ci 2357777dab0Sopenharmony_ci/** 2367777dab0Sopenharmony_ci * Character that separates converter names from options and options from each other. 2377777dab0Sopenharmony_ci * @see ucnv_open 2387777dab0Sopenharmony_ci * @stable ICU 2.0 2397777dab0Sopenharmony_ci */ 2407777dab0Sopenharmony_ci#define UCNV_OPTION_SEP_CHAR ',' 2417777dab0Sopenharmony_ci 2427777dab0Sopenharmony_ci/** 2437777dab0Sopenharmony_ci * String version of UCNV_OPTION_SEP_CHAR. 2447777dab0Sopenharmony_ci * @see ucnv_open 2457777dab0Sopenharmony_ci * @stable ICU 2.0 2467777dab0Sopenharmony_ci */ 2477777dab0Sopenharmony_ci#define UCNV_OPTION_SEP_STRING "," 2487777dab0Sopenharmony_ci 2497777dab0Sopenharmony_ci/** 2507777dab0Sopenharmony_ci * Character that separates a converter option from its value. 2517777dab0Sopenharmony_ci * @see ucnv_open 2527777dab0Sopenharmony_ci * @stable ICU 2.0 2537777dab0Sopenharmony_ci */ 2547777dab0Sopenharmony_ci#define UCNV_VALUE_SEP_CHAR '=' 2557777dab0Sopenharmony_ci 2567777dab0Sopenharmony_ci/** 2577777dab0Sopenharmony_ci * String version of UCNV_VALUE_SEP_CHAR. 2587777dab0Sopenharmony_ci * @see ucnv_open 2597777dab0Sopenharmony_ci * @stable ICU 2.0 2607777dab0Sopenharmony_ci */ 2617777dab0Sopenharmony_ci#define UCNV_VALUE_SEP_STRING "=" 2627777dab0Sopenharmony_ci 2637777dab0Sopenharmony_ci/** 2647777dab0Sopenharmony_ci * Converter option for specifying a locale. 2657777dab0Sopenharmony_ci * For example, ucnv_open("SCSU,locale=ja", &errorCode); 2667777dab0Sopenharmony_ci * See convrtrs.txt. 2677777dab0Sopenharmony_ci * 2687777dab0Sopenharmony_ci * @see ucnv_open 2697777dab0Sopenharmony_ci * @stable ICU 2.0 2707777dab0Sopenharmony_ci */ 2717777dab0Sopenharmony_ci#define UCNV_LOCALE_OPTION_STRING ",locale=" 2727777dab0Sopenharmony_ci 2737777dab0Sopenharmony_ci/** 2747777dab0Sopenharmony_ci * Converter option for specifying a version selector (0..9) for some converters. 2757777dab0Sopenharmony_ci * For example, 2767777dab0Sopenharmony_ci * \code 2777777dab0Sopenharmony_ci * ucnv_open("UTF-7,version=1", &errorCode); 2787777dab0Sopenharmony_ci * \endcode 2797777dab0Sopenharmony_ci * See convrtrs.txt. 2807777dab0Sopenharmony_ci * 2817777dab0Sopenharmony_ci * @see ucnv_open 2827777dab0Sopenharmony_ci * @stable ICU 2.4 2837777dab0Sopenharmony_ci */ 2847777dab0Sopenharmony_ci#define UCNV_VERSION_OPTION_STRING ",version=" 2857777dab0Sopenharmony_ci 2867777dab0Sopenharmony_ci/** 2877777dab0Sopenharmony_ci * Converter option for EBCDIC SBCS or mixed-SBCS/DBCS (stateful) codepages. 2887777dab0Sopenharmony_ci * Swaps Unicode mappings for EBCDIC LF and NL codes, as used on 2897777dab0Sopenharmony_ci * S/390 (z/OS) Unix System Services (Open Edition). 2907777dab0Sopenharmony_ci * For example, ucnv_open("ibm-1047,swaplfnl", &errorCode); 2917777dab0Sopenharmony_ci * See convrtrs.txt. 2927777dab0Sopenharmony_ci * 2937777dab0Sopenharmony_ci * @see ucnv_open 2947777dab0Sopenharmony_ci * @stable ICU 2.4 2957777dab0Sopenharmony_ci */ 2967777dab0Sopenharmony_ci#define UCNV_SWAP_LFNL_OPTION_STRING ",swaplfnl" 2977777dab0Sopenharmony_ci 2987777dab0Sopenharmony_ci/** 2997777dab0Sopenharmony_ci * Do a fuzzy compare of two converter/alias names. 3007777dab0Sopenharmony_ci * The comparison is case-insensitive, ignores leading zeroes if they are not 3017777dab0Sopenharmony_ci * followed by further digits, and ignores all but letters and digits. 3027777dab0Sopenharmony_ci * Thus the strings "UTF-8", "utf_8", "u*T@f08" and "Utf 8" are exactly equivalent. 3037777dab0Sopenharmony_ci * See section 1.4, Charset Alias Matching in Unicode Technical Standard #22 3047777dab0Sopenharmony_ci * at http://www.unicode.org/reports/tr22/ 3057777dab0Sopenharmony_ci * 3067777dab0Sopenharmony_ci * @param name1 a converter name or alias, zero-terminated 3077777dab0Sopenharmony_ci * @param name2 a converter name or alias, zero-terminated 3087777dab0Sopenharmony_ci * @return 0 if the names match, or a negative value if the name1 3097777dab0Sopenharmony_ci * lexically precedes name2, or a positive value if the name1 3107777dab0Sopenharmony_ci * lexically follows name2. 3117777dab0Sopenharmony_ci * @stable ICU 2.0 3127777dab0Sopenharmony_ci */ 3137777dab0Sopenharmony_ciU_CAPI int U_EXPORT2 3147777dab0Sopenharmony_ciucnv_compareNames(const char *name1, const char *name2); 3157777dab0Sopenharmony_ci 3167777dab0Sopenharmony_ci 3177777dab0Sopenharmony_ci/** 3187777dab0Sopenharmony_ci * Creates a UConverter object with the name of a coded character set specified as a C string. 3197777dab0Sopenharmony_ci * The actual name will be resolved with the alias file 3207777dab0Sopenharmony_ci * using a case-insensitive string comparison that ignores 3217777dab0Sopenharmony_ci * leading zeroes and all non-alphanumeric characters. 3227777dab0Sopenharmony_ci * E.g., the names "UTF8", "utf-8", "u*T@f08" and "Utf 8" are all equivalent. 3237777dab0Sopenharmony_ci * (See also ucnv_compareNames().) 3247777dab0Sopenharmony_ci * If <code>NULL</code> is passed for the converter name, it will create one with the 3257777dab0Sopenharmony_ci * getDefaultName return value. 3267777dab0Sopenharmony_ci * 3277777dab0Sopenharmony_ci * <p>A converter name for ICU 1.5 and above may contain options 3287777dab0Sopenharmony_ci * like a locale specification to control the specific behavior of 3297777dab0Sopenharmony_ci * the newly instantiated converter. 3307777dab0Sopenharmony_ci * The meaning of the options depends on the particular converter. 3317777dab0Sopenharmony_ci * If an option is not defined for or recognized by a given converter, then it is ignored.</p> 3327777dab0Sopenharmony_ci * 3337777dab0Sopenharmony_ci * <p>Options are appended to the converter name string, with a 3347777dab0Sopenharmony_ci * <code>UCNV_OPTION_SEP_CHAR</code> between the name and the first option and 3357777dab0Sopenharmony_ci * also between adjacent options.</p> 3367777dab0Sopenharmony_ci * 3377777dab0Sopenharmony_ci * <p>If the alias is ambiguous, then the preferred converter is used 3387777dab0Sopenharmony_ci * and the status is set to U_AMBIGUOUS_ALIAS_WARNING.</p> 3397777dab0Sopenharmony_ci * 3407777dab0Sopenharmony_ci * <p>The conversion behavior and names can vary between platforms. ICU may 3417777dab0Sopenharmony_ci * convert some characters differently from other platforms. Details on this topic 3427777dab0Sopenharmony_ci * are in the <a href="https://unicode-org.github.io/icu/userguide/conversion/">User 3437777dab0Sopenharmony_ci * Guide</a>. Aliases starting with a "cp" prefix have no specific meaning 3447777dab0Sopenharmony_ci * other than its an alias starting with the letters "cp". Please do not 3457777dab0Sopenharmony_ci * associate any meaning to these aliases.</p> 3467777dab0Sopenharmony_ci * 3477777dab0Sopenharmony_ci * \snippet samples/ucnv/convsamp.cpp ucnv_open 3487777dab0Sopenharmony_ci * 3497777dab0Sopenharmony_ci * @param converterName Name of the coded character set table. 3507777dab0Sopenharmony_ci * This may have options appended to the string. 3517777dab0Sopenharmony_ci * IANA alias character set names, IBM CCSIDs starting with "ibm-", 3527777dab0Sopenharmony_ci * Windows codepage numbers starting with "windows-" are frequently 3537777dab0Sopenharmony_ci * used for this parameter. See ucnv_getAvailableName and 3547777dab0Sopenharmony_ci * ucnv_getAlias for a complete list that is available. 3557777dab0Sopenharmony_ci * If this parameter is NULL, the default converter will be used. 3567777dab0Sopenharmony_ci * @param err outgoing error status <TT>U_MEMORY_ALLOCATION_ERROR, U_FILE_ACCESS_ERROR</TT> 3577777dab0Sopenharmony_ci * @return the created Unicode converter object, or <TT>NULL</TT> if an error occurred 3587777dab0Sopenharmony_ci * @see ucnv_openU 3597777dab0Sopenharmony_ci * @see ucnv_openCCSID 3607777dab0Sopenharmony_ci * @see ucnv_getAvailableName 3617777dab0Sopenharmony_ci * @see ucnv_getAlias 3627777dab0Sopenharmony_ci * @see ucnv_getDefaultName 3637777dab0Sopenharmony_ci * @see ucnv_close 3647777dab0Sopenharmony_ci * @see ucnv_compareNames 3657777dab0Sopenharmony_ci * @stable ICU 2.0 3667777dab0Sopenharmony_ci */ 3677777dab0Sopenharmony_ciU_CAPI UConverter* U_EXPORT2 3687777dab0Sopenharmony_ciucnv_open(const char *converterName, UErrorCode *err); 3697777dab0Sopenharmony_ci 3707777dab0Sopenharmony_ci 3717777dab0Sopenharmony_ci/** 3727777dab0Sopenharmony_ci * Creates a Unicode converter with the names specified as unicode string. 3737777dab0Sopenharmony_ci * The name should be limited to the ASCII-7 alphanumerics range. 3747777dab0Sopenharmony_ci * The actual name will be resolved with the alias file 3757777dab0Sopenharmony_ci * using a case-insensitive string comparison that ignores 3767777dab0Sopenharmony_ci * leading zeroes and all non-alphanumeric characters. 3777777dab0Sopenharmony_ci * E.g., the names "UTF8", "utf-8", "u*T@f08" and "Utf 8" are all equivalent. 3787777dab0Sopenharmony_ci * (See also ucnv_compareNames().) 3797777dab0Sopenharmony_ci * If <TT>NULL</TT> is passed for the converter name, it will create 3807777dab0Sopenharmony_ci * one with the ucnv_getDefaultName() return value. 3817777dab0Sopenharmony_ci * If the alias is ambiguous, then the preferred converter is used 3827777dab0Sopenharmony_ci * and the status is set to U_AMBIGUOUS_ALIAS_WARNING. 3837777dab0Sopenharmony_ci * 3847777dab0Sopenharmony_ci * <p>See ucnv_open for the complete details</p> 3857777dab0Sopenharmony_ci * @param name Name of the UConverter table in a zero terminated 3867777dab0Sopenharmony_ci * Unicode string 3877777dab0Sopenharmony_ci * @param err outgoing error status <TT>U_MEMORY_ALLOCATION_ERROR, 3887777dab0Sopenharmony_ci * U_FILE_ACCESS_ERROR</TT> 3897777dab0Sopenharmony_ci * @return the created Unicode converter object, or <TT>NULL</TT> if an 3907777dab0Sopenharmony_ci * error occurred 3917777dab0Sopenharmony_ci * @see ucnv_open 3927777dab0Sopenharmony_ci * @see ucnv_openCCSID 3937777dab0Sopenharmony_ci * @see ucnv_close 3947777dab0Sopenharmony_ci * @see ucnv_compareNames 3957777dab0Sopenharmony_ci * @stable ICU 2.0 3967777dab0Sopenharmony_ci */ 3977777dab0Sopenharmony_ciU_CAPI UConverter* U_EXPORT2 3987777dab0Sopenharmony_ciucnv_openU(const UChar *name, 3997777dab0Sopenharmony_ci UErrorCode *err); 4007777dab0Sopenharmony_ci 4017777dab0Sopenharmony_ci/** 4027777dab0Sopenharmony_ci * Creates a UConverter object from a CCSID number and platform pair. 4037777dab0Sopenharmony_ci * Note that the usefulness of this function is limited to platforms with numeric 4047777dab0Sopenharmony_ci * encoding IDs. Only IBM and Microsoft platforms use numeric (16-bit) identifiers for 4057777dab0Sopenharmony_ci * encodings. 4067777dab0Sopenharmony_ci * 4077777dab0Sopenharmony_ci * In addition, IBM CCSIDs and Unicode conversion tables are not 1:1 related. 4087777dab0Sopenharmony_ci * For many IBM CCSIDs there are multiple (up to six) Unicode conversion tables, and 4097777dab0Sopenharmony_ci * for some Unicode conversion tables there are multiple CCSIDs. 4107777dab0Sopenharmony_ci * Some "alternate" Unicode conversion tables are provided by the 4117777dab0Sopenharmony_ci * IBM CDRA conversion table registry. 4127777dab0Sopenharmony_ci * The most prominent example of a systematic modification of conversion tables that is 4137777dab0Sopenharmony_ci * not provided in the form of conversion table files in the repository is 4147777dab0Sopenharmony_ci * that S/390 Unix System Services swaps the codes for Line Feed and New Line in all 4157777dab0Sopenharmony_ci * EBCDIC codepages, which requires such a swap in the Unicode conversion tables as well. 4167777dab0Sopenharmony_ci * 4177777dab0Sopenharmony_ci * Only IBM default conversion tables are accessible with ucnv_openCCSID(). 4187777dab0Sopenharmony_ci * ucnv_getCCSID() will return the same CCSID for all conversion tables that are associated 4197777dab0Sopenharmony_ci * with that CCSID. 4207777dab0Sopenharmony_ci * 4217777dab0Sopenharmony_ci * Currently, the only "platform" supported in the ICU converter API is UCNV_IBM. 4227777dab0Sopenharmony_ci * 4237777dab0Sopenharmony_ci * In summary, the use of CCSIDs and the associated API functions is not recommended. 4247777dab0Sopenharmony_ci * 4257777dab0Sopenharmony_ci * In order to open a converter with the default IBM CDRA Unicode conversion table, 4267777dab0Sopenharmony_ci * you can use this function or use the prefix "ibm-": 4277777dab0Sopenharmony_ci * \code 4287777dab0Sopenharmony_ci * char name[20]; 4297777dab0Sopenharmony_ci * sprintf(name, "ibm-%hu", ccsid); 4307777dab0Sopenharmony_ci * cnv=ucnv_open(name, &errorCode); 4317777dab0Sopenharmony_ci * \endcode 4327777dab0Sopenharmony_ci * 4337777dab0Sopenharmony_ci * In order to open a converter with the IBM S/390 Unix System Services variant 4347777dab0Sopenharmony_ci * of a Unicode/EBCDIC conversion table, 4357777dab0Sopenharmony_ci * you can use the prefix "ibm-" together with the option string UCNV_SWAP_LFNL_OPTION_STRING: 4367777dab0Sopenharmony_ci * \code 4377777dab0Sopenharmony_ci * char name[20]; 4387777dab0Sopenharmony_ci * sprintf(name, "ibm-%hu" UCNV_SWAP_LFNL_OPTION_STRING, ccsid); 4397777dab0Sopenharmony_ci * cnv=ucnv_open(name, &errorCode); 4407777dab0Sopenharmony_ci * \endcode 4417777dab0Sopenharmony_ci * 4427777dab0Sopenharmony_ci * In order to open a converter from a Microsoft codepage number, use the prefix "cp": 4437777dab0Sopenharmony_ci * \code 4447777dab0Sopenharmony_ci * char name[20]; 4457777dab0Sopenharmony_ci * sprintf(name, "cp%hu", codepageID); 4467777dab0Sopenharmony_ci * cnv=ucnv_open(name, &errorCode); 4477777dab0Sopenharmony_ci * \endcode 4487777dab0Sopenharmony_ci * 4497777dab0Sopenharmony_ci * If the alias is ambiguous, then the preferred converter is used 4507777dab0Sopenharmony_ci * and the status is set to U_AMBIGUOUS_ALIAS_WARNING. 4517777dab0Sopenharmony_ci * 4527777dab0Sopenharmony_ci * @param codepage codepage number to create 4537777dab0Sopenharmony_ci * @param platform the platform in which the codepage number exists 4547777dab0Sopenharmony_ci * @param err error status <TT>U_MEMORY_ALLOCATION_ERROR, U_FILE_ACCESS_ERROR</TT> 4557777dab0Sopenharmony_ci * @return the created Unicode converter object, or <TT>NULL</TT> if an error 4567777dab0Sopenharmony_ci * occurred. 4577777dab0Sopenharmony_ci * @see ucnv_open 4587777dab0Sopenharmony_ci * @see ucnv_openU 4597777dab0Sopenharmony_ci * @see ucnv_close 4607777dab0Sopenharmony_ci * @see ucnv_getCCSID 4617777dab0Sopenharmony_ci * @see ucnv_getPlatform 4627777dab0Sopenharmony_ci * @see UConverterPlatform 4637777dab0Sopenharmony_ci * @stable ICU 2.0 4647777dab0Sopenharmony_ci */ 4657777dab0Sopenharmony_ciU_CAPI UConverter* U_EXPORT2 4667777dab0Sopenharmony_ciucnv_openCCSID(int32_t codepage, 4677777dab0Sopenharmony_ci UConverterPlatform platform, 4687777dab0Sopenharmony_ci UErrorCode * err); 4697777dab0Sopenharmony_ci 4707777dab0Sopenharmony_ci/** 4717777dab0Sopenharmony_ci * <p>Creates a UConverter object specified from a packageName and a converterName.</p> 4727777dab0Sopenharmony_ci * 4737777dab0Sopenharmony_ci * <p>The packageName and converterName must point to an ICU udata object, as defined by 4747777dab0Sopenharmony_ci * <code> udata_open( packageName, "cnv", converterName, err) </code> or equivalent. 4757777dab0Sopenharmony_ci * Typically, packageName will refer to a (.dat) file, or to a package registered with 4767777dab0Sopenharmony_ci * udata_setAppData(). Using a full file or directory pathname for packageName is deprecated.</p> 4777777dab0Sopenharmony_ci * 4787777dab0Sopenharmony_ci * <p>The name will NOT be looked up in the alias mechanism, nor will the converter be 4797777dab0Sopenharmony_ci * stored in the converter cache or the alias table. The only way to open further converters 4807777dab0Sopenharmony_ci * is call this function multiple times, or use the ucnv_clone() function to clone a 4817777dab0Sopenharmony_ci * 'primary' converter.</p> 4827777dab0Sopenharmony_ci * 4837777dab0Sopenharmony_ci * <p>A future version of ICU may add alias table lookups and/or caching 4847777dab0Sopenharmony_ci * to this function.</p> 4857777dab0Sopenharmony_ci * 4867777dab0Sopenharmony_ci * <p>Example Use: 4877777dab0Sopenharmony_ci * <code>cnv = ucnv_openPackage("myapp", "myconverter", &err);</code> 4887777dab0Sopenharmony_ci * </p> 4897777dab0Sopenharmony_ci * 4907777dab0Sopenharmony_ci * @param packageName name of the package (equivalent to 'path' in udata_open() call) 4917777dab0Sopenharmony_ci * @param converterName name of the data item to be used, without suffix. 4927777dab0Sopenharmony_ci * @param err outgoing error status <TT>U_MEMORY_ALLOCATION_ERROR, U_FILE_ACCESS_ERROR</TT> 4937777dab0Sopenharmony_ci * @return the created Unicode converter object, or <TT>NULL</TT> if an error occurred 4947777dab0Sopenharmony_ci * @see udata_open 4957777dab0Sopenharmony_ci * @see ucnv_open 4967777dab0Sopenharmony_ci * @see ucnv_clone 4977777dab0Sopenharmony_ci * @see ucnv_close 4987777dab0Sopenharmony_ci * @stable ICU 2.2 4997777dab0Sopenharmony_ci */ 5007777dab0Sopenharmony_ciU_CAPI UConverter* U_EXPORT2 5017777dab0Sopenharmony_ciucnv_openPackage(const char *packageName, const char *converterName, UErrorCode *err); 5027777dab0Sopenharmony_ci 5037777dab0Sopenharmony_ci/** 5047777dab0Sopenharmony_ci * Thread safe converter cloning operation. 5057777dab0Sopenharmony_ci * 5067777dab0Sopenharmony_ci * You must ucnv_close() the clone. 5077777dab0Sopenharmony_ci * 5087777dab0Sopenharmony_ci * @param cnv converter to be cloned 5097777dab0Sopenharmony_ci * @param status to indicate whether the operation went on smoothly or there were errors 5107777dab0Sopenharmony_ci * @return pointer to the new clone 5117777dab0Sopenharmony_ci * @stable ICU 71 5127777dab0Sopenharmony_ci */ 5137777dab0Sopenharmony_ciU_CAPI UConverter* U_EXPORT2 ucnv_clone(const UConverter *cnv, UErrorCode *status); 5147777dab0Sopenharmony_ci 5157777dab0Sopenharmony_ci/** 5167777dab0Sopenharmony_ci * Deletes the unicode converter and releases resources associated 5177777dab0Sopenharmony_ci * with just this instance. 5187777dab0Sopenharmony_ci * Does not free up shared converter tables. 5197777dab0Sopenharmony_ci * 5207777dab0Sopenharmony_ci * @param converter the converter object to be deleted 5217777dab0Sopenharmony_ci * @see ucnv_open 5227777dab0Sopenharmony_ci * @see ucnv_openU 5237777dab0Sopenharmony_ci * @see ucnv_openCCSID 5247777dab0Sopenharmony_ci * @stable ICU 2.0 5257777dab0Sopenharmony_ci */ 5267777dab0Sopenharmony_ciU_CAPI void U_EXPORT2 5277777dab0Sopenharmony_ciucnv_close(UConverter * converter); 5287777dab0Sopenharmony_ci 5297777dab0Sopenharmony_ci#if U_SHOW_CPLUSPLUS_API 5307777dab0Sopenharmony_ci 5317777dab0Sopenharmony_ciU_NAMESPACE_BEGIN 5327777dab0Sopenharmony_ci 5337777dab0Sopenharmony_ci/** 5347777dab0Sopenharmony_ci * \class LocalUConverterPointer 5357777dab0Sopenharmony_ci * "Smart pointer" class, closes a UConverter via ucnv_close(). 5367777dab0Sopenharmony_ci * For most methods see the LocalPointerBase base class. 5377777dab0Sopenharmony_ci * 5387777dab0Sopenharmony_ci * @see LocalPointerBase 5397777dab0Sopenharmony_ci * @see LocalPointer 5407777dab0Sopenharmony_ci * @stable ICU 4.4 5417777dab0Sopenharmony_ci */ 5427777dab0Sopenharmony_ciU_DEFINE_LOCAL_OPEN_POINTER(LocalUConverterPointer, UConverter, ucnv_close); 5437777dab0Sopenharmony_ci 5447777dab0Sopenharmony_ciU_NAMESPACE_END 5457777dab0Sopenharmony_ci 5467777dab0Sopenharmony_ci#endif 5477777dab0Sopenharmony_ci 5487777dab0Sopenharmony_ci/** 5497777dab0Sopenharmony_ci * Fills in the output parameter, subChars, with the substitution characters 5507777dab0Sopenharmony_ci * as multiple bytes. 5517777dab0Sopenharmony_ci * If ucnv_setSubstString() set a Unicode string because the converter is 5527777dab0Sopenharmony_ci * stateful, then subChars will be an empty string. 5537777dab0Sopenharmony_ci * 5547777dab0Sopenharmony_ci * @param converter the Unicode converter 5557777dab0Sopenharmony_ci * @param subChars the substitution characters 5567777dab0Sopenharmony_ci * @param len on input the capacity of subChars, on output the number 5577777dab0Sopenharmony_ci * of bytes copied to it 5587777dab0Sopenharmony_ci * @param err the outgoing error status code. 5597777dab0Sopenharmony_ci * If the substitution character array is too small, an 5607777dab0Sopenharmony_ci * <TT>U_INDEX_OUTOFBOUNDS_ERROR</TT> will be returned. 5617777dab0Sopenharmony_ci * @see ucnv_setSubstString 5627777dab0Sopenharmony_ci * @see ucnv_setSubstChars 5637777dab0Sopenharmony_ci * @stable ICU 2.0 5647777dab0Sopenharmony_ci */ 5657777dab0Sopenharmony_ciU_CAPI void U_EXPORT2 5667777dab0Sopenharmony_ciucnv_getSubstChars(const UConverter *converter, 5677777dab0Sopenharmony_ci char *subChars, 5687777dab0Sopenharmony_ci int8_t *len, 5697777dab0Sopenharmony_ci UErrorCode *err); 5707777dab0Sopenharmony_ci 5717777dab0Sopenharmony_ci/** 5727777dab0Sopenharmony_ci * Sets the substitution chars when converting from unicode to a codepage. The 5737777dab0Sopenharmony_ci * substitution is specified as a string of 1-4 bytes, and may contain 5747777dab0Sopenharmony_ci * <TT>NULL</TT> bytes. 5757777dab0Sopenharmony_ci * The subChars must represent a single character. The caller needs to know the 5767777dab0Sopenharmony_ci * byte sequence of a valid character in the converter's charset. 5777777dab0Sopenharmony_ci * For some converters, for example some ISO 2022 variants, only single-byte 5787777dab0Sopenharmony_ci * substitution characters may be supported. 5797777dab0Sopenharmony_ci * The newer ucnv_setSubstString() function relaxes these limitations. 5807777dab0Sopenharmony_ci * 5817777dab0Sopenharmony_ci * @param converter the Unicode converter 5827777dab0Sopenharmony_ci * @param subChars the substitution character byte sequence we want set 5837777dab0Sopenharmony_ci * @param len the number of bytes in subChars 5847777dab0Sopenharmony_ci * @param err the error status code. <TT>U_INDEX_OUTOFBOUNDS_ERROR </TT> if 5857777dab0Sopenharmony_ci * len is bigger than the maximum number of bytes allowed in subchars 5867777dab0Sopenharmony_ci * @see ucnv_setSubstString 5877777dab0Sopenharmony_ci * @see ucnv_getSubstChars 5887777dab0Sopenharmony_ci * @stable ICU 2.0 5897777dab0Sopenharmony_ci */ 5907777dab0Sopenharmony_ciU_CAPI void U_EXPORT2 5917777dab0Sopenharmony_ciucnv_setSubstChars(UConverter *converter, 5927777dab0Sopenharmony_ci const char *subChars, 5937777dab0Sopenharmony_ci int8_t len, 5947777dab0Sopenharmony_ci UErrorCode *err); 5957777dab0Sopenharmony_ci 5967777dab0Sopenharmony_ci/** 5977777dab0Sopenharmony_ci * Set a substitution string for converting from Unicode to a charset. 5987777dab0Sopenharmony_ci * The caller need not know the charset byte sequence for each charset. 5997777dab0Sopenharmony_ci * 6007777dab0Sopenharmony_ci * Unlike ucnv_setSubstChars() which is designed to set a charset byte sequence 6017777dab0Sopenharmony_ci * for a single character, this function takes a Unicode string with 6027777dab0Sopenharmony_ci * zero, one or more characters, and immediately verifies that the string can be 6037777dab0Sopenharmony_ci * converted to the charset. 6047777dab0Sopenharmony_ci * If not, or if the result is too long (more than 32 bytes as of ICU 3.6), 6057777dab0Sopenharmony_ci * then the function returns with an error accordingly. 6067777dab0Sopenharmony_ci * 6077777dab0Sopenharmony_ci * Also unlike ucnv_setSubstChars(), this function works for stateful charsets 6087777dab0Sopenharmony_ci * by converting on the fly at the point of substitution rather than setting 6097777dab0Sopenharmony_ci * a fixed byte sequence. 6107777dab0Sopenharmony_ci * 6117777dab0Sopenharmony_ci * @param cnv The UConverter object. 6127777dab0Sopenharmony_ci * @param s The Unicode string. 6137777dab0Sopenharmony_ci * @param length The number of UChars in s, or -1 for a NUL-terminated string. 6147777dab0Sopenharmony_ci * @param err Pointer to a standard ICU error code. Its input value must 6157777dab0Sopenharmony_ci * pass the U_SUCCESS() test, or else the function returns 6167777dab0Sopenharmony_ci * immediately. Check for U_FAILURE() on output or use with 6177777dab0Sopenharmony_ci * function chaining. (See User Guide for details.) 6187777dab0Sopenharmony_ci * 6197777dab0Sopenharmony_ci * @see ucnv_setSubstChars 6207777dab0Sopenharmony_ci * @see ucnv_getSubstChars 6217777dab0Sopenharmony_ci * @stable ICU 3.6 6227777dab0Sopenharmony_ci */ 6237777dab0Sopenharmony_ciU_CAPI void U_EXPORT2 6247777dab0Sopenharmony_ciucnv_setSubstString(UConverter *cnv, 6257777dab0Sopenharmony_ci const UChar *s, 6267777dab0Sopenharmony_ci int32_t length, 6277777dab0Sopenharmony_ci UErrorCode *err); 6287777dab0Sopenharmony_ci 6297777dab0Sopenharmony_ci/** 6307777dab0Sopenharmony_ci * Fills in the output parameter, errBytes, with the error characters from the 6317777dab0Sopenharmony_ci * last failing conversion. 6327777dab0Sopenharmony_ci * 6337777dab0Sopenharmony_ci * @param converter the Unicode converter 6347777dab0Sopenharmony_ci * @param errBytes the codepage bytes which were in error 6357777dab0Sopenharmony_ci * @param len on input the capacity of errBytes, on output the number of 6367777dab0Sopenharmony_ci * bytes which were copied to it 6377777dab0Sopenharmony_ci * @param err the error status code. 6387777dab0Sopenharmony_ci * If the substitution character array is too small, an 6397777dab0Sopenharmony_ci * <TT>U_INDEX_OUTOFBOUNDS_ERROR</TT> will be returned. 6407777dab0Sopenharmony_ci * @stable ICU 2.0 6417777dab0Sopenharmony_ci */ 6427777dab0Sopenharmony_ciU_CAPI void U_EXPORT2 6437777dab0Sopenharmony_ciucnv_getInvalidChars(const UConverter *converter, 6447777dab0Sopenharmony_ci char *errBytes, 6457777dab0Sopenharmony_ci int8_t *len, 6467777dab0Sopenharmony_ci UErrorCode *err); 6477777dab0Sopenharmony_ci 6487777dab0Sopenharmony_ci/** 6497777dab0Sopenharmony_ci * Fills in the output parameter, errChars, with the error characters from the 6507777dab0Sopenharmony_ci * last failing conversion. 6517777dab0Sopenharmony_ci * 6527777dab0Sopenharmony_ci * @param converter the Unicode converter 6537777dab0Sopenharmony_ci * @param errUChars the UChars which were in error 6547777dab0Sopenharmony_ci * @param len on input the capacity of errUChars, on output the number of 6557777dab0Sopenharmony_ci * UChars which were copied to it 6567777dab0Sopenharmony_ci * @param err the error status code. 6577777dab0Sopenharmony_ci * If the substitution character array is too small, an 6587777dab0Sopenharmony_ci * <TT>U_INDEX_OUTOFBOUNDS_ERROR</TT> will be returned. 6597777dab0Sopenharmony_ci * @stable ICU 2.0 6607777dab0Sopenharmony_ci */ 6617777dab0Sopenharmony_ciU_CAPI void U_EXPORT2 6627777dab0Sopenharmony_ciucnv_getInvalidUChars(const UConverter *converter, 6637777dab0Sopenharmony_ci UChar *errUChars, 6647777dab0Sopenharmony_ci int8_t *len, 6657777dab0Sopenharmony_ci UErrorCode *err); 6667777dab0Sopenharmony_ci 6677777dab0Sopenharmony_ci/** 6687777dab0Sopenharmony_ci * Resets the state of a converter to the default state. This is used 6697777dab0Sopenharmony_ci * in the case of an error, to restart a conversion from a known default state. 6707777dab0Sopenharmony_ci * It will also empty the internal output buffers. 6717777dab0Sopenharmony_ci * @param converter the Unicode converter 6727777dab0Sopenharmony_ci * @stable ICU 2.0 6737777dab0Sopenharmony_ci */ 6747777dab0Sopenharmony_ciU_CAPI void U_EXPORT2 6757777dab0Sopenharmony_ciucnv_reset(UConverter *converter); 6767777dab0Sopenharmony_ci 6777777dab0Sopenharmony_ci/** 6787777dab0Sopenharmony_ci * Resets the to-Unicode part of a converter state to the default state. 6797777dab0Sopenharmony_ci * This is used in the case of an error to restart a conversion to 6807777dab0Sopenharmony_ci * Unicode to a known default state. It will also empty the internal 6817777dab0Sopenharmony_ci * output buffers used for the conversion to Unicode codepoints. 6827777dab0Sopenharmony_ci * @param converter the Unicode converter 6837777dab0Sopenharmony_ci * @stable ICU 2.0 6847777dab0Sopenharmony_ci */ 6857777dab0Sopenharmony_ciU_CAPI void U_EXPORT2 6867777dab0Sopenharmony_ciucnv_resetToUnicode(UConverter *converter); 6877777dab0Sopenharmony_ci 6887777dab0Sopenharmony_ci/** 6897777dab0Sopenharmony_ci * Resets the from-Unicode part of a converter state to the default state. 6907777dab0Sopenharmony_ci * This is used in the case of an error to restart a conversion from 6917777dab0Sopenharmony_ci * Unicode to a known default state. It will also empty the internal output 6927777dab0Sopenharmony_ci * buffers used for the conversion from Unicode codepoints. 6937777dab0Sopenharmony_ci * @param converter the Unicode converter 6947777dab0Sopenharmony_ci * @stable ICU 2.0 6957777dab0Sopenharmony_ci */ 6967777dab0Sopenharmony_ciU_CAPI void U_EXPORT2 6977777dab0Sopenharmony_ciucnv_resetFromUnicode(UConverter *converter); 6987777dab0Sopenharmony_ci 6997777dab0Sopenharmony_ci/** 7007777dab0Sopenharmony_ci * Returns the maximum number of bytes that are output per UChar in conversion 7017777dab0Sopenharmony_ci * from Unicode using this converter. 7027777dab0Sopenharmony_ci * The returned number can be used with UCNV_GET_MAX_BYTES_FOR_STRING 7037777dab0Sopenharmony_ci * to calculate the size of a target buffer for conversion from Unicode. 7047777dab0Sopenharmony_ci * 7057777dab0Sopenharmony_ci * Note: Before ICU 2.8, this function did not return reliable numbers for 7067777dab0Sopenharmony_ci * some stateful converters (EBCDIC_STATEFUL, ISO-2022) and LMBCS. 7077777dab0Sopenharmony_ci * 7087777dab0Sopenharmony_ci * This number may not be the same as the maximum number of bytes per 7097777dab0Sopenharmony_ci * "conversion unit". In other words, it may not be the intuitively expected 7107777dab0Sopenharmony_ci * number of bytes per character that would be published for a charset, 7117777dab0Sopenharmony_ci * and may not fulfill any other purpose than the allocation of an output 7127777dab0Sopenharmony_ci * buffer of guaranteed sufficient size for a given input length and converter. 7137777dab0Sopenharmony_ci * 7147777dab0Sopenharmony_ci * Examples for special cases that are taken into account: 7157777dab0Sopenharmony_ci * - Supplementary code points may convert to more bytes than BMP code points. 7167777dab0Sopenharmony_ci * This function returns bytes per UChar (UTF-16 code unit), not per 7177777dab0Sopenharmony_ci * Unicode code point, for efficient buffer allocation. 7187777dab0Sopenharmony_ci * - State-shifting output (SI/SO, escapes, etc.) from stateful converters. 7197777dab0Sopenharmony_ci * - When m input UChars are converted to n output bytes, then the maximum m/n 7207777dab0Sopenharmony_ci * is taken into account. 7217777dab0Sopenharmony_ci * 7227777dab0Sopenharmony_ci * The number returned here does not take into account 7237777dab0Sopenharmony_ci * (see UCNV_GET_MAX_BYTES_FOR_STRING): 7247777dab0Sopenharmony_ci * - callbacks which output more than one charset character sequence per call, 7257777dab0Sopenharmony_ci * like escape callbacks 7267777dab0Sopenharmony_ci * - initial and final non-character bytes that are output by some converters 7277777dab0Sopenharmony_ci * (automatic BOMs, initial escape sequence, final SI, etc.) 7287777dab0Sopenharmony_ci * 7297777dab0Sopenharmony_ci * Examples for returned values: 7307777dab0Sopenharmony_ci * - SBCS charsets: 1 7317777dab0Sopenharmony_ci * - Shift-JIS: 2 7327777dab0Sopenharmony_ci * - UTF-16: 2 (2 per BMP, 4 per surrogate _pair_, BOM not counted) 7337777dab0Sopenharmony_ci * - UTF-8: 3 (3 per BMP, 4 per surrogate _pair_) 7347777dab0Sopenharmony_ci * - EBCDIC_STATEFUL (EBCDIC mixed SBCS/DBCS): 3 (SO + DBCS) 7357777dab0Sopenharmony_ci * - ISO-2022: 3 (always outputs UTF-8) 7367777dab0Sopenharmony_ci * - ISO-2022-JP: 6 (4-byte escape sequences + DBCS) 7377777dab0Sopenharmony_ci * - ISO-2022-CN: 8 (4-byte designator sequences + 2-byte SS2/SS3 + DBCS) 7387777dab0Sopenharmony_ci * 7397777dab0Sopenharmony_ci * @param converter The Unicode converter. 7407777dab0Sopenharmony_ci * @return The maximum number of bytes per UChar (16 bit code unit) 7417777dab0Sopenharmony_ci * that are output by ucnv_fromUnicode(), 7427777dab0Sopenharmony_ci * to be used together with UCNV_GET_MAX_BYTES_FOR_STRING 7437777dab0Sopenharmony_ci * for buffer allocation. 7447777dab0Sopenharmony_ci * 7457777dab0Sopenharmony_ci * @see UCNV_GET_MAX_BYTES_FOR_STRING 7467777dab0Sopenharmony_ci * @see ucnv_getMinCharSize 7477777dab0Sopenharmony_ci * @stable ICU 2.0 7487777dab0Sopenharmony_ci */ 7497777dab0Sopenharmony_ciU_CAPI int8_t U_EXPORT2 7507777dab0Sopenharmony_ciucnv_getMaxCharSize(const UConverter *converter); 7517777dab0Sopenharmony_ci 7527777dab0Sopenharmony_ci/** 7537777dab0Sopenharmony_ci * Calculates the size of a buffer for conversion from Unicode to a charset. 7547777dab0Sopenharmony_ci * The calculated size is guaranteed to be sufficient for this conversion. 7557777dab0Sopenharmony_ci * 7567777dab0Sopenharmony_ci * It takes into account initial and final non-character bytes that are output 7577777dab0Sopenharmony_ci * by some converters. 7587777dab0Sopenharmony_ci * It does not take into account callbacks which output more than one charset 7597777dab0Sopenharmony_ci * character sequence per call, like escape callbacks. 7607777dab0Sopenharmony_ci * The default (substitution) callback only outputs one charset character sequence. 7617777dab0Sopenharmony_ci * 7627777dab0Sopenharmony_ci * @param length Number of UChars to be converted. 7637777dab0Sopenharmony_ci * @param maxCharSize Return value from ucnv_getMaxCharSize() for the converter 7647777dab0Sopenharmony_ci * that will be used. 7657777dab0Sopenharmony_ci * @return Size of a buffer that will be large enough to hold the output bytes of 7667777dab0Sopenharmony_ci * converting length UChars with the converter that returned the maxCharSize. 7677777dab0Sopenharmony_ci * 7687777dab0Sopenharmony_ci * @see ucnv_getMaxCharSize 7697777dab0Sopenharmony_ci * @stable ICU 2.8 7707777dab0Sopenharmony_ci */ 7717777dab0Sopenharmony_ci#define UCNV_GET_MAX_BYTES_FOR_STRING(length, maxCharSize) \ 7727777dab0Sopenharmony_ci (((int32_t)(length)+10)*(int32_t)(maxCharSize)) 7737777dab0Sopenharmony_ci 7747777dab0Sopenharmony_ci/** 7757777dab0Sopenharmony_ci * Returns the minimum byte length (per codepoint) for characters in this codepage. 7767777dab0Sopenharmony_ci * This is usually either 1 or 2. 7777777dab0Sopenharmony_ci * @param converter the Unicode converter 7787777dab0Sopenharmony_ci * @return the minimum number of bytes per codepoint allowed by this particular converter 7797777dab0Sopenharmony_ci * @see ucnv_getMaxCharSize 7807777dab0Sopenharmony_ci * @stable ICU 2.0 7817777dab0Sopenharmony_ci */ 7827777dab0Sopenharmony_ciU_CAPI int8_t U_EXPORT2 7837777dab0Sopenharmony_ciucnv_getMinCharSize(const UConverter *converter); 7847777dab0Sopenharmony_ci 7857777dab0Sopenharmony_ci/** 7867777dab0Sopenharmony_ci * Returns the display name of the converter passed in based on the Locale 7877777dab0Sopenharmony_ci * passed in. If the locale contains no display name, the internal ASCII 7887777dab0Sopenharmony_ci * name will be filled in. 7897777dab0Sopenharmony_ci * 7907777dab0Sopenharmony_ci * @param converter the Unicode converter. 7917777dab0Sopenharmony_ci * @param displayLocale is the specific Locale we want to localized for 7927777dab0Sopenharmony_ci * @param displayName user provided buffer to be filled in 7937777dab0Sopenharmony_ci * @param displayNameCapacity size of displayName Buffer 7947777dab0Sopenharmony_ci * @param err error status code 7957777dab0Sopenharmony_ci * @return displayNameLength number of UChar needed in displayName 7967777dab0Sopenharmony_ci * @see ucnv_getName 7977777dab0Sopenharmony_ci * @stable ICU 2.0 7987777dab0Sopenharmony_ci */ 7997777dab0Sopenharmony_ciU_CAPI int32_t U_EXPORT2 8007777dab0Sopenharmony_ciucnv_getDisplayName(const UConverter *converter, 8017777dab0Sopenharmony_ci const char *displayLocale, 8027777dab0Sopenharmony_ci UChar *displayName, 8037777dab0Sopenharmony_ci int32_t displayNameCapacity, 8047777dab0Sopenharmony_ci UErrorCode *err); 8057777dab0Sopenharmony_ci 8067777dab0Sopenharmony_ci/** 8077777dab0Sopenharmony_ci * Gets the internal, canonical name of the converter (zero-terminated). 8087777dab0Sopenharmony_ci * The lifetime of the returned string will be that of the converter 8097777dab0Sopenharmony_ci * passed to this function. 8107777dab0Sopenharmony_ci * @param converter the Unicode converter 8117777dab0Sopenharmony_ci * @param err UErrorCode status 8127777dab0Sopenharmony_ci * @return the internal name of the converter 8137777dab0Sopenharmony_ci * @see ucnv_getDisplayName 8147777dab0Sopenharmony_ci * @stable ICU 2.0 8157777dab0Sopenharmony_ci */ 8167777dab0Sopenharmony_ciU_CAPI const char * U_EXPORT2 8177777dab0Sopenharmony_ciucnv_getName(const UConverter *converter, UErrorCode *err); 8187777dab0Sopenharmony_ci 8197777dab0Sopenharmony_ci/** 8207777dab0Sopenharmony_ci * Gets a codepage number associated with the converter. This is not guaranteed 8217777dab0Sopenharmony_ci * to be the one used to create the converter. Some converters do not represent 8227777dab0Sopenharmony_ci * platform registered codepages and return zero for the codepage number. 8237777dab0Sopenharmony_ci * The error code fill-in parameter indicates if the codepage number 8247777dab0Sopenharmony_ci * is available. 8257777dab0Sopenharmony_ci * Does not check if the converter is <TT>NULL</TT> or if converter's data 8267777dab0Sopenharmony_ci * table is <TT>NULL</TT>. 8277777dab0Sopenharmony_ci * 8287777dab0Sopenharmony_ci * Important: The use of CCSIDs is not recommended because it is limited 8297777dab0Sopenharmony_ci * to only two platforms in principle and only one (UCNV_IBM) in the current 8307777dab0Sopenharmony_ci * ICU converter API. 8317777dab0Sopenharmony_ci * Also, CCSIDs are insufficient to identify IBM Unicode conversion tables precisely. 8327777dab0Sopenharmony_ci * For more details see ucnv_openCCSID(). 8337777dab0Sopenharmony_ci * 8347777dab0Sopenharmony_ci * @param converter the Unicode converter 8357777dab0Sopenharmony_ci * @param err the error status code. 8367777dab0Sopenharmony_ci * @return If any error occurs, -1 will be returned otherwise, the codepage number 8377777dab0Sopenharmony_ci * will be returned 8387777dab0Sopenharmony_ci * @see ucnv_openCCSID 8397777dab0Sopenharmony_ci * @see ucnv_getPlatform 8407777dab0Sopenharmony_ci * @stable ICU 2.0 8417777dab0Sopenharmony_ci */ 8427777dab0Sopenharmony_ciU_CAPI int32_t U_EXPORT2 8437777dab0Sopenharmony_ciucnv_getCCSID(const UConverter *converter, 8447777dab0Sopenharmony_ci UErrorCode *err); 8457777dab0Sopenharmony_ci 8467777dab0Sopenharmony_ci/** 8477777dab0Sopenharmony_ci * Gets a codepage platform associated with the converter. Currently, 8487777dab0Sopenharmony_ci * only <TT>UCNV_IBM</TT> will be returned. 8497777dab0Sopenharmony_ci * Does not test if the converter is <TT>NULL</TT> or if converter's data 8507777dab0Sopenharmony_ci * table is <TT>NULL</TT>. 8517777dab0Sopenharmony_ci * @param converter the Unicode converter 8527777dab0Sopenharmony_ci * @param err the error status code. 8537777dab0Sopenharmony_ci * @return The codepage platform 8547777dab0Sopenharmony_ci * @stable ICU 2.0 8557777dab0Sopenharmony_ci */ 8567777dab0Sopenharmony_ciU_CAPI UConverterPlatform U_EXPORT2 8577777dab0Sopenharmony_ciucnv_getPlatform(const UConverter *converter, 8587777dab0Sopenharmony_ci UErrorCode *err); 8597777dab0Sopenharmony_ci 8607777dab0Sopenharmony_ci/** 8617777dab0Sopenharmony_ci * Gets the type of the converter 8627777dab0Sopenharmony_ci * e.g. SBCS, MBCS, DBCS, UTF8, UTF16_BE, UTF16_LE, ISO_2022, 8637777dab0Sopenharmony_ci * EBCDIC_STATEFUL, LATIN_1 8647777dab0Sopenharmony_ci * @param converter a valid, opened converter 8657777dab0Sopenharmony_ci * @return the type of the converter 8667777dab0Sopenharmony_ci * @stable ICU 2.0 8677777dab0Sopenharmony_ci */ 8687777dab0Sopenharmony_ciU_CAPI UConverterType U_EXPORT2 8697777dab0Sopenharmony_ciucnv_getType(const UConverter * converter); 8707777dab0Sopenharmony_ci 8717777dab0Sopenharmony_ci/** 8727777dab0Sopenharmony_ci * Gets the "starter" (lead) bytes for converters of type MBCS. 8737777dab0Sopenharmony_ci * Will fill in an <TT>U_ILLEGAL_ARGUMENT_ERROR</TT> if converter passed in 8747777dab0Sopenharmony_ci * is not MBCS. Fills in an array of type UBool, with the value of the byte 8757777dab0Sopenharmony_ci * as offset to the array. For example, if (starters[0x20] == true) at return, 8767777dab0Sopenharmony_ci * it means that the byte 0x20 is a starter byte in this converter. 8777777dab0Sopenharmony_ci * Context pointers are always owned by the caller. 8787777dab0Sopenharmony_ci * 8797777dab0Sopenharmony_ci * @param converter a valid, opened converter of type MBCS 8807777dab0Sopenharmony_ci * @param starters an array of size 256 to be filled in 8817777dab0Sopenharmony_ci * @param err error status, <TT>U_ILLEGAL_ARGUMENT_ERROR</TT> if the 8827777dab0Sopenharmony_ci * converter is not a type which can return starters. 8837777dab0Sopenharmony_ci * @see ucnv_getType 8847777dab0Sopenharmony_ci * @stable ICU 2.0 8857777dab0Sopenharmony_ci */ 8867777dab0Sopenharmony_ciU_CAPI void U_EXPORT2 8877777dab0Sopenharmony_ciucnv_getStarters(const UConverter* converter, 8887777dab0Sopenharmony_ci UBool starters[256], 8897777dab0Sopenharmony_ci UErrorCode* err); 8907777dab0Sopenharmony_ci 8917777dab0Sopenharmony_ci/** 8927777dab0Sopenharmony_ci * Gets the current callback function used by the converter when an illegal 8937777dab0Sopenharmony_ci * or invalid codepage sequence is found. 8947777dab0Sopenharmony_ci * Context pointers are always owned by the caller. 8957777dab0Sopenharmony_ci * 8967777dab0Sopenharmony_ci * @param converter the unicode converter 8977777dab0Sopenharmony_ci * @param action fillin: returns the callback function pointer 8987777dab0Sopenharmony_ci * @param context fillin: returns the callback's private void* context 8997777dab0Sopenharmony_ci * @see ucnv_setToUCallBack 9007777dab0Sopenharmony_ci * @stable ICU 2.0 9017777dab0Sopenharmony_ci */ 9027777dab0Sopenharmony_ciU_CAPI void U_EXPORT2 9037777dab0Sopenharmony_ciucnv_getToUCallBack (const UConverter * converter, 9047777dab0Sopenharmony_ci UConverterToUCallback *action, 9057777dab0Sopenharmony_ci const void **context); 9067777dab0Sopenharmony_ci 9077777dab0Sopenharmony_ci/** 9087777dab0Sopenharmony_ci * Gets the current callback function used by the converter when illegal 9097777dab0Sopenharmony_ci * or invalid Unicode sequence is found. 9107777dab0Sopenharmony_ci * Context pointers are always owned by the caller. 9117777dab0Sopenharmony_ci * 9127777dab0Sopenharmony_ci * @param converter the unicode converter 9137777dab0Sopenharmony_ci * @param action fillin: returns the callback function pointer 9147777dab0Sopenharmony_ci * @param context fillin: returns the callback's private void* context 9157777dab0Sopenharmony_ci * @see ucnv_setFromUCallBack 9167777dab0Sopenharmony_ci * @stable ICU 2.0 9177777dab0Sopenharmony_ci */ 9187777dab0Sopenharmony_ciU_CAPI void U_EXPORT2 9197777dab0Sopenharmony_ciucnv_getFromUCallBack (const UConverter * converter, 9207777dab0Sopenharmony_ci UConverterFromUCallback *action, 9217777dab0Sopenharmony_ci const void **context); 9227777dab0Sopenharmony_ci 9237777dab0Sopenharmony_ci/** 9247777dab0Sopenharmony_ci * Changes the callback function used by the converter when 9257777dab0Sopenharmony_ci * an illegal or invalid sequence is found. 9267777dab0Sopenharmony_ci * Context pointers are always owned by the caller. 9277777dab0Sopenharmony_ci * Predefined actions and contexts can be found in the ucnv_err.h header. 9287777dab0Sopenharmony_ci * 9297777dab0Sopenharmony_ci * @param converter the unicode converter 9307777dab0Sopenharmony_ci * @param newAction the new callback function 9317777dab0Sopenharmony_ci * @param newContext the new toUnicode callback context pointer. This can be NULL. 9327777dab0Sopenharmony_ci * @param oldAction fillin: returns the old callback function pointer. This can be NULL. 9337777dab0Sopenharmony_ci * @param oldContext fillin: returns the old callback's private void* context. This can be NULL. 9347777dab0Sopenharmony_ci * @param err The error code status 9357777dab0Sopenharmony_ci * @see ucnv_getToUCallBack 9367777dab0Sopenharmony_ci * @stable ICU 2.0 9377777dab0Sopenharmony_ci */ 9387777dab0Sopenharmony_ciU_CAPI void U_EXPORT2 9397777dab0Sopenharmony_ciucnv_setToUCallBack (UConverter * converter, 9407777dab0Sopenharmony_ci UConverterToUCallback newAction, 9417777dab0Sopenharmony_ci const void* newContext, 9427777dab0Sopenharmony_ci UConverterToUCallback *oldAction, 9437777dab0Sopenharmony_ci const void** oldContext, 9447777dab0Sopenharmony_ci UErrorCode * err); 9457777dab0Sopenharmony_ci 9467777dab0Sopenharmony_ci/** 9477777dab0Sopenharmony_ci * Changes the current callback function used by the converter when 9487777dab0Sopenharmony_ci * an illegal or invalid sequence is found. 9497777dab0Sopenharmony_ci * Context pointers are always owned by the caller. 9507777dab0Sopenharmony_ci * Predefined actions and contexts can be found in the ucnv_err.h header. 9517777dab0Sopenharmony_ci * 9527777dab0Sopenharmony_ci * @param converter the unicode converter 9537777dab0Sopenharmony_ci * @param newAction the new callback function 9547777dab0Sopenharmony_ci * @param newContext the new fromUnicode callback context pointer. This can be NULL. 9557777dab0Sopenharmony_ci * @param oldAction fillin: returns the old callback function pointer. This can be NULL. 9567777dab0Sopenharmony_ci * @param oldContext fillin: returns the old callback's private void* context. This can be NULL. 9577777dab0Sopenharmony_ci * @param err The error code status 9587777dab0Sopenharmony_ci * @see ucnv_getFromUCallBack 9597777dab0Sopenharmony_ci * @stable ICU 2.0 9607777dab0Sopenharmony_ci */ 9617777dab0Sopenharmony_ciU_CAPI void U_EXPORT2 9627777dab0Sopenharmony_ciucnv_setFromUCallBack (UConverter * converter, 9637777dab0Sopenharmony_ci UConverterFromUCallback newAction, 9647777dab0Sopenharmony_ci const void *newContext, 9657777dab0Sopenharmony_ci UConverterFromUCallback *oldAction, 9667777dab0Sopenharmony_ci const void **oldContext, 9677777dab0Sopenharmony_ci UErrorCode * err); 9687777dab0Sopenharmony_ci 9697777dab0Sopenharmony_ci/** 9707777dab0Sopenharmony_ci * Converts an array of unicode characters to an array of codepage 9717777dab0Sopenharmony_ci * characters. This function is optimized for converting a continuous 9727777dab0Sopenharmony_ci * stream of data in buffer-sized chunks, where the entire source and 9737777dab0Sopenharmony_ci * target does not fit in available buffers. 9747777dab0Sopenharmony_ci * 9757777dab0Sopenharmony_ci * The source pointer is an in/out parameter. It starts out pointing where the 9767777dab0Sopenharmony_ci * conversion is to begin, and ends up pointing after the last UChar consumed. 9777777dab0Sopenharmony_ci * 9787777dab0Sopenharmony_ci * Target similarly starts out pointer at the first available byte in the output 9797777dab0Sopenharmony_ci * buffer, and ends up pointing after the last byte written to the output. 9807777dab0Sopenharmony_ci * 9817777dab0Sopenharmony_ci * The converter always attempts to consume the entire source buffer, unless 9827777dab0Sopenharmony_ci * (1.) the target buffer is full, or (2.) a failing error is returned from the 9837777dab0Sopenharmony_ci * current callback function. When a successful error status has been 9847777dab0Sopenharmony_ci * returned, it means that all of the source buffer has been 9857777dab0Sopenharmony_ci * consumed. At that point, the caller should reset the source and 9867777dab0Sopenharmony_ci * sourceLimit pointers to point to the next chunk. 9877777dab0Sopenharmony_ci * 9887777dab0Sopenharmony_ci * At the end of the stream (flush==true), the input is completely consumed 9897777dab0Sopenharmony_ci * when *source==sourceLimit and no error code is set. 9907777dab0Sopenharmony_ci * The converter object is then automatically reset by this function. 9917777dab0Sopenharmony_ci * (This means that a converter need not be reset explicitly between data 9927777dab0Sopenharmony_ci * streams if it finishes the previous stream without errors.) 9937777dab0Sopenharmony_ci * 9947777dab0Sopenharmony_ci * This is a <I>stateful</I> conversion. Additionally, even when all source data has 9957777dab0Sopenharmony_ci * been consumed, some data may be in the converters' internal state. 9967777dab0Sopenharmony_ci * Call this function repeatedly, updating the target pointers with 9977777dab0Sopenharmony_ci * the next empty chunk of target in case of a 9987777dab0Sopenharmony_ci * <TT>U_BUFFER_OVERFLOW_ERROR</TT>, and updating the source pointers 9997777dab0Sopenharmony_ci * with the next chunk of source when a successful error status is 10007777dab0Sopenharmony_ci * returned, until there are no more chunks of source data. 10017777dab0Sopenharmony_ci * @param converter the Unicode converter 10027777dab0Sopenharmony_ci * @param target I/O parameter. Input : Points to the beginning of the buffer to copy 10037777dab0Sopenharmony_ci * codepage characters to. Output : points to after the last codepage character copied 10047777dab0Sopenharmony_ci * to <TT>target</TT>. 10057777dab0Sopenharmony_ci * @param targetLimit the pointer just after last of the <TT>target</TT> buffer 10067777dab0Sopenharmony_ci * @param source I/O parameter, pointer to pointer to the source Unicode character buffer. 10077777dab0Sopenharmony_ci * @param sourceLimit the pointer just after the last of the source buffer 10087777dab0Sopenharmony_ci * @param offsets if NULL is passed, nothing will happen to it, otherwise it needs to have the same number 10097777dab0Sopenharmony_ci * of allocated cells as <TT>target</TT>. Will fill in offsets from target to source pointer 10107777dab0Sopenharmony_ci * e.g: <TT>offsets[3]</TT> is equal to 6, it means that the <TT>target[3]</TT> was a result of transcoding <TT>source[6]</TT> 10117777dab0Sopenharmony_ci * For output data carried across calls, and other data without a specific source character 10127777dab0Sopenharmony_ci * (such as from escape sequences or callbacks) -1 will be placed for offsets. 10137777dab0Sopenharmony_ci * @param flush set to <TT>true</TT> if the current source buffer is the last available 10147777dab0Sopenharmony_ci * chunk of the source, <TT>false</TT> otherwise. Note that if a failing status is returned, 10157777dab0Sopenharmony_ci * this function may have to be called multiple times with flush set to <TT>true</TT> until 10167777dab0Sopenharmony_ci * the source buffer is consumed. 10177777dab0Sopenharmony_ci * @param err the error status. <TT>U_ILLEGAL_ARGUMENT_ERROR</TT> will be set if the 10187777dab0Sopenharmony_ci * converter is <TT>NULL</TT>. 10197777dab0Sopenharmony_ci * <code>U_BUFFER_OVERFLOW_ERROR</code> will be set if the target is full and there is 10207777dab0Sopenharmony_ci * still data to be written to the target. 10217777dab0Sopenharmony_ci * @see ucnv_fromUChars 10227777dab0Sopenharmony_ci * @see ucnv_convert 10237777dab0Sopenharmony_ci * @see ucnv_getMinCharSize 10247777dab0Sopenharmony_ci * @see ucnv_setToUCallBack 10257777dab0Sopenharmony_ci * @stable ICU 2.0 10267777dab0Sopenharmony_ci */ 10277777dab0Sopenharmony_ciU_CAPI void U_EXPORT2 10287777dab0Sopenharmony_ciucnv_fromUnicode (UConverter * converter, 10297777dab0Sopenharmony_ci char **target, 10307777dab0Sopenharmony_ci const char *targetLimit, 10317777dab0Sopenharmony_ci const UChar ** source, 10327777dab0Sopenharmony_ci const UChar * sourceLimit, 10337777dab0Sopenharmony_ci int32_t* offsets, 10347777dab0Sopenharmony_ci UBool flush, 10357777dab0Sopenharmony_ci UErrorCode * err); 10367777dab0Sopenharmony_ci 10377777dab0Sopenharmony_ci/** 10387777dab0Sopenharmony_ci * Converts a buffer of codepage bytes into an array of unicode UChars 10397777dab0Sopenharmony_ci * characters. This function is optimized for converting a continuous 10407777dab0Sopenharmony_ci * stream of data in buffer-sized chunks, where the entire source and 10417777dab0Sopenharmony_ci * target does not fit in available buffers. 10427777dab0Sopenharmony_ci * 10437777dab0Sopenharmony_ci * The source pointer is an in/out parameter. It starts out pointing where the 10447777dab0Sopenharmony_ci * conversion is to begin, and ends up pointing after the last byte of source consumed. 10457777dab0Sopenharmony_ci * 10467777dab0Sopenharmony_ci * Target similarly starts out pointer at the first available UChar in the output 10477777dab0Sopenharmony_ci * buffer, and ends up pointing after the last UChar written to the output. 10487777dab0Sopenharmony_ci * It does NOT necessarily keep UChar sequences together. 10497777dab0Sopenharmony_ci * 10507777dab0Sopenharmony_ci * The converter always attempts to consume the entire source buffer, unless 10517777dab0Sopenharmony_ci * (1.) the target buffer is full, or (2.) a failing error is returned from the 10527777dab0Sopenharmony_ci * current callback function. When a successful error status has been 10537777dab0Sopenharmony_ci * returned, it means that all of the source buffer has been 10547777dab0Sopenharmony_ci * consumed. At that point, the caller should reset the source and 10557777dab0Sopenharmony_ci * sourceLimit pointers to point to the next chunk. 10567777dab0Sopenharmony_ci * 10577777dab0Sopenharmony_ci * At the end of the stream (flush==true), the input is completely consumed 10587777dab0Sopenharmony_ci * when *source==sourceLimit and no error code is set 10597777dab0Sopenharmony_ci * The converter object is then automatically reset by this function. 10607777dab0Sopenharmony_ci * (This means that a converter need not be reset explicitly between data 10617777dab0Sopenharmony_ci * streams if it finishes the previous stream without errors.) 10627777dab0Sopenharmony_ci * 10637777dab0Sopenharmony_ci * This is a <I>stateful</I> conversion. Additionally, even when all source data has 10647777dab0Sopenharmony_ci * been consumed, some data may be in the converters' internal state. 10657777dab0Sopenharmony_ci * Call this function repeatedly, updating the target pointers with 10667777dab0Sopenharmony_ci * the next empty chunk of target in case of a 10677777dab0Sopenharmony_ci * <TT>U_BUFFER_OVERFLOW_ERROR</TT>, and updating the source pointers 10687777dab0Sopenharmony_ci * with the next chunk of source when a successful error status is 10697777dab0Sopenharmony_ci * returned, until there are no more chunks of source data. 10707777dab0Sopenharmony_ci * @param converter the Unicode converter 10717777dab0Sopenharmony_ci * @param target I/O parameter. Input : Points to the beginning of the buffer to copy 10727777dab0Sopenharmony_ci * UChars into. Output : points to after the last UChar copied. 10737777dab0Sopenharmony_ci * @param targetLimit the pointer just after the end of the <TT>target</TT> buffer 10747777dab0Sopenharmony_ci * @param source I/O parameter, pointer to pointer to the source codepage buffer. 10757777dab0Sopenharmony_ci * @param sourceLimit the pointer to the byte after the end of the source buffer 10767777dab0Sopenharmony_ci * @param offsets if NULL is passed, nothing will happen to it, otherwise it needs to have the same number 10777777dab0Sopenharmony_ci * of allocated cells as <TT>target</TT>. Will fill in offsets from target to source pointer 10787777dab0Sopenharmony_ci * e.g: <TT>offsets[3]</TT> is equal to 6, it means that the <TT>target[3]</TT> was a result of transcoding <TT>source[6]</TT> 10797777dab0Sopenharmony_ci * For output data carried across calls, and other data without a specific source character 10807777dab0Sopenharmony_ci * (such as from escape sequences or callbacks) -1 will be placed for offsets. 10817777dab0Sopenharmony_ci * @param flush set to <TT>true</TT> if the current source buffer is the last available 10827777dab0Sopenharmony_ci * chunk of the source, <TT>false</TT> otherwise. Note that if a failing status is returned, 10837777dab0Sopenharmony_ci * this function may have to be called multiple times with flush set to <TT>true</TT> until 10847777dab0Sopenharmony_ci * the source buffer is consumed. 10857777dab0Sopenharmony_ci * @param err the error status. <TT>U_ILLEGAL_ARGUMENT_ERROR</TT> will be set if the 10867777dab0Sopenharmony_ci * converter is <TT>NULL</TT>. 10877777dab0Sopenharmony_ci * <code>U_BUFFER_OVERFLOW_ERROR</code> will be set if the target is full and there is 10887777dab0Sopenharmony_ci * still data to be written to the target. 10897777dab0Sopenharmony_ci * @see ucnv_fromUChars 10907777dab0Sopenharmony_ci * @see ucnv_convert 10917777dab0Sopenharmony_ci * @see ucnv_getMinCharSize 10927777dab0Sopenharmony_ci * @see ucnv_setFromUCallBack 10937777dab0Sopenharmony_ci * @see ucnv_getNextUChar 10947777dab0Sopenharmony_ci * @stable ICU 2.0 10957777dab0Sopenharmony_ci */ 10967777dab0Sopenharmony_ciU_CAPI void U_EXPORT2 10977777dab0Sopenharmony_ciucnv_toUnicode(UConverter *converter, 10987777dab0Sopenharmony_ci UChar **target, 10997777dab0Sopenharmony_ci const UChar *targetLimit, 11007777dab0Sopenharmony_ci const char **source, 11017777dab0Sopenharmony_ci const char *sourceLimit, 11027777dab0Sopenharmony_ci int32_t *offsets, 11037777dab0Sopenharmony_ci UBool flush, 11047777dab0Sopenharmony_ci UErrorCode *err); 11057777dab0Sopenharmony_ci 11067777dab0Sopenharmony_ci/** 11077777dab0Sopenharmony_ci * Convert the Unicode string into a codepage string using an existing UConverter. 11087777dab0Sopenharmony_ci * The output string is NUL-terminated if possible. 11097777dab0Sopenharmony_ci * 11107777dab0Sopenharmony_ci * This function is a more convenient but less powerful version of ucnv_fromUnicode(). 11117777dab0Sopenharmony_ci * It is only useful for whole strings, not for streaming conversion. 11127777dab0Sopenharmony_ci * 11137777dab0Sopenharmony_ci * The maximum output buffer capacity required (barring output from callbacks) will be 11147777dab0Sopenharmony_ci * UCNV_GET_MAX_BYTES_FOR_STRING(srcLength, ucnv_getMaxCharSize(cnv)). 11157777dab0Sopenharmony_ci * 11167777dab0Sopenharmony_ci * @param cnv the converter object to be used (ucnv_resetFromUnicode() will be called) 11177777dab0Sopenharmony_ci * @param src the input Unicode string 11187777dab0Sopenharmony_ci * @param srcLength the input string length, or -1 if NUL-terminated 11197777dab0Sopenharmony_ci * @param dest destination string buffer, can be NULL if destCapacity==0 11207777dab0Sopenharmony_ci * @param destCapacity the number of chars available at dest 11217777dab0Sopenharmony_ci * @param pErrorCode normal ICU error code; 11227777dab0Sopenharmony_ci * common error codes that may be set by this function include 11237777dab0Sopenharmony_ci * U_BUFFER_OVERFLOW_ERROR, U_STRING_NOT_TERMINATED_WARNING, 11247777dab0Sopenharmony_ci * U_ILLEGAL_ARGUMENT_ERROR, and conversion errors 11257777dab0Sopenharmony_ci * @return the length of the output string, not counting the terminating NUL; 11267777dab0Sopenharmony_ci * if the length is greater than destCapacity, then the string will not fit 11277777dab0Sopenharmony_ci * and a buffer of the indicated length would need to be passed in 11287777dab0Sopenharmony_ci * @see ucnv_fromUnicode 11297777dab0Sopenharmony_ci * @see ucnv_convert 11307777dab0Sopenharmony_ci * @see UCNV_GET_MAX_BYTES_FOR_STRING 11317777dab0Sopenharmony_ci * @stable ICU 2.0 11327777dab0Sopenharmony_ci */ 11337777dab0Sopenharmony_ciU_CAPI int32_t U_EXPORT2 11347777dab0Sopenharmony_ciucnv_fromUChars(UConverter *cnv, 11357777dab0Sopenharmony_ci char *dest, int32_t destCapacity, 11367777dab0Sopenharmony_ci const UChar *src, int32_t srcLength, 11377777dab0Sopenharmony_ci UErrorCode *pErrorCode); 11387777dab0Sopenharmony_ci 11397777dab0Sopenharmony_ci/** 11407777dab0Sopenharmony_ci * Convert the codepage string into a Unicode string using an existing UConverter. 11417777dab0Sopenharmony_ci * The output string is NUL-terminated if possible. 11427777dab0Sopenharmony_ci * 11437777dab0Sopenharmony_ci * This function is a more convenient but less powerful version of ucnv_toUnicode(). 11447777dab0Sopenharmony_ci * It is only useful for whole strings, not for streaming conversion. 11457777dab0Sopenharmony_ci * 11467777dab0Sopenharmony_ci * The maximum output buffer capacity required (barring output from callbacks) will be 11477777dab0Sopenharmony_ci * 2*srcLength (each char may be converted into a surrogate pair). 11487777dab0Sopenharmony_ci * 11497777dab0Sopenharmony_ci * @param cnv the converter object to be used (ucnv_resetToUnicode() will be called) 11507777dab0Sopenharmony_ci * @param src the input codepage string 11517777dab0Sopenharmony_ci * @param srcLength the input string length, or -1 if NUL-terminated 11527777dab0Sopenharmony_ci * @param dest destination string buffer, can be NULL if destCapacity==0 11537777dab0Sopenharmony_ci * @param destCapacity the number of UChars available at dest 11547777dab0Sopenharmony_ci * @param pErrorCode normal ICU error code; 11557777dab0Sopenharmony_ci * common error codes that may be set by this function include 11567777dab0Sopenharmony_ci * U_BUFFER_OVERFLOW_ERROR, U_STRING_NOT_TERMINATED_WARNING, 11577777dab0Sopenharmony_ci * U_ILLEGAL_ARGUMENT_ERROR, and conversion errors 11587777dab0Sopenharmony_ci * @return the length of the output string, not counting the terminating NUL; 11597777dab0Sopenharmony_ci * if the length is greater than destCapacity, then the string will not fit 11607777dab0Sopenharmony_ci * and a buffer of the indicated length would need to be passed in 11617777dab0Sopenharmony_ci * @see ucnv_toUnicode 11627777dab0Sopenharmony_ci * @see ucnv_convert 11637777dab0Sopenharmony_ci * @stable ICU 2.0 11647777dab0Sopenharmony_ci */ 11657777dab0Sopenharmony_ciU_CAPI int32_t U_EXPORT2 11667777dab0Sopenharmony_ciucnv_toUChars(UConverter *cnv, 11677777dab0Sopenharmony_ci UChar *dest, int32_t destCapacity, 11687777dab0Sopenharmony_ci const char *src, int32_t srcLength, 11697777dab0Sopenharmony_ci UErrorCode *pErrorCode); 11707777dab0Sopenharmony_ci 11717777dab0Sopenharmony_ci/** 11727777dab0Sopenharmony_ci * Convert a codepage buffer into Unicode one character at a time. 11737777dab0Sopenharmony_ci * The input is completely consumed when the U_INDEX_OUTOFBOUNDS_ERROR is set. 11747777dab0Sopenharmony_ci * 11757777dab0Sopenharmony_ci * Advantage compared to ucnv_toUnicode() or ucnv_toUChars(): 11767777dab0Sopenharmony_ci * - Faster for small amounts of data, for most converters, e.g., 11777777dab0Sopenharmony_ci * US-ASCII, ISO-8859-1, UTF-8/16/32, and most "normal" charsets. 11787777dab0Sopenharmony_ci * (For complex converters, e.g., SCSU, UTF-7 and ISO 2022 variants, 11797777dab0Sopenharmony_ci * it uses ucnv_toUnicode() internally.) 11807777dab0Sopenharmony_ci * - Convenient. 11817777dab0Sopenharmony_ci * 11827777dab0Sopenharmony_ci * Limitations compared to ucnv_toUnicode(): 11837777dab0Sopenharmony_ci * - Always assumes flush=true. 11847777dab0Sopenharmony_ci * This makes ucnv_getNextUChar() unsuitable for "streaming" conversion, 11857777dab0Sopenharmony_ci * that is, for where the input is supplied in multiple buffers, 11867777dab0Sopenharmony_ci * because ucnv_getNextUChar() will assume the end of the input at the end 11877777dab0Sopenharmony_ci * of the first buffer. 11887777dab0Sopenharmony_ci * - Does not provide offset output. 11897777dab0Sopenharmony_ci * 11907777dab0Sopenharmony_ci * It is possible to "mix" ucnv_getNextUChar() and ucnv_toUnicode() because 11917777dab0Sopenharmony_ci * ucnv_getNextUChar() uses the current state of the converter 11927777dab0Sopenharmony_ci * (unlike ucnv_toUChars() which always resets first). 11937777dab0Sopenharmony_ci * However, if ucnv_getNextUChar() is called after ucnv_toUnicode() 11947777dab0Sopenharmony_ci * stopped in the middle of a character sequence (with flush=false), 11957777dab0Sopenharmony_ci * then ucnv_getNextUChar() will always use the slower ucnv_toUnicode() 11967777dab0Sopenharmony_ci * internally until the next character boundary. 11977777dab0Sopenharmony_ci * (This is new in ICU 2.6. In earlier releases, ucnv_getNextUChar() had to 11987777dab0Sopenharmony_ci * start at a character boundary.) 11997777dab0Sopenharmony_ci * 12007777dab0Sopenharmony_ci * Instead of using ucnv_getNextUChar(), it is recommended 12017777dab0Sopenharmony_ci * to convert using ucnv_toUnicode() or ucnv_toUChars() 12027777dab0Sopenharmony_ci * and then iterate over the text using U16_NEXT() or a UCharIterator (uiter.h) 12037777dab0Sopenharmony_ci * or a C++ CharacterIterator or similar. 12047777dab0Sopenharmony_ci * This allows streaming conversion and offset output, for example. 12057777dab0Sopenharmony_ci * 12067777dab0Sopenharmony_ci * <p>Handling of surrogate pairs and supplementary-plane code points:<br> 12077777dab0Sopenharmony_ci * There are two different kinds of codepages that provide mappings for surrogate characters: 12087777dab0Sopenharmony_ci * <ul> 12097777dab0Sopenharmony_ci * <li>Codepages like UTF-8, UTF-32, and GB 18030 provide direct representations for Unicode 12107777dab0Sopenharmony_ci * code points U+10000-U+10ffff as well as for single surrogates U+d800-U+dfff. 12117777dab0Sopenharmony_ci * Each valid sequence will result in exactly one returned code point. 12127777dab0Sopenharmony_ci * If a sequence results in a single surrogate, then that will be returned 12137777dab0Sopenharmony_ci * by itself, even if a neighboring sequence encodes the matching surrogate.</li> 12147777dab0Sopenharmony_ci * <li>Codepages like SCSU and LMBCS (and UTF-16) provide direct representations only for BMP code points 12157777dab0Sopenharmony_ci * including surrogates. Code points in supplementary planes are represented with 12167777dab0Sopenharmony_ci * two sequences, each encoding a surrogate. 12177777dab0Sopenharmony_ci * For these codepages, matching pairs of surrogates will be combined into single 12187777dab0Sopenharmony_ci * code points for returning from this function. 12197777dab0Sopenharmony_ci * (Note that SCSU is actually a mix of these codepage types.)</li> 12207777dab0Sopenharmony_ci * </ul></p> 12217777dab0Sopenharmony_ci * 12227777dab0Sopenharmony_ci * @param converter an open UConverter 12237777dab0Sopenharmony_ci * @param source the address of a pointer to the codepage buffer, will be 12247777dab0Sopenharmony_ci * updated to point after the bytes consumed in the conversion call. 12257777dab0Sopenharmony_ci * @param sourceLimit points to the end of the input buffer 12267777dab0Sopenharmony_ci * @param err fills in error status (see ucnv_toUnicode) 12277777dab0Sopenharmony_ci * <code>U_INDEX_OUTOFBOUNDS_ERROR</code> will be set if the input 12287777dab0Sopenharmony_ci * is empty or does not convert to any output (e.g.: pure state-change 12297777dab0Sopenharmony_ci * codes SI/SO, escape sequences for ISO 2022, 12307777dab0Sopenharmony_ci * or if the callback did not output anything, ...). 12317777dab0Sopenharmony_ci * This function will not set a <code>U_BUFFER_OVERFLOW_ERROR</code> because 12327777dab0Sopenharmony_ci * the "buffer" is the return code. However, there might be subsequent output 12337777dab0Sopenharmony_ci * stored in the converter object 12347777dab0Sopenharmony_ci * that will be returned in following calls to this function. 12357777dab0Sopenharmony_ci * @return a UChar32 resulting from the partial conversion of source 12367777dab0Sopenharmony_ci * @see ucnv_toUnicode 12377777dab0Sopenharmony_ci * @see ucnv_toUChars 12387777dab0Sopenharmony_ci * @see ucnv_convert 12397777dab0Sopenharmony_ci * @stable ICU 2.0 12407777dab0Sopenharmony_ci */ 12417777dab0Sopenharmony_ciU_CAPI UChar32 U_EXPORT2 12427777dab0Sopenharmony_ciucnv_getNextUChar(UConverter * converter, 12437777dab0Sopenharmony_ci const char **source, 12447777dab0Sopenharmony_ci const char * sourceLimit, 12457777dab0Sopenharmony_ci UErrorCode * err); 12467777dab0Sopenharmony_ci 12477777dab0Sopenharmony_ci/** 12487777dab0Sopenharmony_ci * Convert from one external charset to another using two existing UConverters. 12497777dab0Sopenharmony_ci * Internally, two conversions - ucnv_toUnicode() and ucnv_fromUnicode() - 12507777dab0Sopenharmony_ci * are used, "pivoting" through 16-bit Unicode. 12517777dab0Sopenharmony_ci * 12527777dab0Sopenharmony_ci * Important: For streaming conversion (multiple function calls for successive 12537777dab0Sopenharmony_ci * parts of a text stream), the caller must provide a pivot buffer explicitly, 12547777dab0Sopenharmony_ci * and must preserve the pivot buffer and associated pointers from one 12557777dab0Sopenharmony_ci * call to another. (The buffer may be moved if its contents and the relative 12567777dab0Sopenharmony_ci * pointer positions are preserved.) 12577777dab0Sopenharmony_ci * 12587777dab0Sopenharmony_ci * There is a similar function, ucnv_convert(), 12597777dab0Sopenharmony_ci * which has the following limitations: 12607777dab0Sopenharmony_ci * - it takes charset names, not converter objects, so that 12617777dab0Sopenharmony_ci * - two converters are opened for each call 12627777dab0Sopenharmony_ci * - only single-string conversion is possible, not streaming operation 12637777dab0Sopenharmony_ci * - it does not provide enough information to find out, 12647777dab0Sopenharmony_ci * in case of failure, whether the toUnicode or 12657777dab0Sopenharmony_ci * the fromUnicode conversion failed 12667777dab0Sopenharmony_ci * 12677777dab0Sopenharmony_ci * By contrast, ucnv_convertEx() 12687777dab0Sopenharmony_ci * - takes UConverter parameters instead of charset names 12697777dab0Sopenharmony_ci * - fully exposes the pivot buffer for streaming conversion and complete error handling 12707777dab0Sopenharmony_ci * 12717777dab0Sopenharmony_ci * ucnv_convertEx() also provides further convenience: 12727777dab0Sopenharmony_ci * - an option to reset the converters at the beginning 12737777dab0Sopenharmony_ci * (if reset==true, see parameters; 12747777dab0Sopenharmony_ci * also sets *pivotTarget=*pivotSource=pivotStart) 12757777dab0Sopenharmony_ci * - allow NUL-terminated input 12767777dab0Sopenharmony_ci * (only a single NUL byte, will not work for charsets with multi-byte NULs) 12777777dab0Sopenharmony_ci * (if sourceLimit==NULL, see parameters) 12787777dab0Sopenharmony_ci * - terminate with a NUL on output 12797777dab0Sopenharmony_ci * (only a single NUL byte, not useful for charsets with multi-byte NULs), 12807777dab0Sopenharmony_ci * or set U_STRING_NOT_TERMINATED_WARNING if the output exactly fills 12817777dab0Sopenharmony_ci * the target buffer 12827777dab0Sopenharmony_ci * - the pivot buffer can be provided internally; 12837777dab0Sopenharmony_ci * possible only for whole-string conversion, not streaming conversion; 12847777dab0Sopenharmony_ci * in this case, the caller will not be able to get details about where an 12857777dab0Sopenharmony_ci * error occurred 12867777dab0Sopenharmony_ci * (if pivotStart==NULL, see below) 12877777dab0Sopenharmony_ci * 12887777dab0Sopenharmony_ci * The function returns when one of the following is true: 12897777dab0Sopenharmony_ci * - the entire source text has been converted successfully to the target buffer 12907777dab0Sopenharmony_ci * - a target buffer overflow occurred (U_BUFFER_OVERFLOW_ERROR) 12917777dab0Sopenharmony_ci * - a conversion error occurred 12927777dab0Sopenharmony_ci * (other U_FAILURE(), see description of pErrorCode) 12937777dab0Sopenharmony_ci * 12947777dab0Sopenharmony_ci * Limitation compared to the direct use of 12957777dab0Sopenharmony_ci * ucnv_fromUnicode() and ucnv_toUnicode(): 12967777dab0Sopenharmony_ci * ucnv_convertEx() does not provide offset information. 12977777dab0Sopenharmony_ci * 12987777dab0Sopenharmony_ci * Limitation compared to ucnv_fromUChars() and ucnv_toUChars(): 12997777dab0Sopenharmony_ci * ucnv_convertEx() does not support preflighting directly. 13007777dab0Sopenharmony_ci * 13017777dab0Sopenharmony_ci * Sample code for converting a single string from 13027777dab0Sopenharmony_ci * one external charset to UTF-8, ignoring the location of errors: 13037777dab0Sopenharmony_ci * 13047777dab0Sopenharmony_ci * \code 13057777dab0Sopenharmony_ci * int32_t 13067777dab0Sopenharmony_ci * myToUTF8(UConverter *cnv, 13077777dab0Sopenharmony_ci * const char *s, int32_t length, 13087777dab0Sopenharmony_ci * char *u8, int32_t capacity, 13097777dab0Sopenharmony_ci * UErrorCode *pErrorCode) { 13107777dab0Sopenharmony_ci * UConverter *utf8Cnv; 13117777dab0Sopenharmony_ci * char *target; 13127777dab0Sopenharmony_ci * 13137777dab0Sopenharmony_ci * if(U_FAILURE(*pErrorCode)) { 13147777dab0Sopenharmony_ci * return 0; 13157777dab0Sopenharmony_ci * } 13167777dab0Sopenharmony_ci * 13177777dab0Sopenharmony_ci * utf8Cnv=myGetCachedUTF8Converter(pErrorCode); 13187777dab0Sopenharmony_ci * if(U_FAILURE(*pErrorCode)) { 13197777dab0Sopenharmony_ci * return 0; 13207777dab0Sopenharmony_ci * } 13217777dab0Sopenharmony_ci * 13227777dab0Sopenharmony_ci * if(length<0) { 13237777dab0Sopenharmony_ci * length=strlen(s); 13247777dab0Sopenharmony_ci * } 13257777dab0Sopenharmony_ci * target=u8; 13267777dab0Sopenharmony_ci * ucnv_convertEx(utf8Cnv, cnv, 13277777dab0Sopenharmony_ci * &target, u8+capacity, 13287777dab0Sopenharmony_ci * &s, s+length, 13297777dab0Sopenharmony_ci * NULL, NULL, NULL, NULL, 13307777dab0Sopenharmony_ci * true, true, 13317777dab0Sopenharmony_ci * pErrorCode); 13327777dab0Sopenharmony_ci * 13337777dab0Sopenharmony_ci * myReleaseCachedUTF8Converter(utf8Cnv); 13347777dab0Sopenharmony_ci * 13357777dab0Sopenharmony_ci * // return the output string length, but without preflighting 13367777dab0Sopenharmony_ci * return (int32_t)(target-u8); 13377777dab0Sopenharmony_ci * } 13387777dab0Sopenharmony_ci * \endcode 13397777dab0Sopenharmony_ci * 13407777dab0Sopenharmony_ci * @param targetCnv Output converter, used to convert from the UTF-16 pivot 13417777dab0Sopenharmony_ci * to the target using ucnv_fromUnicode(). 13427777dab0Sopenharmony_ci * @param sourceCnv Input converter, used to convert from the source to 13437777dab0Sopenharmony_ci * the UTF-16 pivot using ucnv_toUnicode(). 13447777dab0Sopenharmony_ci * @param target I/O parameter, same as for ucnv_fromUChars(). 13457777dab0Sopenharmony_ci * Input: *target points to the beginning of the target buffer. 13467777dab0Sopenharmony_ci * Output: *target points to the first unit after the last char written. 13477777dab0Sopenharmony_ci * @param targetLimit Pointer to the first unit after the target buffer. 13487777dab0Sopenharmony_ci * @param source I/O parameter, same as for ucnv_toUChars(). 13497777dab0Sopenharmony_ci * Input: *source points to the beginning of the source buffer. 13507777dab0Sopenharmony_ci * Output: *source points to the first unit after the last char read. 13517777dab0Sopenharmony_ci * @param sourceLimit Pointer to the first unit after the source buffer. 13527777dab0Sopenharmony_ci * @param pivotStart Pointer to the UTF-16 pivot buffer. If pivotStart==NULL, 13537777dab0Sopenharmony_ci * then an internal buffer is used and the other pivot 13547777dab0Sopenharmony_ci * arguments are ignored and can be NULL as well. 13557777dab0Sopenharmony_ci * @param pivotSource I/O parameter, same as source in ucnv_fromUChars() for 13567777dab0Sopenharmony_ci * conversion from the pivot buffer to the target buffer. 13577777dab0Sopenharmony_ci * @param pivotTarget I/O parameter, same as target in ucnv_toUChars() for 13587777dab0Sopenharmony_ci * conversion from the source buffer to the pivot buffer. 13597777dab0Sopenharmony_ci * It must be pivotStart<=*pivotSource<=*pivotTarget<=pivotLimit 13607777dab0Sopenharmony_ci * and pivotStart<pivotLimit (unless pivotStart==NULL). 13617777dab0Sopenharmony_ci * @param pivotLimit Pointer to the first unit after the pivot buffer. 13627777dab0Sopenharmony_ci * @param reset If true, then ucnv_resetToUnicode(sourceCnv) and 13637777dab0Sopenharmony_ci * ucnv_resetFromUnicode(targetCnv) are called, and the 13647777dab0Sopenharmony_ci * pivot pointers are reset (*pivotTarget=*pivotSource=pivotStart). 13657777dab0Sopenharmony_ci * @param flush If true, indicates the end of the input. 13667777dab0Sopenharmony_ci * Passed directly to ucnv_toUnicode(), and carried over to 13677777dab0Sopenharmony_ci * ucnv_fromUnicode() when the source is empty as well. 13687777dab0Sopenharmony_ci * @param pErrorCode ICU error code in/out parameter. 13697777dab0Sopenharmony_ci * Must fulfill U_SUCCESS before the function call. 13707777dab0Sopenharmony_ci * U_BUFFER_OVERFLOW_ERROR always refers to the target buffer 13717777dab0Sopenharmony_ci * because overflows into the pivot buffer are handled internally. 13727777dab0Sopenharmony_ci * Other conversion errors are from the source-to-pivot 13737777dab0Sopenharmony_ci * conversion if *pivotSource==pivotStart, otherwise from 13747777dab0Sopenharmony_ci * the pivot-to-target conversion. 13757777dab0Sopenharmony_ci * 13767777dab0Sopenharmony_ci * @see ucnv_convert 13777777dab0Sopenharmony_ci * @see ucnv_fromAlgorithmic 13787777dab0Sopenharmony_ci * @see ucnv_toAlgorithmic 13797777dab0Sopenharmony_ci * @see ucnv_fromUnicode 13807777dab0Sopenharmony_ci * @see ucnv_toUnicode 13817777dab0Sopenharmony_ci * @see ucnv_fromUChars 13827777dab0Sopenharmony_ci * @see ucnv_toUChars 13837777dab0Sopenharmony_ci * @stable ICU 2.6 13847777dab0Sopenharmony_ci */ 13857777dab0Sopenharmony_ciU_CAPI void U_EXPORT2 13867777dab0Sopenharmony_ciucnv_convertEx(UConverter *targetCnv, UConverter *sourceCnv, 13877777dab0Sopenharmony_ci char **target, const char *targetLimit, 13887777dab0Sopenharmony_ci const char **source, const char *sourceLimit, 13897777dab0Sopenharmony_ci UChar *pivotStart, UChar **pivotSource, 13907777dab0Sopenharmony_ci UChar **pivotTarget, const UChar *pivotLimit, 13917777dab0Sopenharmony_ci UBool reset, UBool flush, 13927777dab0Sopenharmony_ci UErrorCode *pErrorCode); 13937777dab0Sopenharmony_ci 13947777dab0Sopenharmony_ci/** 13957777dab0Sopenharmony_ci * Convert from one external charset to another. 13967777dab0Sopenharmony_ci * Internally, two converters are opened according to the name arguments, 13977777dab0Sopenharmony_ci * then the text is converted to and from the 16-bit Unicode "pivot" 13987777dab0Sopenharmony_ci * using ucnv_convertEx(), then the converters are closed again. 13997777dab0Sopenharmony_ci * 14007777dab0Sopenharmony_ci * This is a convenience function, not an efficient way to convert a lot of text: 14017777dab0Sopenharmony_ci * ucnv_convert() 14027777dab0Sopenharmony_ci * - takes charset names, not converter objects, so that 14037777dab0Sopenharmony_ci * - two converters are opened for each call 14047777dab0Sopenharmony_ci * - only single-string conversion is possible, not streaming operation 14057777dab0Sopenharmony_ci * - does not provide enough information to find out, 14067777dab0Sopenharmony_ci * in case of failure, whether the toUnicode or 14077777dab0Sopenharmony_ci * the fromUnicode conversion failed 14087777dab0Sopenharmony_ci * - allows NUL-terminated input 14097777dab0Sopenharmony_ci * (only a single NUL byte, will not work for charsets with multi-byte NULs) 14107777dab0Sopenharmony_ci * (if sourceLength==-1, see parameters) 14117777dab0Sopenharmony_ci * - terminate with a NUL on output 14127777dab0Sopenharmony_ci * (only a single NUL byte, not useful for charsets with multi-byte NULs), 14137777dab0Sopenharmony_ci * or set U_STRING_NOT_TERMINATED_WARNING if the output exactly fills 14147777dab0Sopenharmony_ci * the target buffer 14157777dab0Sopenharmony_ci * - a pivot buffer is provided internally 14167777dab0Sopenharmony_ci * 14177777dab0Sopenharmony_ci * The function returns when one of the following is true: 14187777dab0Sopenharmony_ci * - the entire source text has been converted successfully to the target buffer 14197777dab0Sopenharmony_ci * and either the target buffer is terminated with a single NUL byte 14207777dab0Sopenharmony_ci * or the error code is set to U_STRING_NOT_TERMINATED_WARNING 14217777dab0Sopenharmony_ci * - a target buffer overflow occurred (U_BUFFER_OVERFLOW_ERROR) 14227777dab0Sopenharmony_ci * and the full output string length is returned ("preflighting") 14237777dab0Sopenharmony_ci * - a conversion error occurred 14247777dab0Sopenharmony_ci * (other U_FAILURE(), see description of pErrorCode) 14257777dab0Sopenharmony_ci * 14267777dab0Sopenharmony_ci * @param toConverterName The name of the converter that is used to convert 14277777dab0Sopenharmony_ci * from the UTF-16 pivot buffer to the target. 14287777dab0Sopenharmony_ci * @param fromConverterName The name of the converter that is used to convert 14297777dab0Sopenharmony_ci * from the source to the UTF-16 pivot buffer. 14307777dab0Sopenharmony_ci * @param target Pointer to the output buffer. 14317777dab0Sopenharmony_ci * @param targetCapacity Capacity of the target, in bytes. 14327777dab0Sopenharmony_ci * @param source Pointer to the input buffer. 14337777dab0Sopenharmony_ci * @param sourceLength Length of the input text, in bytes, or -1 for NUL-terminated input. 14347777dab0Sopenharmony_ci * @param pErrorCode ICU error code in/out parameter. 14357777dab0Sopenharmony_ci * Must fulfill U_SUCCESS before the function call. 14367777dab0Sopenharmony_ci * @return Length of the complete output text in bytes, even if it exceeds the targetCapacity 14377777dab0Sopenharmony_ci * and a U_BUFFER_OVERFLOW_ERROR is set. 14387777dab0Sopenharmony_ci * 14397777dab0Sopenharmony_ci * @see ucnv_convertEx 14407777dab0Sopenharmony_ci * @see ucnv_fromAlgorithmic 14417777dab0Sopenharmony_ci * @see ucnv_toAlgorithmic 14427777dab0Sopenharmony_ci * @see ucnv_fromUnicode 14437777dab0Sopenharmony_ci * @see ucnv_toUnicode 14447777dab0Sopenharmony_ci * @see ucnv_fromUChars 14457777dab0Sopenharmony_ci * @see ucnv_toUChars 14467777dab0Sopenharmony_ci * @see ucnv_getNextUChar 14477777dab0Sopenharmony_ci * @stable ICU 2.0 14487777dab0Sopenharmony_ci */ 14497777dab0Sopenharmony_ciU_CAPI int32_t U_EXPORT2 14507777dab0Sopenharmony_ciucnv_convert(const char *toConverterName, 14517777dab0Sopenharmony_ci const char *fromConverterName, 14527777dab0Sopenharmony_ci char *target, 14537777dab0Sopenharmony_ci int32_t targetCapacity, 14547777dab0Sopenharmony_ci const char *source, 14557777dab0Sopenharmony_ci int32_t sourceLength, 14567777dab0Sopenharmony_ci UErrorCode *pErrorCode); 14577777dab0Sopenharmony_ci 14587777dab0Sopenharmony_ci/** 14597777dab0Sopenharmony_ci * Convert from one external charset to another. 14607777dab0Sopenharmony_ci * Internally, the text is converted to and from the 16-bit Unicode "pivot" 14617777dab0Sopenharmony_ci * using ucnv_convertEx(). ucnv_toAlgorithmic() works exactly like ucnv_convert() 14627777dab0Sopenharmony_ci * except that the two converters need not be looked up and opened completely. 14637777dab0Sopenharmony_ci * 14647777dab0Sopenharmony_ci * The source-to-pivot conversion uses the cnv converter parameter. 14657777dab0Sopenharmony_ci * The pivot-to-target conversion uses a purely algorithmic converter 14667777dab0Sopenharmony_ci * according to the specified type, e.g., UCNV_UTF8 for a UTF-8 converter. 14677777dab0Sopenharmony_ci * 14687777dab0Sopenharmony_ci * Internally, the algorithmic converter is opened and closed for each 14697777dab0Sopenharmony_ci * function call, which is more efficient than using the public ucnv_open() 14707777dab0Sopenharmony_ci * but somewhat less efficient than only resetting an existing converter 14717777dab0Sopenharmony_ci * and using ucnv_convertEx(). 14727777dab0Sopenharmony_ci * 14737777dab0Sopenharmony_ci * This function is more convenient than ucnv_convertEx() for single-string 14747777dab0Sopenharmony_ci * conversions, especially when "preflighting" is desired (returning the length 14757777dab0Sopenharmony_ci * of the complete output even if it does not fit into the target buffer; 14767777dab0Sopenharmony_ci * see the User Guide Strings chapter). See ucnv_convert() for details. 14777777dab0Sopenharmony_ci * 14787777dab0Sopenharmony_ci * @param algorithmicType UConverterType constant identifying the desired target 14797777dab0Sopenharmony_ci * charset as a purely algorithmic converter. 14807777dab0Sopenharmony_ci * Those are converters for Unicode charsets like 14817777dab0Sopenharmony_ci * UTF-8, BOCU-1, SCSU, UTF-7, IMAP-mailbox-name, etc., 14827777dab0Sopenharmony_ci * as well as US-ASCII and ISO-8859-1. 14837777dab0Sopenharmony_ci * @param cnv The converter that is used to convert 14847777dab0Sopenharmony_ci * from the source to the UTF-16 pivot buffer. 14857777dab0Sopenharmony_ci * @param target Pointer to the output buffer. 14867777dab0Sopenharmony_ci * @param targetCapacity Capacity of the target, in bytes. 14877777dab0Sopenharmony_ci * @param source Pointer to the input buffer. 14887777dab0Sopenharmony_ci * @param sourceLength Length of the input text, in bytes 14897777dab0Sopenharmony_ci * @param pErrorCode ICU error code in/out parameter. 14907777dab0Sopenharmony_ci * Must fulfill U_SUCCESS before the function call. 14917777dab0Sopenharmony_ci * @return Length of the complete output text in bytes, even if it exceeds the targetCapacity 14927777dab0Sopenharmony_ci * and a U_BUFFER_OVERFLOW_ERROR is set. 14937777dab0Sopenharmony_ci * 14947777dab0Sopenharmony_ci * @see ucnv_fromAlgorithmic 14957777dab0Sopenharmony_ci * @see ucnv_convert 14967777dab0Sopenharmony_ci * @see ucnv_convertEx 14977777dab0Sopenharmony_ci * @see ucnv_fromUnicode 14987777dab0Sopenharmony_ci * @see ucnv_toUnicode 14997777dab0Sopenharmony_ci * @see ucnv_fromUChars 15007777dab0Sopenharmony_ci * @see ucnv_toUChars 15017777dab0Sopenharmony_ci * @stable ICU 2.6 15027777dab0Sopenharmony_ci */ 15037777dab0Sopenharmony_ciU_CAPI int32_t U_EXPORT2 15047777dab0Sopenharmony_ciucnv_toAlgorithmic(UConverterType algorithmicType, 15057777dab0Sopenharmony_ci UConverter *cnv, 15067777dab0Sopenharmony_ci char *target, int32_t targetCapacity, 15077777dab0Sopenharmony_ci const char *source, int32_t sourceLength, 15087777dab0Sopenharmony_ci UErrorCode *pErrorCode); 15097777dab0Sopenharmony_ci 15107777dab0Sopenharmony_ci/** 15117777dab0Sopenharmony_ci * Convert from one external charset to another. 15127777dab0Sopenharmony_ci * Internally, the text is converted to and from the 16-bit Unicode "pivot" 15137777dab0Sopenharmony_ci * using ucnv_convertEx(). ucnv_fromAlgorithmic() works exactly like ucnv_convert() 15147777dab0Sopenharmony_ci * except that the two converters need not be looked up and opened completely. 15157777dab0Sopenharmony_ci * 15167777dab0Sopenharmony_ci * The source-to-pivot conversion uses a purely algorithmic converter 15177777dab0Sopenharmony_ci * according to the specified type, e.g., UCNV_UTF8 for a UTF-8 converter. 15187777dab0Sopenharmony_ci * The pivot-to-target conversion uses the cnv converter parameter. 15197777dab0Sopenharmony_ci * 15207777dab0Sopenharmony_ci * Internally, the algorithmic converter is opened and closed for each 15217777dab0Sopenharmony_ci * function call, which is more efficient than using the public ucnv_open() 15227777dab0Sopenharmony_ci * but somewhat less efficient than only resetting an existing converter 15237777dab0Sopenharmony_ci * and using ucnv_convertEx(). 15247777dab0Sopenharmony_ci * 15257777dab0Sopenharmony_ci * This function is more convenient than ucnv_convertEx() for single-string 15267777dab0Sopenharmony_ci * conversions, especially when "preflighting" is desired (returning the length 15277777dab0Sopenharmony_ci * of the complete output even if it does not fit into the target buffer; 15287777dab0Sopenharmony_ci * see the User Guide Strings chapter). See ucnv_convert() for details. 15297777dab0Sopenharmony_ci * 15307777dab0Sopenharmony_ci * @param cnv The converter that is used to convert 15317777dab0Sopenharmony_ci * from the UTF-16 pivot buffer to the target. 15327777dab0Sopenharmony_ci * @param algorithmicType UConverterType constant identifying the desired source 15337777dab0Sopenharmony_ci * charset as a purely algorithmic converter. 15347777dab0Sopenharmony_ci * Those are converters for Unicode charsets like 15357777dab0Sopenharmony_ci * UTF-8, BOCU-1, SCSU, UTF-7, IMAP-mailbox-name, etc., 15367777dab0Sopenharmony_ci * as well as US-ASCII and ISO-8859-1. 15377777dab0Sopenharmony_ci * @param target Pointer to the output buffer. 15387777dab0Sopenharmony_ci * @param targetCapacity Capacity of the target, in bytes. 15397777dab0Sopenharmony_ci * @param source Pointer to the input buffer. 15407777dab0Sopenharmony_ci * @param sourceLength Length of the input text, in bytes 15417777dab0Sopenharmony_ci * @param pErrorCode ICU error code in/out parameter. 15427777dab0Sopenharmony_ci * Must fulfill U_SUCCESS before the function call. 15437777dab0Sopenharmony_ci * @return Length of the complete output text in bytes, even if it exceeds the targetCapacity 15447777dab0Sopenharmony_ci * and a U_BUFFER_OVERFLOW_ERROR is set. 15457777dab0Sopenharmony_ci * 15467777dab0Sopenharmony_ci * @see ucnv_fromAlgorithmic 15477777dab0Sopenharmony_ci * @see ucnv_convert 15487777dab0Sopenharmony_ci * @see ucnv_convertEx 15497777dab0Sopenharmony_ci * @see ucnv_fromUnicode 15507777dab0Sopenharmony_ci * @see ucnv_toUnicode 15517777dab0Sopenharmony_ci * @see ucnv_fromUChars 15527777dab0Sopenharmony_ci * @see ucnv_toUChars 15537777dab0Sopenharmony_ci * @stable ICU 2.6 15547777dab0Sopenharmony_ci */ 15557777dab0Sopenharmony_ciU_CAPI int32_t U_EXPORT2 15567777dab0Sopenharmony_ciucnv_fromAlgorithmic(UConverter *cnv, 15577777dab0Sopenharmony_ci UConverterType algorithmicType, 15587777dab0Sopenharmony_ci char *target, int32_t targetCapacity, 15597777dab0Sopenharmony_ci const char *source, int32_t sourceLength, 15607777dab0Sopenharmony_ci UErrorCode *pErrorCode); 15617777dab0Sopenharmony_ci 15627777dab0Sopenharmony_ci/** 15637777dab0Sopenharmony_ci * Frees up memory occupied by unused, cached converter shared data. 15647777dab0Sopenharmony_ci * 15657777dab0Sopenharmony_ci * @return the number of cached converters successfully deleted 15667777dab0Sopenharmony_ci * @see ucnv_close 15677777dab0Sopenharmony_ci * @stable ICU 2.0 15687777dab0Sopenharmony_ci */ 15697777dab0Sopenharmony_ciU_CAPI int32_t U_EXPORT2 15707777dab0Sopenharmony_ciucnv_flushCache(void); 15717777dab0Sopenharmony_ci 15727777dab0Sopenharmony_ci/** 15737777dab0Sopenharmony_ci * Returns the number of available converters, as per the alias file. 15747777dab0Sopenharmony_ci * 15757777dab0Sopenharmony_ci * @return the number of available converters 15767777dab0Sopenharmony_ci * @see ucnv_getAvailableName 15777777dab0Sopenharmony_ci * @stable ICU 2.0 15787777dab0Sopenharmony_ci */ 15797777dab0Sopenharmony_ciU_CAPI int32_t U_EXPORT2 15807777dab0Sopenharmony_ciucnv_countAvailable(void); 15817777dab0Sopenharmony_ci 15827777dab0Sopenharmony_ci/** 15837777dab0Sopenharmony_ci * Gets the canonical converter name of the specified converter from a list of 15847777dab0Sopenharmony_ci * all available converters contained in the alias file. All converters 15857777dab0Sopenharmony_ci * in this list can be opened. 15867777dab0Sopenharmony_ci * 15877777dab0Sopenharmony_ci * @param n the index to a converter available on the system (in the range <TT>[0..ucnv_countAvailable()]</TT>) 15887777dab0Sopenharmony_ci * @return a pointer a string (library owned), or <TT>NULL</TT> if the index is out of bounds. 15897777dab0Sopenharmony_ci * @see ucnv_countAvailable 15907777dab0Sopenharmony_ci * @stable ICU 2.0 15917777dab0Sopenharmony_ci */ 15927777dab0Sopenharmony_ciU_CAPI const char* U_EXPORT2 15937777dab0Sopenharmony_ciucnv_getAvailableName(int32_t n); 15947777dab0Sopenharmony_ci 15957777dab0Sopenharmony_ci/** 15967777dab0Sopenharmony_ci * Returns a UEnumeration to enumerate all of the canonical converter 15977777dab0Sopenharmony_ci * names, as per the alias file, regardless of the ability to open each 15987777dab0Sopenharmony_ci * converter. 15997777dab0Sopenharmony_ci * 16007777dab0Sopenharmony_ci * @return A UEnumeration object for getting all the recognized canonical 16017777dab0Sopenharmony_ci * converter names. 16027777dab0Sopenharmony_ci * @see ucnv_getAvailableName 16037777dab0Sopenharmony_ci * @see uenum_close 16047777dab0Sopenharmony_ci * @see uenum_next 16057777dab0Sopenharmony_ci * @stable ICU 2.4 16067777dab0Sopenharmony_ci */ 16077777dab0Sopenharmony_ciU_CAPI UEnumeration * U_EXPORT2 16087777dab0Sopenharmony_ciucnv_openAllNames(UErrorCode *pErrorCode); 16097777dab0Sopenharmony_ci 16107777dab0Sopenharmony_ci/** 16117777dab0Sopenharmony_ci * Gives the number of aliases for a given converter or alias name. 16127777dab0Sopenharmony_ci * If the alias is ambiguous, then the preferred converter is used 16137777dab0Sopenharmony_ci * and the status is set to U_AMBIGUOUS_ALIAS_WARNING. 16147777dab0Sopenharmony_ci * This method only enumerates the listed entries in the alias file. 16157777dab0Sopenharmony_ci * @param alias alias name 16167777dab0Sopenharmony_ci * @param pErrorCode error status 16177777dab0Sopenharmony_ci * @return number of names on alias list for given alias 16187777dab0Sopenharmony_ci * @stable ICU 2.0 16197777dab0Sopenharmony_ci */ 16207777dab0Sopenharmony_ciU_CAPI uint16_t U_EXPORT2 16217777dab0Sopenharmony_ciucnv_countAliases(const char *alias, UErrorCode *pErrorCode); 16227777dab0Sopenharmony_ci 16237777dab0Sopenharmony_ci/** 16247777dab0Sopenharmony_ci * Gives the name of the alias at given index of alias list. 16257777dab0Sopenharmony_ci * This method only enumerates the listed entries in the alias file. 16267777dab0Sopenharmony_ci * If the alias is ambiguous, then the preferred converter is used 16277777dab0Sopenharmony_ci * and the status is set to U_AMBIGUOUS_ALIAS_WARNING. 16287777dab0Sopenharmony_ci * @param alias alias name 16297777dab0Sopenharmony_ci * @param n index in alias list 16307777dab0Sopenharmony_ci * @param pErrorCode result of operation 16317777dab0Sopenharmony_ci * @return returns the name of the alias at given index 16327777dab0Sopenharmony_ci * @see ucnv_countAliases 16337777dab0Sopenharmony_ci * @stable ICU 2.0 16347777dab0Sopenharmony_ci */ 16357777dab0Sopenharmony_ciU_CAPI const char * U_EXPORT2 16367777dab0Sopenharmony_ciucnv_getAlias(const char *alias, uint16_t n, UErrorCode *pErrorCode); 16377777dab0Sopenharmony_ci 16387777dab0Sopenharmony_ci/** 16397777dab0Sopenharmony_ci * Fill-up the list of alias names for the given alias. 16407777dab0Sopenharmony_ci * This method only enumerates the listed entries in the alias file. 16417777dab0Sopenharmony_ci * If the alias is ambiguous, then the preferred converter is used 16427777dab0Sopenharmony_ci * and the status is set to U_AMBIGUOUS_ALIAS_WARNING. 16437777dab0Sopenharmony_ci * @param alias alias name 16447777dab0Sopenharmony_ci * @param aliases fill-in list, aliases is a pointer to an array of 16457777dab0Sopenharmony_ci * <code>ucnv_countAliases()</code> string-pointers 16467777dab0Sopenharmony_ci * (<code>const char *</code>) that will be filled in. 16477777dab0Sopenharmony_ci * The strings themselves are owned by the library. 16487777dab0Sopenharmony_ci * @param pErrorCode result of operation 16497777dab0Sopenharmony_ci * @stable ICU 2.0 16507777dab0Sopenharmony_ci */ 16517777dab0Sopenharmony_ciU_CAPI void U_EXPORT2 16527777dab0Sopenharmony_ciucnv_getAliases(const char *alias, const char **aliases, UErrorCode *pErrorCode); 16537777dab0Sopenharmony_ci 16547777dab0Sopenharmony_ci/** 16557777dab0Sopenharmony_ci * Return a new UEnumeration object for enumerating all the 16567777dab0Sopenharmony_ci * alias names for a given converter that are recognized by a standard. 16577777dab0Sopenharmony_ci * This method only enumerates the listed entries in the alias file. 16587777dab0Sopenharmony_ci * The convrtrs.txt file can be modified to change the results of 16597777dab0Sopenharmony_ci * this function. 16607777dab0Sopenharmony_ci * The first result in this list is the same result given by 16617777dab0Sopenharmony_ci * <code>ucnv_getStandardName</code>, which is the default alias for 16627777dab0Sopenharmony_ci * the specified standard name. The returned object must be closed with 16637777dab0Sopenharmony_ci * <code>uenum_close</code> when you are done with the object. 16647777dab0Sopenharmony_ci * 16657777dab0Sopenharmony_ci * @param convName original converter name 16667777dab0Sopenharmony_ci * @param standard name of the standard governing the names; MIME and IANA 16677777dab0Sopenharmony_ci * are such standards 16687777dab0Sopenharmony_ci * @param pErrorCode The error code 16697777dab0Sopenharmony_ci * @return A UEnumeration object for getting all aliases that are recognized 16707777dab0Sopenharmony_ci * by a standard. If any of the parameters are invalid, NULL 16717777dab0Sopenharmony_ci * is returned. 16727777dab0Sopenharmony_ci * @see ucnv_getStandardName 16737777dab0Sopenharmony_ci * @see uenum_close 16747777dab0Sopenharmony_ci * @see uenum_next 16757777dab0Sopenharmony_ci * @stable ICU 2.2 16767777dab0Sopenharmony_ci */ 16777777dab0Sopenharmony_ciU_CAPI UEnumeration * U_EXPORT2 16787777dab0Sopenharmony_ciucnv_openStandardNames(const char *convName, 16797777dab0Sopenharmony_ci const char *standard, 16807777dab0Sopenharmony_ci UErrorCode *pErrorCode); 16817777dab0Sopenharmony_ci 16827777dab0Sopenharmony_ci/** 16837777dab0Sopenharmony_ci * Gives the number of standards associated to converter names. 16847777dab0Sopenharmony_ci * @return number of standards 16857777dab0Sopenharmony_ci * @stable ICU 2.0 16867777dab0Sopenharmony_ci */ 16877777dab0Sopenharmony_ciU_CAPI uint16_t U_EXPORT2 16887777dab0Sopenharmony_ciucnv_countStandards(void); 16897777dab0Sopenharmony_ci 16907777dab0Sopenharmony_ci/** 16917777dab0Sopenharmony_ci * Gives the name of the standard at given index of standard list. 16927777dab0Sopenharmony_ci * @param n index in standard list 16937777dab0Sopenharmony_ci * @param pErrorCode result of operation 16947777dab0Sopenharmony_ci * @return returns the name of the standard at given index. Owned by the library. 16957777dab0Sopenharmony_ci * @stable ICU 2.0 16967777dab0Sopenharmony_ci */ 16977777dab0Sopenharmony_ciU_CAPI const char * U_EXPORT2 16987777dab0Sopenharmony_ciucnv_getStandard(uint16_t n, UErrorCode *pErrorCode); 16997777dab0Sopenharmony_ci 17007777dab0Sopenharmony_ci/** 17017777dab0Sopenharmony_ci * Returns a standard name for a given converter name. 17027777dab0Sopenharmony_ci * <p> 17037777dab0Sopenharmony_ci * Example alias table:<br> 17047777dab0Sopenharmony_ci * conv alias1 { STANDARD1 } alias2 { STANDARD1* } 17057777dab0Sopenharmony_ci * <p> 17067777dab0Sopenharmony_ci * Result of ucnv_getStandardName("conv", "STANDARD1") from example 17077777dab0Sopenharmony_ci * alias table:<br> 17087777dab0Sopenharmony_ci * <b>"alias2"</b> 17097777dab0Sopenharmony_ci * 17107777dab0Sopenharmony_ci * @param name original converter name 17117777dab0Sopenharmony_ci * @param standard name of the standard governing the names; MIME and IANA 17127777dab0Sopenharmony_ci * are such standards 17137777dab0Sopenharmony_ci * @param pErrorCode result of operation 17147777dab0Sopenharmony_ci * @return returns the standard converter name; 17157777dab0Sopenharmony_ci * if a standard converter name cannot be determined, 17167777dab0Sopenharmony_ci * then <code>NULL</code> is returned. Owned by the library. 17177777dab0Sopenharmony_ci * @stable ICU 2.0 17187777dab0Sopenharmony_ci */ 17197777dab0Sopenharmony_ciU_CAPI const char * U_EXPORT2 17207777dab0Sopenharmony_ciucnv_getStandardName(const char *name, const char *standard, UErrorCode *pErrorCode); 17217777dab0Sopenharmony_ci 17227777dab0Sopenharmony_ci/** 17237777dab0Sopenharmony_ci * This function will return the internal canonical converter name of the 17247777dab0Sopenharmony_ci * tagged alias. This is the opposite of ucnv_openStandardNames, which 17257777dab0Sopenharmony_ci * returns the tagged alias given the canonical name. 17267777dab0Sopenharmony_ci * <p> 17277777dab0Sopenharmony_ci * Example alias table:<br> 17287777dab0Sopenharmony_ci * conv alias1 { STANDARD1 } alias2 { STANDARD1* } 17297777dab0Sopenharmony_ci * <p> 17307777dab0Sopenharmony_ci * Result of ucnv_getStandardName("alias1", "STANDARD1") from example 17317777dab0Sopenharmony_ci * alias table:<br> 17327777dab0Sopenharmony_ci * <b>"conv"</b> 17337777dab0Sopenharmony_ci * 17347777dab0Sopenharmony_ci * @return returns the canonical converter name; 17357777dab0Sopenharmony_ci * if a standard or alias name cannot be determined, 17367777dab0Sopenharmony_ci * then <code>NULL</code> is returned. The returned string is 17377777dab0Sopenharmony_ci * owned by the library. 17387777dab0Sopenharmony_ci * @see ucnv_getStandardName 17397777dab0Sopenharmony_ci * @stable ICU 2.4 17407777dab0Sopenharmony_ci */ 17417777dab0Sopenharmony_ciU_CAPI const char * U_EXPORT2 17427777dab0Sopenharmony_ciucnv_getCanonicalName(const char *alias, const char *standard, UErrorCode *pErrorCode); 17437777dab0Sopenharmony_ci 17447777dab0Sopenharmony_ci/** 17457777dab0Sopenharmony_ci * Returns the current default converter name. If you want to open 17467777dab0Sopenharmony_ci * a default converter, you do not need to use this function. 17477777dab0Sopenharmony_ci * It is faster if you pass a NULL argument to ucnv_open the 17487777dab0Sopenharmony_ci * default converter. 17497777dab0Sopenharmony_ci * 17507777dab0Sopenharmony_ci * If U_CHARSET_IS_UTF8 is defined to 1 in utypes.h then this function 17517777dab0Sopenharmony_ci * always returns "UTF-8". 17527777dab0Sopenharmony_ci * 17537777dab0Sopenharmony_ci * @return returns the current default converter name. 17547777dab0Sopenharmony_ci * Storage owned by the library 17557777dab0Sopenharmony_ci * @see ucnv_setDefaultName 17567777dab0Sopenharmony_ci * @stable ICU 2.0 17577777dab0Sopenharmony_ci */ 17587777dab0Sopenharmony_ciU_CAPI const char * U_EXPORT2 17597777dab0Sopenharmony_ciucnv_getDefaultName(void); 17607777dab0Sopenharmony_ci 17617777dab0Sopenharmony_ci#ifndef U_HIDE_SYSTEM_API 17627777dab0Sopenharmony_ci/** 17637777dab0Sopenharmony_ci * This function is not thread safe. DO NOT call this function when ANY ICU 17647777dab0Sopenharmony_ci * function is being used from more than one thread! This function sets the 17657777dab0Sopenharmony_ci * current default converter name. If this function needs to be called, it 17667777dab0Sopenharmony_ci * should be called during application initialization. Most of the time, the 17677777dab0Sopenharmony_ci * results from ucnv_getDefaultName() or ucnv_open with a NULL string argument 17687777dab0Sopenharmony_ci * is sufficient for your application. 17697777dab0Sopenharmony_ci * 17707777dab0Sopenharmony_ci * If U_CHARSET_IS_UTF8 is defined to 1 in utypes.h then this function 17717777dab0Sopenharmony_ci * does nothing. 17727777dab0Sopenharmony_ci * 17737777dab0Sopenharmony_ci * @param name the converter name to be the default (must be known by ICU). 17747777dab0Sopenharmony_ci * @see ucnv_getDefaultName 17757777dab0Sopenharmony_ci * @system 17767777dab0Sopenharmony_ci * @stable ICU 2.0 17777777dab0Sopenharmony_ci */ 17787777dab0Sopenharmony_ciU_CAPI void U_EXPORT2 17797777dab0Sopenharmony_ciucnv_setDefaultName(const char *name); 17807777dab0Sopenharmony_ci#endif /* U_HIDE_SYSTEM_API */ 17817777dab0Sopenharmony_ci 17827777dab0Sopenharmony_ci/** 17837777dab0Sopenharmony_ci * Fixes the backslash character mismapping. For example, in SJIS, the backslash 17847777dab0Sopenharmony_ci * character in the ASCII portion is also used to represent the yen currency sign. 17857777dab0Sopenharmony_ci * When mapping from Unicode character 0x005C, it's unclear whether to map the 17867777dab0Sopenharmony_ci * character back to yen or backslash in SJIS. This function will take the input 17877777dab0Sopenharmony_ci * buffer and replace all the yen sign characters with backslash. This is necessary 17887777dab0Sopenharmony_ci * when the user tries to open a file with the input buffer on Windows. 17897777dab0Sopenharmony_ci * This function will test the converter to see whether such mapping is 17907777dab0Sopenharmony_ci * required. You can sometimes avoid using this function by using the correct version 17917777dab0Sopenharmony_ci * of Shift-JIS. 17927777dab0Sopenharmony_ci * 17937777dab0Sopenharmony_ci * @param cnv The converter representing the target codepage. 17947777dab0Sopenharmony_ci * @param source the input buffer to be fixed 17957777dab0Sopenharmony_ci * @param sourceLen the length of the input buffer 17967777dab0Sopenharmony_ci * @see ucnv_isAmbiguous 17977777dab0Sopenharmony_ci * @stable ICU 2.0 17987777dab0Sopenharmony_ci */ 17997777dab0Sopenharmony_ciU_CAPI void U_EXPORT2 18007777dab0Sopenharmony_ciucnv_fixFileSeparator(const UConverter *cnv, UChar *source, int32_t sourceLen); 18017777dab0Sopenharmony_ci 18027777dab0Sopenharmony_ci/** 18037777dab0Sopenharmony_ci * Determines if the converter contains ambiguous mappings of the same 18047777dab0Sopenharmony_ci * character or not. 18057777dab0Sopenharmony_ci * @param cnv the converter to be tested 18067777dab0Sopenharmony_ci * @return true if the converter contains ambiguous mapping of the same 18077777dab0Sopenharmony_ci * character, false otherwise. 18087777dab0Sopenharmony_ci * @stable ICU 2.0 18097777dab0Sopenharmony_ci */ 18107777dab0Sopenharmony_ciU_CAPI UBool U_EXPORT2 18117777dab0Sopenharmony_ciucnv_isAmbiguous(const UConverter *cnv); 18127777dab0Sopenharmony_ci 18137777dab0Sopenharmony_ci/** 18147777dab0Sopenharmony_ci * Sets the converter to use fallback mappings or not. 18157777dab0Sopenharmony_ci * Regardless of this flag, the converter will always use 18167777dab0Sopenharmony_ci * fallbacks from Unicode Private Use code points, as well as 18177777dab0Sopenharmony_ci * reverse fallbacks (to Unicode). 18187777dab0Sopenharmony_ci * For details see ".ucm File Format" 18197777dab0Sopenharmony_ci * in the Conversion Data chapter of the ICU User Guide: 18207777dab0Sopenharmony_ci * https://unicode-org.github.io/icu/userguide/conversion/data.html#ucm-file-format 18217777dab0Sopenharmony_ci * 18227777dab0Sopenharmony_ci * @param cnv The converter to set the fallback mapping usage on. 18237777dab0Sopenharmony_ci * @param usesFallback true if the user wants the converter to take advantage of the fallback 18247777dab0Sopenharmony_ci * mapping, false otherwise. 18257777dab0Sopenharmony_ci * @stable ICU 2.0 18267777dab0Sopenharmony_ci * @see ucnv_usesFallback 18277777dab0Sopenharmony_ci */ 18287777dab0Sopenharmony_ciU_CAPI void U_EXPORT2 18297777dab0Sopenharmony_ciucnv_setFallback(UConverter *cnv, UBool usesFallback); 18307777dab0Sopenharmony_ci 18317777dab0Sopenharmony_ci/** 18327777dab0Sopenharmony_ci * Determines if the converter uses fallback mappings or not. 18337777dab0Sopenharmony_ci * This flag has restrictions, see ucnv_setFallback(). 18347777dab0Sopenharmony_ci * 18357777dab0Sopenharmony_ci * @param cnv The converter to be tested 18367777dab0Sopenharmony_ci * @return true if the converter uses fallback, false otherwise. 18377777dab0Sopenharmony_ci * @stable ICU 2.0 18387777dab0Sopenharmony_ci * @see ucnv_setFallback 18397777dab0Sopenharmony_ci */ 18407777dab0Sopenharmony_ciU_CAPI UBool U_EXPORT2 18417777dab0Sopenharmony_ciucnv_usesFallback(const UConverter *cnv); 18427777dab0Sopenharmony_ci 18437777dab0Sopenharmony_ci/** 18447777dab0Sopenharmony_ci * Detects Unicode signature byte sequences at the start of the byte stream 18457777dab0Sopenharmony_ci * and returns the charset name of the indicated Unicode charset. 18467777dab0Sopenharmony_ci * NULL is returned when no Unicode signature is recognized. 18477777dab0Sopenharmony_ci * The number of bytes in the signature is output as well. 18487777dab0Sopenharmony_ci * 18497777dab0Sopenharmony_ci * The caller can ucnv_open() a converter using the charset name. 18507777dab0Sopenharmony_ci * The first code unit (UChar) from the start of the stream will be U+FEFF 18517777dab0Sopenharmony_ci * (the Unicode BOM/signature character) and can usually be ignored. 18527777dab0Sopenharmony_ci * 18537777dab0Sopenharmony_ci * For most Unicode charsets it is also possible to ignore the indicated 18547777dab0Sopenharmony_ci * number of initial stream bytes and start converting after them. 18557777dab0Sopenharmony_ci * However, there are stateful Unicode charsets (UTF-7 and BOCU-1) for which 18567777dab0Sopenharmony_ci * this will not work. Therefore, it is best to ignore the first output UChar 18577777dab0Sopenharmony_ci * instead of the input signature bytes. 18587777dab0Sopenharmony_ci * <p> 18597777dab0Sopenharmony_ci * Usage: 18607777dab0Sopenharmony_ci * \snippet samples/ucnv/convsamp.cpp ucnv_detectUnicodeSignature 18617777dab0Sopenharmony_ci * 18627777dab0Sopenharmony_ci * @param source The source string in which the signature should be detected. 18637777dab0Sopenharmony_ci * @param sourceLength Length of the input string, or -1 if terminated with a NUL byte. 18647777dab0Sopenharmony_ci * @param signatureLength A pointer to int32_t to receive the number of bytes that make up the signature 18657777dab0Sopenharmony_ci * of the detected UTF. 0 if not detected. 18667777dab0Sopenharmony_ci * Can be a NULL pointer. 18677777dab0Sopenharmony_ci * @param pErrorCode ICU error code in/out parameter. 18687777dab0Sopenharmony_ci * Must fulfill U_SUCCESS before the function call. 18697777dab0Sopenharmony_ci * @return The name of the encoding detected. NULL if encoding is not detected. 18707777dab0Sopenharmony_ci * @stable ICU 2.4 18717777dab0Sopenharmony_ci */ 18727777dab0Sopenharmony_ciU_CAPI const char* U_EXPORT2 18737777dab0Sopenharmony_ciucnv_detectUnicodeSignature(const char* source, 18747777dab0Sopenharmony_ci int32_t sourceLength, 18757777dab0Sopenharmony_ci int32_t *signatureLength, 18767777dab0Sopenharmony_ci UErrorCode *pErrorCode); 18777777dab0Sopenharmony_ci 18787777dab0Sopenharmony_ci/** 18797777dab0Sopenharmony_ci * Returns the number of UChars held in the converter's internal state 18807777dab0Sopenharmony_ci * because more input is needed for completing the conversion. This function is 18817777dab0Sopenharmony_ci * useful for mapping semantics of ICU's converter interface to those of iconv, 18827777dab0Sopenharmony_ci * and this information is not needed for normal conversion. 18837777dab0Sopenharmony_ci * @param cnv The converter in which the input is held 18847777dab0Sopenharmony_ci * @param status ICU error code in/out parameter. 18857777dab0Sopenharmony_ci * Must fulfill U_SUCCESS before the function call. 18867777dab0Sopenharmony_ci * @return The number of UChars in the state. -1 if an error is encountered. 18877777dab0Sopenharmony_ci * @stable ICU 3.4 18887777dab0Sopenharmony_ci */ 18897777dab0Sopenharmony_ciU_CAPI int32_t U_EXPORT2 18907777dab0Sopenharmony_ciucnv_fromUCountPending(const UConverter* cnv, UErrorCode* status); 18917777dab0Sopenharmony_ci 18927777dab0Sopenharmony_ci/** 18937777dab0Sopenharmony_ci * Returns the number of chars held in the converter's internal state 18947777dab0Sopenharmony_ci * because more input is needed for completing the conversion. This function is 18957777dab0Sopenharmony_ci * useful for mapping semantics of ICU's converter interface to those of iconv, 18967777dab0Sopenharmony_ci * and this information is not needed for normal conversion. 18977777dab0Sopenharmony_ci * @param cnv The converter in which the input is held as internal state 18987777dab0Sopenharmony_ci * @param status ICU error code in/out parameter. 18997777dab0Sopenharmony_ci * Must fulfill U_SUCCESS before the function call. 19007777dab0Sopenharmony_ci * @return The number of chars in the state. -1 if an error is encountered. 19017777dab0Sopenharmony_ci * @stable ICU 3.4 19027777dab0Sopenharmony_ci */ 19037777dab0Sopenharmony_ciU_CAPI int32_t U_EXPORT2 19047777dab0Sopenharmony_ciucnv_toUCountPending(const UConverter* cnv, UErrorCode* status); 19057777dab0Sopenharmony_ci 19067777dab0Sopenharmony_ci/** 19077777dab0Sopenharmony_ci * Returns whether or not the charset of the converter has a fixed number of bytes 19087777dab0Sopenharmony_ci * per charset character. 19097777dab0Sopenharmony_ci * An example of this are converters that are of the type UCNV_SBCS or UCNV_DBCS. 19107777dab0Sopenharmony_ci * Another example is UTF-32 which is always 4 bytes per character. 19117777dab0Sopenharmony_ci * A Unicode code point may be represented by more than one UTF-8 or UTF-16 code unit 19127777dab0Sopenharmony_ci * but a UTF-32 converter encodes each code point with 4 bytes. 19137777dab0Sopenharmony_ci * Note: This method is not intended to be used to determine whether the charset has a 19147777dab0Sopenharmony_ci * fixed ratio of bytes to Unicode codes <i>units</i> for any particular Unicode encoding form. 19157777dab0Sopenharmony_ci * false is returned with the UErrorCode if error occurs or cnv is NULL. 19167777dab0Sopenharmony_ci * @param cnv The converter to be tested 19177777dab0Sopenharmony_ci * @param status ICU error code in/out parameter 19187777dab0Sopenharmony_ci * @return true if the converter is fixed-width 19197777dab0Sopenharmony_ci * @stable ICU 4.8 19207777dab0Sopenharmony_ci */ 19217777dab0Sopenharmony_ciU_CAPI UBool U_EXPORT2 19227777dab0Sopenharmony_ciucnv_isFixedWidth(UConverter *cnv, UErrorCode *status); 19237777dab0Sopenharmony_ci 19247777dab0Sopenharmony_ci#endif 19257777dab0Sopenharmony_ci 19267777dab0Sopenharmony_ci#endif 19277777dab0Sopenharmony_ci/*_UCNV*/ 1928