2 **********************************************************************
3 * Copyright (C) 1999-2006, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
7 * External APIs for the ICU's codeset conversion library
10 * Modification History:
12 * Date Name Description
13 * 04/04/99 helena Fixed internal header inclusion.
14 * 05/11/00 helena Added setFallback and usesFallback APIs.
15 * 06/29/2000 helena Major rewrite of the callback APIs.
16 * 12/07/2000 srl Update of documentation
21 * \brief C API: Character conversion
23 * <h2>Character Conversion C API</h2>
25 * <p>This API is used to convert codepage or character encoded data to and
26 * from UTF-16. You can open a converter with {@link ucnv_open() }. With that
27 * converter, you can get its properties, set options, convert your data and
28 * close the converter.</p>
30 * <p>Since many software programs recogize different converter names for
31 * different types of converters, there are other functions in this API to
32 * iterate over the converter aliases. The functions {@link ucnv_getAvailableName() },
33 * {@link ucnv_getAlias() } and {@link ucnv_getStandardName() } are some of the
34 * more frequently used alias functions to get this information.</p>
36 * <p>When a converter encounters an illegal, irregular, invalid or unmappable character
37 * its default behavior is to use a substitution character to replace the
38 * bad byte sequence. This behavior can be changed by using {@link ucnv_setFromUCallBack() }
39 * or {@link ucnv_setToUCallBack() } on the converter. The header ucnv_err.h defines
40 * many other callback actions that can be used instead of a character substitution.</p>
42 * <p>More information about this API can be found in our
43 * <a href="http://icu.sourceforge.net/userguide/conversion.html">User's
50 #include "unicode/ucnv_err.h"
51 #include "unicode/uenum.h"
56 * USet is the C API type for Unicode sets.
57 * It is forward-declared here to avoid including the header file if related
58 * conversion APIs are not used.
61 * @see ucnv_getUnicodeSet
65 /** @stable ICU 2.6 */
66 typedef struct USet USet
;
70 #if !UCONFIG_NO_CONVERSION
74 /** Maximum length of a converter name including the terminating NULL @stable ICU 2.0 */
75 #define UCNV_MAX_CONVERTER_NAME_LENGTH 60
76 /** Maximum length of a converter name including path and terminating NULL @stable ICU 2.0 */
77 #define UCNV_MAX_FULL_FILE_NAME_LENGTH (600+UCNV_MAX_CONVERTER_NAME_LENGTH)
79 /** Shift in for EBDCDIC_STATEFUL and iso2022 states @stable ICU 2.0 */
81 /** Shift out for EBDCDIC_STATEFUL and iso2022 states @stable ICU 2.0 */
85 * Enum for specifying basic types of converters
90 UCNV_UNSUPPORTED_CONVERTER
= -1,
96 UCNV_UTF16_BigEndian
= 5,
97 UCNV_UTF16_LittleEndian
= 6,
98 UCNV_UTF32_BigEndian
= 7,
99 UCNV_UTF32_LittleEndian
= 8,
100 UCNV_EBCDIC_STATEFUL
= 9,
115 UCNV_LMBCS_LAST
= UCNV_LMBCS_19
,
127 /* Number of converter types for which we have conversion routines. */
128 UCNV_NUMBER_OF_SUPPORTED_CONVERTER_TYPES
133 * Enum for specifying which platform a converter ID refers to.
134 * The use of platform/CCSID is not recommended. See ucnv_openCCSID().
136 * @see ucnv_getPlatform
137 * @see ucnv_openCCSID
144 } UConverterPlatform
;
147 * Function pointer for error callback in the codepage to unicode direction.
148 * Called when an error has occured in conversion to unicode, or on open/close of the callback (see reason).
149 * @param context Pointer to the callback's private data
150 * @param args Information about the conversion in progress
151 * @param codeUnits Points to 'length' bytes of the concerned codepage sequence
152 * @param length Size (in bytes) of the concerned codepage sequence
153 * @param reason Defines the reason the callback was invoked
154 * @param pErrorCode ICU error code in/out parameter.
155 * For converter callback functions, set to a conversion error
156 * before the call, and the callback may reset it to U_ZERO_ERROR.
157 * @see ucnv_setToUCallBack
158 * @see UConverterToUnicodeArgs
161 typedef void (U_EXPORT2
*UConverterToUCallback
) (
163 UConverterToUnicodeArgs
*args
,
164 const char *codeUnits
,
166 UConverterCallbackReason reason
,
167 UErrorCode
*pErrorCode
);
170 * Function pointer for error callback in the unicode to codepage direction.
171 * Called when an error has occured in conversion from unicode, or on open/close of the callback (see reason).
172 * @param context Pointer to the callback's private data
173 * @param args Information about the conversion in progress
174 * @param codeUnits Points to 'length' UChars of the concerned Unicode sequence
175 * @param length Size (in bytes) of the concerned codepage sequence
176 * @param codePoint Single UChar32 (UTF-32) containing the concerend Unicode codepoint.
177 * @param reason Defines the reason the callback was invoked
178 * @param pErrorCode ICU error code in/out parameter.
179 * For converter callback functions, set to a conversion error
180 * before the call, and the callback may reset it to U_ZERO_ERROR.
181 * @see ucnv_setFromUCallBack
184 typedef void (U_EXPORT2
*UConverterFromUCallback
) (
186 UConverterFromUnicodeArgs
*args
,
187 const UChar
* codeUnits
,
190 UConverterCallbackReason reason
,
191 UErrorCode
*pErrorCode
);
196 * Character that separates converter names from options and options from each other.
200 #define UCNV_OPTION_SEP_CHAR ','
203 * String version of UCNV_OPTION_SEP_CHAR.
207 #define UCNV_OPTION_SEP_STRING ","
210 * Character that separates a converter option from its value.
214 #define UCNV_VALUE_SEP_CHAR '='
217 * String version of UCNV_VALUE_SEP_CHAR.
221 #define UCNV_VALUE_SEP_STRING "="
224 * Converter option for specifying a locale.
225 * For example, ucnv_open("SCSU,locale=ja", &errorCode);
231 #define UCNV_LOCALE_OPTION_STRING ",locale="
234 * Converter option for specifying a version selector (0..9) for some converters.
235 * For example, ucnv_open("UTF-7,version=1", &errorCode);
241 #define UCNV_VERSION_OPTION_STRING ",version="
244 * Converter option for EBCDIC SBCS or mixed-SBCS/DBCS (stateful) codepages.
245 * Swaps Unicode mappings for EBCDIC LF and NL codes, as used on
246 * S/390 (z/OS) Unix System Services (Open Edition).
247 * For example, ucnv_open("ibm-1047,swaplfnl", &errorCode);
253 #define UCNV_SWAP_LFNL_OPTION_STRING ",swaplfnl"
256 * Do a fuzzy compare of two converter/alias names.
257 * The comparison is case-insensitive, ignores leading zeroes if they are not
258 * followed by further digits, and ignores all but letters and digits.
259 * Thus the strings "UTF-8", "utf_8", "u*T@f08" and "Utf 8" are exactly equivalent.
260 * See section 1.4, Charset Alias Matching in Unicode Technical Standard #22
261 * at http://www.unicode.org/reports/tr22/
263 * @param name1 a converter name or alias, zero-terminated
264 * @param name2 a converter name or alias, zero-terminated
265 * @return 0 if the names match, or a negative value if the name1
266 * lexically precedes name2, or a positive value if the name1
267 * lexically follows name2.
270 U_STABLE
int U_EXPORT2
271 ucnv_compareNames(const char *name1
, const char *name2
);
275 * Creates a UConverter object with the name of a coded character set specified as a C string.
276 * The actual name will be resolved with the alias file
277 * using a case-insensitive string comparison that ignores
278 * leading zeroes and all non-alphanumeric characters.
279 * E.g., the names "UTF8", "utf-8", "u*T@f08" and "Utf 8" are all equivalent.
280 * (See also ucnv_compareNames().)
281 * If <code>NULL</code> is passed for the converter name, it will create one with the
282 * getDefaultName return value.
284 * <p>A converter name for ICU 1.5 and above may contain options
285 * like a locale specification to control the specific behavior of
286 * the newly instantiated converter.
287 * The meaning of the options depends on the particular converter.
288 * If an option is not defined for or recognized by a given converter, then it is ignored.</p>
290 * <p>Options are appended to the converter name string, with a
291 * <code>UCNV_OPTION_SEP_CHAR</code> between the name and the first option and
292 * also between adjacent options.</p>
294 * <p>If the alias is ambiguous, then the preferred converter is used
295 * and the status is set to U_AMBIGUOUS_ALIAS_WARNING.</p>
297 * <p>The conversion behavior and names can vary between platforms. ICU may
298 * convert some characters differently from other platforms. Details on this topic
299 * are in the <a href="http://icu.sourceforge.net/userguide/conversion.html">User's
300 * Guide</a>. Aliases starting with a "cp" prefix have no specific meaning
301 * other than its an alias starting with the letters "cp". Please do not
302 * associate any meaning to these aliases.</p>
304 * @param converterName Name of the coded character set table.
305 * This may have options appended to the string.
306 * IANA alias character set names, IBM CCSIDs starting with "ibm-",
307 * Windows codepage numbers starting with "windows-" are frequently
308 * used for this parameter. See ucnv_getAvailableName and
309 * ucnv_getAlias for a complete list that is available.
310 * If this parameter is NULL, the default converter will be used.
311 * @param err outgoing error status <TT>U_MEMORY_ALLOCATION_ERROR, U_FILE_ACCESS_ERROR</TT>
312 * @return the created Unicode converter object, or <TT>NULL</TT> if an error occured
314 * @see ucnv_openCCSID
315 * @see ucnv_getAvailableName
317 * @see ucnv_getDefaultName
319 * @ee ucnv_compareNames
322 U_STABLE UConverter
* U_EXPORT2
323 ucnv_open(const char *converterName
, UErrorCode
*err
);
327 * Creates a Unicode converter with the names specified as unicode string.
328 * The name should be limited to the ASCII-7 alphanumerics range.
329 * The actual name will be resolved with the alias file
330 * using a case-insensitive string comparison that ignores
331 * leading zeroes and all non-alphanumeric characters.
332 * E.g., the names "UTF8", "utf-8", "u*T@f08" and "Utf 8" are all equivalent.
333 * (See also ucnv_compareNames().)
334 * If <TT>NULL</TT> is passed for the converter name, it will create
335 * one with the ucnv_getDefaultName() return value.
336 * If the alias is ambiguous, then the preferred converter is used
337 * and the status is set to U_AMBIGUOUS_ALIAS_WARNING.
339 * <p>See ucnv_open for the complete details</p>
340 * @param name Name of the UConverter table in a zero terminated
342 * @param err outgoing error status <TT>U_MEMORY_ALLOCATION_ERROR,
343 * U_FILE_ACCESS_ERROR</TT>
344 * @return the created Unicode converter object, or <TT>NULL</TT> if an
347 * @see ucnv_openCCSID
349 * @ee ucnv_compareNames
352 U_STABLE UConverter
* U_EXPORT2
353 ucnv_openU(const UChar
*name
,
357 * Creates a UConverter object from a CCSID number and platform pair.
358 * Note that the usefulness of this function is limited to platforms with numeric
359 * encoding IDs. Only IBM and Microsoft platforms use numeric (16-bit) identifiers for
362 * In addition, IBM CCSIDs and Unicode conversion tables are not 1:1 related.
363 * For many IBM CCSIDs there are multiple (up to six) Unicode conversion tables, and
364 * for some Unicode conversion tables there are multiple CCSIDs.
365 * Some "alternate" Unicode conversion tables are provided by the
366 * IBM CDRA conversion table registry.
367 * The most prominent example of a systematic modification of conversion tables that is
368 * not provided in the form of conversion table files in the repository is
369 * that S/390 Unix System Services swaps the codes for Line Feed and New Line in all
370 * EBCDIC codepages, which requires such a swap in the Unicode conversion tables as well.
372 * Only IBM default conversion tables are accessible with ucnv_openCCSID().
373 * ucnv_getCCSID() will return the same CCSID for all conversion tables that are associated
376 * Currently, the only "platform" supported in the ICU converter API is UCNV_IBM.
378 * In summary, the use of CCSIDs and the associated API functions is not recommended.
380 * In order to open a converter with the default IBM CDRA Unicode conversion table,
381 * you can use this function or use the prefix "ibm-":
384 * sprintf(name, "ibm-%hu", ccsid);
385 * cnv=ucnv_open(name, &errorCode);
388 * In order to open a converter with the IBM S/390 Unix System Services variant
389 * of a Unicode/EBCDIC conversion table,
390 * you can use the prefix "ibm-" together with the option string UCNV_SWAP_LFNL_OPTION_STRING:
393 * sprintf(name, "ibm-%hu" UCNV_SWAP_LFNL_OPTION_STRING, ccsid);
394 * cnv=ucnv_open(name, &errorCode);
397 * In order to open a converter from a Microsoft codepage number, use the prefix "cp":
400 * sprintf(name, "cp%hu", codepageID);
401 * cnv=ucnv_open(name, &errorCode);
404 * If the alias is ambiguous, then the preferred converter is used
405 * and the status is set to U_AMBIGUOUS_ALIAS_WARNING.
407 * @param codepage codepage number to create
408 * @param platform the platform in which the codepage number exists
409 * @param err error status <TT>U_MEMORY_ALLOCATION_ERROR, U_FILE_ACCESS_ERROR</TT>
410 * @return the created Unicode converter object, or <TT>NULL</TT> if an error
416 * @see ucnv_getPlatform
417 * @see UConverterPlatform
420 U_STABLE UConverter
* U_EXPORT2
421 ucnv_openCCSID(int32_t codepage
,
422 UConverterPlatform platform
,
426 * <p>Creates a UConverter object specified from a packageName and a converterName.</p>
428 * <p>The packageName and converterName must point to an ICU udata object, as defined by
429 * <code> udata_open( packageName, "cnv", converterName, err) </code> or equivalent.
430 * Typically, packageName will refer to a (.dat) file, or to a package registered with
431 * udata_setAppData(). Using a full file or directory pathname for packageName is deprecated.</p>
433 * <p>The name will NOT be looked up in the alias mechanism, nor will the converter be
434 * stored in the converter cache or the alias table. The only way to open further converters
435 * is call this function multiple times, or use the ucnv_safeClone() function to clone a
436 * 'master' converter.</p>
438 * <p>A future version of ICU may add alias table lookups and/or caching
439 * to this function.</p>
442 * <code>cnv = ucnv_openPackage("myapp", "myconverter", &err);</code>
445 * @param packageName name of the package (equivalent to 'path' in udata_open() call)
446 * @param converterName name of the data item to be used, without suffix.
447 * @param err outgoing error status <TT>U_MEMORY_ALLOCATION_ERROR, U_FILE_ACCESS_ERROR</TT>
448 * @return the created Unicode converter object, or <TT>NULL</TT> if an error occured
451 * @see ucnv_safeClone
455 U_STABLE UConverter
* U_EXPORT2
456 ucnv_openPackage(const char *packageName
, const char *converterName
, UErrorCode
*err
);
459 * Thread safe converter cloning operation.
460 * For most efficient operation, pass in a stackBuffer (and a *pBufferSize)
461 * with at least U_CNV_SAFECLONE_BUFFERSIZE bytes of space.
462 * If the buffer size is sufficient, then the clone will use the stack buffer;
463 * otherwise, it will be allocated, and *pBufferSize will indicate
464 * the actual size. (This should not occur with U_CNV_SAFECLONE_BUFFERSIZE.)
466 * You must ucnv_close() the clone in any case.
468 * If *pBufferSize==0, (regardless of whether stackBuffer==NULL or not)
469 * then *pBufferSize will be changed to a sufficient size
470 * for cloning this converter,
471 * without actually cloning the converter ("pure pre-flighting").
473 * If *pBufferSize is greater than zero but not large enough for a stack-based
474 * clone, then the converter is cloned using newly allocated memory
475 * and *pBufferSize is changed to the necessary size.
477 * If the converter clone fits into the stack buffer but the stack buffer is not
478 * sufficiently aligned for the clone, then the clone will use an
479 * adjusted pointer and use an accordingly smaller buffer size.
481 * @param cnv converter to be cloned
482 * @param stackBuffer user allocated space for the new clone. If NULL new memory will be allocated.
483 * If buffer is not large enough, new memory will be allocated.
484 * Clients can use the U_CNV_SAFECLONE_BUFFERSIZE. This will probably be enough to avoid memory allocations.
485 * @param pBufferSize pointer to size of allocated space. pBufferSize must not be NULL.
486 * @param status to indicate whether the operation went on smoothly or there were errors
487 * An informational status value, U_SAFECLONE_ALLOCATED_WARNING,
488 * is used if any allocations were necessary.
489 * However, it is better to check if *pBufferSize grew for checking for
490 * allocations because warning codes can be overridden by subsequent
492 * @return pointer to the new clone
495 U_STABLE UConverter
* U_EXPORT2
496 ucnv_safeClone(const UConverter
*cnv
,
498 int32_t *pBufferSize
,
502 * \def U_CNV_SAFECLONE_BUFFERSIZE
503 * Definition of a buffer size that is designed to be large enough for
504 * converters to be cloned with ucnv_safeClone().
507 #define U_CNV_SAFECLONE_BUFFERSIZE 1024
510 * Deletes the unicode converter and releases resources associated
511 * with just this instance.
512 * Does not free up shared converter tables.
514 * @param converter the converter object to be deleted
517 * @see ucnv_openCCSID
520 U_STABLE
void U_EXPORT2
521 ucnv_close(UConverter
* converter
);
524 * Fills in the output parameter, subChars, with the substitution characters
526 * If ucnv_setSubstString() set a Unicode string because the converter is
527 * stateful, then subChars will be an empty string.
529 * @param converter the Unicode converter
530 * @param subChars the subsitution characters
531 * @param len on input the capacity of subChars, on output the number
532 * of bytes copied to it
533 * @param err the outgoing error status code.
534 * If the substitution character array is too small, an
535 * <TT>U_INDEX_OUTOFBOUNDS_ERROR</TT> will be returned.
536 * @see ucnv_setSubstString
537 * @see ucnv_setSubstChars
540 U_STABLE
void U_EXPORT2
541 ucnv_getSubstChars(const UConverter
*converter
,
547 * Sets the substitution chars when converting from unicode to a codepage. The
548 * substitution is specified as a string of 1-4 bytes, and may contain
549 * <TT>NULL</TT> bytes.
550 * The subChars must represent a single character. The caller needs to know the
551 * byte sequence of a valid character in the converter's charset.
552 * For some converters, for example some ISO 2022 variants, only single-byte
553 * substitution characters may be supported.
554 * The newer ucnv_setSubstString() function relaxes these limitations.
556 * @param converter the Unicode converter
557 * @param subChars the substitution character byte sequence we want set
558 * @param len the number of bytes in subChars
559 * @param err the error status code. <TT>U_INDEX_OUTOFBOUNDS_ERROR </TT> if
560 * len is bigger than the maximum number of bytes allowed in subchars
561 * @see ucnv_setSubstString
562 * @see ucnv_getSubstChars
565 U_STABLE
void U_EXPORT2
566 ucnv_setSubstChars(UConverter
*converter
,
567 const char *subChars
,
572 * Set a substitution string for converting from Unicode to a charset.
573 * The caller need not know the charset byte sequence for each charset.
575 * Unlike ucnv_setSubstChars() which is designed to set a charset byte sequence
576 * for a single character, this function takes a Unicode string with
577 * zero, one or more characters, and immediately verifies that the string can be
578 * converted to the charset.
579 * If not, or if the result is too long (more than 32 bytes as of ICU 3.6),
580 * then the function returns with an error accordingly.
582 * Also unlike ucnv_setSubstChars(), this function works for stateful charsets
583 * by converting on the fly at the point of substitution rather than setting
584 * a fixed byte sequence.
586 * @param cnv The UConverter object.
587 * @param s The Unicode string.
588 * @param length The number of UChars in s, or -1 for a NUL-terminated string.
589 * @param err Pointer to a standard ICU error code. Its input value must
590 * pass the U_SUCCESS() test, or else the function returns
591 * immediately. Check for U_FAILURE() on output or use with
592 * function chaining. (See User Guide for details.)
594 * @see ucnv_setSubstChars
595 * @see ucnv_getSubstChars
598 U_DRAFT
void U_EXPORT2
599 ucnv_setSubstString(UConverter
*cnv
,
605 * Fills in the output parameter, errBytes, with the error characters from the
606 * last failing conversion.
608 * @param converter the Unicode converter
609 * @param errBytes the codepage bytes which were in error
610 * @param len on input the capacity of errBytes, on output the number of
611 * bytes which were copied to it
612 * @param err the error status code.
613 * If the substitution character array is too small, an
614 * <TT>U_INDEX_OUTOFBOUNDS_ERROR</TT> will be returned.
617 U_STABLE
void U_EXPORT2
618 ucnv_getInvalidChars(const UConverter
*converter
,
624 * Fills in the output parameter, errChars, with the error characters from the
625 * last failing conversion.
627 * @param converter the Unicode converter
628 * @param errUChars the UChars which were in error
629 * @param len on input the capacity of errUChars, on output the number of
630 * UChars which were copied to it
631 * @param err the error status code.
632 * If the substitution character array is too small, an
633 * <TT>U_INDEX_OUTOFBOUNDS_ERROR</TT> will be returned.
636 U_STABLE
void U_EXPORT2
637 ucnv_getInvalidUChars(const UConverter
*converter
,
643 * Resets the state of a converter to the default state. This is used
644 * in the case of an error, to restart a conversion from a known default state.
645 * It will also empty the internal output buffers.
646 * @param converter the Unicode converter
649 U_STABLE
void U_EXPORT2
650 ucnv_reset(UConverter
*converter
);
653 * Resets the to-Unicode part of a converter state to the default state.
654 * This is used in the case of an error to restart a conversion to
655 * Unicode to a known default state. It will also empty the internal
656 * output buffers used for the conversion to Unicode codepoints.
657 * @param converter the Unicode converter
660 U_STABLE
void U_EXPORT2
661 ucnv_resetToUnicode(UConverter
*converter
);
664 * Resets the from-Unicode part of a converter state to the default state.
665 * This is used in the case of an error to restart a conversion from
666 * Unicode to a known default state. It will also empty the internal output
667 * buffers used for the conversion from Unicode codepoints.
668 * @param converter the Unicode converter
671 U_STABLE
void U_EXPORT2
672 ucnv_resetFromUnicode(UConverter
*converter
);
675 * Returns the maximum number of bytes that are output per UChar in conversion
676 * from Unicode using this converter.
677 * The returned number can be used with UCNV_GET_MAX_BYTES_FOR_STRING
678 * to calculate the size of a target buffer for conversion from Unicode.
680 * Note: Before ICU 2.8, this function did not return reliable numbers for
681 * some stateful converters (EBCDIC_STATEFUL, ISO-2022) and LMBCS.
683 * This number may not be the same as the maximum number of bytes per
684 * "conversion unit". In other words, it may not be the intuitively expected
685 * number of bytes per character that would be published for a charset,
686 * and may not fulfill any other purpose than the allocation of an output
687 * buffer of guaranteed sufficient size for a given input length and converter.
689 * Examples for special cases that are taken into account:
690 * - Supplementary code points may convert to more bytes than BMP code points.
691 * This function returns bytes per UChar (UTF-16 code unit), not per
692 * Unicode code point, for efficient buffer allocation.
693 * - State-shifting output (SI/SO, escapes, etc.) from stateful converters.
694 * - When m input UChars are converted to n output bytes, then the maximum m/n
695 * is taken into account.
697 * The number returned here does not take into account
698 * (see UCNV_GET_MAX_BYTES_FOR_STRING):
699 * - callbacks which output more than one charset character sequence per call,
700 * like escape callbacks
701 * - initial and final non-character bytes that are output by some converters
702 * (automatic BOMs, initial escape sequence, final SI, etc.)
704 * Examples for returned values:
707 * - UTF-16: 2 (2 per BMP, 4 per surrogate _pair_, BOM not counted)
708 * - UTF-8: 3 (3 per BMP, 4 per surrogate _pair_)
709 * - EBCDIC_STATEFUL (EBCDIC mixed SBCS/DBCS): 3 (SO + DBCS)
710 * - ISO-2022: 3 (always outputs UTF-8)
711 * - ISO-2022-JP: 6 (4-byte escape sequences + DBCS)
712 * - ISO-2022-CN: 8 (4-byte designator sequences + 2-byte SS2/SS3 + DBCS)
714 * @param converter The Unicode converter.
715 * @return The maximum number of bytes per UChar that are output by ucnv_fromUnicode(),
716 * to be used together with UCNV_GET_MAX_BYTES_FOR_STRING for buffer allocation.
718 * @see UCNV_GET_MAX_BYTES_FOR_STRING
719 * @see ucnv_getMinCharSize
722 U_STABLE
int8_t U_EXPORT2
723 ucnv_getMaxCharSize(const UConverter
*converter
);
726 * Calculates the size of a buffer for conversion from Unicode to a charset.
727 * The calculated size is guaranteed to be sufficient for this conversion.
729 * It takes into account initial and final non-character bytes that are output
730 * by some converters.
731 * It does not take into account callbacks which output more than one charset
732 * character sequence per call, like escape callbacks.
733 * The default (substitution) callback only outputs one charset character sequence.
735 * @param length Number of UChars to be converted.
736 * @param maxCharSize Return value from ucnv_getMaxCharSize() for the converter
738 * @return Size of a buffer that will be large enough to hold the output bytes of
739 * converting length UChars with the converter that returned the maxCharSize.
741 * @see ucnv_getMaxCharSize
744 #define UCNV_GET_MAX_BYTES_FOR_STRING(length, maxCharSize) \
745 (((int32_t)(length)+10)*(int32_t)(maxCharSize))
748 * Returns the minimum byte length for characters in this codepage.
749 * This is usually either 1 or 2.
750 * @param converter the Unicode converter
751 * @return the minimum number of bytes allowed by this particular converter
752 * @see ucnv_getMaxCharSize
755 U_STABLE
int8_t U_EXPORT2
756 ucnv_getMinCharSize(const UConverter
*converter
);
759 * Returns the display name of the converter passed in based on the Locale
760 * passed in. If the locale contains no display name, the internal ASCII
761 * name will be filled in.
763 * @param converter the Unicode converter.
764 * @param displayLocale is the specific Locale we want to localised for
765 * @param displayName user provided buffer to be filled in
766 * @param displayNameCapacity size of displayName Buffer
767 * @param err error status code
768 * @return displayNameLength number of UChar needed in displayName
772 U_STABLE
int32_t U_EXPORT2
773 ucnv_getDisplayName(const UConverter
*converter
,
774 const char *displayLocale
,
776 int32_t displayNameCapacity
,
780 * Gets the internal, canonical name of the converter (zero-terminated).
781 * The lifetime of the returned string will be that of the converter
782 * passed to this function.
783 * @param converter the Unicode converter
784 * @param err UErrorCode status
785 * @return the internal name of the converter
786 * @see ucnv_getDisplayName
789 U_STABLE
const char * U_EXPORT2
790 ucnv_getName(const UConverter
*converter
, UErrorCode
*err
);
793 * Gets a codepage number associated with the converter. This is not guaranteed
794 * to be the one used to create the converter. Some converters do not represent
795 * platform registered codepages and return zero for the codepage number.
796 * The error code fill-in parameter indicates if the codepage number
798 * Does not check if the converter is <TT>NULL</TT> or if converter's data
799 * table is <TT>NULL</TT>.
801 * Important: The use of CCSIDs is not recommended because it is limited
802 * to only two platforms in principle and only one (UCNV_IBM) in the current
804 * Also, CCSIDs are insufficient to identify IBM Unicode conversion tables precisely.
805 * For more details see ucnv_openCCSID().
807 * @param converter the Unicode converter
808 * @param err the error status code.
809 * @return If any error occurrs, -1 will be returned otherwise, the codepage number
811 * @see ucnv_openCCSID
812 * @see ucnv_getPlatform
815 U_STABLE
int32_t U_EXPORT2
816 ucnv_getCCSID(const UConverter
*converter
,
820 * Gets a codepage platform associated with the converter. Currently,
821 * only <TT>UCNV_IBM</TT> will be returned.
822 * Does not test if the converter is <TT>NULL</TT> or if converter's data
823 * table is <TT>NULL</TT>.
824 * @param converter the Unicode converter
825 * @param err the error status code.
826 * @return The codepage platform
829 U_STABLE UConverterPlatform U_EXPORT2
830 ucnv_getPlatform(const UConverter
*converter
,
834 * Gets the type of the converter
835 * e.g. SBCS, MBCS, DBCS, UTF8, UTF16_BE, UTF16_LE, ISO_2022,
836 * EBCDIC_STATEFUL, LATIN_1
837 * @param converter a valid, opened converter
838 * @return the type of the converter
841 U_STABLE UConverterType U_EXPORT2
842 ucnv_getType(const UConverter
* converter
);
845 * Gets the "starter" (lead) bytes for converters of type MBCS.
846 * Will fill in an <TT>U_ILLEGAL_ARGUMENT_ERROR</TT> if converter passed in
847 * is not MBCS. Fills in an array of type UBool, with the value of the byte
848 * as offset to the array. For example, if (starters[0x20] == TRUE) at return,
849 * it means that the byte 0x20 is a starter byte in this converter.
850 * Context pointers are always owned by the caller.
852 * @param converter a valid, opened converter of type MBCS
853 * @param starters an array of size 256 to be filled in
854 * @param err error status, <TT>U_ILLEGAL_ARGUMENT_ERROR</TT> if the
855 * converter is not a type which can return starters.
859 U_STABLE
void U_EXPORT2
860 ucnv_getStarters(const UConverter
* converter
,
866 * Selectors for Unicode sets that can be returned by ucnv_getUnicodeSet().
867 * @see ucnv_getUnicodeSet
870 typedef enum UConverterUnicodeSet
{
871 /** Select the set of roundtrippable Unicode code points. @stable ICU 2.6 */
873 /** Number of UConverterUnicodeSet selectors. @stable ICU 2.6 */
875 } UConverterUnicodeSet
;
879 * Returns the set of Unicode code points that can be converted by an ICU converter.
881 * The current implementation returns only one kind of set (UCNV_ROUNDTRIP_SET):
882 * The set of all Unicode code points that can be roundtrip-converted
883 * (converted without any data loss) with the converter.
884 * This set will not include code points that have fallback mappings
885 * or are only the result of reverse fallback mappings.
886 * See UTR #22 "Character Mapping Markup Language"
887 * at http://www.unicode.org/reports/tr22/
889 * This is useful for example for
890 * - checking that a string or document can be roundtrip-converted with a converter,
891 * without/before actually performing the conversion
892 * - testing if a converter can be used for text for typical text for a certain locale,
893 * by comparing its roundtrip set with the set of ExemplarCharacters from
894 * ICU's locale data or other sources
896 * In the future, there may be more UConverterUnicodeSet choices to select
897 * sets with different properties.
899 * @param cnv The converter for which a set is requested.
900 * @param setFillIn A valid USet *. It will be cleared by this function before
901 * the converter's specific set is filled into the USet.
902 * @param whichSet A UConverterUnicodeSet selector;
903 * currently UCNV_ROUNDTRIP_SET is the only supported value.
904 * @param pErrorCode ICU error code in/out parameter.
905 * Must fulfill U_SUCCESS before the function call.
907 * @see UConverterUnicodeSet
912 U_STABLE
void U_EXPORT2
913 ucnv_getUnicodeSet(const UConverter
*cnv
,
915 UConverterUnicodeSet whichSet
,
916 UErrorCode
*pErrorCode
);
919 * Gets the current calback function used by the converter when an illegal
920 * or invalid codepage sequence is found.
921 * Context pointers are always owned by the caller.
923 * @param converter the unicode converter
924 * @param action fillin: returns the callback function pointer
925 * @param context fillin: returns the callback's private void* context
926 * @see ucnv_setToUCallBack
929 U_STABLE
void U_EXPORT2
930 ucnv_getToUCallBack (const UConverter
* converter
,
931 UConverterToUCallback
*action
,
932 const void **context
);
935 * Gets the current callback function used by the converter when illegal
936 * or invalid Unicode sequence is found.
937 * Context pointers are always owned by the caller.
939 * @param converter the unicode converter
940 * @param action fillin: returns the callback function pointer
941 * @param context fillin: returns the callback's private void* context
942 * @see ucnv_setFromUCallBack
945 U_STABLE
void U_EXPORT2
946 ucnv_getFromUCallBack (const UConverter
* converter
,
947 UConverterFromUCallback
*action
,
948 const void **context
);
951 * Changes the callback function used by the converter when
952 * an illegal or invalid sequence is found.
953 * Context pointers are always owned by the caller.
954 * Predefined actions and contexts can be found in the ucnv_err.h header.
956 * @param converter the unicode converter
957 * @param newAction the new callback function
958 * @param newContext the new toUnicode callback context pointer. This can be NULL.
959 * @param oldAction fillin: returns the old callback function pointer. This can be NULL.
960 * @param oldContext fillin: returns the old callback's private void* context. This can be NULL.
961 * @param err The error code status
962 * @see ucnv_getToUCallBack
965 U_STABLE
void U_EXPORT2
966 ucnv_setToUCallBack (UConverter
* converter
,
967 UConverterToUCallback newAction
,
968 const void* newContext
,
969 UConverterToUCallback
*oldAction
,
970 const void** oldContext
,
974 * Changes the current callback function used by the converter when
975 * an illegal or invalid sequence is found.
976 * Context pointers are always owned by the caller.
977 * Predefined actions and contexts can be found in the ucnv_err.h header.
979 * @param converter the unicode converter
980 * @param newAction the new callback function
981 * @param newContext the new fromUnicode callback context pointer. This can be NULL.
982 * @param oldAction fillin: returns the old callback function pointer. This can be NULL.
983 * @param oldContext fillin: returns the old callback's private void* context. This can be NULL.
984 * @param err The error code status
985 * @see ucnv_getFromUCallBack
988 U_STABLE
void U_EXPORT2
989 ucnv_setFromUCallBack (UConverter
* converter
,
990 UConverterFromUCallback newAction
,
991 const void *newContext
,
992 UConverterFromUCallback
*oldAction
,
993 const void **oldContext
,
997 * Converts an array of unicode characters to an array of codepage
998 * characters. This function is optimized for converting a continuous
999 * stream of data in buffer-sized chunks, where the entire source and
1000 * target does not fit in available buffers.
1002 * The source pointer is an in/out parameter. It starts out pointing where the
1003 * conversion is to begin, and ends up pointing after the last UChar consumed.
1005 * Target similarly starts out pointer at the first available byte in the output
1006 * buffer, and ends up pointing after the last byte written to the output.
1008 * The converter always attempts to consume the entire source buffer, unless
1009 * (1.) the target buffer is full, or (2.) a failing error is returned from the
1010 * current callback function. When a successful error status has been
1011 * returned, it means that all of the source buffer has been
1012 * consumed. At that point, the caller should reset the source and
1013 * sourceLimit pointers to point to the next chunk.
1015 * At the end of the stream (flush==TRUE), the input is completely consumed
1016 * when *source==sourceLimit and no error code is set.
1017 * The converter object is then automatically reset by this function.
1018 * (This means that a converter need not be reset explicitly between data
1019 * streams if it finishes the previous stream without errors.)
1021 * This is a <I>stateful</I> conversion. Additionally, even when all source data has
1022 * been consumed, some data may be in the converters' internal state.
1023 * Call this function repeatedly, updating the target pointers with
1024 * the next empty chunk of target in case of a
1025 * <TT>U_BUFFER_OVERFLOW_ERROR</TT>, and updating the source pointers
1026 * with the next chunk of source when a successful error status is
1027 * returned, until there are no more chunks of source data.
1028 * @param converter the Unicode converter
1029 * @param target I/O parameter. Input : Points to the beginning of the buffer to copy
1030 * codepage characters to. Output : points to after the last codepage character copied
1031 * to <TT>target</TT>.
1032 * @param targetLimit the pointer just after last of the <TT>target</TT> buffer
1033 * @param source I/O parameter, pointer to pointer to the source Unicode character buffer.
1034 * @param sourceLimit the pointer just after the last of the source buffer
1035 * @param offsets if NULL is passed, nothing will happen to it, otherwise it needs to have the same number
1036 * of allocated cells as <TT>target</TT>. Will fill in offsets from target to source pointer
1037 * 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>
1038 * For output data carried across calls, and other data without a specific source character
1039 * (such as from escape sequences or callbacks) -1 will be placed for offsets.
1040 * @param flush set to <TT>TRUE</TT> if the current source buffer is the last available
1041 * chunk of the source, <TT>FALSE</TT> otherwise. Note that if a failing status is returned,
1042 * this function may have to be called multiple times with flush set to <TT>TRUE</TT> until
1043 * the source buffer is consumed.
1044 * @param err the error status. <TT>U_ILLEGAL_ARGUMENT_ERROR</TT> will be set if the
1045 * converter is <TT>NULL</TT>.
1046 * <code>U_BUFFER_OVERFLOW_ERROR</code> will be set if the target is full and there is
1047 * still data to be written to the target.
1048 * @see ucnv_fromUChars
1050 * @see ucnv_getMinCharSize
1051 * @see ucnv_setToUCallBack
1054 U_STABLE
void U_EXPORT2
1055 ucnv_fromUnicode (UConverter
* converter
,
1057 const char *targetLimit
,
1058 const UChar
** source
,
1059 const UChar
* sourceLimit
,
1065 * Converts a buffer of codepage bytes into an array of unicode UChars
1066 * characters. This function is optimized for converting a continuous
1067 * stream of data in buffer-sized chunks, where the entire source and
1068 * target does not fit in available buffers.
1070 * The source pointer is an in/out parameter. It starts out pointing where the
1071 * conversion is to begin, and ends up pointing after the last byte of source consumed.
1073 * Target similarly starts out pointer at the first available UChar in the output
1074 * buffer, and ends up pointing after the last UChar written to the output.
1075 * It does NOT necessarily keep UChar sequences together.
1077 * The converter always attempts to consume the entire source buffer, unless
1078 * (1.) the target buffer is full, or (2.) a failing error is returned from the
1079 * current callback function. When a successful error status has been
1080 * returned, it means that all of the source buffer has been
1081 * consumed. At that point, the caller should reset the source and
1082 * sourceLimit pointers to point to the next chunk.
1084 * At the end of the stream (flush==TRUE), the input is completely consumed
1085 * when *source==sourceLimit and no error code is set
1086 * The converter object is then automatically reset by this function.
1087 * (This means that a converter need not be reset explicitly between data
1088 * streams if it finishes the previous stream without errors.)
1090 * This is a <I>stateful</I> conversion. Additionally, even when all source data has
1091 * been consumed, some data may be in the converters' internal state.
1092 * Call this function repeatedly, updating the target pointers with
1093 * the next empty chunk of target in case of a
1094 * <TT>U_BUFFER_OVERFLOW_ERROR</TT>, and updating the source pointers
1095 * with the next chunk of source when a successful error status is
1096 * returned, until there are no more chunks of source data.
1097 * @param converter the Unicode converter
1098 * @param target I/O parameter. Input : Points to the beginning of the buffer to copy
1099 * UChars into. Output : points to after the last UChar copied.
1100 * @param targetLimit the pointer just after the end of the <TT>target</TT> buffer
1101 * @param source I/O parameter, pointer to pointer to the source codepage buffer.
1102 * @param sourceLimit the pointer to the byte after the end of the source buffer
1103 * @param offsets if NULL is passed, nothing will happen to it, otherwise it needs to have the same number
1104 * of allocated cells as <TT>target</TT>. Will fill in offsets from target to source pointer
1105 * 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>
1106 * For output data carried across calls, and other data without a specific source character
1107 * (such as from escape sequences or callbacks) -1 will be placed for offsets.
1108 * @param flush set to <TT>TRUE</TT> if the current source buffer is the last available
1109 * chunk of the source, <TT>FALSE</TT> otherwise. Note that if a failing status is returned,
1110 * this function may have to be called multiple times with flush set to <TT>TRUE</TT> until
1111 * the source buffer is consumed.
1112 * @param err the error status. <TT>U_ILLEGAL_ARGUMENT_ERROR</TT> will be set if the
1113 * converter is <TT>NULL</TT>.
1114 * <code>U_BUFFER_OVERFLOW_ERROR</code> will be set if the target is full and there is
1115 * still data to be written to the target.
1116 * @see ucnv_fromUChars
1118 * @see ucnv_getMinCharSize
1119 * @see ucnv_setFromUCallBack
1120 * @see ucnv_getNextUChar
1123 U_STABLE
void U_EXPORT2
1124 ucnv_toUnicode(UConverter
*converter
,
1126 const UChar
*targetLimit
,
1127 const char **source
,
1128 const char *sourceLimit
,
1134 * Convert the Unicode string into a codepage string using an existing UConverter.
1135 * The output string is NUL-terminated if possible.
1137 * This function is a more convenient but less powerful version of ucnv_fromUnicode().
1138 * It is only useful for whole strings, not for streaming conversion.
1140 * The maximum output buffer capacity required (barring output from callbacks) will be
1141 * UCNV_GET_MAX_BYTES_FOR_STRING(srcLength, ucnv_getMaxCharSize(cnv)).
1143 * @param cnv the converter object to be used (ucnv_resetFromUnicode() will be called)
1144 * @param src the input Unicode string
1145 * @param srcLength the input string length, or -1 if NUL-terminated
1146 * @param dest destination string buffer, can be NULL if destCapacity==0
1147 * @param destCapacity the number of chars available at dest
1148 * @param pErrorCode normal ICU error code;
1149 * common error codes that may be set by this function include
1150 * U_BUFFER_OVERFLOW_ERROR, U_STRING_NOT_TERMINATED_WARNING,
1151 * U_ILLEGAL_ARGUMENT_ERROR, and conversion errors
1152 * @return the length of the output string, not counting the terminating NUL;
1153 * if the length is greater than destCapacity, then the string will not fit
1154 * and a buffer of the indicated length would need to be passed in
1155 * @see ucnv_fromUnicode
1157 * @see UCNV_GET_MAX_BYTES_FOR_STRING
1160 U_STABLE
int32_t U_EXPORT2
1161 ucnv_fromUChars(UConverter
*cnv
,
1162 char *dest
, int32_t destCapacity
,
1163 const UChar
*src
, int32_t srcLength
,
1164 UErrorCode
*pErrorCode
);
1167 * Convert the codepage string into a Unicode string using an existing UConverter.
1168 * The output string is NUL-terminated if possible.
1170 * This function is a more convenient but less powerful version of ucnv_toUnicode().
1171 * It is only useful for whole strings, not for streaming conversion.
1173 * The maximum output buffer capacity required (barring output from callbacks) will be
1174 * 2*srcLength (each char may be converted into a surrogate pair).
1176 * @param cnv the converter object to be used (ucnv_resetToUnicode() will be called)
1177 * @param src the input codepage string
1178 * @param srcLength the input string length, or -1 if NUL-terminated
1179 * @param dest destination string buffer, can be NULL if destCapacity==0
1180 * @param destCapacity the number of UChars available at dest
1181 * @param pErrorCode normal ICU error code;
1182 * common error codes that may be set by this function include
1183 * U_BUFFER_OVERFLOW_ERROR, U_STRING_NOT_TERMINATED_WARNING,
1184 * U_ILLEGAL_ARGUMENT_ERROR, and conversion errors
1185 * @return the length of the output string, not counting the terminating NUL;
1186 * if the length is greater than destCapacity, then the string will not fit
1187 * and a buffer of the indicated length would need to be passed in
1188 * @see ucnv_toUnicode
1192 U_STABLE
int32_t U_EXPORT2
1193 ucnv_toUChars(UConverter
*cnv
,
1194 UChar
*dest
, int32_t destCapacity
,
1195 const char *src
, int32_t srcLength
,
1196 UErrorCode
*pErrorCode
);
1199 * Convert a codepage buffer into Unicode one character at a time.
1200 * The input is completely consumed when the U_INDEX_OUTOFBOUNDS_ERROR is set.
1202 * Advantage compared to ucnv_toUnicode() or ucnv_toUChars():
1203 * - Faster for small amounts of data, for most converters, e.g.,
1204 * US-ASCII, ISO-8859-1, UTF-8/16/32, and most "normal" charsets.
1205 * (For complex converters, e.g., SCSU, UTF-7 and ISO 2022 variants,
1206 * it uses ucnv_toUnicode() internally.)
1209 * Limitations compared to ucnv_toUnicode():
1210 * - Always assumes flush=TRUE.
1211 * This makes ucnv_getNextUChar() unsuitable for "streaming" conversion,
1212 * that is, for where the input is supplied in multiple buffers,
1213 * because ucnv_getNextUChar() will assume the end of the input at the end
1214 * of the first buffer.
1215 * - Does not provide offset output.
1217 * It is possible to "mix" ucnv_getNextUChar() and ucnv_toUnicode() because
1218 * ucnv_getNextUChar() uses the current state of the converter
1219 * (unlike ucnv_toUChars() which always resets first).
1220 * However, if ucnv_getNextUChar() is called after ucnv_toUnicode()
1221 * stopped in the middle of a character sequence (with flush=FALSE),
1222 * then ucnv_getNextUChar() will always use the slower ucnv_toUnicode()
1223 * internally until the next character boundary.
1224 * (This is new in ICU 2.6. In earlier releases, ucnv_getNextUChar() had to
1225 * start at a character boundary.)
1227 * Instead of using ucnv_getNextUChar(), it is recommended
1228 * to convert using ucnv_toUnicode() or ucnv_toUChars()
1229 * and then iterate over the text using U16_NEXT() or a UCharIterator (uiter.h)
1230 * or a C++ CharacterIterator or similar.
1231 * This allows streaming conversion and offset output, for example.
1233 * <p>Handling of surrogate pairs and supplementary-plane code points:<br>
1234 * There are two different kinds of codepages that provide mappings for surrogate characters:
1236 * <li>Codepages like UTF-8, UTF-32, and GB 18030 provide direct representations for Unicode
1237 * code points U+10000-U+10ffff as well as for single surrogates U+d800-U+dfff.
1238 * Each valid sequence will result in exactly one returned code point.
1239 * If a sequence results in a single surrogate, then that will be returned
1240 * by itself, even if a neighboring sequence encodes the matching surrogate.</li>
1241 * <li>Codepages like SCSU and LMBCS (and UTF-16) provide direct representations only for BMP code points
1242 * including surrogates. Code points in supplementary planes are represented with
1243 * two sequences, each encoding a surrogate.
1244 * For these codepages, matching pairs of surrogates will be combined into single
1245 * code points for returning from this function.
1246 * (Note that SCSU is actually a mix of these codepage types.)</li>
1249 * @param converter an open UConverter
1250 * @param source the address of a pointer to the codepage buffer, will be
1251 * updated to point after the bytes consumed in the conversion call.
1252 * @param sourceLimit points to the end of the input buffer
1253 * @param err fills in error status (see ucnv_toUnicode)
1254 * <code>U_INDEX_OUTOFBOUNDS_ERROR</code> will be set if the input
1255 * is empty or does not convert to any output (e.g.: pure state-change
1256 * codes SI/SO, escape sequences for ISO 2022,
1257 * or if the callback did not output anything, ...).
1258 * This function will not set a <code>U_BUFFER_OVERFLOW_ERROR</code> because
1259 * the "buffer" is the return code. However, there might be subsequent output
1260 * stored in the converter object
1261 * that will be returned in following calls to this function.
1262 * @return a UChar32 resulting from the partial conversion of source
1263 * @see ucnv_toUnicode
1264 * @see ucnv_toUChars
1268 U_STABLE UChar32 U_EXPORT2
1269 ucnv_getNextUChar(UConverter
* converter
,
1270 const char **source
,
1271 const char * sourceLimit
,
1275 * Convert from one external charset to another using two existing UConverters.
1276 * Internally, two conversions - ucnv_toUnicode() and ucnv_fromUnicode() -
1277 * are used, "pivoting" through 16-bit Unicode.
1279 * Important: For streaming conversion (multiple function calls for successive
1280 * parts of a text stream), the caller must provide a pivot buffer explicitly,
1281 * and must preserve the pivot buffer and associated pointers from one
1282 * call to another. (The buffer may be moved if its contents and the relative
1283 * pointer positions are preserved.)
1285 * There is a similar function, ucnv_convert(),
1286 * which has the following limitations:
1287 * - it takes charset names, not converter objects, so that
1288 * - two converters are opened for each call
1289 * - only single-string conversion is possible, not streaming operation
1290 * - it does not provide enough information to find out,
1291 * in case of failure, whether the toUnicode or
1292 * the fromUnicode conversion failed
1294 * By contrast, ucnv_convertEx()
1295 * - takes UConverter parameters instead of charset names
1296 * - fully exposes the pivot buffer for streaming conversion and complete error handling
1298 * ucnv_convertEx() also provides further convenience:
1299 * - an option to reset the converters at the beginning
1300 * (if reset==TRUE, see parameters;
1301 * also sets *pivotTarget=*pivotSource=pivotStart)
1302 * - allow NUL-terminated input
1303 * (only a single NUL byte, will not work for charsets with multi-byte NULs)
1304 * (if sourceLimit==NULL, see parameters)
1305 * - terminate with a NUL on output
1306 * (only a single NUL byte, not useful for charsets with multi-byte NULs),
1307 * or set U_STRING_NOT_TERMINATED_WARNING if the output exactly fills
1309 * - the pivot buffer can be provided internally;
1310 * possible only for whole-string conversion, not streaming conversion;
1311 * in this case, the caller will not be able to get details about where an
1313 * (if pivotStart==NULL, see below)
1315 * The function returns when one of the following is true:
1316 * - the entire source text has been converted successfully to the target buffer
1317 * - a target buffer overflow occurred (U_BUFFER_OVERFLOW_ERROR)
1318 * - a conversion error occurred
1319 * (other U_FAILURE(), see description of pErrorCode)
1321 * Limitation compared to the direct use of
1322 * ucnv_fromUnicode() and ucnv_toUnicode():
1323 * ucnv_convertEx() does not provide offset information.
1325 * Limitation compared to ucnv_fromUChars() and ucnv_toUChars():
1326 * ucnv_convertEx() does not support preflighting directly.
1328 * Sample code for converting a single string from
1329 * one external charset to UTF-8, ignoring the location of errors:
1333 * myToUTF8(UConverter *cnv,
1334 * const char *s, int32_t length,
1335 * char *u8, int32_t capacity,
1336 * UErrorCode *pErrorCode) {
1337 * UConverter *utf8Cnv;
1340 * if(U_FAILURE(*pErrorCode)) {
1344 * utf8Cnv=myGetCachedUTF8Converter(pErrorCode);
1345 * if(U_FAILURE(*pErrorCode)) {
1350 * ucnv_convertEx(cnv, utf8Cnv,
1351 * &target, u8+capacity,
1352 * &s, length>=0 ? s+length : NULL,
1353 * NULL, NULL, NULL, NULL,
1357 * myReleaseCachedUTF8Converter(utf8Cnv);
1359 * // return the output string length, but without preflighting
1360 * return (int32_t)(target-u8);
1364 * @param targetCnv Output converter, used to convert from the UTF-16 pivot
1365 * to the target using ucnv_fromUnicode().
1366 * @param sourceCnv Input converter, used to convert from the source to
1367 * the UTF-16 pivot using ucnv_toUnicode().
1368 * @param target I/O parameter, same as for ucnv_fromUChars().
1369 * Input: *target points to the beginning of the target buffer.
1370 * Output: *target points to the first unit after the last char written.
1371 * @param targetLimit Pointer to the first unit after the target buffer.
1372 * @param source I/O parameter, same as for ucnv_toUChars().
1373 * Input: *source points to the beginning of the source buffer.
1374 * Output: *source points to the first unit after the last char read.
1375 * @param sourceLimit Pointer to the first unit after the source buffer.
1376 * @param pivotStart Pointer to the UTF-16 pivot buffer. If pivotStart==NULL,
1377 * then an internal buffer is used and the other pivot
1378 * arguments are ignored and can be NULL as well.
1379 * @param pivotSource I/O parameter, same as source in ucnv_fromUChars() for
1380 * conversion from the pivot buffer to the target buffer.
1381 * @param pivotTarget I/O parameter, same as target in ucnv_toUChars() for
1382 * conversion from the source buffer to the pivot buffer.
1383 * It must be pivotStart<=*pivotSource<=*pivotTarget<=pivotLimit
1384 * and pivotStart<pivotLimit (unless pivotStart==NULL).
1385 * @param pivotLimit Pointer to the first unit after the pivot buffer.
1386 * @param reset If TRUE, then ucnv_resetToUnicode(sourceCnv) and
1387 * ucnv_resetFromUnicode(targetCnv) are called, and the
1388 * pivot pointers are reset (*pivotTarget=*pivotSource=pivotStart).
1389 * @param flush If true, indicates the end of the input.
1390 * Passed directly to ucnv_toUnicode(), and carried over to
1391 * ucnv_fromUnicode() when the source is empty as well.
1392 * @param pErrorCode ICU error code in/out parameter.
1393 * Must fulfill U_SUCCESS before the function call.
1394 * U_BUFFER_OVERFLOW_ERROR always refers to the target buffer
1395 * because overflows into the pivot buffer are handled internally.
1396 * Other conversion errors are from the source-to-pivot
1397 * conversion if *pivotSource==pivotStart, otherwise from
1398 * the pivot-to-target conversion.
1401 * @see ucnv_fromAlgorithmic
1402 * @see ucnv_toAlgorithmic
1403 * @see ucnv_fromUnicode
1404 * @see ucnv_toUnicode
1405 * @see ucnv_fromUChars
1406 * @see ucnv_toUChars
1409 U_STABLE
void U_EXPORT2
1410 ucnv_convertEx(UConverter
*targetCnv
, UConverter
*sourceCnv
,
1411 char **target
, const char *targetLimit
,
1412 const char **source
, const char *sourceLimit
,
1413 UChar
*pivotStart
, UChar
**pivotSource
,
1414 UChar
**pivotTarget
, const UChar
*pivotLimit
,
1415 UBool reset
, UBool flush
,
1416 UErrorCode
*pErrorCode
);
1419 * Convert from one external charset to another.
1420 * Internally, two converters are opened according to the name arguments,
1421 * then the text is converted to and from the 16-bit Unicode "pivot"
1422 * using ucnv_convertEx(), then the converters are closed again.
1424 * This is a convenience function, not an efficient way to convert a lot of text:
1426 * - takes charset names, not converter objects, so that
1427 * - two converters are opened for each call
1428 * - only single-string conversion is possible, not streaming operation
1429 * - does not provide enough information to find out,
1430 * in case of failure, whether the toUnicode or
1431 * the fromUnicode conversion failed
1432 * - allows NUL-terminated input
1433 * (only a single NUL byte, will not work for charsets with multi-byte NULs)
1434 * (if sourceLength==-1, see parameters)
1435 * - terminate with a NUL on output
1436 * (only a single NUL byte, not useful for charsets with multi-byte NULs),
1437 * or set U_STRING_NOT_TERMINATED_WARNING if the output exactly fills
1439 * - a pivot buffer is provided internally
1441 * The function returns when one of the following is true:
1442 * - the entire source text has been converted successfully to the target buffer
1443 * and either the target buffer is terminated with a single NUL byte
1444 * or the error code is set to U_STRING_NOT_TERMINATED_WARNING
1445 * - a target buffer overflow occurred (U_BUFFER_OVERFLOW_ERROR)
1446 * and the full output string length is returned ("preflighting")
1447 * - a conversion error occurred
1448 * (other U_FAILURE(), see description of pErrorCode)
1450 * @param toConverterName The name of the converter that is used to convert
1451 * from the UTF-16 pivot buffer to the target.
1452 * @param fromConverterName The name of the converter that is used to convert
1453 * from the source to the UTF-16 pivot buffer.
1454 * @param target Pointer to the output buffer.
1455 * @param targetCapacity Capacity of the target, in bytes.
1456 * @param source Pointer to the input buffer.
1457 * @param sourceLength Length of the input text, in bytes, or -1 for NUL-terminated input.
1458 * @param pErrorCode ICU error code in/out parameter.
1459 * Must fulfill U_SUCCESS before the function call.
1460 * @return Length of the complete output text in bytes, even if it exceeds the targetCapacity
1461 * and a U_BUFFER_OVERFLOW_ERROR is set.
1463 * @see ucnv_convertEx
1464 * @see ucnv_fromAlgorithmic
1465 * @see ucnv_toAlgorithmic
1466 * @see ucnv_fromUnicode
1467 * @see ucnv_toUnicode
1468 * @see ucnv_fromUChars
1469 * @see ucnv_toUChars
1470 * @see ucnv_getNextUChar
1473 U_STABLE
int32_t U_EXPORT2
1474 ucnv_convert(const char *toConverterName
,
1475 const char *fromConverterName
,
1477 int32_t targetCapacity
,
1479 int32_t sourceLength
,
1480 UErrorCode
*pErrorCode
);
1483 * Convert from one external charset to another.
1484 * Internally, the text is converted to and from the 16-bit Unicode "pivot"
1485 * using ucnv_convertEx(). ucnv_toAlgorithmic() works exactly like ucnv_convert()
1486 * except that the two converters need not be looked up and opened completely.
1488 * The source-to-pivot conversion uses the cnv converter parameter.
1489 * The pivot-to-target conversion uses a purely algorithmic converter
1490 * according to the specified type, e.g., UCNV_UTF8 for a UTF-8 converter.
1492 * Internally, the algorithmic converter is opened and closed for each
1493 * function call, which is more efficient than using the public ucnv_open()
1494 * but somewhat less efficient than only resetting an existing converter
1495 * and using ucnv_convertEx().
1497 * This function is more convenient than ucnv_convertEx() for single-string
1498 * conversions, especially when "preflighting" is desired (returning the length
1499 * of the complete output even if it does not fit into the target buffer;
1500 * see the User Guide Strings chapter). See ucnv_convert() for details.
1502 * @param algorithmicType UConverterType constant identifying the desired target
1503 * charset as a purely algorithmic converter.
1504 * Those are converters for Unicode charsets like
1505 * UTF-8, BOCU-1, SCSU, UTF-7, IMAP-mailbox-name, etc.,
1506 * as well as US-ASCII and ISO-8859-1.
1507 * @param cnv The converter that is used to convert
1508 * from the source to the UTF-16 pivot buffer.
1509 * @param target Pointer to the output buffer.
1510 * @param targetCapacity Capacity of the target, in bytes.
1511 * @param source Pointer to the input buffer.
1512 * @param sourceLength Length of the input text, in bytes
1513 * @param pErrorCode ICU error code in/out parameter.
1514 * Must fulfill U_SUCCESS before the function call.
1515 * @return Length of the complete output text in bytes, even if it exceeds the targetCapacity
1516 * and a U_BUFFER_OVERFLOW_ERROR is set.
1518 * @see ucnv_fromAlgorithmic
1520 * @see ucnv_convertEx
1521 * @see ucnv_fromUnicode
1522 * @see ucnv_toUnicode
1523 * @see ucnv_fromUChars
1524 * @see ucnv_toUChars
1527 U_STABLE
int32_t U_EXPORT2
1528 ucnv_toAlgorithmic(UConverterType algorithmicType
,
1530 char *target
, int32_t targetCapacity
,
1531 const char *source
, int32_t sourceLength
,
1532 UErrorCode
*pErrorCode
);
1535 * Convert from one external charset to another.
1536 * Internally, the text is converted to and from the 16-bit Unicode "pivot"
1537 * using ucnv_convertEx(). ucnv_fromAlgorithmic() works exactly like ucnv_convert()
1538 * except that the two converters need not be looked up and opened completely.
1540 * The source-to-pivot conversion uses a purely algorithmic converter
1541 * according to the specified type, e.g., UCNV_UTF8 for a UTF-8 converter.
1542 * The pivot-to-target conversion uses the cnv converter parameter.
1544 * Internally, the algorithmic converter is opened and closed for each
1545 * function call, which is more efficient than using the public ucnv_open()
1546 * but somewhat less efficient than only resetting an existing converter
1547 * and using ucnv_convertEx().
1549 * This function is more convenient than ucnv_convertEx() for single-string
1550 * conversions, especially when "preflighting" is desired (returning the length
1551 * of the complete output even if it does not fit into the target buffer;
1552 * see the User Guide Strings chapter). See ucnv_convert() for details.
1554 * @param cnv The converter that is used to convert
1555 * from the UTF-16 pivot buffer to the target.
1556 * @param algorithmicType UConverterType constant identifying the desired source
1557 * charset as a purely algorithmic converter.
1558 * Those are converters for Unicode charsets like
1559 * UTF-8, BOCU-1, SCSU, UTF-7, IMAP-mailbox-name, etc.,
1560 * as well as US-ASCII and ISO-8859-1.
1561 * @param target Pointer to the output buffer.
1562 * @param targetCapacity Capacity of the target, in bytes.
1563 * @param source Pointer to the input buffer.
1564 * @param sourceLength Length of the input text, in bytes
1565 * @param pErrorCode ICU error code in/out parameter.
1566 * Must fulfill U_SUCCESS before the function call.
1567 * @return Length of the complete output text in bytes, even if it exceeds the targetCapacity
1568 * and a U_BUFFER_OVERFLOW_ERROR is set.
1570 * @see ucnv_fromAlgorithmic
1572 * @see ucnv_convertEx
1573 * @see ucnv_fromUnicode
1574 * @see ucnv_toUnicode
1575 * @see ucnv_fromUChars
1576 * @see ucnv_toUChars
1579 U_STABLE
int32_t U_EXPORT2
1580 ucnv_fromAlgorithmic(UConverter
*cnv
,
1581 UConverterType algorithmicType
,
1582 char *target
, int32_t targetCapacity
,
1583 const char *source
, int32_t sourceLength
,
1584 UErrorCode
*pErrorCode
);
1587 * Frees up memory occupied by unused, cached converter shared data.
1589 * @return the number of cached converters successfully deleted
1593 U_STABLE
int32_t U_EXPORT2
1594 ucnv_flushCache(void);
1597 * Returns the number of available converters, as per the alias file.
1599 * @return the number of available converters
1600 * @see ucnv_getAvailableName
1603 U_STABLE
int32_t U_EXPORT2
1604 ucnv_countAvailable(void);
1607 * Gets the canonical converter name of the specified converter from a list of
1608 * all available converters contaied in the alias file. All converters
1609 * in this list can be opened.
1611 * @param n the index to a converter available on the system (in the range <TT>[0..ucnv_countAvaiable()]</TT>)
1612 * @return a pointer a string (library owned), or <TT>NULL</TT> if the index is out of bounds.
1613 * @see ucnv_countAvailable
1616 U_STABLE
const char* U_EXPORT2
1617 ucnv_getAvailableName(int32_t n
);
1620 * Returns a UEnumeration to enumerate all of the canonical converter
1621 * names, as per the alias file, regardless of the ability to open each
1624 * @return A UEnumeration object for getting all the recognized canonical
1626 * @see ucnv_getAvailableName
1631 U_STABLE UEnumeration
* U_EXPORT2
1632 ucnv_openAllNames(UErrorCode
*pErrorCode
);
1635 * Gives the number of aliases for a given converter or alias name.
1636 * If the alias is ambiguous, then the preferred converter is used
1637 * and the status is set to U_AMBIGUOUS_ALIAS_WARNING.
1638 * This method only enumerates the listed entries in the alias file.
1639 * @param alias alias name
1640 * @param pErrorCode error status
1641 * @return number of names on alias list for given alias
1644 U_STABLE
uint16_t U_EXPORT2
1645 ucnv_countAliases(const char *alias
, UErrorCode
*pErrorCode
);
1648 * Gives the name of the alias at given index of alias list.
1649 * This method only enumerates the listed entries in the alias file.
1650 * If the alias is ambiguous, then the preferred converter is used
1651 * and the status is set to U_AMBIGUOUS_ALIAS_WARNING.
1652 * @param alias alias name
1653 * @param n index in alias list
1654 * @param pErrorCode result of operation
1655 * @return returns the name of the alias at given index
1656 * @see ucnv_countAliases
1659 U_STABLE
const char * U_EXPORT2
1660 ucnv_getAlias(const char *alias
, uint16_t n
, UErrorCode
*pErrorCode
);
1663 * Fill-up the list of alias names for the given alias.
1664 * This method only enumerates the listed entries in the alias file.
1665 * If the alias is ambiguous, then the preferred converter is used
1666 * and the status is set to U_AMBIGUOUS_ALIAS_WARNING.
1667 * @param alias alias name
1668 * @param aliases fill-in list, aliases is a pointer to an array of
1669 * <code>ucnv_countAliases()</code> string-pointers
1670 * (<code>const char *</code>) that will be filled in.
1671 * The strings themselves are owned by the library.
1672 * @param pErrorCode result of operation
1675 U_STABLE
void U_EXPORT2
1676 ucnv_getAliases(const char *alias
, const char **aliases
, UErrorCode
*pErrorCode
);
1679 * Return a new UEnumeration object for enumerating all the
1680 * alias names for a given converter that are recognized by a standard.
1681 * This method only enumerates the listed entries in the alias file.
1682 * The convrtrs.txt file can be modified to change the results of
1684 * The first result in this list is the same result given by
1685 * <code>ucnv_getStandardName</code>, which is the default alias for
1686 * the specified standard name. The returned object must be closed with
1687 * <code>uenum_close</code> when you are done with the object.
1689 * @param convName original converter name
1690 * @param standard name of the standard governing the names; MIME and IANA
1691 * are such standards
1692 * @param pErrorCode The error code
1693 * @return A UEnumeration object for getting all aliases that are recognized
1694 * by a standard. If any of the parameters are invalid, NULL
1696 * @see ucnv_getStandardName
1701 U_STABLE UEnumeration
* U_EXPORT2
1702 ucnv_openStandardNames(const char *convName
,
1703 const char *standard
,
1704 UErrorCode
*pErrorCode
);
1707 * Gives the number of standards associated to converter names.
1708 * @return number of standards
1711 U_STABLE
uint16_t U_EXPORT2
1712 ucnv_countStandards(void);
1715 * Gives the name of the standard at given index of standard list.
1716 * @param n index in standard list
1717 * @param pErrorCode result of operation
1718 * @return returns the name of the standard at given index. Owned by the library.
1721 U_STABLE
const char * U_EXPORT2
1722 ucnv_getStandard(uint16_t n
, UErrorCode
*pErrorCode
);
1725 * Returns a standard name for a given converter name.
1727 * Example alias table:<br>
1728 * conv alias1 { STANDARD1 } alias2 { STANDARD1* }
1730 * Result of ucnv_getStandardName("conv", "STANDARD1") from example
1734 * @param name original converter name
1735 * @param standard name of the standard governing the names; MIME and IANA
1736 * are such standards
1737 * @param pErrorCode result of operation
1738 * @return returns the standard converter name;
1739 * if a standard converter name cannot be determined,
1740 * then <code>NULL</code> is returned. Owned by the library.
1743 U_STABLE
const char * U_EXPORT2
1744 ucnv_getStandardName(const char *name
, const char *standard
, UErrorCode
*pErrorCode
);
1747 * This function will return the internal canonical converter name of the
1748 * tagged alias. This is the opposite of ucnv_openStandardNames, which
1749 * returns the tagged alias given the canonical name.
1751 * Example alias table:<br>
1752 * conv alias1 { STANDARD1 } alias2 { STANDARD1* }
1754 * Result of ucnv_getStandardName("alias1", "STANDARD1") from example
1758 * @return returns the canonical converter name;
1759 * if a standard or alias name cannot be determined,
1760 * then <code>NULL</code> is returned. The returned string is
1761 * owned by the library.
1762 * @see ucnv_getStandardName
1765 U_STABLE
const char * U_EXPORT2
1766 ucnv_getCanonicalName(const char *alias
, const char *standard
, UErrorCode
*pErrorCode
);
1769 * returns the current default converter name.
1771 * @return returns the current default converter name;
1772 * if a default converter name cannot be determined,
1773 * then <code>NULL</code> is returned.
1774 * Storage owned by the library
1775 * @see ucnv_setDefaultName
1778 U_STABLE
const char * U_EXPORT2
1779 ucnv_getDefaultName(void);
1782 * This function sets the current default converter name.
1783 * DO NOT call this function from multiple threads! This function is not
1784 * thread safe. If this function needs to be called, it should be called
1785 * during application initialization. Most of the time, the results from
1786 * ucnv_getDefaultName() is sufficient for your application.
1787 * @param name the converter name to be the default (must exist).
1788 * @see ucnv_getDefaultName
1792 U_STABLE
void U_EXPORT2
1793 ucnv_setDefaultName(const char *name
);
1796 * Fixes the backslash character mismapping. For example, in SJIS, the backslash
1797 * character in the ASCII portion is also used to represent the yen currency sign.
1798 * When mapping from Unicode character 0x005C, it's unclear whether to map the
1799 * character back to yen or backslash in SJIS. This function will take the input
1800 * buffer and replace all the yen sign characters with backslash. This is necessary
1801 * when the user tries to open a file with the input buffer on Windows.
1802 * This function will test the converter to see whether such mapping is
1803 * required. You can sometimes avoid using this function by using the correct version
1806 * @param cnv The converter representing the target codepage.
1807 * @param source the input buffer to be fixed
1808 * @param sourceLen the length of the input buffer
1809 * @see ucnv_isAmbiguous
1812 U_STABLE
void U_EXPORT2
1813 ucnv_fixFileSeparator(const UConverter
*cnv
, UChar
*source
, int32_t sourceLen
);
1816 * Determines if the converter contains ambiguous mappings of the same
1818 * @param cnv the converter to be tested
1819 * @return TRUE if the converter contains ambiguous mapping of the same
1820 * character, FALSE otherwise.
1823 U_STABLE UBool U_EXPORT2
1824 ucnv_isAmbiguous(const UConverter
*cnv
);
1827 * Sets the converter to use fallback mapping or not.
1828 * @param cnv The converter to set the fallback mapping usage on.
1829 * @param usesFallback TRUE if the user wants the converter to take advantage of the fallback
1830 * mapping, FALSE otherwise.
1833 U_STABLE
void U_EXPORT2
1834 ucnv_setFallback(UConverter
*cnv
, UBool usesFallback
);
1837 * Determines if the converter uses fallback mappings or not.
1838 * @param cnv The converter to be tested
1839 * @return TRUE if the converter uses fallback, FALSE otherwise.
1842 U_STABLE UBool U_EXPORT2
1843 ucnv_usesFallback(const UConverter
*cnv
);
1846 * Detects Unicode signature byte sequences at the start of the byte stream
1847 * and returns the charset name of the indicated Unicode charset.
1848 * NULL is returned when no Unicode signature is recognized.
1849 * The number of bytes in the signature is output as well.
1851 * The caller can ucnv_open() a converter using the charset name.
1852 * The first code unit (UChar) from the start of the stream will be U+FEFF
1853 * (the Unicode BOM/signature character) and can usually be ignored.
1855 * For most Unicode charsets it is also possible to ignore the indicated
1856 * number of initial stream bytes and start converting after them.
1857 * However, there are stateful Unicode charsets (UTF-7 and BOCU-1) for which
1858 * this will not work. Therefore, it is best to ignore the first output UChar
1859 * instead of the input signature bytes.
1863 * UErrorCode err = U_ZERO_ERROR;
1864 * char input[] = { '\xEF','\xBB', '\xBF','\x41','\x42','\x43' };
1865 * int32_t signatureLength = 0;
1866 * char *encoding = ucnv_detectUnicodeSignature(input,sizeof(input),&signatureLength,&err);
1867 * UConverter *conv = NULL;
1868 * UChar output[100];
1869 * UChar *target = output, *out;
1870 * char *source = input;
1871 * if(encoding!=NULL && U_SUCCESS(err)){
1872 * // should signature be discarded ?
1873 * conv = ucnv_open(encoding, &err);
1874 * // do the conversion
1875 * ucnv_toUnicode(conv,
1876 * target, output + sizeof(output)/U_SIZEOF_UCHAR,
1877 * source, input + sizeof(input),
1878 * NULL, TRUE, &err);
1880 * if (discardSignature){
1881 * ++out; // ignore initial U+FEFF
1883 * while(out != target) {
1884 * printf("%04x ", *out++);
1891 * @param source The source string in which the signature should be detected.
1892 * @param sourceLength Length of the input string, or -1 if terminated with a NUL byte.
1893 * @param signatureLength A pointer to int32_t to receive the number of bytes that make up the signature
1894 * of the detected UTF. 0 if not detected.
1895 * Can be a NULL pointer.
1896 * @param pErrorCode ICU error code in/out parameter.
1897 * Must fulfill U_SUCCESS before the function call.
1898 * @return The name of the encoding detected. NULL if encoding is not detected.
1901 U_STABLE
const char* U_EXPORT2
1902 ucnv_detectUnicodeSignature(const char* source
,
1903 int32_t sourceLength
,
1904 int32_t *signatureLength
,
1905 UErrorCode
*pErrorCode
);
1908 * Returns the number of UChars held in the converter's internal state
1909 * because more input is needed for completing the conversion. This function is
1910 * useful for mapping semantics of ICU's converter interface to those of iconv,
1911 * and this information is not needed for normal conversion.
1912 * @param cnv The converter in which the input is held
1913 * @param status ICU error code in/out parameter.
1914 * Must fulfill U_SUCCESS before the function call.
1915 * @return The number of UChars in the state. -1 if an error is encountered.
1918 U_DRAFT
int32_t U_EXPORT2
1919 ucnv_fromUCountPending(const UConverter
* cnv
, UErrorCode
* status
);
1922 * Returns the number of chars held in the converter's internal state
1923 * because more input is needed for completing the conversion. This function is
1924 * useful for mapping semantics of ICU's converter interface to those of iconv,
1925 * and this information is not needed for normal conversion.
1926 * @param cnv The converter in which the input is held as internal state
1927 * @param status ICU error code in/out parameter.
1928 * Must fulfill U_SUCCESS before the function call.
1929 * @return The number of chars in the state. -1 if an error is encountered.
1932 U_DRAFT
int32_t U_EXPORT2
1933 ucnv_toUCountPending(const UConverter
* cnv
, UErrorCode
* status
);