1*0e209d39SAndroid Build Coastguard Worker // © 2016 and later: Unicode, Inc. and others. 2*0e209d39SAndroid Build Coastguard Worker // License & terms of use: http://www.unicode.org/copyright.html 3*0e209d39SAndroid Build Coastguard Worker /* 4*0e209d39SAndroid Build Coastguard Worker ********************************************************************** 5*0e209d39SAndroid Build Coastguard Worker * Copyright (C) 2000-2004, International Business Machines 6*0e209d39SAndroid Build Coastguard Worker * Corporation and others. All Rights Reserved. 7*0e209d39SAndroid Build Coastguard Worker ********************************************************************** 8*0e209d39SAndroid Build Coastguard Worker * ucnv_cb.h: 9*0e209d39SAndroid Build Coastguard Worker * External APIs for the ICU's codeset conversion library 10*0e209d39SAndroid Build Coastguard Worker * Helena Shih 11*0e209d39SAndroid Build Coastguard Worker * 12*0e209d39SAndroid Build Coastguard Worker * Modification History: 13*0e209d39SAndroid Build Coastguard Worker * 14*0e209d39SAndroid Build Coastguard Worker * Date Name Description 15*0e209d39SAndroid Build Coastguard Worker */ 16*0e209d39SAndroid Build Coastguard Worker 17*0e209d39SAndroid Build Coastguard Worker /** 18*0e209d39SAndroid Build Coastguard Worker * \file 19*0e209d39SAndroid Build Coastguard Worker * \brief C API: UConverter functions to aid the writers of callbacks 20*0e209d39SAndroid Build Coastguard Worker * 21*0e209d39SAndroid Build Coastguard Worker * <h2> Callback API for UConverter </h2> 22*0e209d39SAndroid Build Coastguard Worker * 23*0e209d39SAndroid Build Coastguard Worker * These functions are provided here for the convenience of the callback 24*0e209d39SAndroid Build Coastguard Worker * writer. If you are just looking for callback functions to use, please 25*0e209d39SAndroid Build Coastguard Worker * see ucnv_err.h. DO NOT call these functions directly when you are 26*0e209d39SAndroid Build Coastguard Worker * working with converters, unless your code has been called as a callback 27*0e209d39SAndroid Build Coastguard Worker * via ucnv_setFromUCallback or ucnv_setToUCallback !! 28*0e209d39SAndroid Build Coastguard Worker * 29*0e209d39SAndroid Build Coastguard Worker * A note about error codes and overflow. Unlike other ICU functions, 30*0e209d39SAndroid Build Coastguard Worker * these functions do not expect the error status to be U_ZERO_ERROR. 31*0e209d39SAndroid Build Coastguard Worker * Callbacks must be much more careful about their error codes. 32*0e209d39SAndroid Build Coastguard Worker * The error codes used here are in/out parameters, which should be passed 33*0e209d39SAndroid Build Coastguard Worker * back in the callback's error parameter. 34*0e209d39SAndroid Build Coastguard Worker * 35*0e209d39SAndroid Build Coastguard Worker * For example, if you call ucnv_cbfromUWriteBytes to write data out 36*0e209d39SAndroid Build Coastguard Worker * to the output codepage, it may return U_BUFFER_OVERFLOW_ERROR if 37*0e209d39SAndroid Build Coastguard Worker * the data did not fit in the target. But this isn't a failing error, 38*0e209d39SAndroid Build Coastguard Worker * in fact, ucnv_cbfromUWriteBytes may be called AGAIN with the error 39*0e209d39SAndroid Build Coastguard Worker * status still U_BUFFER_OVERFLOW_ERROR to attempt to write further bytes, 40*0e209d39SAndroid Build Coastguard Worker * which will also go into the internal overflow buffers. 41*0e209d39SAndroid Build Coastguard Worker * 42*0e209d39SAndroid Build Coastguard Worker * Concerning offsets, the 'offset' parameters here are relative to the start 43*0e209d39SAndroid Build Coastguard Worker * of SOURCE. For example, Suppose the string "ABCD" was being converted 44*0e209d39SAndroid Build Coastguard Worker * from Unicode into a codepage which doesn't have a mapping for 'B'. 45*0e209d39SAndroid Build Coastguard Worker * 'A' will be written out correctly, but 46*0e209d39SAndroid Build Coastguard Worker * The FromU Callback will be called on an unassigned character for 'B'. 47*0e209d39SAndroid Build Coastguard Worker * At this point, this is the state of the world: 48*0e209d39SAndroid Build Coastguard Worker * Target: A [..] [points after A] 49*0e209d39SAndroid Build Coastguard Worker * Source: A B [C] D [points to C - B has been consumed] 50*0e209d39SAndroid Build Coastguard Worker * 0 1 2 3 51*0e209d39SAndroid Build Coastguard Worker * codePoint = "B" [the unassigned codepoint] 52*0e209d39SAndroid Build Coastguard Worker * 53*0e209d39SAndroid Build Coastguard Worker * Now, suppose a callback wants to write the substitution character '?' to 54*0e209d39SAndroid Build Coastguard Worker * the target. It calls ucnv_cbFromUWriteBytes() to write the ?. 55*0e209d39SAndroid Build Coastguard Worker * It should pass ZERO as the offset, because the offset as far as the 56*0e209d39SAndroid Build Coastguard Worker * callback is concerned is relative to the SOURCE pointer [which points 57*0e209d39SAndroid Build Coastguard Worker * before 'C'.] If the callback goes into the args and consumes 'C' also, 58*0e209d39SAndroid Build Coastguard Worker * it would call FromUWriteBytes with an offset of 1 (and advance the source 59*0e209d39SAndroid Build Coastguard Worker * pointer). 60*0e209d39SAndroid Build Coastguard Worker * 61*0e209d39SAndroid Build Coastguard Worker */ 62*0e209d39SAndroid Build Coastguard Worker 63*0e209d39SAndroid Build Coastguard Worker #ifndef UCNV_CB_H 64*0e209d39SAndroid Build Coastguard Worker #define UCNV_CB_H 65*0e209d39SAndroid Build Coastguard Worker 66*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h" 67*0e209d39SAndroid Build Coastguard Worker 68*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_CONVERSION 69*0e209d39SAndroid Build Coastguard Worker 70*0e209d39SAndroid Build Coastguard Worker #include "unicode/ucnv.h" 71*0e209d39SAndroid Build Coastguard Worker #include "unicode/ucnv_err.h" 72*0e209d39SAndroid Build Coastguard Worker 73*0e209d39SAndroid Build Coastguard Worker /** 74*0e209d39SAndroid Build Coastguard Worker * ONLY used by FromU callback functions. 75*0e209d39SAndroid Build Coastguard Worker * Writes out the specified byte output bytes to the target byte buffer or to converter internal buffers. 76*0e209d39SAndroid Build Coastguard Worker * 77*0e209d39SAndroid Build Coastguard Worker * @param args callback fromUnicode arguments 78*0e209d39SAndroid Build Coastguard Worker * @param source source bytes to write 79*0e209d39SAndroid Build Coastguard Worker * @param length length of bytes to write 80*0e209d39SAndroid Build Coastguard Worker * @param offsetIndex the relative offset index from callback. 81*0e209d39SAndroid Build Coastguard Worker * @param err error status. If <TT>U_BUFFER_OVERFLOW</TT> is returned, then U_BUFFER_OVERFLOW <STRONG>must</STRONG> 82*0e209d39SAndroid Build Coastguard Worker * be returned to the user, because it means that not all data could be written into the target buffer, and some is 83*0e209d39SAndroid Build Coastguard Worker * in the converter error buffer. 84*0e209d39SAndroid Build Coastguard Worker * @see ucnv_cbFromUWriteSub 85*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0 86*0e209d39SAndroid Build Coastguard Worker */ 87*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2 88*0e209d39SAndroid Build Coastguard Worker ucnv_cbFromUWriteBytes (UConverterFromUnicodeArgs *args, 89*0e209d39SAndroid Build Coastguard Worker const char* source, 90*0e209d39SAndroid Build Coastguard Worker int32_t length, 91*0e209d39SAndroid Build Coastguard Worker int32_t offsetIndex, 92*0e209d39SAndroid Build Coastguard Worker UErrorCode * err); 93*0e209d39SAndroid Build Coastguard Worker 94*0e209d39SAndroid Build Coastguard Worker /** 95*0e209d39SAndroid Build Coastguard Worker * ONLY used by FromU callback functions. 96*0e209d39SAndroid Build Coastguard Worker * This function will write out the correct substitution character sequence 97*0e209d39SAndroid Build Coastguard Worker * to the target. 98*0e209d39SAndroid Build Coastguard Worker * 99*0e209d39SAndroid Build Coastguard Worker * @param args callback fromUnicode arguments 100*0e209d39SAndroid Build Coastguard Worker * @param offsetIndex the relative offset index from the current source pointer to be used 101*0e209d39SAndroid Build Coastguard Worker * @param err error status. If <TT>U_BUFFER_OVERFLOW</TT> is returned, then U_BUFFER_OVERFLOW <STRONG>must</STRONG> 102*0e209d39SAndroid Build Coastguard Worker * be returned to the user, because it means that not all data could be written into the target buffer, and some is 103*0e209d39SAndroid Build Coastguard Worker * in the converter error buffer. 104*0e209d39SAndroid Build Coastguard Worker * @see ucnv_cbFromUWriteBytes 105*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0 106*0e209d39SAndroid Build Coastguard Worker */ 107*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2 108*0e209d39SAndroid Build Coastguard Worker ucnv_cbFromUWriteSub (UConverterFromUnicodeArgs *args, 109*0e209d39SAndroid Build Coastguard Worker int32_t offsetIndex, 110*0e209d39SAndroid Build Coastguard Worker UErrorCode * err); 111*0e209d39SAndroid Build Coastguard Worker 112*0e209d39SAndroid Build Coastguard Worker /** 113*0e209d39SAndroid Build Coastguard Worker * ONLY used by fromU callback functions. 114*0e209d39SAndroid Build Coastguard Worker * This function will write out the error character(s) to the target UChar buffer. 115*0e209d39SAndroid Build Coastguard Worker * 116*0e209d39SAndroid Build Coastguard Worker * @param args callback fromUnicode arguments 117*0e209d39SAndroid Build Coastguard Worker * @param source pointer to pointer to first UChar to write [on exit: 1 after last UChar processed] 118*0e209d39SAndroid Build Coastguard Worker * @param sourceLimit pointer after last UChar to write 119*0e209d39SAndroid Build Coastguard Worker * @param offsetIndex the relative offset index from callback which will be set 120*0e209d39SAndroid Build Coastguard Worker * @param err error status <TT>U_BUFFER_OVERFLOW</TT> 121*0e209d39SAndroid Build Coastguard Worker * @see ucnv_cbToUWriteSub 122*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0 123*0e209d39SAndroid Build Coastguard Worker */ 124*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2 ucnv_cbFromUWriteUChars(UConverterFromUnicodeArgs *args, 125*0e209d39SAndroid Build Coastguard Worker const UChar** source, 126*0e209d39SAndroid Build Coastguard Worker const UChar* sourceLimit, 127*0e209d39SAndroid Build Coastguard Worker int32_t offsetIndex, 128*0e209d39SAndroid Build Coastguard Worker UErrorCode * err); 129*0e209d39SAndroid Build Coastguard Worker 130*0e209d39SAndroid Build Coastguard Worker /** 131*0e209d39SAndroid Build Coastguard Worker * ONLY used by ToU callback functions. 132*0e209d39SAndroid Build Coastguard Worker * This function will write out the specified characters to the target 133*0e209d39SAndroid Build Coastguard Worker * UChar buffer. 134*0e209d39SAndroid Build Coastguard Worker * 135*0e209d39SAndroid Build Coastguard Worker * @param args callback toUnicode arguments 136*0e209d39SAndroid Build Coastguard Worker * @param source source string to write 137*0e209d39SAndroid Build Coastguard Worker * @param length the length of source string 138*0e209d39SAndroid Build Coastguard Worker * @param offsetIndex the relative offset index which will be written. 139*0e209d39SAndroid Build Coastguard Worker * @param err error status <TT>U_BUFFER_OVERFLOW</TT> 140*0e209d39SAndroid Build Coastguard Worker * @see ucnv_cbToUWriteSub 141*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0 142*0e209d39SAndroid Build Coastguard Worker */ 143*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2 ucnv_cbToUWriteUChars (UConverterToUnicodeArgs *args, 144*0e209d39SAndroid Build Coastguard Worker const UChar* source, 145*0e209d39SAndroid Build Coastguard Worker int32_t length, 146*0e209d39SAndroid Build Coastguard Worker int32_t offsetIndex, 147*0e209d39SAndroid Build Coastguard Worker UErrorCode * err); 148*0e209d39SAndroid Build Coastguard Worker 149*0e209d39SAndroid Build Coastguard Worker /** 150*0e209d39SAndroid Build Coastguard Worker * ONLY used by ToU callback functions. 151*0e209d39SAndroid Build Coastguard Worker * This function will write out the Unicode substitution character (U+FFFD). 152*0e209d39SAndroid Build Coastguard Worker * 153*0e209d39SAndroid Build Coastguard Worker * @param args callback fromUnicode arguments 154*0e209d39SAndroid Build Coastguard Worker * @param offsetIndex the relative offset index from callback. 155*0e209d39SAndroid Build Coastguard Worker * @param err error status <TT>U_BUFFER_OVERFLOW</TT> 156*0e209d39SAndroid Build Coastguard Worker * @see ucnv_cbToUWriteUChars 157*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0 158*0e209d39SAndroid Build Coastguard Worker */ 159*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2 ucnv_cbToUWriteSub (UConverterToUnicodeArgs *args, 160*0e209d39SAndroid Build Coastguard Worker int32_t offsetIndex, 161*0e209d39SAndroid Build Coastguard Worker UErrorCode * err); 162*0e209d39SAndroid Build Coastguard Worker #endif 163*0e209d39SAndroid Build Coastguard Worker 164*0e209d39SAndroid Build Coastguard Worker #endif 165