jpayne@69: // © 2016 and later: Unicode, Inc. and others. jpayne@69: // License & terms of use: http://www.unicode.org/copyright.html jpayne@69: /* jpayne@69: ********************************************************************** jpayne@69: * Copyright (C) 2000-2004, International Business Machines jpayne@69: * Corporation and others. All Rights Reserved. jpayne@69: ********************************************************************** jpayne@69: * ucnv_cb.h: jpayne@69: * External APIs for the ICU's codeset conversion library jpayne@69: * Helena Shih jpayne@69: * jpayne@69: * Modification History: jpayne@69: * jpayne@69: * Date Name Description jpayne@69: */ jpayne@69: jpayne@69: /** jpayne@69: * \file jpayne@69: * \brief C UConverter functions to aid the writers of callbacks jpayne@69: * jpayne@69: *

Callback API for UConverter

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