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