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