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