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