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