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