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