sl@0: /* sl@0: ********************************************************************** sl@0: * Copyright (C) 2000-2004, International Business Machines sl@0: * Corporation and others. All Rights Reserved. sl@0: ********************************************************************** sl@0: * ucnv_cb.h: sl@0: * External APIs for the ICU's codeset conversion library sl@0: * Helena Shih sl@0: * sl@0: * Modification History: sl@0: * sl@0: * Date Name Description sl@0: */ sl@0: sl@0: /** sl@0: * \file sl@0: * \brief C UConverter functions to aid the writers of callbacks sl@0: * sl@0: *

Callback API for UConverter

sl@0: * sl@0: * These functions are provided here for the convenience of the callback sl@0: * writer. If you are just looking for callback functions to use, please sl@0: * see ucnv_err.h. DO NOT call these functions directly when you are sl@0: * working with converters, unless your code has been called as a callback sl@0: * via ucnv_setFromUCallback or ucnv_setToUCallback !! sl@0: * sl@0: * A note about error codes and overflow. Unlike other ICU functions, sl@0: * these functions do not expect the error status to be U_ZERO_ERROR. sl@0: * Callbacks must be much more careful about their error codes. sl@0: * The error codes used here are in/out parameters, which should be passed sl@0: * back in the callback's error parameter. sl@0: * sl@0: * For example, if you call ucnv_cbfromUWriteBytes to write data out sl@0: * to the output codepage, it may return U_BUFFER_OVERFLOW_ERROR if sl@0: * the data did not fit in the target. But this isn't a failing error, sl@0: * in fact, ucnv_cbfromUWriteBytes may be called AGAIN with the error sl@0: * status still U_BUFFER_OVERFLOW_ERROR to attempt to write further bytes, sl@0: * which will also go into the internal overflow buffers. sl@0: * sl@0: * Concerning offsets, the 'offset' parameters here are relative to the start sl@0: * of SOURCE. For example, Suppose the string "ABCD" was being converted sl@0: * from Unicode into a codepage which doesn't have a mapping for 'B'. sl@0: * 'A' will be written out correctly, but sl@0: * The FromU Callback will be called on an unassigned character for 'B'. sl@0: * At this point, this is the state of the world: sl@0: * Target: A [..] [points after A] sl@0: * Source: A B [C] D [points to C - B has been consumed] sl@0: * 0 1 2 3 sl@0: * codePoint = "B" [the unassigned codepoint] sl@0: * sl@0: * Now, suppose a callback wants to write the substitution character '?' to sl@0: * the target. It calls ucnv_cbFromUWriteBytes() to write the ?. sl@0: * It should pass ZERO as the offset, because the offset as far as the sl@0: * callback is concerned is relative to the SOURCE pointer [which points sl@0: * before 'C'.] If the callback goes into the args and consumes 'C' also, sl@0: * it would call FromUWriteBytes with an offset of 1 (and advance the source sl@0: * pointer). sl@0: * sl@0: */ sl@0: sl@0: #ifndef UCNV_CB_H sl@0: #define UCNV_CB_H sl@0: sl@0: #include "unicode/utypes.h" sl@0: sl@0: #if !UCONFIG_NO_CONVERSION sl@0: sl@0: #include "unicode/ucnv.h" sl@0: #include "unicode/ucnv_err.h" sl@0: sl@0: /** sl@0: * ONLY used by FromU callback functions. sl@0: * Writes out the specified byte output bytes to the target byte buffer or to converter internal buffers. sl@0: * sl@0: * @param args callback fromUnicode arguments sl@0: * @param source source bytes to write sl@0: * @param length length of bytes to write sl@0: * @param offsetIndex the relative offset index from callback. sl@0: * @param err error status. If U_BUFFER_OVERFLOW is returned, then U_BUFFER_OVERFLOW must sl@0: * be returned to the user, because it means that not all data could be written into the target buffer, and some is sl@0: * in the converter error buffer. sl@0: * @see ucnv_cbFromUWriteSub sl@0: * @stable ICU 2.0 sl@0: */ sl@0: U_STABLE void U_EXPORT2 sl@0: ucnv_cbFromUWriteBytes (UConverterFromUnicodeArgs *args, sl@0: const char* source, sl@0: int32_t length, sl@0: int32_t offsetIndex, sl@0: UErrorCode * err); sl@0: sl@0: /** sl@0: * ONLY used by FromU callback functions. sl@0: * This function will write out the correct substitution character sequence sl@0: * to the target. sl@0: * sl@0: * @param args callback fromUnicode arguments sl@0: * @param offsetIndex the relative offset index from the current source pointer to be used sl@0: * @param err error status. If U_BUFFER_OVERFLOW is returned, then U_BUFFER_OVERFLOW must sl@0: * be returned to the user, because it means that not all data could be written into the target buffer, and some is sl@0: * in the converter error buffer. sl@0: * @see ucnv_cbFromUWriteBytes sl@0: * @stable ICU 2.0 sl@0: */ sl@0: U_STABLE void U_EXPORT2 sl@0: ucnv_cbFromUWriteSub (UConverterFromUnicodeArgs *args, sl@0: int32_t offsetIndex, sl@0: UErrorCode * err); sl@0: sl@0: /** sl@0: * ONLY used by fromU callback functions. sl@0: * This function will write out the error character(s) to the target UChar buffer. sl@0: * sl@0: * @param args callback fromUnicode arguments sl@0: * @param source pointer to pointer to first UChar to write [on exit: 1 after last UChar processed] sl@0: * @param sourceLimit pointer after last UChar to write sl@0: * @param offsetIndex the relative offset index from callback which will be set sl@0: * @param err error status U_BUFFER_OVERFLOW sl@0: * @see ucnv_cbToUWriteSub sl@0: * @stable ICU 2.0 sl@0: */ sl@0: U_STABLE void U_EXPORT2 ucnv_cbFromUWriteUChars(UConverterFromUnicodeArgs *args, sl@0: const UChar** source, sl@0: const UChar* sourceLimit, sl@0: int32_t offsetIndex, sl@0: UErrorCode * err); sl@0: sl@0: /** sl@0: * ONLY used by ToU callback functions. sl@0: * This function will write out the specified characters to the target sl@0: * UChar buffer. sl@0: * sl@0: * @param args callback toUnicode arguments sl@0: * @param source source string to write sl@0: * @param length the length of source string sl@0: * @param offsetIndex the relative offset index which will be written. sl@0: * @param err error status U_BUFFER_OVERFLOW sl@0: * @see ucnv_cbToUWriteSub sl@0: * @stable ICU 2.0 sl@0: */ sl@0: U_STABLE void U_EXPORT2 ucnv_cbToUWriteUChars (UConverterToUnicodeArgs *args, sl@0: const UChar* source, sl@0: int32_t length, sl@0: int32_t offsetIndex, sl@0: UErrorCode * err); sl@0: sl@0: /** sl@0: * ONLY used by ToU callback functions. sl@0: * This function will write out the Unicode substitution character (U+FFFD). sl@0: * sl@0: * @param args callback fromUnicode arguments sl@0: * @param offsetIndex the relative offset index from callback. sl@0: * @param err error status U_BUFFER_OVERFLOW sl@0: * @see ucnv_cbToUWriteUChars sl@0: * @stable ICU 2.0 sl@0: */ sl@0: U_STABLE void U_EXPORT2 ucnv_cbToUWriteSub (UConverterToUnicodeArgs *args, sl@0: int32_t offsetIndex, sl@0: UErrorCode * err); sl@0: #endif sl@0: sl@0: #endif