00001 /* 00002 ********************************************************************** 00003 * Copyright (C) 1999, International Business Machines 00004 * Corporation and others. All Rights Reserved. 00005 ********************************************************************** 00006 * ucnv.h: 00007 * External APIs for the ICU's codeset conversion library 00008 * Bertrand A. Damiba 00009 * 00010 * Modification History: 00011 * 00012 * Date Name Description 00013 * 04/04/99 helena Fixed internal header inclusion. 00014 * 05/11/00 helena Added setFallback and usesFallback APIs. 00015 */ 00016 00024 #ifndef UCNV_H 00025 #define UCNV_H 00026 00027 #include "unicode/utypes.h" 00028 #include "unicode/ucnv_bld.h" 00029 #include "unicode/ucnv_err.h" 00030 00031 U_CDECL_BEGIN 00032 00033 typedef void (*UConverterToUCallback) (UConverter *, 00034 UChar **, 00035 const UChar *, 00036 const char **, 00037 const char *, 00038 int32_t* offsets, 00039 UBool, 00040 UErrorCode *); 00041 00042 typedef void (*UConverterFromUCallback) (UConverter *, 00043 char **, 00044 const char *, 00045 const UChar **, 00046 const UChar *, 00047 int32_t* offsets, 00048 UBool, 00049 UErrorCode *); 00050 00051 U_CDECL_END 00052 00057 #define UCNV_OPTION_SEP_CHAR ',' 00058 00060 #define UCNV_OPTION_SEP_STRING "," 00061 00066 #define UCNV_VALUE_SEP_CHAR '=' 00067 00069 #define UCNV_VALUE_SEP_STRING "=" 00070 00075 #define UCNV_LOCALE_OPTION_STRING ",locale=" 00076 00102 U_CAPI 00103 UConverter* U_EXPORT2 ucnv_open (const char *converterName, UErrorCode * err); 00104 00105 00119 U_CAPI UConverter* U_EXPORT2 ucnv_openU (const UChar * name, 00120 UErrorCode * err); 00121 00122 00123 00137 U_CAPI UConverter* U_EXPORT2 ucnv_openCCSID (int32_t codepage, 00138 UConverterPlatform platform, 00139 UErrorCode * err); 00140 00141 00151 U_CAPI void U_EXPORT2 ucnv_close (UConverter * converter); 00152 00153 00154 00169 U_CAPI void U_EXPORT2 00170 ucnv_getSubstChars (const UConverter * converter, 00171 char *subChars, 00172 int8_t * len, 00173 UErrorCode * err); 00174 00188 U_CAPI void U_EXPORT2 00189 ucnv_setSubstChars (UConverter * converter, 00190 const char *subChars, 00191 int8_t len, 00192 UErrorCode * err); 00193 00194 00195 00209 U_CAPI void U_EXPORT2 00210 ucnv_getInvalidChars (const UConverter * converter, 00211 char *errBytes, 00212 int8_t * len, 00213 UErrorCode * err); 00214 00215 00229 U_CAPI void U_EXPORT2 00230 ucnv_getInvalidUChars (const UConverter * converter, 00231 char *errUChars, 00232 int8_t * len, 00233 UErrorCode * err); 00234 00243 U_CAPI void U_EXPORT2 00244 ucnv_reset (UConverter * converter); 00245 00253 U_CAPI int8_t U_EXPORT2 00254 ucnv_getMaxCharSize (const UConverter * converter); 00255 00256 00265 U_CAPI int8_t U_EXPORT2 00266 ucnv_getMinCharSize (const UConverter * converter); 00267 00268 00283 U_CAPI 00284 int32_t U_EXPORT2 ucnv_getDisplayName (const UConverter * converter, 00285 const char *displayLocale, 00286 UChar * displayName, 00287 int32_t displayNameCapacity, 00288 UErrorCode * err); 00289 00300 U_CAPI 00301 const char * U_EXPORT2 ucnv_getName (const UConverter * converter, UErrorCode * err); 00302 00303 00316 U_CAPI int32_t U_EXPORT2 00317 ucnv_getCCSID (const UConverter * converter, 00318 UErrorCode * err); 00319 00329 U_CAPI UConverterPlatform U_EXPORT2 00330 ucnv_getPlatform (const UConverter * converter, 00331 UErrorCode * err); 00332 00340 U_CAPI UConverterType U_EXPORT2 00341 ucnv_getType (const UConverter * converter); 00342 00356 U_CAPI void U_EXPORT2 ucnv_getStarters(const UConverter* converter, 00357 UBool starters[256], 00358 UErrorCode* err); 00359 00360 00369 U_CAPI UConverterToUCallback U_EXPORT2 00370 ucnv_getToUCallBack (const UConverter * converter); 00371 00380 U_CAPI UConverterFromUCallback U_EXPORT2 00381 ucnv_getFromUCallBack (const UConverter * converter); 00382 00393 U_CAPI UConverterToUCallback U_EXPORT2 00394 ucnv_setToUCallBack (UConverter * converter, 00395 UConverterToUCallback action, 00396 UErrorCode * err); 00397 00408 U_CAPI UConverterFromUCallback U_EXPORT2 00409 ucnv_setFromUCallBack (UConverter * converter, 00410 UConverterFromUCallback action, 00411 UErrorCode * err); 00412 00413 00447 U_CAPI 00448 void U_EXPORT2 ucnv_fromUnicode (UConverter * converter, 00449 char **target, 00450 const char *targetLimit, 00451 const UChar ** source, 00452 const UChar * sourceLimit, 00453 int32_t* offsets, 00454 UBool flush, 00455 UErrorCode * err); 00456 00457 00487 U_CAPI 00488 void U_EXPORT2 ucnv_toUnicode (UConverter * converter, 00489 UChar ** target, 00490 const UChar * targetLimit, 00491 const char **source, 00492 const char *sourceLimit, 00493 int32_t* offsets, 00494 UBool flush, 00495 UErrorCode * err); 00496 00497 00524 U_CAPI 00525 int32_t U_EXPORT2 ucnv_fromUChars (const UConverter * converter, 00526 char *target, 00527 int32_t targetCapacity, 00528 const UChar * source, 00529 int32_t sourceLength, 00530 UErrorCode * err); 00531 00532 00533 00534 00535 00563 U_CAPI 00564 int32_t U_EXPORT2 ucnv_toUChars (const UConverter * converter, 00565 UChar * target, 00566 int32_t targetCapacity, 00567 const char *source, 00568 int32_t sourceSize, 00569 UErrorCode * err); 00570 00571 /******************************** 00572 * Will convert a codepage buffer one character at a time. 00573 * This function was written to be efficient when transcoding small amounts of data at a time. 00574 * In that case it will be more efficient than \Ref{ucnv_toUnicode}. 00575 * When converting large buffers use \Ref{ucnv_toUnicode}. 00576 *@param converter an open UConverter 00577 *@param source the address of a pointer to the codepage buffer, will be updated to point after 00578 *the bytes consumed in the conversion call. 00579 *@param points to the end of the input buffer 00580 *@param err fills in error status (see ucnv_toUnicode) 00581 *@return a UChar resulting from the partial conversion of source 00582 *@see ucnv_toUnicode 00583 *@see ucnv_toUChars 00584 *@see ucnv_convert 00585 *@stable 00586 */ 00587 U_CAPI 00588 UChar32 U_EXPORT2 ucnv_getNextUChar (UConverter * converter, 00589 const char **source, 00590 const char *sourceLimit, 00591 UErrorCode * err); 00592 00593 00594 /************************** 00595 * Will convert a sequence of bytes from one codepage to another. 00596 * This is <STRONG>NOT AN EFFICIENT</STRONG> way to transcode. 00597 * use \Ref{ucnv_toUnicode} and \Ref{ucnv_fromUnicode} for efficiency 00598 * @param toConverterName: The name of the converter that will be used to encode the output buffer 00599 * @param fromConverterName: The name of the converter that will be used to decode the input buffer 00600 * @param target: Pointer to the output buffer to write to 00601 * @param targetCapacity: on input contains the capacity of target 00602 * @param source: Pointer to the input buffer 00603 * @param sourceLength: on input contains the capacity of source 00604 * @param err: fills in an error status 00605 * @return will be filled in with the number of bytes needed in target 00606 * @see ucnv_fromUnicode 00607 * @see ucnv_toUnicode 00608 * @see ucnv_fromUChars 00609 * @see ucnv_toUChars 00610 * @see ucnv_getNextUChar 00611 * @draft backslash versus Yen sign in shift-JIS 00612 */ 00613 U_CAPI 00614 int32_t U_EXPORT2 ucnv_convert (const char *toConverterName, 00615 const char *fromConverterName, 00616 char *target, 00617 int32_t targetCapacity, 00618 const char *source, 00619 int32_t sourceLength, 00620 UErrorCode * err); 00621 00630 U_CAPI int32_t U_EXPORT2 ucnv_flushCache (void); 00631 00632 00641 U_CAPI 00642 const char * U_EXPORT2 ucnv_getAvailableName (int32_t n); 00643 00651 U_CAPI int32_t U_EXPORT2 ucnv_countAvailable (void); 00652 00653 00661 U_CAPI uint16_t 00662 ucnv_countAliases(const char *alias, UErrorCode *pErrorCode); 00663 00672 U_CAPI const char * 00673 ucnv_getAlias(const char *alias, uint16_t n, UErrorCode *pErrorCode); 00674 00684 U_CAPI void 00685 ucnv_getAliases(const char *alias, const char **aliases, UErrorCode *pErrorCode); 00686 00696 U_CAPI const char * U_EXPORT2 ucnv_getDefaultName (void); 00697 00705 U_CAPI void U_EXPORT2 ucnv_setDefaultName (const char *name); 00706 00718 U_CAPI void U_EXPORT2 ucnv_fixFileSeparator(const UConverter *cnv, UChar* source, int32_t sourceLen); 00719 00727 U_CAPI UBool U_EXPORT2 ucnv_isAmbiguous(const UConverter *cnv); 00728 00736 U_CAPI void U_EXPORT2 ucnv_setFallback(UConverter *cnv, UBool usesFallback); 00737 00743 U_CAPI UBool U_EXPORT2 ucnv_usesFallback(const UConverter *cnv); 00744 00745 #endif 00746 /*_UCNV*/ 00747 00748