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