2 **********************************************************************
3 * Copyright (C) 2000-2001, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
7 * External APIs for the ICU's codeset conversion library
10 * Modification History:
12 * Date Name Description
17 * \brief C UConverter functions to aid the writers of callbacks
19 * <h2> Callback API for UConverter </h2>
21 * These functions are provided here for the convenience of the callback
22 * writer. If you are just looking for callback functions to use, please
23 * see ucnv_err.h. DO NOT call these functions directly when you are
24 * working with converters, unless your code has been called as a callback
25 * via ucnv_setFromUCallback or ucnv_setToUCallback !!
27 * A note about error codes and overflow. Unlike other ICU functions,
28 * these functions do not expect the error status to be U_ZERO_ERROR.
29 * Callbacks must be much more careful about their error codes.
30 * The error codes used here are in/out parameters, which should be passed
31 * back in the callback's error parameter.
33 * For example, if you call ucnv_cbfromUWriteBytes to write data out
34 * to the output codepage, it may return U_BUFFER_OVERFLOW_ERROR if
35 * the data did not fit in the target. But this isn't a failing error,
36 * in fact, ucnv_cbfromUWriteBytes may be called AGAIN with the error
37 * status still U_BUFFER_OVERFLOW_ERROR to attempt to write further bytes,
38 * which will also go into the internal overflow buffers.
40 * Concerning offsets, the 'offset' parameters here are relative to the start
41 * of SOURCE. For example, Suppose the string "ABCD" was being converted
42 * from Unicode into a codepage which doesn't have a mapping for 'B'.
43 * 'A' will be written out correctly, but
44 * The FromU Callback will be called on an unassigned character for 'B'.
45 * At this point, this is the state of the world:
46 * Target: A [..] [points after A]
47 * Source: A B [C] D [points to C - B has been consumed]
49 * codePoint = "B" [the unassigned codepoint]
51 * Now, suppose a callback wants to write the substitution character '?' to
52 * the target. It calls ucnv_cbFromUWriteBytes() to write the ?.
53 * It should pass ZERO as the offset, because the offset as far as the
54 * callback is concerned is relative to the SOURCE pointer [which points
55 * before 'C'.] If the callback goes into the args and consumes 'C' also,
56 * it would call FromUWriteBytes with an offset of 1 (and advance the source
64 #include "unicode/utypes.h"
65 #include "unicode/ucnv.h"
66 #include "unicode/ucnv_err.h"
69 * ONLY used by FromU callback functions.
70 * Writes out the specified byte output bytes to the target byte buffer or to converter internal buffers.
72 * @param args callback fromUnicode arguments
73 * @param source source bytes to write
74 * @param length length of bytes to write
75 * @param offsetIndex the relative offset index from callback.
76 * @param err error status. If <TT>U_BUFFER_OVERFLOW</TT> is returned, then U_BUFFER_OVERFLOW <STRONG>must</STRONG>
77 * be returned to the user, because it means that not all data could be written into the target buffer, and some is
78 * in the converter error buffer.
79 * @see ucnv_cbFromUWriteSub
83 ucnv_cbFromUWriteBytes (UConverterFromUnicodeArgs
*args
,
90 * ONLY used by FromU callback functions.
91 * This function will write out the correct substitution character sequence
94 * @param args callback fromUnicode arguments
95 * @param offsetIndex the relative offset index from the current source pointer to be used
96 * @param err error status. If <TT>U_BUFFER_OVERFLOW</TT> is returned, then U_BUFFER_OVERFLOW <STRONG>must</STRONG>
97 * be returned to the user, because it means that not all data could be written into the target buffer, and some is
98 * in the converter error buffer.
99 * @see ucnv_cbFromUWriteBytes
102 U_CAPI
void U_EXPORT2
103 ucnv_cbFromUWriteSub (UConverterFromUnicodeArgs
*args
,
108 * ONLY used by fromU callback functions.
109 * This function will write out the error character(s) to the target UChar buffer.
111 * @param args callback fromUnicode arguments
112 * @param source pointer to pointer to first UChar to write [on exit: 1 after last UChar processed]
113 * @param sourceLimit pointer after last UChar to write
114 * @param offsetIndex the relative offset index from callback which will be set
115 * @param err error status <TT>U_BUFFER_OVERFLOW</TT>
116 * @see ucnv_cbToUWriteSub
119 U_CAPI
void U_EXPORT2
ucnv_cbFromUWriteUChars(UConverterFromUnicodeArgs
*args
,
120 const UChar
** source
,
121 const UChar
* sourceLimit
,
126 * ONLY used by ToU callback functions.
127 * This function will write out the specified characters to the target
130 * @param args callback toUnicode arguments
131 * @param source source string to write
132 * @param length the length of source string
133 * @param offsetIndex the relative offset index which will be written.
134 * @param err error status <TT>U_BUFFER_OVERFLOW</TT>
135 * @see ucnv_cbToUWriteSub
138 U_CAPI
void U_EXPORT2
ucnv_cbToUWriteUChars (UConverterToUnicodeArgs
*args
,
145 * ONLY used by ToU callback functions.
146 * This function will write out the Unicode substitution character (U+FFFD).
148 * @param args callback fromUnicode arguments
149 * @param offsetIndex the relative offset index from callback.
150 * @param err error status <TT>U_BUFFER_OVERFLOW</TT>
151 * @see ucnv_cbToUWriteUChars
154 U_CAPI
void U_EXPORT2
ucnv_cbToUWriteSub (UConverterToUnicodeArgs
*args
,