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