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