2
**********************************************************************
3
* Copyright (C) 1999-2001, International Business Machines
4
* Corporation and others. All Rights Reserved.
5
**********************************************************************
7
* External APIs for the ICU's codeset conversion library
10
* Modification History:
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
21
* \brief C API: Character conversion
23
* <h2>Character Conversion C API </h2>
30
/** Forward declaring the UConverter structure. @stable */
34
typedef struct UConverter UConverter;
36
#include "unicode/utypes.h"
37
#include "unicode/ucnv_err.h"
41
/* maximum length of the converter names */
42
#define UCNV_MAX_CONVERTER_NAME_LENGTH 60
43
#define UCNV_MAX_FULL_FILE_NAME_LENGTH (600+UCNV_MAX_CONVERTER_NAME_LENGTH)
45
#define UCNV_SI 0x0F /*Shift in for EBDCDIC_STATEFUL and iso2022 states */
46
#define UCNV_SO 0x0E /*Shift out for EBDCDIC_STATEFUL and iso2022 states */
49
* Enum for specifying basic types of converters
54
UCNV_UNSUPPORTED_CONVERTER = -1,
60
UCNV_UTF16_BigEndian = 5,
61
UCNV_UTF16_LittleEndian = 6,
62
UCNV_UTF32_BigEndian = 7,
63
UCNV_UTF32_LittleEndian = 8,
64
UCNV_EBCDIC_STATEFUL = 9,
79
UCNV_LMBCS_LAST = UCNV_LMBCS_19,
86
/* Number of converter types for which we have conversion routines. */
87
UCNV_NUMBER_OF_SUPPORTED_CONVERTER_TYPES
92
* Enum for specifying which platform a converter ID refers to.
93
* The use of platform/CCSID is not recommended. See ucnv_openCCSID().
95
* @see ucnv_getPlatform
103
} UConverterPlatform;
106
* Function pointer for error callback in the codepage to unicode direction.
107
* Called when an error has occured in conversion to unicode, or on open/close of the callback (see reason).
108
* @param context Pointer to the callback's private data
109
* @param args Information about the conversion in progress
110
* @param codePoints Points to 'length' bytes of the concerned codepage sequence
111
* @param length Size (in bytes) of the concerned codepage sequence
112
* @param reason Defines the reason the callback was invoked
113
* @see ucnv_setToUCallBack
114
* @see UConverterToUnicodeArgs
117
typedef void (U_EXPORT2 *UConverterToUCallback) (
119
UConverterToUnicodeArgs *args,
120
const char *codePoints,
122
UConverterCallbackReason reason,
126
* Function pointer for error callback in the unicode to codepage direction.
127
* Called when an error has occured in conversion from unicode, or on open/close of the callback (see reason).
128
* @param context Pointer to the callback's private data
129
* @param args Information about the conversion in progress
130
* @param codeUnits Points to 'length' UChars of the concerned Unicode sequence
131
* @param length Size (in bytes) of the concerned codepage sequence
132
* @param codePoint Single UChar32 (UTF-32) containing the concerend Unicode codepoint.
133
* @param reason Defines the reason the callback was invoked
134
* @see ucnv_setFromUCallBack
137
typedef void (U_EXPORT2 *UConverterFromUCallback) (
139
UConverterFromUnicodeArgs *args,
140
const UChar* codeUnits,
143
UConverterCallbackReason reason,
149
* Character that separates converter names from options and options from each other.
153
#define UCNV_OPTION_SEP_CHAR ','
156
* String version of UCNV_OPTION_SEP_CHAR.
160
#define UCNV_OPTION_SEP_STRING ","
163
* Character that separates a converter option from its value.
167
#define UCNV_VALUE_SEP_CHAR '='
170
* String version of UCNV_VALUE_SEP_CHAR.
174
#define UCNV_VALUE_SEP_STRING "="
177
* Converter option for specifying a locale.
181
#define UCNV_LOCALE_OPTION_STRING ",locale="
184
* Do a fuzzy compare of a two converter/alias names. The comparison
185
* is case-insensitive. It also ignores the characters '-', '_', and
186
* ' ' (dash, underscore, and space). Thus the strings "UTF-8",
187
* "utf_8", and "Utf 8" are exactly equivalent.
189
* @param name1 a converter name or alias, zero-terminated
190
* @param name2 a converter name or alias, zero-terminated
191
* @return 0 if the names match, or a negative value if the name1
192
* lexically precedes name2, or a positive value if the name1
193
* lexically follows name2.
197
ucnv_compareNames(const char *name1, const char *name2);
201
* Creates a UConverter object with the names specified as a C string.
202
* The actual name will be resolved with the alias file
203
* using a case-insensitive string comparison that ignores
204
* the delimiters '-', '_', and ' ' (dash, underscore, and space).
205
* E.g., the names "UTF8", "utf-8", and "Utf 8" are all equivalent.
206
* If <code>NULL</code> is passed for the converter name, it will create one with the
207
* getDefaultName return value.
209
* <p>A converter name for ICU 1.5 and above may contain options
210
* like a locale specification to control the specific behavior of
211
* the newly instantiated converter.
212
* The meaning of the options depends on the particular converter.
213
* If an option is not defined for or recognized by a given converter, then it is ignored.</p>
215
* <p>Options are appended to the converter name string, with a
216
* <code>UCNV_OPTION_SEP_CHAR</code> between the name and the first option and
217
* also between adjacent options.</p>
219
* @param converterName : name of the uconv table, may have options appended
220
* @param err outgoing error status <TT>U_MEMORY_ALLOCATION_ERROR, U_FILE_ACCESS_ERROR</TT>
221
* @return the created Unicode converter object, or <TT>NULL</TT> if an error occured
223
* @see ucnv_openCCSID
227
U_CAPI UConverter* U_EXPORT2
228
ucnv_open (const char *converterName, UErrorCode * err);
232
* Creates a Unicode converter with the names specified as unicode string.
233
* The name should be limited to the ASCII-7 alphanumerics range.
234
* The actual name will be resolved with the alias file
235
* using a case-insensitive string comparison that ignores
236
* the delimiters '-', '_', and ' ' (dash, underscore, and space).
237
* E.g., the names "UTF8", "utf-8", and "Utf 8" are all equivalent.
238
* If <TT>NULL</TT> is passed for the converter name, it will create
239
* one with the ucnv_getDefaultName() return value.
240
* @param converterName : name of the uconv table in a zero terminated
242
* @param err outgoing error status <TT>U_MEMORY_ALLOCATION_ERROR,
243
* U_FILE_ACCESS_ERROR</TT>
244
* @return the created Unicode converter object, or <TT>NULL</TT> if an
247
* @see ucnv_openCCSID
249
* @see ucnv_getDefaultName
252
U_CAPI UConverter* U_EXPORT2
253
ucnv_openU (const UChar * name,
257
* Creates a UConverter object from a CCSID number and platform pair.
258
* Note that the usefulness of this function is limited to platforms with numeric
259
* encoding IDs. Only IBM and Microsoft platforms use numeric (16-bit) identifiers for
262
* In addition, IBM CCSIDs and Unicode conversion tables are not 1:1 related.
263
* For many IBM CCSIDs there are multiple (up to six) Unicode conversion tables, and
264
* for some Unicode conversion tables there are multiple CCSIDs.
265
* Some "alternate" Unicode conversion tables are provided by the
266
* IBM CDRA conversion table registry.
267
* The most prominent example of a systematic modification of conversion tables that is
268
* not provided in the form of conversion table files in the repository is
269
* that S/390 Unix System Services swaps the codes for Line Feed and New Line in all
270
* EBCDIC codepages, which requires such a swap in the Unicode conversion tables as well.
272
* Only IBM default conversion tables are accessible with ucnv_openCCSID().
273
* ucnv_getCCSID() will return the same CCSID for all conversion tables that are associated
276
* Currently, the only "platform" supported in the ICU converter API is UCNV_IBM.
278
* In summary, the use of CCSIDs and the associated API functions is not recommended.
280
* In order to open a converter with the default IBM CDRA Unicode conversion table,
281
* you can use this function or use the prefix "ibm-":
284
* sprintf(name, "ibm-%hu", ccsid);
285
* cnv=ucnv_open(name, &errorCode);
288
* In order to open a converter with the IBM S/390 Unix System Services variant of a Unicode/EBCDIC conversion table,
289
* you can use the prefix "ibm-" together with the suffix "-s390":
292
* sprintf(name, "ibm-%hu-s390", ccsid);
293
* cnv=ucnv_open(name, &errorCode);
296
* In order to open a converter from a Microsoft codepage number, use the prefix "cp":
299
* sprintf(name, "cp%hu", codepageID);
300
* cnv=ucnv_open(name, &errorCode);
303
* @param codepage codepage number to create
304
* @param platform the platform in which the codepage number exists
305
* @param err error status <TT>U_MEMORY_ALLOCATION_ERROR, U_FILE_ACCESS_ERROR</TT>
306
* @return the created Unicode converter object, or <TT>NULL</TT> if an error
312
* @see ucnv_getPlatform
313
* @see UConverterPlatform
316
U_CAPI UConverter* U_EXPORT2
317
ucnv_openCCSID (int32_t codepage,
318
UConverterPlatform platform,
322
* Thread safe cloning operation
323
* @param cnv converter to be cloned
324
* @param stackBuffer user allocated space for the new clone. If NULL new memory will be allocated.
325
* If buffer is not large enough, new memory will be allocated.
326
* Clients can use the U_CNV_SAFECLONE_BUFFERSIZE. This will probably be enough to avoid memory allocations.
327
* @param pBufferSize pointer to size of allocated space.
328
* If *pBufferSize == 0, a sufficient size for use in cloning will
329
* be returned ('pre-flighting')
330
* If *pBufferSize is not enough for a stack-based safe clone,
331
* new memory will be allocated.
332
* @param status to indicate whether the operation went on smoothly or there were errors
333
* An informational status value, U_SAFECLONE_ALLOCATED_ERROR, is used if any allocations were necessary.
334
* @return pointer to the new clone
337
U_CAPI UConverter * U_EXPORT2
338
ucnv_safeClone(const UConverter *cnv,
340
int32_t *pBufferSize,
343
/** @draft ICU 1.8 */
344
#define U_CNV_SAFECLONE_BUFFERSIZE 512
347
* Deletes the unicode converter and releases resources associated
348
* with just this instance.
349
* Does not free up shared converter tables.
351
* @param converter the converter object to be deleted
354
* @see ucnv_openCCSID
357
U_CAPI void U_EXPORT2
358
ucnv_close (UConverter * converter);
361
* Fills in the output parameter, subChars, with the substitution characters
364
* @param converter the Unicode converter
365
* @param subChars the subsitution characters
366
* @param len on input the capacity of subChars, on output the number
367
* of bytes copied to it
368
* @param err the outgoing error status code.
369
* If the substitution character array is too small, an
370
* <TT>U_INDEX_OUTOFBOUNDS_ERROR</TT> will be returned.
371
* @see ucnv_setSubstChars
374
U_CAPI void U_EXPORT2
375
ucnv_getSubstChars (const UConverter * converter,
381
* Sets the substitution chars when converting from unicode to a codepage. The
382
* substitution is specified as a string of 1-4 bytes, and may contain
383
* <TT>NULL</TT> byte.
384
* @param converter the Unicode converter
385
* @param subChars the substitution character byte sequence we want set
386
* @param len the number of bytes in subChars
387
* @param err the error status code. <TT>U_INDEX_OUTOFBOUNDS_ERROR </TT> if
388
* len is bigger than the maximum number of bytes allowed in subchars
389
* @see ucnv_getSubstChars
392
U_CAPI void U_EXPORT2
393
ucnv_setSubstChars (UConverter * converter,
394
const char *subChars,
399
* Fills in the output parameter, errBytes, with the error characters from the
400
* last failing conversion.
402
* @param converter the Unicode converter
403
* @param errBytes the codepage bytes which were in error
404
* @param len on input the capacity of errBytes, on output the number of
405
* bytes which were copied to it
406
* @param err the error status code.
407
* If the substitution character array is too small, an
408
* <TT>U_INDEX_OUTOFBOUNDS_ERROR</TT> will be returned.
411
U_CAPI void U_EXPORT2
412
ucnv_getInvalidChars (const UConverter * converter,
418
* Fills in the output parameter, errChars, with the error characters from the
419
* last failing conversion.
421
* @param converter the Unicode converter
422
* @param errUChars the UChars which were in error
423
* @param len on input the capacity of errUChars, on output the number of
424
* UChars which were copied to it
425
* @param err the error status code.
426
* If the substitution character array is too small, an
427
* <TT>U_INDEX_OUTOFBOUNDS_ERROR</TT> will be returned.
430
U_CAPI void U_EXPORT2
431
ucnv_getInvalidUChars (const UConverter * converter,
437
* Resets the state of a converter to the default state. This is used
438
* in the case of an error, to restart a conversion from a known default state.
439
* It will also empty the internal output buffers.
440
* @param converter the Unicode converter
443
U_CAPI void U_EXPORT2
444
ucnv_reset (UConverter * converter);
447
* Resets the to-Unicode part of a converter state to the default state.
448
* This is used in the case of an error to restart a conversion to
449
* Unicode to a known default state. It will also empty the internal
450
* output buffers used for the conversion to Unicode codepoints.
451
* @param converter the Unicode converter
454
U_CAPI void U_EXPORT2
455
ucnv_resetToUnicode(UConverter *converter);
458
* Resets the from-Unicode part of a converter state to the default state.
459
* This is used in the case of an error to restart a conversion from
460
* Unicode to a known default state. It will also empty the internal output
461
* buffers used for the conversion from Unicode codepoints.
462
* @param converter the Unicode converter
465
U_CAPI void U_EXPORT2
466
ucnv_resetFromUnicode(UConverter *converter);
469
* Returns the maximum length of bytes used by a character. This varies
471
* @param converter the Unicode converter
472
* @return the maximum number of bytes allowed by this particular converter
473
* @see ucnv_getMinCharSize
476
U_CAPI int8_t U_EXPORT2
477
ucnv_getMaxCharSize (const UConverter * converter);
481
* Returns the minimum byte length for characters in this codepage.
482
* This is either 1 or 2 for all supported codepages.
483
* @param converter the Unicode converter
484
* @return the minimum number of bytes allowed by this particular converter
485
* @see ucnv_getMaxCharSize
488
U_CAPI int8_t U_EXPORT2
489
ucnv_getMinCharSize (const UConverter * converter);
492
* Returns the display name of the converter passed in based on the Locale
493
* passed in. If the locale contains no display name, the internal ASCII
494
* name will be filled in.
496
* @param converter the Unicode converter.
497
* @param displayLocale is the specific Locale we want to localised for
498
* @param displayName user provided buffer to be filled in
499
* @param displayNameCapacty size of displayName Buffer
500
* @param err error status code
501
* @return displayNameLength number of UChar needed in displayName
505
U_CAPI int32_t U_EXPORT2
506
ucnv_getDisplayName (const UConverter * converter,
507
const char *displayLocale,
509
int32_t displayNameCapacity,
513
* Gets the internal, canonical name of the converter (zero-terminated).
514
* The lifetime of the returned string will be that of the converter
515
* passed to this function.
516
* @param converter the Unicode converter
517
* @param err UErrorCode status
518
* @return the internal name of the converter
519
* @see ucnv_getDisplayName
522
U_CAPI const char * U_EXPORT2
523
ucnv_getName (const UConverter * converter, UErrorCode * err);
527
* Gets a codepage number associated with the converter. This is not guaranteed
528
* to be the one used to create the converter. Some converters do not represent
529
* platform registered codepages and return zero for the codepage number.
530
* The error code fill-in parameter indicates if the codepage number
532
* Does not check if the converter is <TT>NULL</TT> or if converter's data
533
* table is <TT>NULL</TT>.
535
* Important: The use of CCSIDs is not recommended because it is limited
536
* to only two platforms in principle and only one (UCNV_IBM) in the current
538
* Also, CCSIDs are insufficient to identify IBM Unicode conversion tables precisely.
539
* For more details see ucnv_openCCSID().
541
* @param converter the Unicode converter
542
* @param err the error status code.
543
* @return If any error occurrs, -1 will be returned otherwise, the codepage number
545
* @see ucnv_openCCSID
546
* @see ucnv_getPlatform
549
U_CAPI int32_t U_EXPORT2
550
ucnv_getCCSID (const UConverter * converter,
554
* Gets a codepage platform associated with the converter. Currently,
555
* only <TT>UCNV_IBM</TT> will be returned.
556
* Does not test if the converter is <TT>NULL</TT> or if converter's data
557
* table is <TT>NULL</TT>.
558
* @param converter the Unicode converter
559
* @param err the error status code.
560
* @return The codepage platform
563
U_CAPI UConverterPlatform U_EXPORT2
564
ucnv_getPlatform (const UConverter * converter,
568
* Gets the type of the converter
569
* e.g. SBCS, MBCS, DBCS, UTF8, UTF16_BE, UTF16_LE, ISO_2022,
570
* EBCDIC_STATEFUL, LATIN_1
571
* @param converter a valid, opened converter
572
* @return the type of the converter
575
U_CAPI UConverterType U_EXPORT2
576
ucnv_getType (const UConverter * converter);
579
* Gets the "starter" (lead) bytes for converters of type MBCS.
580
* Will fill in an <TT>U_ILLEGAL_ARGUMENT_ERROR</TT> if converter passed in
581
* is not MBCS. Fills in an array of type UBool, with the value of the byte
582
* as offset to the array. For example, if (starters[0x20] == TRUE) at return,
583
* it means that the byte 0x20 is a starter byte in this converter.
584
* Context pointers are always owned by the caller.
586
* @param converter a valid, opened converter of type MBCS
587
* @param starters an array of size 256 to be filled in
588
* @param err error status, <TT>U_ILLEGAL_ARGUMENT_ERROR</TT> if the
589
* converter is not a type which can return starters.
593
U_CAPI void U_EXPORT2 ucnv_getStarters(const UConverter* converter,
599
* Gets the current calback function used by the converter when an illegal
600
* or invalid codepage sequence is found.
601
* Context pointers are always owned by the caller.
603
* @param converter the unicode converter
604
* @param action fillin: returns the callback function pointer
605
* @param context fillin: returns the callback's private void* context
606
* @see ucnv_setToUCallBack
609
U_CAPI void U_EXPORT2
610
ucnv_getToUCallBack (const UConverter * converter,
611
UConverterToUCallback *action,
612
const void **context);
615
* Gets the current callback function used by the converter when illegal
616
* or invalid Unicode sequence is found.
617
* Context pointers are always owned by the caller.
619
* @param converter the unicode converter
620
* @param action fillin: returns the callback function pointer
621
* @param context fillin: returns the callback's private void* context
622
* @see ucnv_setFromUCallBack
625
U_CAPI void U_EXPORT2
626
ucnv_getFromUCallBack (const UConverter * converter,
627
UConverterFromUCallback *action,
628
const void **context);
631
* Changes the callback function used by the converter when
632
* an illegal or invalid sequence is found.
633
* Context pointers are always owned by the caller.
635
* @param converter the unicode converter
636
* @param newAction the new callback function
637
* @param newContext the new toUnicode callback context pointer
638
* @param oldAction fillin: returns the old callback function pointer
639
* @param oldContext fillin: returns the old callback's private void* context
640
* @param err The error code status
641
* @see ucnv_getToUCallBack
644
U_CAPI void U_EXPORT2
645
ucnv_setToUCallBack (UConverter * converter,
646
UConverterToUCallback newAction,
647
const void* newContext,
648
UConverterToUCallback *oldAction,
649
const void** oldContext,
653
* Changes the current callback function used by the converter when
654
* an illegal or invalid sequence is found.
655
* Context pointers are always owned by the caller.
657
* @param converter the unicode converter
658
* @param newAction the new callback function
659
* @param newContext the new fromUnicode callback context pointer
660
* @param oldAction fillin: returns the old callback function pointer
661
* @param oldContext fillin: returns the old callback's private void* context
662
* @param err The error code status
663
* @see ucnv_getFromUCallBack
666
U_CAPI void U_EXPORT2
667
ucnv_setFromUCallBack (UConverter * converter,
668
UConverterFromUCallback newAction,
669
const void *newContext,
670
UConverterFromUCallback *oldAction,
671
const void **oldContext,
675
* Converts an array of unicode characters to an array of codepage
676
* characters. This function is optimized for converting a continuous
677
* stream of data in buffer-sized chunks, where the entire source and
678
* target does not fit in available buffers.
680
* The source pointer is an in/out parameter. It starts out pointing where the
681
* conversion is to begin, and ends up pointing after the last UChar consumed.
683
* Target similarly starts out pointer at the first available byte in the output
684
* buffer, and ends up pointing after the last byte written to the output.
686
* The converter always attempts to consume the entire source buffer, unless
687
* (1.) the target buffer is full, or (2.) a failing error is returned from the
688
* current callback function. When a successful error status has been
689
* returned, it means that all of the source buffer has been
690
* consumed. At that point, the caller should reset the source and
691
* sourceLimit pointers to point to the next chunk.
693
* This is a <I>stateful</I> conversion. Additionally, even when all source data has
694
* been consumed, some data may be in the converters' internal state.
695
* Call this function repeatedly, updating the target pointers with
696
* the next empty chunk of target in case of a
697
* <TT>U_BUFFER_OVERFLOW_ERROR</TT>, and updating the source pointers
698
* with the next chunk of source when a successful error status is
699
* returned, until there are no more chunks of source data.
700
* @param converter the Unicode converter
701
* @param target I/O parameter. Input : Points to the beginning of the buffer to copy
702
* codepage characters to. Output : points to after the last codepage character copied
703
* to <TT>target</TT>.
704
* @param targetLimit the pointer just after last of the <TT>target</TT> buffer
705
* @param source I/O parameter, pointer to pointer to the source Unicode character buffer.
706
* @param sourceLimit the pointer just after the last of the source buffer
707
* @param offsets if NULL is passed, nothing will happen to it, otherwise it needs to have the same number
708
* of allocated cells as <TT>target</TT>. Will fill in offsets from target to source pointer
709
* 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>
710
* For output data carried across calls, and other data without a specific source character
711
* (such as from escape sequences or callbacks) -1 will be placed for offsets.
712
* @param flush set to <TT>TRUE</TT> if the current source buffer is the last available
713
* chunk of the source, <TT>FALSE</TT> otherwise. Note that if a failing status is returned,
714
* this function may have to be called multiple times wiht flush set to <TT>TRUE</TT> until
715
* the source buffer is consumed.
716
* @param err the error status. <TT>U_ILLEGAL_ARGUMENT_ERROR</TT> will be set if the
717
* converter is <TT>NULL</TT>.
718
* <code>U_BUFFER_OVERFLOW_ERROR</code> will be set if the target is full and there is
719
* still data to be written to the target.
720
* @see ucnv_fromUChars
722
* @see ucnv_getMinCharSize
723
* @see ucnv_setToUCallBack
726
U_CAPI void U_EXPORT2
727
ucnv_fromUnicode (UConverter * converter,
729
const char *targetLimit,
730
const UChar ** source,
731
const UChar * sourceLimit,
737
* Converts a buffer of codepage bytes into an array of unicode UChars
738
* characters. This function is optimized for converting a continuous
739
* stream of data in buffer-sized chunks, where the entire source and
740
* target does not fit in available buffers.
742
* The source pointer is an in/out parameter. It starts out pointing where the
743
* conversion is to begin, and ends up pointing after the last byte of source consumed.
745
* Target similarly starts out pointer at the first available UChar in the output
746
* buffer, and ends up pointing after the last UChar written to the output.
747
* It does NOT necessarily keep UChar sequences together.
749
* The converter always attempts to consume the entire source buffer, unless
750
* (1.) the target buffer is full, or (2.) a failing error is returned from the
751
* current callback function. When a successful error status has been
752
* returned, it means that all of the source buffer has been
753
* consumed. At that point, the caller should reset the source and
754
* sourceLimit pointers to point to the next chunk.
756
* This is a <I>stateful</I> conversion. Additionally, even when all source data has
757
* been consumed, some data may be in the converters' internal state.
758
* Call this function repeatedly, updating the target pointers with
759
* the next empty chunk of target in case of a
760
* <TT>U_BUFFER_OVERFLOW_ERROR</TT>, and updating the source pointers
761
* with the next chunk of source when a successful error status is
762
* returned, until there are no more chunks of source data.
763
* @param converter the Unicode converter
764
* @param target I/O parameter. Input : Points to the beginning of the buffer to copy
765
* UChars into. Output : points to after the last UChar copied.
766
* @param targetLimit the pointer just after the end of the <TT>target</TT> buffer
767
* @param source I/O parameter, pointer to pointer to the source codepage buffer.
768
* @param sourceLimit the pointer to the byte after the end of the source buffer
769
* @param offsets if NULL is passed, nothing will happen to it, otherwise it needs to have the same number
770
* of allocated cells as <TT>target</TT>. Will fill in offsets from target to source pointer
771
* 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>
772
* For output data carried across calls, and other data without a specific source character
773
* (such as from escape sequences or callbacks) -1 will be placed for offsets.
774
* @param flush set to <TT>TRUE</TT> if the current source buffer is the last available
775
* chunk of the source, <TT>FALSE</TT> otherwise. Note that if a failing status is returned,
776
* this function may have to be called multiple times wiht flush set to <TT>TRUE</TT> until
777
* the source buffer is consumed.
778
* @param err the error status. <TT>U_ILLEGAL_ARGUMENT_ERROR</TT> will be set if the
779
* converter is <TT>NULL</TT>.
780
* <code>U_BUFFER_OVERFLOW_ERROR</code> will be set if the target is full and there is
781
* still data to be written to the target.
782
* @see ucnv_fromUChars
784
* @see ucnv_getMinCharSize
785
* @see ucnv_setFromUCallBack
786
* @see ucnv_getNextUChar
789
U_CAPI void U_EXPORT2
790
ucnv_toUnicode (UConverter * converter,
792
const UChar * targetLimit,
794
const char *sourceLimit,
801
* Convert the Unicode string into a codepage string using an existing UConverter.
802
* The output string is NUL-terminated if possible.
804
* This function is a more convenient but less powerful version of ucnv_fromUnicode().
805
* It is only useful for whole strings, not for streaming conversion.
807
* The maximum output buffer capacity required (barring output from callbacks) will be
808
* srcLength*ucnv_getMaxCharSize(cnv).
810
* @param cnv the converter object to be used (ucnv_resetFromUnicode() will be called)
811
* @param src the input Unicode string
812
* @param srcLength the input string length, or -1 if NUL-terminated
813
* @param dest destination string buffer, can be NULL if destCapacity==0
814
* @param destCapacity the number of chars available at dest
815
* @param errorCode normal ICU error code;
816
* common error codes that may be set by this function include
817
* U_BUFFER_OVERFLOW_ERROR, U_STRING_NOT_TERMINATED_WARNING,
818
* U_ILLEGAL_ARGUMENT_ERROR, and conversion errors
819
* @return the length of the output string, not counting the terminating NUL;
820
* if the length is greater than destCapacity, then the string will not fit
821
* and a buffer of the indicated length would need to be passed in
822
* @see ucnv_fromUnicode
824
* @draft ICU 2.0 (new NUL-termination semantics)
826
U_CAPI int32_t U_EXPORT2
827
ucnv_fromUChars(UConverter *cnv,
828
char *dest, int32_t destCapacity,
829
const UChar *src, int32_t srcLength,
830
UErrorCode *pErrorCode);
834
* Convert the codepage string into a Unicode string using an existing UConverter.
835
* The output string is NUL-terminated if possible.
837
* This function is a more convenient but less powerful version of ucnv_toUnicode().
838
* It is only useful for whole strings, not for streaming conversion.
840
* The maximum output buffer capacity required (barring output from callbacks) will be
841
* 2*srcLength (each char may be converted into a surrogate pair).
843
* @param cnv the converter object to be used (ucnv_resetToUnicode() will be called)
844
* @param src the input codepage string
845
* @param srcLength the input string length, or -1 if NUL-terminated
846
* @param dest destination string buffer, can be NULL if destCapacity==0
847
* @param destCapacity the number of UChars available at dest
848
* @param errorCode normal ICU error code;
849
* common error codes that may be set by this function include
850
* U_BUFFER_OVERFLOW_ERROR, U_STRING_NOT_TERMINATED_WARNING,
851
* U_ILLEGAL_ARGUMENT_ERROR, and conversion errors
852
* @return the length of the output string, not counting the terminating NUL;
853
* if the length is greater than destCapacity, then the string will not fit
854
* and a buffer of the indicated length would need to be passed in
855
* @see ucnv_toUnicode
857
* @draft ICU 2.0 (new NUL-termination semantics)
859
U_CAPI int32_t U_EXPORT2
860
ucnv_toUChars(UConverter *cnv,
861
UChar *dest, int32_t destCapacity,
862
const char *src, int32_t srcLength,
863
UErrorCode *pErrorCode);
866
* Will convert a codepage buffer into unicode one character at a time.
867
* <p>This function was written to be efficient when transcoding small
868
* amounts of data at a time.
869
* In that case it will be more efficient than \Ref{ucnv_toUnicode}.
870
* When converting large buffers use \Ref{ucnv_toUnicode}.</p>
872
* <p>Handling of surrogate pairs and supplementary-plane code points:<br>
873
* There are two different kinds of codepages that provide mappings for surrogate characters:
875
* <li>Codepages like UTF-8, UTF-32, and GB 18030 provide direct representations for Unicode
876
* code points U+10000-U+10ffff as well as for single surrogates U+d800-U+dfff.
877
* Each valid sequence will result in exactly one returned code point.
878
* If a sequence results in a single surrogate, then that will be returned
879
* by itself, even if a neighboring sequence encodes the matching surrogate.</li>
880
* <li>Codepages like SCSU and LMBCS (and UTF-16) provide direct representations only for BMP code points
881
* including surrogates. Code points in supplementary planes are represented with
882
* two sequences, each encoding a surrogate.
883
* For these codepages, matching pairs of surrogates will be combined into single
884
* code points for returning from this function.
885
* (Note that SCSU is actually a mix of these codepage types.)</li>
888
* @param converter an open UConverter
889
* @param source the address of a pointer to the codepage buffer, will be
890
* updated to point after the bytes consumed in the conversion call.
891
* @param sourceLimit points to the end of the input buffer
892
* @param err fills in error status (see ucnv_toUnicode)
893
* <code>U_INDEX_OUTOFBOUNDS_ERROR</code> will be set if the input
894
* is empty or does not convert to any output (e.g.: pure state-change
895
* codes SI/SO, escape sequences for ISO 2022,
896
* or if the callback did not output anything, ...).
897
* This function will not set a <code>U_BUFFER_OVERFLOW_ERROR</code> because
898
* the "buffer" is the return code. However, there might be subsequent output
899
* stored in the converter object
900
* that will be returned in following calls to this function.
901
* @return a UChar32 resulting from the partial conversion of source
902
* @see ucnv_toUnicode
907
U_CAPI UChar32 U_EXPORT2
908
ucnv_getNextUChar (UConverter * converter,
910
const char * sourceLimit,
915
* Will convert a sequence of bytes from one codepage to another.
916
* This is <STRONG>NOT AN EFFICIENT</STRONG> way to transcode.
917
* use \Ref{ucnv_toUnicode} and \Ref{ucnv_fromUnicode} for efficiency.
918
* @param toConverterName The name of the converter that will be used
919
* in conversion from unicode into the output buffer
920
* @param fromConverterName: The name of the converter that will be used
921
* in conversion from the source buffer into intermediate unicode.
922
* @param target Pointer to the output buffer
923
* @param targetCapacity capacity of the target, in bytes
924
* @param source Pointer to the input buffer
925
* @param sourceLength capacity of the source, in bytes
926
* @param err error status.
927
* <code>U_BUFFER_OVERFLOW_ERROR</code> will be set if the target is full and there is still input left in the source.
928
* @return will be filled in with the number of bytes needed in target
929
* @see ucnv_fromUnicode
930
* @see ucnv_toUnicode
931
* @see ucnv_fromUChars
933
* @see ucnv_getNextUChar
936
U_CAPI int32_t U_EXPORT2
937
ucnv_convert (const char *toConverterName,
938
const char *fromConverterName,
940
int32_t targetCapacity,
942
int32_t sourceLength,
946
* Frees up memory occupied by unused, cached converter shared data.
948
* @return the number of cached converters successfully deleted
952
U_CAPI int32_t U_EXPORT2
953
ucnv_flushCache (void);
957
* returns the number of available converters, as per the alias file.
959
* @return the number of available converters
960
* @see ucnv_getAvailableName
963
U_CAPI int32_t U_EXPORT2
964
ucnv_countAvailable (void);
967
* Gets the name of the specified converter from a list of all converters
968
* contaied in the alias file.
969
* @param n the index to a converter available on the system (in the range <TT>[0..ucnv_countAvaiable()]</TT>)
970
* @return a pointer a string (library owned), or <TT>NULL</TT> if the index is out of bounds.
971
* @see ucnv_countAvailable
974
U_CAPI const char* U_EXPORT2
975
ucnv_getAvailableName (int32_t n);
978
* Gives the number of aliases for a given converter or alias name.
979
* Note that additional aliases are recognized by ucnv_open().
980
* This method only enumerates the listed entries in the alias file.
981
* @param alias alias name
982
* @param pErrorCode error status
983
* @return number of names on alias list for given alias
986
U_CAPI uint16_t U_EXPORT2
987
ucnv_countAliases(const char *alias, UErrorCode *pErrorCode);
990
* Gives the name of the alias at given index of alias list.
991
* Note that additional aliases are recognized by ucnv_open().
992
* This method only enumerates the listed entries in the alias file.
993
* @param alias alias name
994
* @param n index in alias list
995
* @param pErrorCode result of operation
996
* @return returns the name of the alias at given index
997
* @see ucnv_countAliases
1000
U_CAPI const char * U_EXPORT2
1001
ucnv_getAlias(const char *alias, uint16_t n, UErrorCode *pErrorCode);
1004
* Fill-up the list of alias names for the given alias.
1005
* Note that additional aliases are recognized by ucnv_open().
1006
* This method only enumerates the listed entries in the alias file.
1007
* @param alias alias name
1008
* @param aliases fill-in list, aliases is a pointer to an array of
1009
* <code>ucnv_countAliases()</code> string-pointers
1010
* (<code>const char *</code>) that will be filled in.
1011
* The strings themselves are owned by the library.
1012
* @param pErrorCode result of operation
1015
U_CAPI void U_EXPORT2
1016
ucnv_getAliases(const char *alias, const char **aliases, UErrorCode *pErrorCode);
1019
* Gives the number of standards associated to converter names.
1020
* @return number of standards
1023
U_CAPI uint16_t U_EXPORT2
1024
ucnv_countStandards(void);
1027
* Gives the name of the standard at given index of standard list.
1028
* @param n index in standard list
1029
* @param pErrorCode result of operation
1030
* @return returns the name of the standard at given index. Owned by the library.
1033
U_CAPI const char * U_EXPORT2
1034
ucnv_getStandard(uint16_t n, UErrorCode *pErrorCode);
1037
* Returns a standard name for a given converter name.
1039
* @param name original converter name
1040
* @param standard name of the standard governing the names; MIME and IANA
1041
* are such standards
1042
* @return returns the standard converter name;
1043
* if a standard converter name cannot be determined,
1044
* then <code>NULL</code> is returned. Owned by the library.
1047
U_CAPI const char * U_EXPORT2
1048
ucnv_getStandardName(const char *name, const char *standard, UErrorCode *pErrorCode);
1051
* returns the current default converter name.
1053
* @return returns the current default converter name;
1054
* if a default converter name cannot be determined,
1055
* then <code>NULL</code> is returned.
1056
* Storage owned by the library
1057
* @see ucnv_setDefaultName
1060
U_CAPI const char * U_EXPORT2
1061
ucnv_getDefaultName (void);
1064
* sets the current default converter name. Caller must own the storage for 'name'
1065
* and preserve it indefinitely.
1066
* @param name the converter name to be the default (must exist).
1067
* @see ucnv_getDefaultName
1068
* @system SYSTEM API
1071
U_CAPI void U_EXPORT2
1072
ucnv_setDefaultName (const char *name);
1075
* Fixes the backslash character mismapping. For example, in SJIS, the backslash
1076
* character in the ASCII portion is also used to represent the yen currency sign.
1077
* When mapping from Unicode character 0x005C, it's unclear whether to map the
1078
* character back to yen or backslash in SJIS. This function will take the input
1079
* buffer and replace all the yen sign characters with backslash. This is necessary
1080
* when the user tries to open a file with the input buffer on Windows.
1081
* This function will test the converter to see whether such mapping is
1082
* required. You can sometimes avoid using this function by using the correct version
1085
* @param cnv The converter representing the target codepage.
1086
* @param source the input buffer to be fixed
1087
* @param sourceLength the length of the input buffer
1088
* @see ucnv_isAmbiguous
1091
U_CAPI void U_EXPORT2
1092
ucnv_fixFileSeparator(const UConverter *cnv, UChar* source, int32_t sourceLen);
1095
* Determines if the converter contains ambiguous mappings of the same
1097
* @return TRUE if the converter contains ambiguous mapping of the same
1098
* character, FALSE otherwise.
1101
U_CAPI UBool U_EXPORT2
1102
ucnv_isAmbiguous(const UConverter *cnv);
1105
* Sets the converter to use fallback mapping or not.
1106
* @param cnv The converter to set the fallback mapping usage on.
1107
* @param usesFallback TRUE if the user wants the converter to take advantage of the fallback
1108
* mapping, FALSE otherwise.
1111
U_CAPI void U_EXPORT2
1112
ucnv_setFallback(UConverter *cnv, UBool usesFallback);
1115
* Determines if the converter uses fallback mappings or not.
1116
* @return TRUE if the converter uses fallback, FALSE otherwise.
1119
U_CAPI UBool U_EXPORT2
1120
ucnv_usesFallback(const UConverter *cnv);
1123
* Detects Unicode signatures in the given byte stream. The signature bytes are not consumed,
1124
* instead the number of bytes that make up the signature is returned. The conversion APIs
1125
* donot discard signature bytes, so if the caller wishes to discard them, the caller should
1126
* explicity add code to do that after calling this function.
1130
* UErrorCode err = U_ZERO_ERROR;
1131
* char input[] = { '\xEF','\xBB', '\xBF','\x41','\x42','\x43' };
1132
* char* source = input;
1133
* int32_t signatureLength = 0;
1134
* char* encoding = ucnv_detectUnicodeSignatures(source,sizeof(input),&signatureLength,&err);
1135
* UConverter* conv = NULL;
1136
* if(encoding!=NULL && U_SUCCESS(err)){
1137
* // should signature be discarded ?
1138
* if (discardSignature){
1139
* source += signatureLength;
1141
* conv = ucnv_open(encoding, &err);
1142
* .... do the conversion ....
1147
* @param source The source string in which the signature should be detected.
1148
* @param sourceLength Length of the input string, or -1 if NUL-terminated.
1149
* @param signatureLength A pointer to int8_t to receive the number of bytes that make up the signature
1150
* of the detected UTF. 0 if not detected.
1151
* @param pErrorCode A pointer to receive information about any errors that may occur during detection.
1152
* Must be a valid pointer to an error code value, which must not indicate a failure
1153
* before the function call.
1154
* @return The name of the encoding detected. NULL if encoding is not detected.
1156
U_CAPI const char* U_EXPORT2
1157
ucnv_detectUnicodeSignature( const char* source,
1158
int32_t sourceLength,
1159
int32_t* signatureLength,
1160
UErrorCode* pErrorCode);