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