|
|
|||
File indexing completed on 2026-01-09 10:29:06
0001 // © 2016 and later: Unicode, Inc. and others. 0002 // License & terms of use: http://www.unicode.org/copyright.html 0003 /* 0004 ********************************************************************** 0005 * Copyright (C) 1999-2014, International Business Machines 0006 * Corporation and others. All Rights Reserved. 0007 ********************************************************************** 0008 * ucnv.h: 0009 * External APIs for the ICU's codeset conversion library 0010 * Bertrand A. Damiba 0011 * 0012 * Modification History: 0013 * 0014 * Date Name Description 0015 * 04/04/99 helena Fixed internal header inclusion. 0016 * 05/11/00 helena Added setFallback and usesFallback APIs. 0017 * 06/29/2000 helena Major rewrite of the callback APIs. 0018 * 12/07/2000 srl Update of documentation 0019 */ 0020 0021 /** 0022 * \file 0023 * \brief C API: Character conversion 0024 * 0025 * <h2>Character Conversion C API</h2> 0026 * 0027 * <p>This API is used to convert codepage or character encoded data to and 0028 * from UTF-16. You can open a converter with {@link ucnv_open() }. With that 0029 * converter, you can get its properties, set options, convert your data and 0030 * close the converter.</p> 0031 * 0032 * <p>Since many software programs recognize different converter names for 0033 * different types of converters, there are other functions in this API to 0034 * iterate over the converter aliases. The functions {@link ucnv_getAvailableName() }, 0035 * {@link ucnv_getAlias() } and {@link ucnv_getStandardName() } are some of the 0036 * more frequently used alias functions to get this information.</p> 0037 * 0038 * <p>When a converter encounters an illegal, irregular, invalid or unmappable character 0039 * its default behavior is to use a substitution character to replace the 0040 * bad byte sequence. This behavior can be changed by using {@link ucnv_setFromUCallBack() } 0041 * or {@link ucnv_setToUCallBack() } on the converter. The header ucnv_err.h defines 0042 * many other callback actions that can be used instead of a character substitution.</p> 0043 * 0044 * <p>More information about this API can be found in our 0045 * <a href="https://unicode-org.github.io/icu/userguide/conversion/">User Guide</a>.</p> 0046 */ 0047 0048 #ifndef UCNV_H 0049 #define UCNV_H 0050 0051 #include "unicode/ucnv_err.h" 0052 #include "unicode/uenum.h" 0053 0054 #if U_SHOW_CPLUSPLUS_API 0055 #include "unicode/localpointer.h" 0056 #endif // U_SHOW_CPLUSPLUS_API 0057 0058 #if !defined(USET_DEFINED) && !defined(U_IN_DOXYGEN) 0059 0060 #define USET_DEFINED 0061 0062 /** 0063 * USet is the C API type corresponding to C++ class UnicodeSet. 0064 * It is forward-declared here to avoid including unicode/uset.h file if related 0065 * conversion APIs are not used. 0066 * 0067 * @see ucnv_getUnicodeSet 0068 * @stable ICU 2.4 0069 */ 0070 typedef struct USet USet; 0071 0072 #endif 0073 0074 #if !UCONFIG_NO_CONVERSION 0075 0076 U_CDECL_BEGIN 0077 0078 /** Maximum length of a converter name including the terminating NULL @stable ICU 2.0 */ 0079 #define UCNV_MAX_CONVERTER_NAME_LENGTH 60 0080 /** Maximum length of a converter name including path and terminating NULL @stable ICU 2.0 */ 0081 #define UCNV_MAX_FULL_FILE_NAME_LENGTH (600+UCNV_MAX_CONVERTER_NAME_LENGTH) 0082 0083 /** Shift in for EBDCDIC_STATEFUL and iso2022 states @stable ICU 2.0 */ 0084 #define UCNV_SI 0x0F 0085 /** Shift out for EBDCDIC_STATEFUL and iso2022 states @stable ICU 2.0 */ 0086 #define UCNV_SO 0x0E 0087 0088 /** 0089 * Enum for specifying basic types of converters 0090 * @see ucnv_getType 0091 * @stable ICU 2.0 0092 */ 0093 typedef enum { 0094 /** @stable ICU 2.0 */ 0095 UCNV_UNSUPPORTED_CONVERTER = -1, 0096 /** @stable ICU 2.0 */ 0097 UCNV_SBCS = 0, 0098 /** @stable ICU 2.0 */ 0099 UCNV_DBCS = 1, 0100 /** @stable ICU 2.0 */ 0101 UCNV_MBCS = 2, 0102 /** @stable ICU 2.0 */ 0103 UCNV_LATIN_1 = 3, 0104 /** @stable ICU 2.0 */ 0105 UCNV_UTF8 = 4, 0106 /** @stable ICU 2.0 */ 0107 UCNV_UTF16_BigEndian = 5, 0108 /** @stable ICU 2.0 */ 0109 UCNV_UTF16_LittleEndian = 6, 0110 /** @stable ICU 2.0 */ 0111 UCNV_UTF32_BigEndian = 7, 0112 /** @stable ICU 2.0 */ 0113 UCNV_UTF32_LittleEndian = 8, 0114 /** @stable ICU 2.0 */ 0115 UCNV_EBCDIC_STATEFUL = 9, 0116 /** @stable ICU 2.0 */ 0117 UCNV_ISO_2022 = 10, 0118 0119 /** @stable ICU 2.0 */ 0120 UCNV_LMBCS_1 = 11, 0121 /** @stable ICU 2.0 */ 0122 UCNV_LMBCS_2, 0123 /** @stable ICU 2.0 */ 0124 UCNV_LMBCS_3, 0125 /** @stable ICU 2.0 */ 0126 UCNV_LMBCS_4, 0127 /** @stable ICU 2.0 */ 0128 UCNV_LMBCS_5, 0129 /** @stable ICU 2.0 */ 0130 UCNV_LMBCS_6, 0131 /** @stable ICU 2.0 */ 0132 UCNV_LMBCS_8, 0133 /** @stable ICU 2.0 */ 0134 UCNV_LMBCS_11, 0135 /** @stable ICU 2.0 */ 0136 UCNV_LMBCS_16, 0137 /** @stable ICU 2.0 */ 0138 UCNV_LMBCS_17, 0139 /** @stable ICU 2.0 */ 0140 UCNV_LMBCS_18, 0141 /** @stable ICU 2.0 */ 0142 UCNV_LMBCS_19, 0143 /** @stable ICU 2.0 */ 0144 UCNV_LMBCS_LAST = UCNV_LMBCS_19, 0145 /** @stable ICU 2.0 */ 0146 UCNV_HZ, 0147 /** @stable ICU 2.0 */ 0148 UCNV_SCSU, 0149 /** @stable ICU 2.0 */ 0150 UCNV_ISCII, 0151 /** @stable ICU 2.0 */ 0152 UCNV_US_ASCII, 0153 /** @stable ICU 2.0 */ 0154 UCNV_UTF7, 0155 /** @stable ICU 2.2 */ 0156 UCNV_BOCU1, 0157 /** @stable ICU 2.2 */ 0158 UCNV_UTF16, 0159 /** @stable ICU 2.2 */ 0160 UCNV_UTF32, 0161 /** @stable ICU 2.2 */ 0162 UCNV_CESU8, 0163 /** @stable ICU 2.4 */ 0164 UCNV_IMAP_MAILBOX, 0165 /** @stable ICU 4.8 */ 0166 UCNV_COMPOUND_TEXT, 0167 0168 /* Number of converter types for which we have conversion routines. */ 0169 UCNV_NUMBER_OF_SUPPORTED_CONVERTER_TYPES 0170 } UConverterType; 0171 0172 /** 0173 * Enum for specifying which platform a converter ID refers to. 0174 * The use of platform/CCSID is not recommended. See ucnv_openCCSID(). 0175 * 0176 * @see ucnv_getPlatform 0177 * @see ucnv_openCCSID 0178 * @see ucnv_getCCSID 0179 * @stable ICU 2.0 0180 */ 0181 typedef enum { 0182 UCNV_UNKNOWN = -1, 0183 UCNV_IBM = 0 0184 } UConverterPlatform; 0185 0186 /** 0187 * Function pointer for error callback in the codepage to unicode direction. 0188 * Called when an error has occurred in conversion to unicode, or on open/close of the callback (see reason). 0189 * @param context Pointer to the callback's private data 0190 * @param args Information about the conversion in progress 0191 * @param codeUnits Points to 'length' bytes of the concerned codepage sequence 0192 * @param length Size (in bytes) of the concerned codepage sequence 0193 * @param reason Defines the reason the callback was invoked 0194 * @param pErrorCode ICU error code in/out parameter. 0195 * For converter callback functions, set to a conversion error 0196 * before the call, and the callback may reset it to U_ZERO_ERROR. 0197 * @see ucnv_setToUCallBack 0198 * @see UConverterToUnicodeArgs 0199 * @stable ICU 2.0 0200 */ 0201 typedef void (U_EXPORT2 *UConverterToUCallback) ( 0202 const void* context, 0203 UConverterToUnicodeArgs *args, 0204 const char *codeUnits, 0205 int32_t length, 0206 UConverterCallbackReason reason, 0207 UErrorCode *pErrorCode); 0208 0209 /** 0210 * Function pointer for error callback in the unicode to codepage direction. 0211 * Called when an error has occurred in conversion from unicode, or on open/close of the callback (see reason). 0212 * @param context Pointer to the callback's private data 0213 * @param args Information about the conversion in progress 0214 * @param codeUnits Points to 'length' UChars of the concerned Unicode sequence 0215 * @param length Size (in bytes) of the concerned codepage sequence 0216 * @param codePoint Single UChar32 (UTF-32) containing the concerend Unicode codepoint. 0217 * @param reason Defines the reason the callback was invoked 0218 * @param pErrorCode ICU error code in/out parameter. 0219 * For converter callback functions, set to a conversion error 0220 * before the call, and the callback may reset it to U_ZERO_ERROR. 0221 * @see ucnv_setFromUCallBack 0222 * @stable ICU 2.0 0223 */ 0224 typedef void (U_EXPORT2 *UConverterFromUCallback) ( 0225 const void* context, 0226 UConverterFromUnicodeArgs *args, 0227 const UChar* codeUnits, 0228 int32_t length, 0229 UChar32 codePoint, 0230 UConverterCallbackReason reason, 0231 UErrorCode *pErrorCode); 0232 0233 U_CDECL_END 0234 0235 /** 0236 * Character that separates converter names from options and options from each other. 0237 * @see ucnv_open 0238 * @stable ICU 2.0 0239 */ 0240 #define UCNV_OPTION_SEP_CHAR ',' 0241 0242 /** 0243 * String version of UCNV_OPTION_SEP_CHAR. 0244 * @see ucnv_open 0245 * @stable ICU 2.0 0246 */ 0247 #define UCNV_OPTION_SEP_STRING "," 0248 0249 /** 0250 * Character that separates a converter option from its value. 0251 * @see ucnv_open 0252 * @stable ICU 2.0 0253 */ 0254 #define UCNV_VALUE_SEP_CHAR '=' 0255 0256 /** 0257 * String version of UCNV_VALUE_SEP_CHAR. 0258 * @see ucnv_open 0259 * @stable ICU 2.0 0260 */ 0261 #define UCNV_VALUE_SEP_STRING "=" 0262 0263 /** 0264 * Converter option for specifying a locale. 0265 * For example, ucnv_open("SCSU,locale=ja", &errorCode); 0266 * See convrtrs.txt. 0267 * 0268 * @see ucnv_open 0269 * @stable ICU 2.0 0270 */ 0271 #define UCNV_LOCALE_OPTION_STRING ",locale=" 0272 0273 /** 0274 * Converter option for specifying a version selector (0..9) for some converters. 0275 * For example, 0276 * \code 0277 * ucnv_open("UTF-7,version=1", &errorCode); 0278 * \endcode 0279 * See convrtrs.txt. 0280 * 0281 * @see ucnv_open 0282 * @stable ICU 2.4 0283 */ 0284 #define UCNV_VERSION_OPTION_STRING ",version=" 0285 0286 /** 0287 * Converter option for EBCDIC SBCS or mixed-SBCS/DBCS (stateful) codepages. 0288 * Swaps Unicode mappings for EBCDIC LF and NL codes, as used on 0289 * S/390 (z/OS) Unix System Services (Open Edition). 0290 * For example, ucnv_open("ibm-1047,swaplfnl", &errorCode); 0291 * See convrtrs.txt. 0292 * 0293 * @see ucnv_open 0294 * @stable ICU 2.4 0295 */ 0296 #define UCNV_SWAP_LFNL_OPTION_STRING ",swaplfnl" 0297 0298 /** 0299 * Do a fuzzy compare of two converter/alias names. 0300 * The comparison is case-insensitive, ignores leading zeroes if they are not 0301 * followed by further digits, and ignores all but letters and digits. 0302 * Thus the strings "UTF-8", "utf_8", "u*T@f08" and "Utf 8" are exactly equivalent. 0303 * See section 1.4, Charset Alias Matching in Unicode Technical Standard #22 0304 * at http://www.unicode.org/reports/tr22/ 0305 * 0306 * @param name1 a converter name or alias, zero-terminated 0307 * @param name2 a converter name or alias, zero-terminated 0308 * @return 0 if the names match, or a negative value if the name1 0309 * lexically precedes name2, or a positive value if the name1 0310 * lexically follows name2. 0311 * @stable ICU 2.0 0312 */ 0313 U_CAPI int U_EXPORT2 0314 ucnv_compareNames(const char *name1, const char *name2); 0315 0316 0317 /** 0318 * Creates a UConverter object with the name of a coded character set specified as a C string. 0319 * The actual name will be resolved with the alias file 0320 * using a case-insensitive string comparison that ignores 0321 * leading zeroes and all non-alphanumeric characters. 0322 * E.g., the names "UTF8", "utf-8", "u*T@f08" and "Utf 8" are all equivalent. 0323 * (See also ucnv_compareNames().) 0324 * If <code>NULL</code> is passed for the converter name, it will create one with the 0325 * getDefaultName return value. 0326 * 0327 * <p>A converter name for ICU 1.5 and above may contain options 0328 * like a locale specification to control the specific behavior of 0329 * the newly instantiated converter. 0330 * The meaning of the options depends on the particular converter. 0331 * If an option is not defined for or recognized by a given converter, then it is ignored.</p> 0332 * 0333 * <p>Options are appended to the converter name string, with a 0334 * <code>UCNV_OPTION_SEP_CHAR</code> between the name and the first option and 0335 * also between adjacent options.</p> 0336 * 0337 * <p>If the alias is ambiguous, then the preferred converter is used 0338 * and the status is set to U_AMBIGUOUS_ALIAS_WARNING.</p> 0339 * 0340 * <p>The conversion behavior and names can vary between platforms. ICU may 0341 * convert some characters differently from other platforms. Details on this topic 0342 * are in the <a href="https://unicode-org.github.io/icu/userguide/conversion/">User 0343 * Guide</a>. Aliases starting with a "cp" prefix have no specific meaning 0344 * other than its an alias starting with the letters "cp". Please do not 0345 * associate any meaning to these aliases.</p> 0346 * 0347 * @param converterName Name of the coded character set table. 0348 * This may have options appended to the string. 0349 * IANA alias character set names, IBM CCSIDs starting with "ibm-", 0350 * Windows codepage numbers starting with "windows-" are frequently 0351 * used for this parameter. See ucnv_getAvailableName and 0352 * ucnv_getAlias for a complete list that is available. 0353 * If this parameter is NULL, the default converter will be used. 0354 * @param err outgoing error status <TT>U_MEMORY_ALLOCATION_ERROR, U_FILE_ACCESS_ERROR</TT> 0355 * @return the created Unicode converter object, or <TT>NULL</TT> if an error occurred 0356 * @see ucnv_openU 0357 * @see ucnv_openCCSID 0358 * @see ucnv_getAvailableName 0359 * @see ucnv_getAlias 0360 * @see ucnv_getDefaultName 0361 * @see ucnv_close 0362 * @see ucnv_compareNames 0363 * @stable ICU 2.0 0364 */ 0365 U_CAPI UConverter* U_EXPORT2 0366 ucnv_open(const char *converterName, UErrorCode *err); 0367 0368 0369 /** 0370 * Creates a Unicode converter with the names specified as unicode string. 0371 * The name should be limited to the ASCII-7 alphanumerics range. 0372 * The actual name will be resolved with the alias file 0373 * using a case-insensitive string comparison that ignores 0374 * leading zeroes and all non-alphanumeric characters. 0375 * E.g., the names "UTF8", "utf-8", "u*T@f08" and "Utf 8" are all equivalent. 0376 * (See also ucnv_compareNames().) 0377 * If <TT>NULL</TT> is passed for the converter name, it will create 0378 * one with the ucnv_getDefaultName() return value. 0379 * If the alias is ambiguous, then the preferred converter is used 0380 * and the status is set to U_AMBIGUOUS_ALIAS_WARNING. 0381 * 0382 * <p>See ucnv_open for the complete details</p> 0383 * @param name Name of the UConverter table in a zero terminated 0384 * Unicode string 0385 * @param err outgoing error status <TT>U_MEMORY_ALLOCATION_ERROR, 0386 * U_FILE_ACCESS_ERROR</TT> 0387 * @return the created Unicode converter object, or <TT>NULL</TT> if an 0388 * error occurred 0389 * @see ucnv_open 0390 * @see ucnv_openCCSID 0391 * @see ucnv_close 0392 * @see ucnv_compareNames 0393 * @stable ICU 2.0 0394 */ 0395 U_CAPI UConverter* U_EXPORT2 0396 ucnv_openU(const UChar *name, 0397 UErrorCode *err); 0398 0399 /** 0400 * Creates a UConverter object from a CCSID number and platform pair. 0401 * Note that the usefulness of this function is limited to platforms with numeric 0402 * encoding IDs. Only IBM and Microsoft platforms use numeric (16-bit) identifiers for 0403 * encodings. 0404 * 0405 * In addition, IBM CCSIDs and Unicode conversion tables are not 1:1 related. 0406 * For many IBM CCSIDs there are multiple (up to six) Unicode conversion tables, and 0407 * for some Unicode conversion tables there are multiple CCSIDs. 0408 * Some "alternate" Unicode conversion tables are provided by the 0409 * IBM CDRA conversion table registry. 0410 * The most prominent example of a systematic modification of conversion tables that is 0411 * not provided in the form of conversion table files in the repository is 0412 * that S/390 Unix System Services swaps the codes for Line Feed and New Line in all 0413 * EBCDIC codepages, which requires such a swap in the Unicode conversion tables as well. 0414 * 0415 * Only IBM default conversion tables are accessible with ucnv_openCCSID(). 0416 * ucnv_getCCSID() will return the same CCSID for all conversion tables that are associated 0417 * with that CCSID. 0418 * 0419 * Currently, the only "platform" supported in the ICU converter API is UCNV_IBM. 0420 * 0421 * In summary, the use of CCSIDs and the associated API functions is not recommended. 0422 * 0423 * In order to open a converter with the default IBM CDRA Unicode conversion table, 0424 * you can use this function or use the prefix "ibm-": 0425 * \code 0426 * char name[20]; 0427 * sprintf(name, "ibm-%hu", ccsid); 0428 * cnv=ucnv_open(name, &errorCode); 0429 * \endcode 0430 * 0431 * In order to open a converter with the IBM S/390 Unix System Services variant 0432 * of a Unicode/EBCDIC conversion table, 0433 * you can use the prefix "ibm-" together with the option string UCNV_SWAP_LFNL_OPTION_STRING: 0434 * \code 0435 * char name[20]; 0436 * sprintf(name, "ibm-%hu" UCNV_SWAP_LFNL_OPTION_STRING, ccsid); 0437 * cnv=ucnv_open(name, &errorCode); 0438 * \endcode 0439 * 0440 * In order to open a converter from a Microsoft codepage number, use the prefix "cp": 0441 * \code 0442 * char name[20]; 0443 * sprintf(name, "cp%hu", codepageID); 0444 * cnv=ucnv_open(name, &errorCode); 0445 * \endcode 0446 * 0447 * If the alias is ambiguous, then the preferred converter is used 0448 * and the status is set to U_AMBIGUOUS_ALIAS_WARNING. 0449 * 0450 * @param codepage codepage number to create 0451 * @param platform the platform in which the codepage number exists 0452 * @param err error status <TT>U_MEMORY_ALLOCATION_ERROR, U_FILE_ACCESS_ERROR</TT> 0453 * @return the created Unicode converter object, or <TT>NULL</TT> if an error 0454 * occurred. 0455 * @see ucnv_open 0456 * @see ucnv_openU 0457 * @see ucnv_close 0458 * @see ucnv_getCCSID 0459 * @see ucnv_getPlatform 0460 * @see UConverterPlatform 0461 * @stable ICU 2.0 0462 */ 0463 U_CAPI UConverter* U_EXPORT2 0464 ucnv_openCCSID(int32_t codepage, 0465 UConverterPlatform platform, 0466 UErrorCode * err); 0467 0468 /** 0469 * <p>Creates a UConverter object specified from a packageName and a converterName.</p> 0470 * 0471 * <p>The packageName and converterName must point to an ICU udata object, as defined by 0472 * <code> udata_open( packageName, "cnv", converterName, err) </code> or equivalent. 0473 * Typically, packageName will refer to a (.dat) file, or to a package registered with 0474 * udata_setAppData(). Using a full file or directory pathname for packageName is deprecated.</p> 0475 * 0476 * <p>The name will NOT be looked up in the alias mechanism, nor will the converter be 0477 * stored in the converter cache or the alias table. The only way to open further converters 0478 * is call this function multiple times, or use the ucnv_clone() function to clone a 0479 * 'primary' converter.</p> 0480 * 0481 * <p>A future version of ICU may add alias table lookups and/or caching 0482 * to this function.</p> 0483 * 0484 * <p>Example Use: 0485 * <code>cnv = ucnv_openPackage("myapp", "myconverter", &err);</code> 0486 * </p> 0487 * 0488 * @param packageName name of the package (equivalent to 'path' in udata_open() call) 0489 * @param converterName name of the data item to be used, without suffix. 0490 * @param err outgoing error status <TT>U_MEMORY_ALLOCATION_ERROR, U_FILE_ACCESS_ERROR</TT> 0491 * @return the created Unicode converter object, or <TT>NULL</TT> if an error occurred 0492 * @see udata_open 0493 * @see ucnv_open 0494 * @see ucnv_clone 0495 * @see ucnv_close 0496 * @stable ICU 2.2 0497 */ 0498 U_CAPI UConverter* U_EXPORT2 0499 ucnv_openPackage(const char *packageName, const char *converterName, UErrorCode *err); 0500 0501 /** 0502 * Thread safe converter cloning operation. 0503 * 0504 * You must ucnv_close() the clone. 0505 * 0506 * @param cnv converter to be cloned 0507 * @param status to indicate whether the operation went on smoothly or there were errors 0508 * @return pointer to the new clone 0509 * @stable ICU 71 0510 */ 0511 U_CAPI UConverter* U_EXPORT2 ucnv_clone(const UConverter *cnv, UErrorCode *status); 0512 0513 #ifndef U_HIDE_DEPRECATED_API 0514 0515 /** 0516 * Thread safe converter cloning operation. 0517 * For most efficient operation, pass in a stackBuffer (and a *pBufferSize) 0518 * with at least U_CNV_SAFECLONE_BUFFERSIZE bytes of space. 0519 * If the buffer size is sufficient, then the clone will use the stack buffer; 0520 * otherwise, it will be allocated, and *pBufferSize will indicate 0521 * the actual size. (This should not occur with U_CNV_SAFECLONE_BUFFERSIZE.) 0522 * 0523 * You must ucnv_close() the clone in any case. 0524 * 0525 * If *pBufferSize==0, (regardless of whether stackBuffer==NULL or not) 0526 * then *pBufferSize will be changed to a sufficient size 0527 * for cloning this converter, 0528 * without actually cloning the converter ("pure pre-flighting"). 0529 * 0530 * If *pBufferSize is greater than zero but not large enough for a stack-based 0531 * clone, then the converter is cloned using newly allocated memory 0532 * and *pBufferSize is changed to the necessary size. 0533 * 0534 * If the converter clone fits into the stack buffer but the stack buffer is not 0535 * sufficiently aligned for the clone, then the clone will use an 0536 * adjusted pointer and use an accordingly smaller buffer size. 0537 * 0538 * @param cnv converter to be cloned 0539 * @param stackBuffer <em>Deprecated functionality as of ICU 52, use NULL.</em><br> 0540 * user allocated space for the new clone. If NULL new memory will be allocated. 0541 * If buffer is not large enough, new memory will be allocated. 0542 * Clients can use the U_CNV_SAFECLONE_BUFFERSIZE. This will probably be enough to avoid memory allocations. 0543 * @param pBufferSize <em>Deprecated functionality as of ICU 52, use NULL or 1.</em><br> 0544 * pointer to size of allocated space. 0545 * @param status to indicate whether the operation went on smoothly or there were errors 0546 * An informational status value, U_SAFECLONE_ALLOCATED_WARNING, 0547 * is used if pBufferSize != NULL and any allocations were necessary 0548 * However, it is better to check if *pBufferSize grew for checking for 0549 * allocations because warning codes can be overridden by subsequent 0550 * function calls. 0551 * @return pointer to the new clone 0552 * @deprecated ICU 71 Use ucnv_clone() instead. 0553 */ 0554 U_DEPRECATED UConverter * U_EXPORT2 0555 ucnv_safeClone(const UConverter *cnv, 0556 void *stackBuffer, 0557 int32_t *pBufferSize, 0558 UErrorCode *status); 0559 0560 /** 0561 * \def U_CNV_SAFECLONE_BUFFERSIZE 0562 * Definition of a buffer size that is designed to be large enough for 0563 * converters to be cloned with ucnv_safeClone(). 0564 * @deprecated ICU 52. Do not rely on ucnv_safeClone() cloning into any provided buffer. 0565 */ 0566 #define U_CNV_SAFECLONE_BUFFERSIZE 1024 0567 0568 #endif /* U_HIDE_DEPRECATED_API */ 0569 0570 /** 0571 * Deletes the unicode converter and releases resources associated 0572 * with just this instance. 0573 * Does not free up shared converter tables. 0574 * 0575 * @param converter the converter object to be deleted 0576 * @see ucnv_open 0577 * @see ucnv_openU 0578 * @see ucnv_openCCSID 0579 * @stable ICU 2.0 0580 */ 0581 U_CAPI void U_EXPORT2 0582 ucnv_close(UConverter * converter); 0583 0584 #if U_SHOW_CPLUSPLUS_API 0585 0586 U_NAMESPACE_BEGIN 0587 0588 /** 0589 * \class LocalUConverterPointer 0590 * "Smart pointer" class, closes a UConverter via ucnv_close(). 0591 * For most methods see the LocalPointerBase base class. 0592 * 0593 * @see LocalPointerBase 0594 * @see LocalPointer 0595 * @stable ICU 4.4 0596 */ 0597 U_DEFINE_LOCAL_OPEN_POINTER(LocalUConverterPointer, UConverter, ucnv_close); 0598 0599 U_NAMESPACE_END 0600 0601 #endif 0602 0603 /** 0604 * Fills in the output parameter, subChars, with the substitution characters 0605 * as multiple bytes. 0606 * If ucnv_setSubstString() set a Unicode string because the converter is 0607 * stateful, then subChars will be an empty string. 0608 * 0609 * @param converter the Unicode converter 0610 * @param subChars the substitution characters 0611 * @param len on input the capacity of subChars, on output the number 0612 * of bytes copied to it 0613 * @param err the outgoing error status code. 0614 * If the substitution character array is too small, an 0615 * <TT>U_INDEX_OUTOFBOUNDS_ERROR</TT> will be returned. 0616 * @see ucnv_setSubstString 0617 * @see ucnv_setSubstChars 0618 * @stable ICU 2.0 0619 */ 0620 U_CAPI void U_EXPORT2 0621 ucnv_getSubstChars(const UConverter *converter, 0622 char *subChars, 0623 int8_t *len, 0624 UErrorCode *err); 0625 0626 /** 0627 * Sets the substitution chars when converting from unicode to a codepage. The 0628 * substitution is specified as a string of 1-4 bytes, and may contain 0629 * <TT>NULL</TT> bytes. 0630 * The subChars must represent a single character. The caller needs to know the 0631 * byte sequence of a valid character in the converter's charset. 0632 * For some converters, for example some ISO 2022 variants, only single-byte 0633 * substitution characters may be supported. 0634 * The newer ucnv_setSubstString() function relaxes these limitations. 0635 * 0636 * @param converter the Unicode converter 0637 * @param subChars the substitution character byte sequence we want set 0638 * @param len the number of bytes in subChars 0639 * @param err the error status code. <TT>U_INDEX_OUTOFBOUNDS_ERROR </TT> if 0640 * len is bigger than the maximum number of bytes allowed in subchars 0641 * @see ucnv_setSubstString 0642 * @see ucnv_getSubstChars 0643 * @stable ICU 2.0 0644 */ 0645 U_CAPI void U_EXPORT2 0646 ucnv_setSubstChars(UConverter *converter, 0647 const char *subChars, 0648 int8_t len, 0649 UErrorCode *err); 0650 0651 /** 0652 * Set a substitution string for converting from Unicode to a charset. 0653 * The caller need not know the charset byte sequence for each charset. 0654 * 0655 * Unlike ucnv_setSubstChars() which is designed to set a charset byte sequence 0656 * for a single character, this function takes a Unicode string with 0657 * zero, one or more characters, and immediately verifies that the string can be 0658 * converted to the charset. 0659 * If not, or if the result is too long (more than 32 bytes as of ICU 3.6), 0660 * then the function returns with an error accordingly. 0661 * 0662 * Also unlike ucnv_setSubstChars(), this function works for stateful charsets 0663 * by converting on the fly at the point of substitution rather than setting 0664 * a fixed byte sequence. 0665 * 0666 * @param cnv The UConverter object. 0667 * @param s The Unicode string. 0668 * @param length The number of UChars in s, or -1 for a NUL-terminated string. 0669 * @param err Pointer to a standard ICU error code. Its input value must 0670 * pass the U_SUCCESS() test, or else the function returns 0671 * immediately. Check for U_FAILURE() on output or use with 0672 * function chaining. (See User Guide for details.) 0673 * 0674 * @see ucnv_setSubstChars 0675 * @see ucnv_getSubstChars 0676 * @stable ICU 3.6 0677 */ 0678 U_CAPI void U_EXPORT2 0679 ucnv_setSubstString(UConverter *cnv, 0680 const UChar *s, 0681 int32_t length, 0682 UErrorCode *err); 0683 0684 /** 0685 * Fills in the output parameter, errBytes, with the error characters from the 0686 * last failing conversion. 0687 * 0688 * @param converter the Unicode converter 0689 * @param errBytes the codepage bytes which were in error 0690 * @param len on input the capacity of errBytes, on output the number of 0691 * bytes which were copied to it 0692 * @param err the error status code. 0693 * If the substitution character array is too small, an 0694 * <TT>U_INDEX_OUTOFBOUNDS_ERROR</TT> will be returned. 0695 * @stable ICU 2.0 0696 */ 0697 U_CAPI void U_EXPORT2 0698 ucnv_getInvalidChars(const UConverter *converter, 0699 char *errBytes, 0700 int8_t *len, 0701 UErrorCode *err); 0702 0703 /** 0704 * Fills in the output parameter, errChars, with the error characters from the 0705 * last failing conversion. 0706 * 0707 * @param converter the Unicode converter 0708 * @param errUChars the UChars which were in error 0709 * @param len on input the capacity of errUChars, on output the number of 0710 * UChars which were copied to it 0711 * @param err the error status code. 0712 * If the substitution character array is too small, an 0713 * <TT>U_INDEX_OUTOFBOUNDS_ERROR</TT> will be returned. 0714 * @stable ICU 2.0 0715 */ 0716 U_CAPI void U_EXPORT2 0717 ucnv_getInvalidUChars(const UConverter *converter, 0718 UChar *errUChars, 0719 int8_t *len, 0720 UErrorCode *err); 0721 0722 /** 0723 * Resets the state of a converter to the default state. This is used 0724 * in the case of an error, to restart a conversion from a known default state. 0725 * It will also empty the internal output buffers. 0726 * @param converter the Unicode converter 0727 * @stable ICU 2.0 0728 */ 0729 U_CAPI void U_EXPORT2 0730 ucnv_reset(UConverter *converter); 0731 0732 /** 0733 * Resets the to-Unicode part of a converter state to the default state. 0734 * This is used in the case of an error to restart a conversion to 0735 * Unicode to a known default state. It will also empty the internal 0736 * output buffers used for the conversion to Unicode codepoints. 0737 * @param converter the Unicode converter 0738 * @stable ICU 2.0 0739 */ 0740 U_CAPI void U_EXPORT2 0741 ucnv_resetToUnicode(UConverter *converter); 0742 0743 /** 0744 * Resets the from-Unicode part of a converter state to the default state. 0745 * This is used in the case of an error to restart a conversion from 0746 * Unicode to a known default state. It will also empty the internal output 0747 * buffers used for the conversion from Unicode codepoints. 0748 * @param converter the Unicode converter 0749 * @stable ICU 2.0 0750 */ 0751 U_CAPI void U_EXPORT2 0752 ucnv_resetFromUnicode(UConverter *converter); 0753 0754 /** 0755 * Returns the maximum number of bytes that are output per UChar in conversion 0756 * from Unicode using this converter. 0757 * The returned number can be used with UCNV_GET_MAX_BYTES_FOR_STRING 0758 * to calculate the size of a target buffer for conversion from Unicode. 0759 * 0760 * Note: Before ICU 2.8, this function did not return reliable numbers for 0761 * some stateful converters (EBCDIC_STATEFUL, ISO-2022) and LMBCS. 0762 * 0763 * This number may not be the same as the maximum number of bytes per 0764 * "conversion unit". In other words, it may not be the intuitively expected 0765 * number of bytes per character that would be published for a charset, 0766 * and may not fulfill any other purpose than the allocation of an output 0767 * buffer of guaranteed sufficient size for a given input length and converter. 0768 * 0769 * Examples for special cases that are taken into account: 0770 * - Supplementary code points may convert to more bytes than BMP code points. 0771 * This function returns bytes per UChar (UTF-16 code unit), not per 0772 * Unicode code point, for efficient buffer allocation. 0773 * - State-shifting output (SI/SO, escapes, etc.) from stateful converters. 0774 * - When m input UChars are converted to n output bytes, then the maximum m/n 0775 * is taken into account. 0776 * 0777 * The number returned here does not take into account 0778 * (see UCNV_GET_MAX_BYTES_FOR_STRING): 0779 * - callbacks which output more than one charset character sequence per call, 0780 * like escape callbacks 0781 * - initial and final non-character bytes that are output by some converters 0782 * (automatic BOMs, initial escape sequence, final SI, etc.) 0783 * 0784 * Examples for returned values: 0785 * - SBCS charsets: 1 0786 * - Shift-JIS: 2 0787 * - UTF-16: 2 (2 per BMP, 4 per surrogate _pair_, BOM not counted) 0788 * - UTF-8: 3 (3 per BMP, 4 per surrogate _pair_) 0789 * - EBCDIC_STATEFUL (EBCDIC mixed SBCS/DBCS): 3 (SO + DBCS) 0790 * - ISO-2022: 3 (always outputs UTF-8) 0791 * - ISO-2022-JP: 6 (4-byte escape sequences + DBCS) 0792 * - ISO-2022-CN: 8 (4-byte designator sequences + 2-byte SS2/SS3 + DBCS) 0793 * 0794 * @param converter The Unicode converter. 0795 * @return The maximum number of bytes per UChar (16 bit code unit) 0796 * that are output by ucnv_fromUnicode(), 0797 * to be used together with UCNV_GET_MAX_BYTES_FOR_STRING 0798 * for buffer allocation. 0799 * 0800 * @see UCNV_GET_MAX_BYTES_FOR_STRING 0801 * @see ucnv_getMinCharSize 0802 * @stable ICU 2.0 0803 */ 0804 U_CAPI int8_t U_EXPORT2 0805 ucnv_getMaxCharSize(const UConverter *converter); 0806 0807 /** 0808 * Calculates the size of a buffer for conversion from Unicode to a charset. 0809 * The calculated size is guaranteed to be sufficient for this conversion. 0810 * 0811 * It takes into account initial and final non-character bytes that are output 0812 * by some converters. 0813 * It does not take into account callbacks which output more than one charset 0814 * character sequence per call, like escape callbacks. 0815 * The default (substitution) callback only outputs one charset character sequence. 0816 * 0817 * @param length Number of UChars to be converted. 0818 * @param maxCharSize Return value from ucnv_getMaxCharSize() for the converter 0819 * that will be used. 0820 * @return Size of a buffer that will be large enough to hold the output bytes of 0821 * converting length UChars with the converter that returned the maxCharSize. 0822 * 0823 * @see ucnv_getMaxCharSize 0824 * @stable ICU 2.8 0825 */ 0826 #define UCNV_GET_MAX_BYTES_FOR_STRING(length, maxCharSize) \ 0827 (((int32_t)(length)+10)*(int32_t)(maxCharSize)) 0828 0829 /** 0830 * Returns the minimum byte length (per codepoint) for characters in this codepage. 0831 * This is usually either 1 or 2. 0832 * @param converter the Unicode converter 0833 * @return the minimum number of bytes per codepoint allowed by this particular converter 0834 * @see ucnv_getMaxCharSize 0835 * @stable ICU 2.0 0836 */ 0837 U_CAPI int8_t U_EXPORT2 0838 ucnv_getMinCharSize(const UConverter *converter); 0839 0840 /** 0841 * Returns the display name of the converter passed in based on the Locale 0842 * passed in. If the locale contains no display name, the internal ASCII 0843 * name will be filled in. 0844 * 0845 * @param converter the Unicode converter. 0846 * @param displayLocale is the specific Locale we want to localized for 0847 * @param displayName user provided buffer to be filled in 0848 * @param displayNameCapacity size of displayName Buffer 0849 * @param err error status code 0850 * @return displayNameLength number of UChar needed in displayName 0851 * @see ucnv_getName 0852 * @stable ICU 2.0 0853 */ 0854 U_CAPI int32_t U_EXPORT2 0855 ucnv_getDisplayName(const UConverter *converter, 0856 const char *displayLocale, 0857 UChar *displayName, 0858 int32_t displayNameCapacity, 0859 UErrorCode *err); 0860 0861 /** 0862 * Gets the internal, canonical name of the converter (zero-terminated). 0863 * The lifetime of the returned string will be that of the converter 0864 * passed to this function. 0865 * @param converter the Unicode converter 0866 * @param err UErrorCode status 0867 * @return the internal name of the converter 0868 * @see ucnv_getDisplayName 0869 * @stable ICU 2.0 0870 */ 0871 U_CAPI const char * U_EXPORT2 0872 ucnv_getName(const UConverter *converter, UErrorCode *err); 0873 0874 /** 0875 * Gets a codepage number associated with the converter. This is not guaranteed 0876 * to be the one used to create the converter. Some converters do not represent 0877 * platform registered codepages and return zero for the codepage number. 0878 * The error code fill-in parameter indicates if the codepage number 0879 * is available. 0880 * Does not check if the converter is <TT>NULL</TT> or if converter's data 0881 * table is <TT>NULL</TT>. 0882 * 0883 * Important: The use of CCSIDs is not recommended because it is limited 0884 * to only two platforms in principle and only one (UCNV_IBM) in the current 0885 * ICU converter API. 0886 * Also, CCSIDs are insufficient to identify IBM Unicode conversion tables precisely. 0887 * For more details see ucnv_openCCSID(). 0888 * 0889 * @param converter the Unicode converter 0890 * @param err the error status code. 0891 * @return If any error occurs, -1 will be returned otherwise, the codepage number 0892 * will be returned 0893 * @see ucnv_openCCSID 0894 * @see ucnv_getPlatform 0895 * @stable ICU 2.0 0896 */ 0897 U_CAPI int32_t U_EXPORT2 0898 ucnv_getCCSID(const UConverter *converter, 0899 UErrorCode *err); 0900 0901 /** 0902 * Gets a codepage platform associated with the converter. Currently, 0903 * only <TT>UCNV_IBM</TT> will be returned. 0904 * Does not test if the converter is <TT>NULL</TT> or if converter's data 0905 * table is <TT>NULL</TT>. 0906 * @param converter the Unicode converter 0907 * @param err the error status code. 0908 * @return The codepage platform 0909 * @stable ICU 2.0 0910 */ 0911 U_CAPI UConverterPlatform U_EXPORT2 0912 ucnv_getPlatform(const UConverter *converter, 0913 UErrorCode *err); 0914 0915 /** 0916 * Gets the type of the converter 0917 * e.g. SBCS, MBCS, DBCS, UTF8, UTF16_BE, UTF16_LE, ISO_2022, 0918 * EBCDIC_STATEFUL, LATIN_1 0919 * @param converter a valid, opened converter 0920 * @return the type of the converter 0921 * @stable ICU 2.0 0922 */ 0923 U_CAPI UConverterType U_EXPORT2 0924 ucnv_getType(const UConverter * converter); 0925 0926 /** 0927 * Gets the "starter" (lead) bytes for converters of type MBCS. 0928 * Will fill in an <TT>U_ILLEGAL_ARGUMENT_ERROR</TT> if converter passed in 0929 * is not MBCS. Fills in an array of type UBool, with the value of the byte 0930 * as offset to the array. For example, if (starters[0x20] == true) at return, 0931 * it means that the byte 0x20 is a starter byte in this converter. 0932 * Context pointers are always owned by the caller. 0933 * 0934 * @param converter a valid, opened converter of type MBCS 0935 * @param starters an array of size 256 to be filled in 0936 * @param err error status, <TT>U_ILLEGAL_ARGUMENT_ERROR</TT> if the 0937 * converter is not a type which can return starters. 0938 * @see ucnv_getType 0939 * @stable ICU 2.0 0940 */ 0941 U_CAPI void U_EXPORT2 0942 ucnv_getStarters(const UConverter* converter, 0943 UBool starters[256], 0944 UErrorCode* err); 0945 0946 0947 /** 0948 * Selectors for Unicode sets that can be returned by ucnv_getUnicodeSet(). 0949 * @see ucnv_getUnicodeSet 0950 * @stable ICU 2.6 0951 */ 0952 typedef enum UConverterUnicodeSet { 0953 /** Select the set of roundtrippable Unicode code points. @stable ICU 2.6 */ 0954 UCNV_ROUNDTRIP_SET, 0955 /** Select the set of Unicode code points with roundtrip or fallback mappings. @stable ICU 4.0 */ 0956 UCNV_ROUNDTRIP_AND_FALLBACK_SET, 0957 #ifndef U_HIDE_DEPRECATED_API 0958 /** 0959 * Number of UConverterUnicodeSet selectors. 0960 * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420. 0961 */ 0962 UCNV_SET_COUNT 0963 #endif // U_HIDE_DEPRECATED_API 0964 } UConverterUnicodeSet; 0965 0966 0967 /** 0968 * Returns the set of Unicode code points that can be converted by an ICU converter. 0969 * 0970 * Returns one of several kinds of set: 0971 * 0972 * 1. UCNV_ROUNDTRIP_SET 0973 * 0974 * The set of all Unicode code points that can be roundtrip-converted 0975 * (converted without any data loss) with the converter (ucnv_fromUnicode()). 0976 * This set will not include code points that have fallback mappings 0977 * or are only the result of reverse fallback mappings. 0978 * This set will also not include PUA code points with fallbacks, although 0979 * ucnv_fromUnicode() will always uses those mappings despite ucnv_setFallback(). 0980 * See UTR #22 "Character Mapping Markup Language" 0981 * at http://www.unicode.org/reports/tr22/ 0982 * 0983 * This is useful for example for 0984 * - checking that a string or document can be roundtrip-converted with a converter, 0985 * without/before actually performing the conversion 0986 * - testing if a converter can be used for text for typical text for a certain locale, 0987 * by comparing its roundtrip set with the set of ExemplarCharacters from 0988 * ICU's locale data or other sources 0989 * 0990 * 2. UCNV_ROUNDTRIP_AND_FALLBACK_SET 0991 * 0992 * The set of all Unicode code points that can be converted with the converter (ucnv_fromUnicode()) 0993 * when fallbacks are turned on (see ucnv_setFallback()). 0994 * This set includes all code points with roundtrips and fallbacks (but not reverse fallbacks). 0995 * 0996 * In the future, there may be more UConverterUnicodeSet choices to select 0997 * sets with different properties. 0998 * 0999 * @param cnv The converter for which a set is requested. 1000 * @param setFillIn A valid USet *. It will be cleared by this function before 1001 * the converter's specific set is filled into the USet. 1002 * @param whichSet A UConverterUnicodeSet selector; 1003 * currently UCNV_ROUNDTRIP_SET is the only supported value. 1004 * @param pErrorCode ICU error code in/out parameter. 1005 * Must fulfill U_SUCCESS before the function call. 1006 * 1007 * @see UConverterUnicodeSet 1008 * @see uset_open 1009 * @see uset_close 1010 * @stable ICU 2.6 1011 */ 1012 U_CAPI void U_EXPORT2 1013 ucnv_getUnicodeSet(const UConverter *cnv, 1014 USet *setFillIn, 1015 UConverterUnicodeSet whichSet, 1016 UErrorCode *pErrorCode); 1017 1018 /** 1019 * Gets the current callback function used by the converter when an illegal 1020 * or invalid codepage sequence is found. 1021 * Context pointers are always owned by the caller. 1022 * 1023 * @param converter the unicode converter 1024 * @param action fillin: returns the callback function pointer 1025 * @param context fillin: returns the callback's private void* context 1026 * @see ucnv_setToUCallBack 1027 * @stable ICU 2.0 1028 */ 1029 U_CAPI void U_EXPORT2 1030 ucnv_getToUCallBack (const UConverter * converter, 1031 UConverterToUCallback *action, 1032 const void **context); 1033 1034 /** 1035 * Gets the current callback function used by the converter when illegal 1036 * or invalid Unicode sequence is found. 1037 * Context pointers are always owned by the caller. 1038 * 1039 * @param converter the unicode converter 1040 * @param action fillin: returns the callback function pointer 1041 * @param context fillin: returns the callback's private void* context 1042 * @see ucnv_setFromUCallBack 1043 * @stable ICU 2.0 1044 */ 1045 U_CAPI void U_EXPORT2 1046 ucnv_getFromUCallBack (const UConverter * converter, 1047 UConverterFromUCallback *action, 1048 const void **context); 1049 1050 /** 1051 * Changes the callback function used by the converter when 1052 * an illegal or invalid sequence is found. 1053 * Context pointers are always owned by the caller. 1054 * Predefined actions and contexts can be found in the ucnv_err.h header. 1055 * 1056 * @param converter the unicode converter 1057 * @param newAction the new callback function 1058 * @param newContext the new toUnicode callback context pointer. This can be NULL. 1059 * @param oldAction fillin: returns the old callback function pointer. This can be NULL. 1060 * @param oldContext fillin: returns the old callback's private void* context. This can be NULL. 1061 * @param err The error code status 1062 * @see ucnv_getToUCallBack 1063 * @stable ICU 2.0 1064 */ 1065 U_CAPI void U_EXPORT2 1066 ucnv_setToUCallBack (UConverter * converter, 1067 UConverterToUCallback newAction, 1068 const void* newContext, 1069 UConverterToUCallback *oldAction, 1070 const void** oldContext, 1071 UErrorCode * err); 1072 1073 /** 1074 * Changes the current callback function used by the converter when 1075 * an illegal or invalid sequence is found. 1076 * Context pointers are always owned by the caller. 1077 * Predefined actions and contexts can be found in the ucnv_err.h header. 1078 * 1079 * @param converter the unicode converter 1080 * @param newAction the new callback function 1081 * @param newContext the new fromUnicode callback context pointer. This can be NULL. 1082 * @param oldAction fillin: returns the old callback function pointer. This can be NULL. 1083 * @param oldContext fillin: returns the old callback's private void* context. This can be NULL. 1084 * @param err The error code status 1085 * @see ucnv_getFromUCallBack 1086 * @stable ICU 2.0 1087 */ 1088 U_CAPI void U_EXPORT2 1089 ucnv_setFromUCallBack (UConverter * converter, 1090 UConverterFromUCallback newAction, 1091 const void *newContext, 1092 UConverterFromUCallback *oldAction, 1093 const void **oldContext, 1094 UErrorCode * err); 1095 1096 /** 1097 * Converts an array of unicode characters to an array of codepage 1098 * characters. This function is optimized for converting a continuous 1099 * stream of data in buffer-sized chunks, where the entire source and 1100 * target does not fit in available buffers. 1101 * 1102 * The source pointer is an in/out parameter. It starts out pointing where the 1103 * conversion is to begin, and ends up pointing after the last UChar consumed. 1104 * 1105 * Target similarly starts out pointer at the first available byte in the output 1106 * buffer, and ends up pointing after the last byte written to the output. 1107 * 1108 * The converter always attempts to consume the entire source buffer, unless 1109 * (1.) the target buffer is full, or (2.) a failing error is returned from the 1110 * current callback function. When a successful error status has been 1111 * returned, it means that all of the source buffer has been 1112 * consumed. At that point, the caller should reset the source and 1113 * sourceLimit pointers to point to the next chunk. 1114 * 1115 * At the end of the stream (flush==true), the input is completely consumed 1116 * when *source==sourceLimit and no error code is set. 1117 * The converter object is then automatically reset by this function. 1118 * (This means that a converter need not be reset explicitly between data 1119 * streams if it finishes the previous stream without errors.) 1120 * 1121 * This is a <I>stateful</I> conversion. Additionally, even when all source data has 1122 * been consumed, some data may be in the converters' internal state. 1123 * Call this function repeatedly, updating the target pointers with 1124 * the next empty chunk of target in case of a 1125 * <TT>U_BUFFER_OVERFLOW_ERROR</TT>, and updating the source pointers 1126 * with the next chunk of source when a successful error status is 1127 * returned, until there are no more chunks of source data. 1128 * @param converter the Unicode converter 1129 * @param target I/O parameter. Input : Points to the beginning of the buffer to copy 1130 * codepage characters to. Output : points to after the last codepage character copied 1131 * to <TT>target</TT>. 1132 * @param targetLimit the pointer just after last of the <TT>target</TT> buffer 1133 * @param source I/O parameter, pointer to pointer to the source Unicode character buffer. 1134 * @param sourceLimit the pointer just after the last of the source buffer 1135 * @param offsets if NULL is passed, nothing will happen to it, otherwise it needs to have the same number 1136 * of allocated cells as <TT>target</TT>. Will fill in offsets from target to source pointer 1137 * 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> 1138 * For output data carried across calls, and other data without a specific source character 1139 * (such as from escape sequences or callbacks) -1 will be placed for offsets. 1140 * @param flush set to <TT>true</TT> if the current source buffer is the last available 1141 * chunk of the source, <TT>false</TT> otherwise. Note that if a failing status is returned, 1142 * this function may have to be called multiple times with flush set to <TT>true</TT> until 1143 * the source buffer is consumed. 1144 * @param err the error status. <TT>U_ILLEGAL_ARGUMENT_ERROR</TT> will be set if the 1145 * converter is <TT>NULL</TT>. 1146 * <code>U_BUFFER_OVERFLOW_ERROR</code> will be set if the target is full and there is 1147 * still data to be written to the target. 1148 * @see ucnv_fromUChars 1149 * @see ucnv_convert 1150 * @see ucnv_getMinCharSize 1151 * @see ucnv_setToUCallBack 1152 * @stable ICU 2.0 1153 */ 1154 U_CAPI void U_EXPORT2 1155 ucnv_fromUnicode (UConverter * converter, 1156 char **target, 1157 const char *targetLimit, 1158 const UChar ** source, 1159 const UChar * sourceLimit, 1160 int32_t* offsets, 1161 UBool flush, 1162 UErrorCode * err); 1163 1164 /** 1165 * Converts a buffer of codepage bytes into an array of unicode UChars 1166 * characters. This function is optimized for converting a continuous 1167 * stream of data in buffer-sized chunks, where the entire source and 1168 * target does not fit in available buffers. 1169 * 1170 * The source pointer is an in/out parameter. It starts out pointing where the 1171 * conversion is to begin, and ends up pointing after the last byte of source consumed. 1172 * 1173 * Target similarly starts out pointer at the first available UChar in the output 1174 * buffer, and ends up pointing after the last UChar written to the output. 1175 * It does NOT necessarily keep UChar sequences together. 1176 * 1177 * The converter always attempts to consume the entire source buffer, unless 1178 * (1.) the target buffer is full, or (2.) a failing error is returned from the 1179 * current callback function. When a successful error status has been 1180 * returned, it means that all of the source buffer has been 1181 * consumed. At that point, the caller should reset the source and 1182 * sourceLimit pointers to point to the next chunk. 1183 * 1184 * At the end of the stream (flush==true), the input is completely consumed 1185 * when *source==sourceLimit and no error code is set 1186 * The converter object is then automatically reset by this function. 1187 * (This means that a converter need not be reset explicitly between data 1188 * streams if it finishes the previous stream without errors.) 1189 * 1190 * This is a <I>stateful</I> conversion. Additionally, even when all source data has 1191 * been consumed, some data may be in the converters' internal state. 1192 * Call this function repeatedly, updating the target pointers with 1193 * the next empty chunk of target in case of a 1194 * <TT>U_BUFFER_OVERFLOW_ERROR</TT>, and updating the source pointers 1195 * with the next chunk of source when a successful error status is 1196 * returned, until there are no more chunks of source data. 1197 * @param converter the Unicode converter 1198 * @param target I/O parameter. Input : Points to the beginning of the buffer to copy 1199 * UChars into. Output : points to after the last UChar copied. 1200 * @param targetLimit the pointer just after the end of the <TT>target</TT> buffer 1201 * @param source I/O parameter, pointer to pointer to the source codepage buffer. 1202 * @param sourceLimit the pointer to the byte after the end of the source buffer 1203 * @param offsets if NULL is passed, nothing will happen to it, otherwise it needs to have the same number 1204 * of allocated cells as <TT>target</TT>. Will fill in offsets from target to source pointer 1205 * 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> 1206 * For output data carried across calls, and other data without a specific source character 1207 * (such as from escape sequences or callbacks) -1 will be placed for offsets. 1208 * @param flush set to <TT>true</TT> if the current source buffer is the last available 1209 * chunk of the source, <TT>false</TT> otherwise. Note that if a failing status is returned, 1210 * this function may have to be called multiple times with flush set to <TT>true</TT> until 1211 * the source buffer is consumed. 1212 * @param err the error status. <TT>U_ILLEGAL_ARGUMENT_ERROR</TT> will be set if the 1213 * converter is <TT>NULL</TT>. 1214 * <code>U_BUFFER_OVERFLOW_ERROR</code> will be set if the target is full and there is 1215 * still data to be written to the target. 1216 * @see ucnv_fromUChars 1217 * @see ucnv_convert 1218 * @see ucnv_getMinCharSize 1219 * @see ucnv_setFromUCallBack 1220 * @see ucnv_getNextUChar 1221 * @stable ICU 2.0 1222 */ 1223 U_CAPI void U_EXPORT2 1224 ucnv_toUnicode(UConverter *converter, 1225 UChar **target, 1226 const UChar *targetLimit, 1227 const char **source, 1228 const char *sourceLimit, 1229 int32_t *offsets, 1230 UBool flush, 1231 UErrorCode *err); 1232 1233 /** 1234 * Convert the Unicode string into a codepage string using an existing UConverter. 1235 * The output string is NUL-terminated if possible. 1236 * 1237 * This function is a more convenient but less powerful version of ucnv_fromUnicode(). 1238 * It is only useful for whole strings, not for streaming conversion. 1239 * 1240 * The maximum output buffer capacity required (barring output from callbacks) will be 1241 * UCNV_GET_MAX_BYTES_FOR_STRING(srcLength, ucnv_getMaxCharSize(cnv)). 1242 * 1243 * @param cnv the converter object to be used (ucnv_resetFromUnicode() will be called) 1244 * @param src the input Unicode string 1245 * @param srcLength the input string length, or -1 if NUL-terminated 1246 * @param dest destination string buffer, can be NULL if destCapacity==0 1247 * @param destCapacity the number of chars available at dest 1248 * @param pErrorCode normal ICU error code; 1249 * common error codes that may be set by this function include 1250 * U_BUFFER_OVERFLOW_ERROR, U_STRING_NOT_TERMINATED_WARNING, 1251 * U_ILLEGAL_ARGUMENT_ERROR, and conversion errors 1252 * @return the length of the output string, not counting the terminating NUL; 1253 * if the length is greater than destCapacity, then the string will not fit 1254 * and a buffer of the indicated length would need to be passed in 1255 * @see ucnv_fromUnicode 1256 * @see ucnv_convert 1257 * @see UCNV_GET_MAX_BYTES_FOR_STRING 1258 * @stable ICU 2.0 1259 */ 1260 U_CAPI int32_t U_EXPORT2 1261 ucnv_fromUChars(UConverter *cnv, 1262 char *dest, int32_t destCapacity, 1263 const UChar *src, int32_t srcLength, 1264 UErrorCode *pErrorCode); 1265 1266 /** 1267 * Convert the codepage string into a Unicode string using an existing UConverter. 1268 * The output string is NUL-terminated if possible. 1269 * 1270 * This function is a more convenient but less powerful version of ucnv_toUnicode(). 1271 * It is only useful for whole strings, not for streaming conversion. 1272 * 1273 * The maximum output buffer capacity required (barring output from callbacks) will be 1274 * 2*srcLength (each char may be converted into a surrogate pair). 1275 * 1276 * @param cnv the converter object to be used (ucnv_resetToUnicode() will be called) 1277 * @param src the input codepage string 1278 * @param srcLength the input string length, or -1 if NUL-terminated 1279 * @param dest destination string buffer, can be NULL if destCapacity==0 1280 * @param destCapacity the number of UChars available at dest 1281 * @param pErrorCode normal ICU error code; 1282 * common error codes that may be set by this function include 1283 * U_BUFFER_OVERFLOW_ERROR, U_STRING_NOT_TERMINATED_WARNING, 1284 * U_ILLEGAL_ARGUMENT_ERROR, and conversion errors 1285 * @return the length of the output string, not counting the terminating NUL; 1286 * if the length is greater than destCapacity, then the string will not fit 1287 * and a buffer of the indicated length would need to be passed in 1288 * @see ucnv_toUnicode 1289 * @see ucnv_convert 1290 * @stable ICU 2.0 1291 */ 1292 U_CAPI int32_t U_EXPORT2 1293 ucnv_toUChars(UConverter *cnv, 1294 UChar *dest, int32_t destCapacity, 1295 const char *src, int32_t srcLength, 1296 UErrorCode *pErrorCode); 1297 1298 /** 1299 * Convert a codepage buffer into Unicode one character at a time. 1300 * The input is completely consumed when the U_INDEX_OUTOFBOUNDS_ERROR is set. 1301 * 1302 * Advantage compared to ucnv_toUnicode() or ucnv_toUChars(): 1303 * - Faster for small amounts of data, for most converters, e.g., 1304 * US-ASCII, ISO-8859-1, UTF-8/16/32, and most "normal" charsets. 1305 * (For complex converters, e.g., SCSU, UTF-7 and ISO 2022 variants, 1306 * it uses ucnv_toUnicode() internally.) 1307 * - Convenient. 1308 * 1309 * Limitations compared to ucnv_toUnicode(): 1310 * - Always assumes flush=true. 1311 * This makes ucnv_getNextUChar() unsuitable for "streaming" conversion, 1312 * that is, for where the input is supplied in multiple buffers, 1313 * because ucnv_getNextUChar() will assume the end of the input at the end 1314 * of the first buffer. 1315 * - Does not provide offset output. 1316 * 1317 * It is possible to "mix" ucnv_getNextUChar() and ucnv_toUnicode() because 1318 * ucnv_getNextUChar() uses the current state of the converter 1319 * (unlike ucnv_toUChars() which always resets first). 1320 * However, if ucnv_getNextUChar() is called after ucnv_toUnicode() 1321 * stopped in the middle of a character sequence (with flush=false), 1322 * then ucnv_getNextUChar() will always use the slower ucnv_toUnicode() 1323 * internally until the next character boundary. 1324 * (This is new in ICU 2.6. In earlier releases, ucnv_getNextUChar() had to 1325 * start at a character boundary.) 1326 * 1327 * Instead of using ucnv_getNextUChar(), it is recommended 1328 * to convert using ucnv_toUnicode() or ucnv_toUChars() 1329 * and then iterate over the text using U16_NEXT() or a UCharIterator (uiter.h) 1330 * or a C++ CharacterIterator or similar. 1331 * This allows streaming conversion and offset output, for example. 1332 * 1333 * <p>Handling of surrogate pairs and supplementary-plane code points:<br> 1334 * There are two different kinds of codepages that provide mappings for surrogate characters: 1335 * <ul> 1336 * <li>Codepages like UTF-8, UTF-32, and GB 18030 provide direct representations for Unicode 1337 * code points U+10000-U+10ffff as well as for single surrogates U+d800-U+dfff. 1338 * Each valid sequence will result in exactly one returned code point. 1339 * If a sequence results in a single surrogate, then that will be returned 1340 * by itself, even if a neighboring sequence encodes the matching surrogate.</li> 1341 * <li>Codepages like SCSU and LMBCS (and UTF-16) provide direct representations only for BMP code points 1342 * including surrogates. Code points in supplementary planes are represented with 1343 * two sequences, each encoding a surrogate. 1344 * For these codepages, matching pairs of surrogates will be combined into single 1345 * code points for returning from this function. 1346 * (Note that SCSU is actually a mix of these codepage types.)</li> 1347 * </ul></p> 1348 * 1349 * @param converter an open UConverter 1350 * @param source the address of a pointer to the codepage buffer, will be 1351 * updated to point after the bytes consumed in the conversion call. 1352 * @param sourceLimit points to the end of the input buffer 1353 * @param err fills in error status (see ucnv_toUnicode) 1354 * <code>U_INDEX_OUTOFBOUNDS_ERROR</code> will be set if the input 1355 * is empty or does not convert to any output (e.g.: pure state-change 1356 * codes SI/SO, escape sequences for ISO 2022, 1357 * or if the callback did not output anything, ...). 1358 * This function will not set a <code>U_BUFFER_OVERFLOW_ERROR</code> because 1359 * the "buffer" is the return code. However, there might be subsequent output 1360 * stored in the converter object 1361 * that will be returned in following calls to this function. 1362 * @return a UChar32 resulting from the partial conversion of source 1363 * @see ucnv_toUnicode 1364 * @see ucnv_toUChars 1365 * @see ucnv_convert 1366 * @stable ICU 2.0 1367 */ 1368 U_CAPI UChar32 U_EXPORT2 1369 ucnv_getNextUChar(UConverter * converter, 1370 const char **source, 1371 const char * sourceLimit, 1372 UErrorCode * err); 1373 1374 /** 1375 * Convert from one external charset to another using two existing UConverters. 1376 * Internally, two conversions - ucnv_toUnicode() and ucnv_fromUnicode() - 1377 * are used, "pivoting" through 16-bit Unicode. 1378 * 1379 * Important: For streaming conversion (multiple function calls for successive 1380 * parts of a text stream), the caller must provide a pivot buffer explicitly, 1381 * and must preserve the pivot buffer and associated pointers from one 1382 * call to another. (The buffer may be moved if its contents and the relative 1383 * pointer positions are preserved.) 1384 * 1385 * There is a similar function, ucnv_convert(), 1386 * which has the following limitations: 1387 * - it takes charset names, not converter objects, so that 1388 * - two converters are opened for each call 1389 * - only single-string conversion is possible, not streaming operation 1390 * - it does not provide enough information to find out, 1391 * in case of failure, whether the toUnicode or 1392 * the fromUnicode conversion failed 1393 * 1394 * By contrast, ucnv_convertEx() 1395 * - takes UConverter parameters instead of charset names 1396 * - fully exposes the pivot buffer for streaming conversion and complete error handling 1397 * 1398 * ucnv_convertEx() also provides further convenience: 1399 * - an option to reset the converters at the beginning 1400 * (if reset==true, see parameters; 1401 * also sets *pivotTarget=*pivotSource=pivotStart) 1402 * - allow NUL-terminated input 1403 * (only a single NUL byte, will not work for charsets with multi-byte NULs) 1404 * (if sourceLimit==NULL, see parameters) 1405 * - terminate with a NUL on output 1406 * (only a single NUL byte, not useful for charsets with multi-byte NULs), 1407 * or set U_STRING_NOT_TERMINATED_WARNING if the output exactly fills 1408 * the target buffer 1409 * - the pivot buffer can be provided internally; 1410 * possible only for whole-string conversion, not streaming conversion; 1411 * in this case, the caller will not be able to get details about where an 1412 * error occurred 1413 * (if pivotStart==NULL, see below) 1414 * 1415 * The function returns when one of the following is true: 1416 * - the entire source text has been converted successfully to the target buffer 1417 * - a target buffer overflow occurred (U_BUFFER_OVERFLOW_ERROR) 1418 * - a conversion error occurred 1419 * (other U_FAILURE(), see description of pErrorCode) 1420 * 1421 * Limitation compared to the direct use of 1422 * ucnv_fromUnicode() and ucnv_toUnicode(): 1423 * ucnv_convertEx() does not provide offset information. 1424 * 1425 * Limitation compared to ucnv_fromUChars() and ucnv_toUChars(): 1426 * ucnv_convertEx() does not support preflighting directly. 1427 * 1428 * Sample code for converting a single string from 1429 * one external charset to UTF-8, ignoring the location of errors: 1430 * 1431 * \code 1432 * int32_t 1433 * myToUTF8(UConverter *cnv, 1434 * const char *s, int32_t length, 1435 * char *u8, int32_t capacity, 1436 * UErrorCode *pErrorCode) { 1437 * UConverter *utf8Cnv; 1438 * char *target; 1439 * 1440 * if(U_FAILURE(*pErrorCode)) { 1441 * return 0; 1442 * } 1443 * 1444 * utf8Cnv=myGetCachedUTF8Converter(pErrorCode); 1445 * if(U_FAILURE(*pErrorCode)) { 1446 * return 0; 1447 * } 1448 * 1449 * if(length<0) { 1450 * length=strlen(s); 1451 * } 1452 * target=u8; 1453 * ucnv_convertEx(utf8Cnv, cnv, 1454 * &target, u8+capacity, 1455 * &s, s+length, 1456 * NULL, NULL, NULL, NULL, 1457 * true, true, 1458 * pErrorCode); 1459 * 1460 * myReleaseCachedUTF8Converter(utf8Cnv); 1461 * 1462 * // return the output string length, but without preflighting 1463 * return (int32_t)(target-u8); 1464 * } 1465 * \endcode 1466 * 1467 * @param targetCnv Output converter, used to convert from the UTF-16 pivot 1468 * to the target using ucnv_fromUnicode(). 1469 * @param sourceCnv Input converter, used to convert from the source to 1470 * the UTF-16 pivot using ucnv_toUnicode(). 1471 * @param target I/O parameter, same as for ucnv_fromUChars(). 1472 * Input: *target points to the beginning of the target buffer. 1473 * Output: *target points to the first unit after the last char written. 1474 * @param targetLimit Pointer to the first unit after the target buffer. 1475 * @param source I/O parameter, same as for ucnv_toUChars(). 1476 * Input: *source points to the beginning of the source buffer. 1477 * Output: *source points to the first unit after the last char read. 1478 * @param sourceLimit Pointer to the first unit after the source buffer. 1479 * @param pivotStart Pointer to the UTF-16 pivot buffer. If pivotStart==NULL, 1480 * then an internal buffer is used and the other pivot 1481 * arguments are ignored and can be NULL as well. 1482 * @param pivotSource I/O parameter, same as source in ucnv_fromUChars() for 1483 * conversion from the pivot buffer to the target buffer. 1484 * @param pivotTarget I/O parameter, same as target in ucnv_toUChars() for 1485 * conversion from the source buffer to the pivot buffer. 1486 * It must be pivotStart<=*pivotSource<=*pivotTarget<=pivotLimit 1487 * and pivotStart<pivotLimit (unless pivotStart==NULL). 1488 * @param pivotLimit Pointer to the first unit after the pivot buffer. 1489 * @param reset If true, then ucnv_resetToUnicode(sourceCnv) and 1490 * ucnv_resetFromUnicode(targetCnv) are called, and the 1491 * pivot pointers are reset (*pivotTarget=*pivotSource=pivotStart). 1492 * @param flush If true, indicates the end of the input. 1493 * Passed directly to ucnv_toUnicode(), and carried over to 1494 * ucnv_fromUnicode() when the source is empty as well. 1495 * @param pErrorCode ICU error code in/out parameter. 1496 * Must fulfill U_SUCCESS before the function call. 1497 * U_BUFFER_OVERFLOW_ERROR always refers to the target buffer 1498 * because overflows into the pivot buffer are handled internally. 1499 * Other conversion errors are from the source-to-pivot 1500 * conversion if *pivotSource==pivotStart, otherwise from 1501 * the pivot-to-target conversion. 1502 * 1503 * @see ucnv_convert 1504 * @see ucnv_fromAlgorithmic 1505 * @see ucnv_toAlgorithmic 1506 * @see ucnv_fromUnicode 1507 * @see ucnv_toUnicode 1508 * @see ucnv_fromUChars 1509 * @see ucnv_toUChars 1510 * @stable ICU 2.6 1511 */ 1512 U_CAPI void U_EXPORT2 1513 ucnv_convertEx(UConverter *targetCnv, UConverter *sourceCnv, 1514 char **target, const char *targetLimit, 1515 const char **source, const char *sourceLimit, 1516 UChar *pivotStart, UChar **pivotSource, 1517 UChar **pivotTarget, const UChar *pivotLimit, 1518 UBool reset, UBool flush, 1519 UErrorCode *pErrorCode); 1520 1521 /** 1522 * Convert from one external charset to another. 1523 * Internally, two converters are opened according to the name arguments, 1524 * then the text is converted to and from the 16-bit Unicode "pivot" 1525 * using ucnv_convertEx(), then the converters are closed again. 1526 * 1527 * This is a convenience function, not an efficient way to convert a lot of text: 1528 * ucnv_convert() 1529 * - takes charset names, not converter objects, so that 1530 * - two converters are opened for each call 1531 * - only single-string conversion is possible, not streaming operation 1532 * - does not provide enough information to find out, 1533 * in case of failure, whether the toUnicode or 1534 * the fromUnicode conversion failed 1535 * - allows NUL-terminated input 1536 * (only a single NUL byte, will not work for charsets with multi-byte NULs) 1537 * (if sourceLength==-1, see parameters) 1538 * - terminate with a NUL on output 1539 * (only a single NUL byte, not useful for charsets with multi-byte NULs), 1540 * or set U_STRING_NOT_TERMINATED_WARNING if the output exactly fills 1541 * the target buffer 1542 * - a pivot buffer is provided internally 1543 * 1544 * The function returns when one of the following is true: 1545 * - the entire source text has been converted successfully to the target buffer 1546 * and either the target buffer is terminated with a single NUL byte 1547 * or the error code is set to U_STRING_NOT_TERMINATED_WARNING 1548 * - a target buffer overflow occurred (U_BUFFER_OVERFLOW_ERROR) 1549 * and the full output string length is returned ("preflighting") 1550 * - a conversion error occurred 1551 * (other U_FAILURE(), see description of pErrorCode) 1552 * 1553 * @param toConverterName The name of the converter that is used to convert 1554 * from the UTF-16 pivot buffer to the target. 1555 * @param fromConverterName The name of the converter that is used to convert 1556 * from the source to the UTF-16 pivot buffer. 1557 * @param target Pointer to the output buffer. 1558 * @param targetCapacity Capacity of the target, in bytes. 1559 * @param source Pointer to the input buffer. 1560 * @param sourceLength Length of the input text, in bytes, or -1 for NUL-terminated input. 1561 * @param pErrorCode ICU error code in/out parameter. 1562 * Must fulfill U_SUCCESS before the function call. 1563 * @return Length of the complete output text in bytes, even if it exceeds the targetCapacity 1564 * and a U_BUFFER_OVERFLOW_ERROR is set. 1565 * 1566 * @see ucnv_convertEx 1567 * @see ucnv_fromAlgorithmic 1568 * @see ucnv_toAlgorithmic 1569 * @see ucnv_fromUnicode 1570 * @see ucnv_toUnicode 1571 * @see ucnv_fromUChars 1572 * @see ucnv_toUChars 1573 * @see ucnv_getNextUChar 1574 * @stable ICU 2.0 1575 */ 1576 U_CAPI int32_t U_EXPORT2 1577 ucnv_convert(const char *toConverterName, 1578 const char *fromConverterName, 1579 char *target, 1580 int32_t targetCapacity, 1581 const char *source, 1582 int32_t sourceLength, 1583 UErrorCode *pErrorCode); 1584 1585 /** 1586 * Convert from one external charset to another. 1587 * Internally, the text is converted to and from the 16-bit Unicode "pivot" 1588 * using ucnv_convertEx(). ucnv_toAlgorithmic() works exactly like ucnv_convert() 1589 * except that the two converters need not be looked up and opened completely. 1590 * 1591 * The source-to-pivot conversion uses the cnv converter parameter. 1592 * The pivot-to-target conversion uses a purely algorithmic converter 1593 * according to the specified type, e.g., UCNV_UTF8 for a UTF-8 converter. 1594 * 1595 * Internally, the algorithmic converter is opened and closed for each 1596 * function call, which is more efficient than using the public ucnv_open() 1597 * but somewhat less efficient than only resetting an existing converter 1598 * and using ucnv_convertEx(). 1599 * 1600 * This function is more convenient than ucnv_convertEx() for single-string 1601 * conversions, especially when "preflighting" is desired (returning the length 1602 * of the complete output even if it does not fit into the target buffer; 1603 * see the User Guide Strings chapter). See ucnv_convert() for details. 1604 * 1605 * @param algorithmicType UConverterType constant identifying the desired target 1606 * charset as a purely algorithmic converter. 1607 * Those are converters for Unicode charsets like 1608 * UTF-8, BOCU-1, SCSU, UTF-7, IMAP-mailbox-name, etc., 1609 * as well as US-ASCII and ISO-8859-1. 1610 * @param cnv The converter that is used to convert 1611 * from the source to the UTF-16 pivot buffer. 1612 * @param target Pointer to the output buffer. 1613 * @param targetCapacity Capacity of the target, in bytes. 1614 * @param source Pointer to the input buffer. 1615 * @param sourceLength Length of the input text, in bytes 1616 * @param pErrorCode ICU error code in/out parameter. 1617 * Must fulfill U_SUCCESS before the function call. 1618 * @return Length of the complete output text in bytes, even if it exceeds the targetCapacity 1619 * and a U_BUFFER_OVERFLOW_ERROR is set. 1620 * 1621 * @see ucnv_fromAlgorithmic 1622 * @see ucnv_convert 1623 * @see ucnv_convertEx 1624 * @see ucnv_fromUnicode 1625 * @see ucnv_toUnicode 1626 * @see ucnv_fromUChars 1627 * @see ucnv_toUChars 1628 * @stable ICU 2.6 1629 */ 1630 U_CAPI int32_t U_EXPORT2 1631 ucnv_toAlgorithmic(UConverterType algorithmicType, 1632 UConverter *cnv, 1633 char *target, int32_t targetCapacity, 1634 const char *source, int32_t sourceLength, 1635 UErrorCode *pErrorCode); 1636 1637 /** 1638 * Convert from one external charset to another. 1639 * Internally, the text is converted to and from the 16-bit Unicode "pivot" 1640 * using ucnv_convertEx(). ucnv_fromAlgorithmic() works exactly like ucnv_convert() 1641 * except that the two converters need not be looked up and opened completely. 1642 * 1643 * The source-to-pivot conversion uses a purely algorithmic converter 1644 * according to the specified type, e.g., UCNV_UTF8 for a UTF-8 converter. 1645 * The pivot-to-target conversion uses the cnv converter parameter. 1646 * 1647 * Internally, the algorithmic converter is opened and closed for each 1648 * function call, which is more efficient than using the public ucnv_open() 1649 * but somewhat less efficient than only resetting an existing converter 1650 * and using ucnv_convertEx(). 1651 * 1652 * This function is more convenient than ucnv_convertEx() for single-string 1653 * conversions, especially when "preflighting" is desired (returning the length 1654 * of the complete output even if it does not fit into the target buffer; 1655 * see the User Guide Strings chapter). See ucnv_convert() for details. 1656 * 1657 * @param cnv The converter that is used to convert 1658 * from the UTF-16 pivot buffer to the target. 1659 * @param algorithmicType UConverterType constant identifying the desired source 1660 * charset as a purely algorithmic converter. 1661 * Those are converters for Unicode charsets like 1662 * UTF-8, BOCU-1, SCSU, UTF-7, IMAP-mailbox-name, etc., 1663 * as well as US-ASCII and ISO-8859-1. 1664 * @param target Pointer to the output buffer. 1665 * @param targetCapacity Capacity of the target, in bytes. 1666 * @param source Pointer to the input buffer. 1667 * @param sourceLength Length of the input text, in bytes 1668 * @param pErrorCode ICU error code in/out parameter. 1669 * Must fulfill U_SUCCESS before the function call. 1670 * @return Length of the complete output text in bytes, even if it exceeds the targetCapacity 1671 * and a U_BUFFER_OVERFLOW_ERROR is set. 1672 * 1673 * @see ucnv_fromAlgorithmic 1674 * @see ucnv_convert 1675 * @see ucnv_convertEx 1676 * @see ucnv_fromUnicode 1677 * @see ucnv_toUnicode 1678 * @see ucnv_fromUChars 1679 * @see ucnv_toUChars 1680 * @stable ICU 2.6 1681 */ 1682 U_CAPI int32_t U_EXPORT2 1683 ucnv_fromAlgorithmic(UConverter *cnv, 1684 UConverterType algorithmicType, 1685 char *target, int32_t targetCapacity, 1686 const char *source, int32_t sourceLength, 1687 UErrorCode *pErrorCode); 1688 1689 /** 1690 * Frees up memory occupied by unused, cached converter shared data. 1691 * 1692 * @return the number of cached converters successfully deleted 1693 * @see ucnv_close 1694 * @stable ICU 2.0 1695 */ 1696 U_CAPI int32_t U_EXPORT2 1697 ucnv_flushCache(void); 1698 1699 /** 1700 * Returns the number of available converters, as per the alias file. 1701 * 1702 * @return the number of available converters 1703 * @see ucnv_getAvailableName 1704 * @stable ICU 2.0 1705 */ 1706 U_CAPI int32_t U_EXPORT2 1707 ucnv_countAvailable(void); 1708 1709 /** 1710 * Gets the canonical converter name of the specified converter from a list of 1711 * all available converters contained in the alias file. All converters 1712 * in this list can be opened. 1713 * 1714 * @param n the index to a converter available on the system (in the range <TT>[0..ucnv_countAvailable()]</TT>) 1715 * @return a pointer a string (library owned), or <TT>NULL</TT> if the index is out of bounds. 1716 * @see ucnv_countAvailable 1717 * @stable ICU 2.0 1718 */ 1719 U_CAPI const char* U_EXPORT2 1720 ucnv_getAvailableName(int32_t n); 1721 1722 /** 1723 * Returns a UEnumeration to enumerate all of the canonical converter 1724 * names, as per the alias file, regardless of the ability to open each 1725 * converter. 1726 * 1727 * @return A UEnumeration object for getting all the recognized canonical 1728 * converter names. 1729 * @see ucnv_getAvailableName 1730 * @see uenum_close 1731 * @see uenum_next 1732 * @stable ICU 2.4 1733 */ 1734 U_CAPI UEnumeration * U_EXPORT2 1735 ucnv_openAllNames(UErrorCode *pErrorCode); 1736 1737 /** 1738 * Gives the number of aliases for a given converter or alias name. 1739 * If the alias is ambiguous, then the preferred converter is used 1740 * and the status is set to U_AMBIGUOUS_ALIAS_WARNING. 1741 * This method only enumerates the listed entries in the alias file. 1742 * @param alias alias name 1743 * @param pErrorCode error status 1744 * @return number of names on alias list for given alias 1745 * @stable ICU 2.0 1746 */ 1747 U_CAPI uint16_t U_EXPORT2 1748 ucnv_countAliases(const char *alias, UErrorCode *pErrorCode); 1749 1750 /** 1751 * Gives the name of the alias at given index of alias list. 1752 * This method only enumerates the listed entries in the alias file. 1753 * If the alias is ambiguous, then the preferred converter is used 1754 * and the status is set to U_AMBIGUOUS_ALIAS_WARNING. 1755 * @param alias alias name 1756 * @param n index in alias list 1757 * @param pErrorCode result of operation 1758 * @return returns the name of the alias at given index 1759 * @see ucnv_countAliases 1760 * @stable ICU 2.0 1761 */ 1762 U_CAPI const char * U_EXPORT2 1763 ucnv_getAlias(const char *alias, uint16_t n, UErrorCode *pErrorCode); 1764 1765 /** 1766 * Fill-up the list of alias names for the given alias. 1767 * This method only enumerates the listed entries in the alias file. 1768 * If the alias is ambiguous, then the preferred converter is used 1769 * and the status is set to U_AMBIGUOUS_ALIAS_WARNING. 1770 * @param alias alias name 1771 * @param aliases fill-in list, aliases is a pointer to an array of 1772 * <code>ucnv_countAliases()</code> string-pointers 1773 * (<code>const char *</code>) that will be filled in. 1774 * The strings themselves are owned by the library. 1775 * @param pErrorCode result of operation 1776 * @stable ICU 2.0 1777 */ 1778 U_CAPI void U_EXPORT2 1779 ucnv_getAliases(const char *alias, const char **aliases, UErrorCode *pErrorCode); 1780 1781 /** 1782 * Return a new UEnumeration object for enumerating all the 1783 * alias names for a given converter that are recognized by a standard. 1784 * This method only enumerates the listed entries in the alias file. 1785 * The convrtrs.txt file can be modified to change the results of 1786 * this function. 1787 * The first result in this list is the same result given by 1788 * <code>ucnv_getStandardName</code>, which is the default alias for 1789 * the specified standard name. The returned object must be closed with 1790 * <code>uenum_close</code> when you are done with the object. 1791 * 1792 * @param convName original converter name 1793 * @param standard name of the standard governing the names; MIME and IANA 1794 * are such standards 1795 * @param pErrorCode The error code 1796 * @return A UEnumeration object for getting all aliases that are recognized 1797 * by a standard. If any of the parameters are invalid, NULL 1798 * is returned. 1799 * @see ucnv_getStandardName 1800 * @see uenum_close 1801 * @see uenum_next 1802 * @stable ICU 2.2 1803 */ 1804 U_CAPI UEnumeration * U_EXPORT2 1805 ucnv_openStandardNames(const char *convName, 1806 const char *standard, 1807 UErrorCode *pErrorCode); 1808 1809 /** 1810 * Gives the number of standards associated to converter names. 1811 * @return number of standards 1812 * @stable ICU 2.0 1813 */ 1814 U_CAPI uint16_t U_EXPORT2 1815 ucnv_countStandards(void); 1816 1817 /** 1818 * Gives the name of the standard at given index of standard list. 1819 * @param n index in standard list 1820 * @param pErrorCode result of operation 1821 * @return returns the name of the standard at given index. Owned by the library. 1822 * @stable ICU 2.0 1823 */ 1824 U_CAPI const char * U_EXPORT2 1825 ucnv_getStandard(uint16_t n, UErrorCode *pErrorCode); 1826 1827 /** 1828 * Returns a standard name for a given converter name. 1829 * <p> 1830 * Example alias table:<br> 1831 * conv alias1 { STANDARD1 } alias2 { STANDARD1* } 1832 * <p> 1833 * Result of ucnv_getStandardName("conv", "STANDARD1") from example 1834 * alias table:<br> 1835 * <b>"alias2"</b> 1836 * 1837 * @param name original converter name 1838 * @param standard name of the standard governing the names; MIME and IANA 1839 * are such standards 1840 * @param pErrorCode result of operation 1841 * @return returns the standard converter name; 1842 * if a standard converter name cannot be determined, 1843 * then <code>NULL</code> is returned. Owned by the library. 1844 * @stable ICU 2.0 1845 */ 1846 U_CAPI const char * U_EXPORT2 1847 ucnv_getStandardName(const char *name, const char *standard, UErrorCode *pErrorCode); 1848 1849 /** 1850 * This function will return the internal canonical converter name of the 1851 * tagged alias. This is the opposite of ucnv_openStandardNames, which 1852 * returns the tagged alias given the canonical name. 1853 * <p> 1854 * Example alias table:<br> 1855 * conv alias1 { STANDARD1 } alias2 { STANDARD1* } 1856 * <p> 1857 * Result of ucnv_getStandardName("alias1", "STANDARD1") from example 1858 * alias table:<br> 1859 * <b>"conv"</b> 1860 * 1861 * @return returns the canonical converter name; 1862 * if a standard or alias name cannot be determined, 1863 * then <code>NULL</code> is returned. The returned string is 1864 * owned by the library. 1865 * @see ucnv_getStandardName 1866 * @stable ICU 2.4 1867 */ 1868 U_CAPI const char * U_EXPORT2 1869 ucnv_getCanonicalName(const char *alias, const char *standard, UErrorCode *pErrorCode); 1870 1871 /** 1872 * Returns the current default converter name. If you want to open 1873 * a default converter, you do not need to use this function. 1874 * It is faster if you pass a NULL argument to ucnv_open the 1875 * default converter. 1876 * 1877 * If U_CHARSET_IS_UTF8 is defined to 1 in utypes.h then this function 1878 * always returns "UTF-8". 1879 * 1880 * @return returns the current default converter name. 1881 * Storage owned by the library 1882 * @see ucnv_setDefaultName 1883 * @stable ICU 2.0 1884 */ 1885 U_CAPI const char * U_EXPORT2 1886 ucnv_getDefaultName(void); 1887 1888 #ifndef U_HIDE_SYSTEM_API 1889 /** 1890 * This function is not thread safe. DO NOT call this function when ANY ICU 1891 * function is being used from more than one thread! This function sets the 1892 * current default converter name. If this function needs to be called, it 1893 * should be called during application initialization. Most of the time, the 1894 * results from ucnv_getDefaultName() or ucnv_open with a NULL string argument 1895 * is sufficient for your application. 1896 * 1897 * If U_CHARSET_IS_UTF8 is defined to 1 in utypes.h then this function 1898 * does nothing. 1899 * 1900 * @param name the converter name to be the default (must be known by ICU). 1901 * @see ucnv_getDefaultName 1902 * @system 1903 * @stable ICU 2.0 1904 */ 1905 U_CAPI void U_EXPORT2 1906 ucnv_setDefaultName(const char *name); 1907 #endif /* U_HIDE_SYSTEM_API */ 1908 1909 /** 1910 * Fixes the backslash character mismapping. For example, in SJIS, the backslash 1911 * character in the ASCII portion is also used to represent the yen currency sign. 1912 * When mapping from Unicode character 0x005C, it's unclear whether to map the 1913 * character back to yen or backslash in SJIS. This function will take the input 1914 * buffer and replace all the yen sign characters with backslash. This is necessary 1915 * when the user tries to open a file with the input buffer on Windows. 1916 * This function will test the converter to see whether such mapping is 1917 * required. You can sometimes avoid using this function by using the correct version 1918 * of Shift-JIS. 1919 * 1920 * @param cnv The converter representing the target codepage. 1921 * @param source the input buffer to be fixed 1922 * @param sourceLen the length of the input buffer 1923 * @see ucnv_isAmbiguous 1924 * @stable ICU 2.0 1925 */ 1926 U_CAPI void U_EXPORT2 1927 ucnv_fixFileSeparator(const UConverter *cnv, UChar *source, int32_t sourceLen); 1928 1929 /** 1930 * Determines if the converter contains ambiguous mappings of the same 1931 * character or not. 1932 * @param cnv the converter to be tested 1933 * @return true if the converter contains ambiguous mapping of the same 1934 * character, false otherwise. 1935 * @stable ICU 2.0 1936 */ 1937 U_CAPI UBool U_EXPORT2 1938 ucnv_isAmbiguous(const UConverter *cnv); 1939 1940 /** 1941 * Sets the converter to use fallback mappings or not. 1942 * Regardless of this flag, the converter will always use 1943 * fallbacks from Unicode Private Use code points, as well as 1944 * reverse fallbacks (to Unicode). 1945 * For details see ".ucm File Format" 1946 * in the Conversion Data chapter of the ICU User Guide: 1947 * https://unicode-org.github.io/icu/userguide/conversion/data.html#ucm-file-format 1948 * 1949 * @param cnv The converter to set the fallback mapping usage on. 1950 * @param usesFallback true if the user wants the converter to take advantage of the fallback 1951 * mapping, false otherwise. 1952 * @stable ICU 2.0 1953 * @see ucnv_usesFallback 1954 */ 1955 U_CAPI void U_EXPORT2 1956 ucnv_setFallback(UConverter *cnv, UBool usesFallback); 1957 1958 /** 1959 * Determines if the converter uses fallback mappings or not. 1960 * This flag has restrictions, see ucnv_setFallback(). 1961 * 1962 * @param cnv The converter to be tested 1963 * @return true if the converter uses fallback, false otherwise. 1964 * @stable ICU 2.0 1965 * @see ucnv_setFallback 1966 */ 1967 U_CAPI UBool U_EXPORT2 1968 ucnv_usesFallback(const UConverter *cnv); 1969 1970 /** 1971 * Detects Unicode signature byte sequences at the start of the byte stream 1972 * and returns the charset name of the indicated Unicode charset. 1973 * NULL is returned when no Unicode signature is recognized. 1974 * The number of bytes in the signature is output as well. 1975 * 1976 * The caller can ucnv_open() a converter using the charset name. 1977 * The first code unit (UChar) from the start of the stream will be U+FEFF 1978 * (the Unicode BOM/signature character) and can usually be ignored. 1979 * 1980 * For most Unicode charsets it is also possible to ignore the indicated 1981 * number of initial stream bytes and start converting after them. 1982 * However, there are stateful Unicode charsets (UTF-7 and BOCU-1) for which 1983 * this will not work. Therefore, it is best to ignore the first output UChar 1984 * instead of the input signature bytes. 1985 * <p> 1986 * Usage: 1987 * 1988 * @param source The source string in which the signature should be detected. 1989 * @param sourceLength Length of the input string, or -1 if terminated with a NUL byte. 1990 * @param signatureLength A pointer to int32_t to receive the number of bytes that make up the signature 1991 * of the detected UTF. 0 if not detected. 1992 * Can be a NULL pointer. 1993 * @param pErrorCode ICU error code in/out parameter. 1994 * Must fulfill U_SUCCESS before the function call. 1995 * @return The name of the encoding detected. NULL if encoding is not detected. 1996 * @stable ICU 2.4 1997 */ 1998 U_CAPI const char* U_EXPORT2 1999 ucnv_detectUnicodeSignature(const char* source, 2000 int32_t sourceLength, 2001 int32_t *signatureLength, 2002 UErrorCode *pErrorCode); 2003 2004 /** 2005 * Returns the number of UChars held in the converter's internal state 2006 * because more input is needed for completing the conversion. This function is 2007 * useful for mapping semantics of ICU's converter interface to those of iconv, 2008 * and this information is not needed for normal conversion. 2009 * @param cnv The converter in which the input is held 2010 * @param status ICU error code in/out parameter. 2011 * Must fulfill U_SUCCESS before the function call. 2012 * @return The number of UChars in the state. -1 if an error is encountered. 2013 * @stable ICU 3.4 2014 */ 2015 U_CAPI int32_t U_EXPORT2 2016 ucnv_fromUCountPending(const UConverter* cnv, UErrorCode* status); 2017 2018 /** 2019 * Returns the number of chars held in the converter's internal state 2020 * because more input is needed for completing the conversion. This function is 2021 * useful for mapping semantics of ICU's converter interface to those of iconv, 2022 * and this information is not needed for normal conversion. 2023 * @param cnv The converter in which the input is held as internal state 2024 * @param status ICU error code in/out parameter. 2025 * Must fulfill U_SUCCESS before the function call. 2026 * @return The number of chars in the state. -1 if an error is encountered. 2027 * @stable ICU 3.4 2028 */ 2029 U_CAPI int32_t U_EXPORT2 2030 ucnv_toUCountPending(const UConverter* cnv, UErrorCode* status); 2031 2032 /** 2033 * Returns whether or not the charset of the converter has a fixed number of bytes 2034 * per charset character. 2035 * An example of this are converters that are of the type UCNV_SBCS or UCNV_DBCS. 2036 * Another example is UTF-32 which is always 4 bytes per character. 2037 * A Unicode code point may be represented by more than one UTF-8 or UTF-16 code unit 2038 * but a UTF-32 converter encodes each code point with 4 bytes. 2039 * Note: This method is not intended to be used to determine whether the charset has a 2040 * fixed ratio of bytes to Unicode codes <i>units</i> for any particular Unicode encoding form. 2041 * false is returned with the UErrorCode if error occurs or cnv is NULL. 2042 * @param cnv The converter to be tested 2043 * @param status ICU error code in/out parameter 2044 * @return true if the converter is fixed-width 2045 * @stable ICU 4.8 2046 */ 2047 U_CAPI UBool U_EXPORT2 2048 ucnv_isFixedWidth(UConverter *cnv, UErrorCode *status); 2049 2050 #endif 2051 2052 #endif 2053 /*_UCNV*/
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|