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