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