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

Callback API for UConverter

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