2 **********************************************************************
3 * Copyright (C) 1999-2008, 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-project.org/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-project.org/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 * @see 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 * @see 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_STABLE
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 /** Select the set of Unicode code points with roundtrip or fallback mappings. @draft ICU 4.0 */
874 UCNV_ROUNDTRIP_AND_FALLBACK_SET
,
875 /** Number of UConverterUnicodeSet selectors. @stable ICU 2.6 */
877 } UConverterUnicodeSet
;
881 * Returns the set of Unicode code points that can be converted by an ICU converter.
883 * Returns one of several kinds of set:
885 * 1. UCNV_ROUNDTRIP_SET
887 * The set of all Unicode code points that can be roundtrip-converted
888 * (converted without any data loss) with the converter (ucnv_fromUnicode()).
889 * This set will not include code points that have fallback mappings
890 * or are only the result of reverse fallback mappings.
891 * This set will also not include PUA code points with fallbacks, although
892 * ucnv_fromUnicode() will always uses those mappings despite ucnv_setFallback().
893 * See UTR #22 "Character Mapping Markup Language"
894 * at http://www.unicode.org/reports/tr22/
896 * This is useful for example for
897 * - checking that a string or document can be roundtrip-converted with a converter,
898 * without/before actually performing the conversion
899 * - testing if a converter can be used for text for typical text for a certain locale,
900 * by comparing its roundtrip set with the set of ExemplarCharacters from
901 * ICU's locale data or other sources
903 * 2. UCNV_ROUNDTRIP_AND_FALLBACK_SET
905 * The set of all Unicode code points that can be converted with the converter (ucnv_fromUnicode())
906 * when fallbacks are turned on (see ucnv_setFallback()).
907 * This set includes all code points with roundtrips and fallbacks (but not reverse fallbacks).
909 * In the future, there may be more UConverterUnicodeSet choices to select
910 * sets with different properties.
912 * @param cnv The converter for which a set is requested.
913 * @param setFillIn A valid USet *. It will be cleared by this function before
914 * the converter's specific set is filled into the USet.
915 * @param whichSet A UConverterUnicodeSet selector;
916 * currently UCNV_ROUNDTRIP_SET is the only supported value.
917 * @param pErrorCode ICU error code in/out parameter.
918 * Must fulfill U_SUCCESS before the function call.
920 * @see UConverterUnicodeSet
925 U_STABLE
void U_EXPORT2
926 ucnv_getUnicodeSet(const UConverter
*cnv
,
928 UConverterUnicodeSet whichSet
,
929 UErrorCode
*pErrorCode
);
932 * Gets the current calback function used by the converter when an illegal
933 * or invalid codepage sequence is found.
934 * Context pointers are always owned by the caller.
936 * @param converter the unicode converter
937 * @param action fillin: returns the callback function pointer
938 * @param context fillin: returns the callback's private void* context
939 * @see ucnv_setToUCallBack
942 U_STABLE
void U_EXPORT2
943 ucnv_getToUCallBack (const UConverter
* converter
,
944 UConverterToUCallback
*action
,
945 const void **context
);
948 * Gets the current callback function used by the converter when illegal
949 * or invalid Unicode sequence is found.
950 * Context pointers are always owned by the caller.
952 * @param converter the unicode converter
953 * @param action fillin: returns the callback function pointer
954 * @param context fillin: returns the callback's private void* context
955 * @see ucnv_setFromUCallBack
958 U_STABLE
void U_EXPORT2
959 ucnv_getFromUCallBack (const UConverter
* converter
,
960 UConverterFromUCallback
*action
,
961 const void **context
);
964 * Changes the callback function used by the converter when
965 * an illegal or invalid sequence is found.
966 * Context pointers are always owned by the caller.
967 * Predefined actions and contexts can be found in the ucnv_err.h header.
969 * @param converter the unicode converter
970 * @param newAction the new callback function
971 * @param newContext the new toUnicode callback context pointer. This can be NULL.
972 * @param oldAction fillin: returns the old callback function pointer. This can be NULL.
973 * @param oldContext fillin: returns the old callback's private void* context. This can be NULL.
974 * @param err The error code status
975 * @see ucnv_getToUCallBack
978 U_STABLE
void U_EXPORT2
979 ucnv_setToUCallBack (UConverter
* converter
,
980 UConverterToUCallback newAction
,
981 const void* newContext
,
982 UConverterToUCallback
*oldAction
,
983 const void** oldContext
,
987 * Changes the current callback function used by the converter when
988 * an illegal or invalid sequence is found.
989 * Context pointers are always owned by the caller.
990 * Predefined actions and contexts can be found in the ucnv_err.h header.
992 * @param converter the unicode converter
993 * @param newAction the new callback function
994 * @param newContext the new fromUnicode callback context pointer. This can be NULL.
995 * @param oldAction fillin: returns the old callback function pointer. This can be NULL.
996 * @param oldContext fillin: returns the old callback's private void* context. This can be NULL.
997 * @param err The error code status
998 * @see ucnv_getFromUCallBack
1001 U_STABLE
void U_EXPORT2
1002 ucnv_setFromUCallBack (UConverter
* converter
,
1003 UConverterFromUCallback newAction
,
1004 const void *newContext
,
1005 UConverterFromUCallback
*oldAction
,
1006 const void **oldContext
,
1010 * Converts an array of unicode characters to an array of codepage
1011 * characters. This function is optimized for converting a continuous
1012 * stream of data in buffer-sized chunks, where the entire source and
1013 * target does not fit in available buffers.
1015 * The source pointer is an in/out parameter. It starts out pointing where the
1016 * conversion is to begin, and ends up pointing after the last UChar consumed.
1018 * Target similarly starts out pointer at the first available byte in the output
1019 * buffer, and ends up pointing after the last byte written to the output.
1021 * The converter always attempts to consume the entire source buffer, unless
1022 * (1.) the target buffer is full, or (2.) a failing error is returned from the
1023 * current callback function. When a successful error status has been
1024 * returned, it means that all of the source buffer has been
1025 * consumed. At that point, the caller should reset the source and
1026 * sourceLimit pointers to point to the next chunk.
1028 * At the end of the stream (flush==TRUE), the input is completely consumed
1029 * when *source==sourceLimit and no error code is set.
1030 * The converter object is then automatically reset by this function.
1031 * (This means that a converter need not be reset explicitly between data
1032 * streams if it finishes the previous stream without errors.)
1034 * This is a <I>stateful</I> conversion. Additionally, even when all source data has
1035 * been consumed, some data may be in the converters' internal state.
1036 * Call this function repeatedly, updating the target pointers with
1037 * the next empty chunk of target in case of a
1038 * <TT>U_BUFFER_OVERFLOW_ERROR</TT>, and updating the source pointers
1039 * with the next chunk of source when a successful error status is
1040 * returned, until there are no more chunks of source data.
1041 * @param converter the Unicode converter
1042 * @param target I/O parameter. Input : Points to the beginning of the buffer to copy
1043 * codepage characters to. Output : points to after the last codepage character copied
1044 * to <TT>target</TT>.
1045 * @param targetLimit the pointer just after last of the <TT>target</TT> buffer
1046 * @param source I/O parameter, pointer to pointer to the source Unicode character buffer.
1047 * @param sourceLimit the pointer just after the last of the source buffer
1048 * @param offsets if NULL is passed, nothing will happen to it, otherwise it needs to have the same number
1049 * of allocated cells as <TT>target</TT>. Will fill in offsets from target to source pointer
1050 * 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>
1051 * For output data carried across calls, and other data without a specific source character
1052 * (such as from escape sequences or callbacks) -1 will be placed for offsets.
1053 * @param flush set to <TT>TRUE</TT> if the current source buffer is the last available
1054 * chunk of the source, <TT>FALSE</TT> otherwise. Note that if a failing status is returned,
1055 * this function may have to be called multiple times with flush set to <TT>TRUE</TT> until
1056 * the source buffer is consumed.
1057 * @param err the error status. <TT>U_ILLEGAL_ARGUMENT_ERROR</TT> will be set if the
1058 * converter is <TT>NULL</TT>.
1059 * <code>U_BUFFER_OVERFLOW_ERROR</code> will be set if the target is full and there is
1060 * still data to be written to the target.
1061 * @see ucnv_fromUChars
1063 * @see ucnv_getMinCharSize
1064 * @see ucnv_setToUCallBack
1067 U_STABLE
void U_EXPORT2
1068 ucnv_fromUnicode (UConverter
* converter
,
1070 const char *targetLimit
,
1071 const UChar
** source
,
1072 const UChar
* sourceLimit
,
1078 * Converts a buffer of codepage bytes into an array of unicode UChars
1079 * characters. This function is optimized for converting a continuous
1080 * stream of data in buffer-sized chunks, where the entire source and
1081 * target does not fit in available buffers.
1083 * The source pointer is an in/out parameter. It starts out pointing where the
1084 * conversion is to begin, and ends up pointing after the last byte of source consumed.
1086 * Target similarly starts out pointer at the first available UChar in the output
1087 * buffer, and ends up pointing after the last UChar written to the output.
1088 * It does NOT necessarily keep UChar sequences together.
1090 * The converter always attempts to consume the entire source buffer, unless
1091 * (1.) the target buffer is full, or (2.) a failing error is returned from the
1092 * current callback function. When a successful error status has been
1093 * returned, it means that all of the source buffer has been
1094 * consumed. At that point, the caller should reset the source and
1095 * sourceLimit pointers to point to the next chunk.
1097 * At the end of the stream (flush==TRUE), the input is completely consumed
1098 * when *source==sourceLimit and no error code is set
1099 * The converter object is then automatically reset by this function.
1100 * (This means that a converter need not be reset explicitly between data
1101 * streams if it finishes the previous stream without errors.)
1103 * This is a <I>stateful</I> conversion. Additionally, even when all source data has
1104 * been consumed, some data may be in the converters' internal state.
1105 * Call this function repeatedly, updating the target pointers with
1106 * the next empty chunk of target in case of a
1107 * <TT>U_BUFFER_OVERFLOW_ERROR</TT>, and updating the source pointers
1108 * with the next chunk of source when a successful error status is
1109 * returned, until there are no more chunks of source data.
1110 * @param converter the Unicode converter
1111 * @param target I/O parameter. Input : Points to the beginning of the buffer to copy
1112 * UChars into. Output : points to after the last UChar copied.
1113 * @param targetLimit the pointer just after the end of the <TT>target</TT> buffer
1114 * @param source I/O parameter, pointer to pointer to the source codepage buffer.
1115 * @param sourceLimit the pointer to the byte after the end of the source buffer
1116 * @param offsets if NULL is passed, nothing will happen to it, otherwise it needs to have the same number
1117 * of allocated cells as <TT>target</TT>. Will fill in offsets from target to source pointer
1118 * 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>
1119 * For output data carried across calls, and other data without a specific source character
1120 * (such as from escape sequences or callbacks) -1 will be placed for offsets.
1121 * @param flush set to <TT>TRUE</TT> if the current source buffer is the last available
1122 * chunk of the source, <TT>FALSE</TT> otherwise. Note that if a failing status is returned,
1123 * this function may have to be called multiple times with flush set to <TT>TRUE</TT> until
1124 * the source buffer is consumed.
1125 * @param err the error status. <TT>U_ILLEGAL_ARGUMENT_ERROR</TT> will be set if the
1126 * converter is <TT>NULL</TT>.
1127 * <code>U_BUFFER_OVERFLOW_ERROR</code> will be set if the target is full and there is
1128 * still data to be written to the target.
1129 * @see ucnv_fromUChars
1131 * @see ucnv_getMinCharSize
1132 * @see ucnv_setFromUCallBack
1133 * @see ucnv_getNextUChar
1136 U_STABLE
void U_EXPORT2
1137 ucnv_toUnicode(UConverter
*converter
,
1139 const UChar
*targetLimit
,
1140 const char **source
,
1141 const char *sourceLimit
,
1147 * Convert the Unicode string into a codepage string using an existing UConverter.
1148 * The output string is NUL-terminated if possible.
1150 * This function is a more convenient but less powerful version of ucnv_fromUnicode().
1151 * It is only useful for whole strings, not for streaming conversion.
1153 * The maximum output buffer capacity required (barring output from callbacks) will be
1154 * UCNV_GET_MAX_BYTES_FOR_STRING(srcLength, ucnv_getMaxCharSize(cnv)).
1156 * @param cnv the converter object to be used (ucnv_resetFromUnicode() will be called)
1157 * @param src the input Unicode string
1158 * @param srcLength the input string length, or -1 if NUL-terminated
1159 * @param dest destination string buffer, can be NULL if destCapacity==0
1160 * @param destCapacity the number of chars available at dest
1161 * @param pErrorCode normal ICU error code;
1162 * common error codes that may be set by this function include
1163 * U_BUFFER_OVERFLOW_ERROR, U_STRING_NOT_TERMINATED_WARNING,
1164 * U_ILLEGAL_ARGUMENT_ERROR, and conversion errors
1165 * @return the length of the output string, not counting the terminating NUL;
1166 * if the length is greater than destCapacity, then the string will not fit
1167 * and a buffer of the indicated length would need to be passed in
1168 * @see ucnv_fromUnicode
1170 * @see UCNV_GET_MAX_BYTES_FOR_STRING
1173 U_STABLE
int32_t U_EXPORT2
1174 ucnv_fromUChars(UConverter
*cnv
,
1175 char *dest
, int32_t destCapacity
,
1176 const UChar
*src
, int32_t srcLength
,
1177 UErrorCode
*pErrorCode
);
1180 * Convert the codepage string into a Unicode string using an existing UConverter.
1181 * The output string is NUL-terminated if possible.
1183 * This function is a more convenient but less powerful version of ucnv_toUnicode().
1184 * It is only useful for whole strings, not for streaming conversion.
1186 * The maximum output buffer capacity required (barring output from callbacks) will be
1187 * 2*srcLength (each char may be converted into a surrogate pair).
1189 * @param cnv the converter object to be used (ucnv_resetToUnicode() will be called)
1190 * @param src the input codepage string
1191 * @param srcLength the input string length, or -1 if NUL-terminated
1192 * @param dest destination string buffer, can be NULL if destCapacity==0
1193 * @param destCapacity the number of UChars available at dest
1194 * @param pErrorCode normal ICU error code;
1195 * common error codes that may be set by this function include
1196 * U_BUFFER_OVERFLOW_ERROR, U_STRING_NOT_TERMINATED_WARNING,
1197 * U_ILLEGAL_ARGUMENT_ERROR, and conversion errors
1198 * @return the length of the output string, not counting the terminating NUL;
1199 * if the length is greater than destCapacity, then the string will not fit
1200 * and a buffer of the indicated length would need to be passed in
1201 * @see ucnv_toUnicode
1205 U_STABLE
int32_t U_EXPORT2
1206 ucnv_toUChars(UConverter
*cnv
,
1207 UChar
*dest
, int32_t destCapacity
,
1208 const char *src
, int32_t srcLength
,
1209 UErrorCode
*pErrorCode
);
1212 * Convert a codepage buffer into Unicode one character at a time.
1213 * The input is completely consumed when the U_INDEX_OUTOFBOUNDS_ERROR is set.
1215 * Advantage compared to ucnv_toUnicode() or ucnv_toUChars():
1216 * - Faster for small amounts of data, for most converters, e.g.,
1217 * US-ASCII, ISO-8859-1, UTF-8/16/32, and most "normal" charsets.
1218 * (For complex converters, e.g., SCSU, UTF-7 and ISO 2022 variants,
1219 * it uses ucnv_toUnicode() internally.)
1222 * Limitations compared to ucnv_toUnicode():
1223 * - Always assumes flush=TRUE.
1224 * This makes ucnv_getNextUChar() unsuitable for "streaming" conversion,
1225 * that is, for where the input is supplied in multiple buffers,
1226 * because ucnv_getNextUChar() will assume the end of the input at the end
1227 * of the first buffer.
1228 * - Does not provide offset output.
1230 * It is possible to "mix" ucnv_getNextUChar() and ucnv_toUnicode() because
1231 * ucnv_getNextUChar() uses the current state of the converter
1232 * (unlike ucnv_toUChars() which always resets first).
1233 * However, if ucnv_getNextUChar() is called after ucnv_toUnicode()
1234 * stopped in the middle of a character sequence (with flush=FALSE),
1235 * then ucnv_getNextUChar() will always use the slower ucnv_toUnicode()
1236 * internally until the next character boundary.
1237 * (This is new in ICU 2.6. In earlier releases, ucnv_getNextUChar() had to
1238 * start at a character boundary.)
1240 * Instead of using ucnv_getNextUChar(), it is recommended
1241 * to convert using ucnv_toUnicode() or ucnv_toUChars()
1242 * and then iterate over the text using U16_NEXT() or a UCharIterator (uiter.h)
1243 * or a C++ CharacterIterator or similar.
1244 * This allows streaming conversion and offset output, for example.
1246 * <p>Handling of surrogate pairs and supplementary-plane code points:<br>
1247 * There are two different kinds of codepages that provide mappings for surrogate characters:
1249 * <li>Codepages like UTF-8, UTF-32, and GB 18030 provide direct representations for Unicode
1250 * code points U+10000-U+10ffff as well as for single surrogates U+d800-U+dfff.
1251 * Each valid sequence will result in exactly one returned code point.
1252 * If a sequence results in a single surrogate, then that will be returned
1253 * by itself, even if a neighboring sequence encodes the matching surrogate.</li>
1254 * <li>Codepages like SCSU and LMBCS (and UTF-16) provide direct representations only for BMP code points
1255 * including surrogates. Code points in supplementary planes are represented with
1256 * two sequences, each encoding a surrogate.
1257 * For these codepages, matching pairs of surrogates will be combined into single
1258 * code points for returning from this function.
1259 * (Note that SCSU is actually a mix of these codepage types.)</li>
1262 * @param converter an open UConverter
1263 * @param source the address of a pointer to the codepage buffer, will be
1264 * updated to point after the bytes consumed in the conversion call.
1265 * @param sourceLimit points to the end of the input buffer
1266 * @param err fills in error status (see ucnv_toUnicode)
1267 * <code>U_INDEX_OUTOFBOUNDS_ERROR</code> will be set if the input
1268 * is empty or does not convert to any output (e.g.: pure state-change
1269 * codes SI/SO, escape sequences for ISO 2022,
1270 * or if the callback did not output anything, ...).
1271 * This function will not set a <code>U_BUFFER_OVERFLOW_ERROR</code> because
1272 * the "buffer" is the return code. However, there might be subsequent output
1273 * stored in the converter object
1274 * that will be returned in following calls to this function.
1275 * @return a UChar32 resulting from the partial conversion of source
1276 * @see ucnv_toUnicode
1277 * @see ucnv_toUChars
1281 U_STABLE UChar32 U_EXPORT2
1282 ucnv_getNextUChar(UConverter
* converter
,
1283 const char **source
,
1284 const char * sourceLimit
,
1288 * Convert from one external charset to another using two existing UConverters.
1289 * Internally, two conversions - ucnv_toUnicode() and ucnv_fromUnicode() -
1290 * are used, "pivoting" through 16-bit Unicode.
1292 * Important: For streaming conversion (multiple function calls for successive
1293 * parts of a text stream), the caller must provide a pivot buffer explicitly,
1294 * and must preserve the pivot buffer and associated pointers from one
1295 * call to another. (The buffer may be moved if its contents and the relative
1296 * pointer positions are preserved.)
1298 * There is a similar function, ucnv_convert(),
1299 * which has the following limitations:
1300 * - it takes charset names, not converter objects, so that
1301 * - two converters are opened for each call
1302 * - only single-string conversion is possible, not streaming operation
1303 * - it does not provide enough information to find out,
1304 * in case of failure, whether the toUnicode or
1305 * the fromUnicode conversion failed
1307 * By contrast, ucnv_convertEx()
1308 * - takes UConverter parameters instead of charset names
1309 * - fully exposes the pivot buffer for streaming conversion and complete error handling
1311 * ucnv_convertEx() also provides further convenience:
1312 * - an option to reset the converters at the beginning
1313 * (if reset==TRUE, see parameters;
1314 * also sets *pivotTarget=*pivotSource=pivotStart)
1315 * - allow NUL-terminated input
1316 * (only a single NUL byte, will not work for charsets with multi-byte NULs)
1317 * (if sourceLimit==NULL, see parameters)
1318 * - terminate with a NUL on output
1319 * (only a single NUL byte, not useful for charsets with multi-byte NULs),
1320 * or set U_STRING_NOT_TERMINATED_WARNING if the output exactly fills
1322 * - the pivot buffer can be provided internally;
1323 * possible only for whole-string conversion, not streaming conversion;
1324 * in this case, the caller will not be able to get details about where an
1326 * (if pivotStart==NULL, see below)
1328 * The function returns when one of the following is true:
1329 * - the entire source text has been converted successfully to the target buffer
1330 * - a target buffer overflow occurred (U_BUFFER_OVERFLOW_ERROR)
1331 * - a conversion error occurred
1332 * (other U_FAILURE(), see description of pErrorCode)
1334 * Limitation compared to the direct use of
1335 * ucnv_fromUnicode() and ucnv_toUnicode():
1336 * ucnv_convertEx() does not provide offset information.
1338 * Limitation compared to ucnv_fromUChars() and ucnv_toUChars():
1339 * ucnv_convertEx() does not support preflighting directly.
1341 * Sample code for converting a single string from
1342 * one external charset to UTF-8, ignoring the location of errors:
1346 * myToUTF8(UConverter *cnv,
1347 * const char *s, int32_t length,
1348 * char *u8, int32_t capacity,
1349 * UErrorCode *pErrorCode) {
1350 * UConverter *utf8Cnv;
1353 * if(U_FAILURE(*pErrorCode)) {
1357 * utf8Cnv=myGetCachedUTF8Converter(pErrorCode);
1358 * if(U_FAILURE(*pErrorCode)) {
1366 * ucnv_convertEx(cnv, utf8Cnv,
1367 * &target, u8+capacity,
1369 * NULL, NULL, NULL, NULL,
1373 * myReleaseCachedUTF8Converter(utf8Cnv);
1375 * // return the output string length, but without preflighting
1376 * return (int32_t)(target-u8);
1380 * @param targetCnv Output converter, used to convert from the UTF-16 pivot
1381 * to the target using ucnv_fromUnicode().
1382 * @param sourceCnv Input converter, used to convert from the source to
1383 * the UTF-16 pivot using ucnv_toUnicode().
1384 * @param target I/O parameter, same as for ucnv_fromUChars().
1385 * Input: *target points to the beginning of the target buffer.
1386 * Output: *target points to the first unit after the last char written.
1387 * @param targetLimit Pointer to the first unit after the target buffer.
1388 * @param source I/O parameter, same as for ucnv_toUChars().
1389 * Input: *source points to the beginning of the source buffer.
1390 * Output: *source points to the first unit after the last char read.
1391 * @param sourceLimit Pointer to the first unit after the source buffer.
1392 * @param pivotStart Pointer to the UTF-16 pivot buffer. If pivotStart==NULL,
1393 * then an internal buffer is used and the other pivot
1394 * arguments are ignored and can be NULL as well.
1395 * @param pivotSource I/O parameter, same as source in ucnv_fromUChars() for
1396 * conversion from the pivot buffer to the target buffer.
1397 * @param pivotTarget I/O parameter, same as target in ucnv_toUChars() for
1398 * conversion from the source buffer to the pivot buffer.
1399 * It must be pivotStart<=*pivotSource<=*pivotTarget<=pivotLimit
1400 * and pivotStart<pivotLimit (unless pivotStart==NULL).
1401 * @param pivotLimit Pointer to the first unit after the pivot buffer.
1402 * @param reset If TRUE, then ucnv_resetToUnicode(sourceCnv) and
1403 * ucnv_resetFromUnicode(targetCnv) are called, and the
1404 * pivot pointers are reset (*pivotTarget=*pivotSource=pivotStart).
1405 * @param flush If true, indicates the end of the input.
1406 * Passed directly to ucnv_toUnicode(), and carried over to
1407 * ucnv_fromUnicode() when the source is empty as well.
1408 * @param pErrorCode ICU error code in/out parameter.
1409 * Must fulfill U_SUCCESS before the function call.
1410 * U_BUFFER_OVERFLOW_ERROR always refers to the target buffer
1411 * because overflows into the pivot buffer are handled internally.
1412 * Other conversion errors are from the source-to-pivot
1413 * conversion if *pivotSource==pivotStart, otherwise from
1414 * the pivot-to-target conversion.
1417 * @see ucnv_fromAlgorithmic
1418 * @see ucnv_toAlgorithmic
1419 * @see ucnv_fromUnicode
1420 * @see ucnv_toUnicode
1421 * @see ucnv_fromUChars
1422 * @see ucnv_toUChars
1425 U_STABLE
void U_EXPORT2
1426 ucnv_convertEx(UConverter
*targetCnv
, UConverter
*sourceCnv
,
1427 char **target
, const char *targetLimit
,
1428 const char **source
, const char *sourceLimit
,
1429 UChar
*pivotStart
, UChar
**pivotSource
,
1430 UChar
**pivotTarget
, const UChar
*pivotLimit
,
1431 UBool reset
, UBool flush
,
1432 UErrorCode
*pErrorCode
);
1435 * Convert from one external charset to another.
1436 * Internally, two converters are opened according to the name arguments,
1437 * then the text is converted to and from the 16-bit Unicode "pivot"
1438 * using ucnv_convertEx(), then the converters are closed again.
1440 * This is a convenience function, not an efficient way to convert a lot of text:
1442 * - takes charset names, not converter objects, so that
1443 * - two converters are opened for each call
1444 * - only single-string conversion is possible, not streaming operation
1445 * - does not provide enough information to find out,
1446 * in case of failure, whether the toUnicode or
1447 * the fromUnicode conversion failed
1448 * - allows NUL-terminated input
1449 * (only a single NUL byte, will not work for charsets with multi-byte NULs)
1450 * (if sourceLength==-1, see parameters)
1451 * - terminate with a NUL on output
1452 * (only a single NUL byte, not useful for charsets with multi-byte NULs),
1453 * or set U_STRING_NOT_TERMINATED_WARNING if the output exactly fills
1455 * - a pivot buffer is provided internally
1457 * The function returns when one of the following is true:
1458 * - the entire source text has been converted successfully to the target buffer
1459 * and either the target buffer is terminated with a single NUL byte
1460 * or the error code is set to U_STRING_NOT_TERMINATED_WARNING
1461 * - a target buffer overflow occurred (U_BUFFER_OVERFLOW_ERROR)
1462 * and the full output string length is returned ("preflighting")
1463 * - a conversion error occurred
1464 * (other U_FAILURE(), see description of pErrorCode)
1466 * @param toConverterName The name of the converter that is used to convert
1467 * from the UTF-16 pivot buffer to the target.
1468 * @param fromConverterName The name of the converter that is used to convert
1469 * from the source to the UTF-16 pivot buffer.
1470 * @param target Pointer to the output buffer.
1471 * @param targetCapacity Capacity of the target, in bytes.
1472 * @param source Pointer to the input buffer.
1473 * @param sourceLength Length of the input text, in bytes, or -1 for NUL-terminated input.
1474 * @param pErrorCode ICU error code in/out parameter.
1475 * Must fulfill U_SUCCESS before the function call.
1476 * @return Length of the complete output text in bytes, even if it exceeds the targetCapacity
1477 * and a U_BUFFER_OVERFLOW_ERROR is set.
1479 * @see ucnv_convertEx
1480 * @see ucnv_fromAlgorithmic
1481 * @see ucnv_toAlgorithmic
1482 * @see ucnv_fromUnicode
1483 * @see ucnv_toUnicode
1484 * @see ucnv_fromUChars
1485 * @see ucnv_toUChars
1486 * @see ucnv_getNextUChar
1489 U_STABLE
int32_t U_EXPORT2
1490 ucnv_convert(const char *toConverterName
,
1491 const char *fromConverterName
,
1493 int32_t targetCapacity
,
1495 int32_t sourceLength
,
1496 UErrorCode
*pErrorCode
);
1499 * Convert from one external charset to another.
1500 * Internally, the text is converted to and from the 16-bit Unicode "pivot"
1501 * using ucnv_convertEx(). ucnv_toAlgorithmic() works exactly like ucnv_convert()
1502 * except that the two converters need not be looked up and opened completely.
1504 * The source-to-pivot conversion uses the cnv converter parameter.
1505 * The pivot-to-target conversion uses a purely algorithmic converter
1506 * according to the specified type, e.g., UCNV_UTF8 for a UTF-8 converter.
1508 * Internally, the algorithmic converter is opened and closed for each
1509 * function call, which is more efficient than using the public ucnv_open()
1510 * but somewhat less efficient than only resetting an existing converter
1511 * and using ucnv_convertEx().
1513 * This function is more convenient than ucnv_convertEx() for single-string
1514 * conversions, especially when "preflighting" is desired (returning the length
1515 * of the complete output even if it does not fit into the target buffer;
1516 * see the User Guide Strings chapter). See ucnv_convert() for details.
1518 * @param algorithmicType UConverterType constant identifying the desired target
1519 * charset as a purely algorithmic converter.
1520 * Those are converters for Unicode charsets like
1521 * UTF-8, BOCU-1, SCSU, UTF-7, IMAP-mailbox-name, etc.,
1522 * as well as US-ASCII and ISO-8859-1.
1523 * @param cnv The converter that is used to convert
1524 * from the source to the UTF-16 pivot buffer.
1525 * @param target Pointer to the output buffer.
1526 * @param targetCapacity Capacity of the target, in bytes.
1527 * @param source Pointer to the input buffer.
1528 * @param sourceLength Length of the input text, in bytes
1529 * @param pErrorCode ICU error code in/out parameter.
1530 * Must fulfill U_SUCCESS before the function call.
1531 * @return Length of the complete output text in bytes, even if it exceeds the targetCapacity
1532 * and a U_BUFFER_OVERFLOW_ERROR is set.
1534 * @see ucnv_fromAlgorithmic
1536 * @see ucnv_convertEx
1537 * @see ucnv_fromUnicode
1538 * @see ucnv_toUnicode
1539 * @see ucnv_fromUChars
1540 * @see ucnv_toUChars
1543 U_STABLE
int32_t U_EXPORT2
1544 ucnv_toAlgorithmic(UConverterType algorithmicType
,
1546 char *target
, int32_t targetCapacity
,
1547 const char *source
, int32_t sourceLength
,
1548 UErrorCode
*pErrorCode
);
1551 * Convert from one external charset to another.
1552 * Internally, the text is converted to and from the 16-bit Unicode "pivot"
1553 * using ucnv_convertEx(). ucnv_fromAlgorithmic() works exactly like ucnv_convert()
1554 * except that the two converters need not be looked up and opened completely.
1556 * The source-to-pivot conversion uses a purely algorithmic converter
1557 * according to the specified type, e.g., UCNV_UTF8 for a UTF-8 converter.
1558 * The pivot-to-target conversion uses the cnv converter parameter.
1560 * Internally, the algorithmic converter is opened and closed for each
1561 * function call, which is more efficient than using the public ucnv_open()
1562 * but somewhat less efficient than only resetting an existing converter
1563 * and using ucnv_convertEx().
1565 * This function is more convenient than ucnv_convertEx() for single-string
1566 * conversions, especially when "preflighting" is desired (returning the length
1567 * of the complete output even if it does not fit into the target buffer;
1568 * see the User Guide Strings chapter). See ucnv_convert() for details.
1570 * @param cnv The converter that is used to convert
1571 * from the UTF-16 pivot buffer to the target.
1572 * @param algorithmicType UConverterType constant identifying the desired source
1573 * charset as a purely algorithmic converter.
1574 * Those are converters for Unicode charsets like
1575 * UTF-8, BOCU-1, SCSU, UTF-7, IMAP-mailbox-name, etc.,
1576 * as well as US-ASCII and ISO-8859-1.
1577 * @param target Pointer to the output buffer.
1578 * @param targetCapacity Capacity of the target, in bytes.
1579 * @param source Pointer to the input buffer.
1580 * @param sourceLength Length of the input text, in bytes
1581 * @param pErrorCode ICU error code in/out parameter.
1582 * Must fulfill U_SUCCESS before the function call.
1583 * @return Length of the complete output text in bytes, even if it exceeds the targetCapacity
1584 * and a U_BUFFER_OVERFLOW_ERROR is set.
1586 * @see ucnv_fromAlgorithmic
1588 * @see ucnv_convertEx
1589 * @see ucnv_fromUnicode
1590 * @see ucnv_toUnicode
1591 * @see ucnv_fromUChars
1592 * @see ucnv_toUChars
1595 U_STABLE
int32_t U_EXPORT2
1596 ucnv_fromAlgorithmic(UConverter
*cnv
,
1597 UConverterType algorithmicType
,
1598 char *target
, int32_t targetCapacity
,
1599 const char *source
, int32_t sourceLength
,
1600 UErrorCode
*pErrorCode
);
1603 * Frees up memory occupied by unused, cached converter shared data.
1605 * @return the number of cached converters successfully deleted
1609 U_STABLE
int32_t U_EXPORT2
1610 ucnv_flushCache(void);
1613 * Returns the number of available converters, as per the alias file.
1615 * @return the number of available converters
1616 * @see ucnv_getAvailableName
1619 U_STABLE
int32_t U_EXPORT2
1620 ucnv_countAvailable(void);
1623 * Gets the canonical converter name of the specified converter from a list of
1624 * all available converters contaied in the alias file. All converters
1625 * in this list can be opened.
1627 * @param n the index to a converter available on the system (in the range <TT>[0..ucnv_countAvaiable()]</TT>)
1628 * @return a pointer a string (library owned), or <TT>NULL</TT> if the index is out of bounds.
1629 * @see ucnv_countAvailable
1632 U_STABLE
const char* U_EXPORT2
1633 ucnv_getAvailableName(int32_t n
);
1636 * Returns a UEnumeration to enumerate all of the canonical converter
1637 * names, as per the alias file, regardless of the ability to open each
1640 * @return A UEnumeration object for getting all the recognized canonical
1642 * @see ucnv_getAvailableName
1647 U_STABLE UEnumeration
* U_EXPORT2
1648 ucnv_openAllNames(UErrorCode
*pErrorCode
);
1651 * Gives the number of aliases for a given converter or alias name.
1652 * If the alias is ambiguous, then the preferred converter is used
1653 * and the status is set to U_AMBIGUOUS_ALIAS_WARNING.
1654 * This method only enumerates the listed entries in the alias file.
1655 * @param alias alias name
1656 * @param pErrorCode error status
1657 * @return number of names on alias list for given alias
1660 U_STABLE
uint16_t U_EXPORT2
1661 ucnv_countAliases(const char *alias
, UErrorCode
*pErrorCode
);
1664 * Gives the name of the alias at given index of alias list.
1665 * This method only enumerates the listed entries in the alias file.
1666 * If the alias is ambiguous, then the preferred converter is used
1667 * and the status is set to U_AMBIGUOUS_ALIAS_WARNING.
1668 * @param alias alias name
1669 * @param n index in alias list
1670 * @param pErrorCode result of operation
1671 * @return returns the name of the alias at given index
1672 * @see ucnv_countAliases
1675 U_STABLE
const char * U_EXPORT2
1676 ucnv_getAlias(const char *alias
, uint16_t n
, UErrorCode
*pErrorCode
);
1679 * Fill-up the list of alias names for the given alias.
1680 * This method only enumerates the listed entries in the alias file.
1681 * If the alias is ambiguous, then the preferred converter is used
1682 * and the status is set to U_AMBIGUOUS_ALIAS_WARNING.
1683 * @param alias alias name
1684 * @param aliases fill-in list, aliases is a pointer to an array of
1685 * <code>ucnv_countAliases()</code> string-pointers
1686 * (<code>const char *</code>) that will be filled in.
1687 * The strings themselves are owned by the library.
1688 * @param pErrorCode result of operation
1691 U_STABLE
void U_EXPORT2
1692 ucnv_getAliases(const char *alias
, const char **aliases
, UErrorCode
*pErrorCode
);
1695 * Return a new UEnumeration object for enumerating all the
1696 * alias names for a given converter that are recognized by a standard.
1697 * This method only enumerates the listed entries in the alias file.
1698 * The convrtrs.txt file can be modified to change the results of
1700 * The first result in this list is the same result given by
1701 * <code>ucnv_getStandardName</code>, which is the default alias for
1702 * the specified standard name. The returned object must be closed with
1703 * <code>uenum_close</code> when you are done with the object.
1705 * @param convName original converter name
1706 * @param standard name of the standard governing the names; MIME and IANA
1707 * are such standards
1708 * @param pErrorCode The error code
1709 * @return A UEnumeration object for getting all aliases that are recognized
1710 * by a standard. If any of the parameters are invalid, NULL
1712 * @see ucnv_getStandardName
1717 U_STABLE UEnumeration
* U_EXPORT2
1718 ucnv_openStandardNames(const char *convName
,
1719 const char *standard
,
1720 UErrorCode
*pErrorCode
);
1723 * Gives the number of standards associated to converter names.
1724 * @return number of standards
1727 U_STABLE
uint16_t U_EXPORT2
1728 ucnv_countStandards(void);
1731 * Gives the name of the standard at given index of standard list.
1732 * @param n index in standard list
1733 * @param pErrorCode result of operation
1734 * @return returns the name of the standard at given index. Owned by the library.
1737 U_STABLE
const char * U_EXPORT2
1738 ucnv_getStandard(uint16_t n
, UErrorCode
*pErrorCode
);
1741 * Returns a standard name for a given converter name.
1743 * Example alias table:<br>
1744 * conv alias1 { STANDARD1 } alias2 { STANDARD1* }
1746 * Result of ucnv_getStandardName("conv", "STANDARD1") from example
1750 * @param name original converter name
1751 * @param standard name of the standard governing the names; MIME and IANA
1752 * are such standards
1753 * @param pErrorCode result of operation
1754 * @return returns the standard converter name;
1755 * if a standard converter name cannot be determined,
1756 * then <code>NULL</code> is returned. Owned by the library.
1759 U_STABLE
const char * U_EXPORT2
1760 ucnv_getStandardName(const char *name
, const char *standard
, UErrorCode
*pErrorCode
);
1763 * This function will return the internal canonical converter name of the
1764 * tagged alias. This is the opposite of ucnv_openStandardNames, which
1765 * returns the tagged alias given the canonical name.
1767 * Example alias table:<br>
1768 * conv alias1 { STANDARD1 } alias2 { STANDARD1* }
1770 * Result of ucnv_getStandardName("alias1", "STANDARD1") from example
1774 * @return returns the canonical converter name;
1775 * if a standard or alias name cannot be determined,
1776 * then <code>NULL</code> is returned. The returned string is
1777 * owned by the library.
1778 * @see ucnv_getStandardName
1781 U_STABLE
const char * U_EXPORT2
1782 ucnv_getCanonicalName(const char *alias
, const char *standard
, UErrorCode
*pErrorCode
);
1785 * Returns the current default converter name. If you want to open
1786 * a default converter, you do not need to use this function.
1787 * It is faster if you pass a NULL argument to ucnv_open the
1788 * default converter.
1790 * @return returns the current default converter name.
1791 * Storage owned by the library
1792 * @see ucnv_setDefaultName
1795 U_STABLE
const char * U_EXPORT2
1796 ucnv_getDefaultName(void);
1799 * This function is not thread safe. DO NOT call this function when ANY ICU
1800 * function is being used from more than one thread! This function sets the
1801 * current default converter name. If this function needs to be called, it
1802 * should be called during application initialization. Most of the time, the
1803 * results from ucnv_getDefaultName() or ucnv_open with a NULL string argument
1804 * is sufficient for your application.
1805 * @param name the converter name to be the default (must be known by ICU).
1806 * @see ucnv_getDefaultName
1810 U_STABLE
void U_EXPORT2
1811 ucnv_setDefaultName(const char *name
);
1814 * Fixes the backslash character mismapping. For example, in SJIS, the backslash
1815 * character in the ASCII portion is also used to represent the yen currency sign.
1816 * When mapping from Unicode character 0x005C, it's unclear whether to map the
1817 * character back to yen or backslash in SJIS. This function will take the input
1818 * buffer and replace all the yen sign characters with backslash. This is necessary
1819 * when the user tries to open a file with the input buffer on Windows.
1820 * This function will test the converter to see whether such mapping is
1821 * required. You can sometimes avoid using this function by using the correct version
1824 * @param cnv The converter representing the target codepage.
1825 * @param source the input buffer to be fixed
1826 * @param sourceLen the length of the input buffer
1827 * @see ucnv_isAmbiguous
1830 U_STABLE
void U_EXPORT2
1831 ucnv_fixFileSeparator(const UConverter
*cnv
, UChar
*source
, int32_t sourceLen
);
1834 * Determines if the converter contains ambiguous mappings of the same
1836 * @param cnv the converter to be tested
1837 * @return TRUE if the converter contains ambiguous mapping of the same
1838 * character, FALSE otherwise.
1841 U_STABLE UBool U_EXPORT2
1842 ucnv_isAmbiguous(const UConverter
*cnv
);
1845 * Sets the converter to use fallback mappings or not.
1846 * Regardless of this flag, the converter will always use
1847 * fallbacks from Unicode Private Use code points, as well as
1848 * reverse fallbacks (to Unicode).
1849 * For details see ".ucm File Format"
1850 * in the Conversion Data chapter of the ICU User Guide:
1851 * http://www.icu-project.org/userguide/conversion-data.html#ucmformat
1853 * @param cnv The converter to set the fallback mapping usage on.
1854 * @param usesFallback TRUE if the user wants the converter to take advantage of the fallback
1855 * mapping, FALSE otherwise.
1857 * @see ucnv_usesFallback
1859 U_STABLE
void U_EXPORT2
1860 ucnv_setFallback(UConverter
*cnv
, UBool usesFallback
);
1863 * Determines if the converter uses fallback mappings or not.
1864 * This flag has restrictions, see ucnv_setFallback().
1866 * @param cnv The converter to be tested
1867 * @return TRUE if the converter uses fallback, FALSE otherwise.
1869 * @see ucnv_setFallback
1871 U_STABLE UBool U_EXPORT2
1872 ucnv_usesFallback(const UConverter
*cnv
);
1875 * Detects Unicode signature byte sequences at the start of the byte stream
1876 * and returns the charset name of the indicated Unicode charset.
1877 * NULL is returned when no Unicode signature is recognized.
1878 * The number of bytes in the signature is output as well.
1880 * The caller can ucnv_open() a converter using the charset name.
1881 * The first code unit (UChar) from the start of the stream will be U+FEFF
1882 * (the Unicode BOM/signature character) and can usually be ignored.
1884 * For most Unicode charsets it is also possible to ignore the indicated
1885 * number of initial stream bytes and start converting after them.
1886 * However, there are stateful Unicode charsets (UTF-7 and BOCU-1) for which
1887 * this will not work. Therefore, it is best to ignore the first output UChar
1888 * instead of the input signature bytes.
1892 * UErrorCode err = U_ZERO_ERROR;
1893 * char input[] = { '\xEF','\xBB', '\xBF','\x41','\x42','\x43' };
1894 * int32_t signatureLength = 0;
1895 * char *encoding = ucnv_detectUnicodeSignature(input,sizeof(input),&signatureLength,&err);
1896 * UConverter *conv = NULL;
1897 * UChar output[100];
1898 * UChar *target = output, *out;
1899 * char *source = input;
1900 * if(encoding!=NULL && U_SUCCESS(err)){
1901 * // should signature be discarded ?
1902 * conv = ucnv_open(encoding, &err);
1903 * // do the conversion
1904 * ucnv_toUnicode(conv,
1905 * target, output + sizeof(output)/U_SIZEOF_UCHAR,
1906 * source, input + sizeof(input),
1907 * NULL, TRUE, &err);
1909 * if (discardSignature){
1910 * ++out; // ignore initial U+FEFF
1912 * while(out != target) {
1913 * printf("%04x ", *out++);
1920 * @param source The source string in which the signature should be detected.
1921 * @param sourceLength Length of the input string, or -1 if terminated with a NUL byte.
1922 * @param signatureLength A pointer to int32_t to receive the number of bytes that make up the signature
1923 * of the detected UTF. 0 if not detected.
1924 * Can be a NULL pointer.
1925 * @param pErrorCode ICU error code in/out parameter.
1926 * Must fulfill U_SUCCESS before the function call.
1927 * @return The name of the encoding detected. NULL if encoding is not detected.
1930 U_STABLE
const char* U_EXPORT2
1931 ucnv_detectUnicodeSignature(const char* source
,
1932 int32_t sourceLength
,
1933 int32_t *signatureLength
,
1934 UErrorCode
*pErrorCode
);
1937 * Returns the number of UChars held in the converter's internal state
1938 * because more input is needed for completing the conversion. This function is
1939 * useful for mapping semantics of ICU's converter interface to those of iconv,
1940 * and this information is not needed for normal conversion.
1941 * @param cnv The converter in which the input is held
1942 * @param status ICU error code in/out parameter.
1943 * Must fulfill U_SUCCESS before the function call.
1944 * @return The number of UChars in the state. -1 if an error is encountered.
1947 U_STABLE
int32_t U_EXPORT2
1948 ucnv_fromUCountPending(const UConverter
* cnv
, UErrorCode
* status
);
1951 * Returns the number of chars held in the converter's internal state
1952 * because more input is needed for completing the conversion. This function is
1953 * useful for mapping semantics of ICU's converter interface to those of iconv,
1954 * and this information is not needed for normal conversion.
1955 * @param cnv The converter in which the input is held as internal state
1956 * @param status ICU error code in/out parameter.
1957 * Must fulfill U_SUCCESS before the function call.
1958 * @return The number of chars in the state. -1 if an error is encountered.
1961 U_STABLE
int32_t U_EXPORT2
1962 ucnv_toUCountPending(const UConverter
* cnv
, UErrorCode
* status
);