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