]> git.saurik.com Git - apple/icu.git/blob - icuSources/common/unicode/ucnv_cb.h
ICU-3.13.tar.gz
[apple/icu.git] / icuSources / common / unicode / ucnv_cb.h
1 /*
2 **********************************************************************
3 * Copyright (C) 2000-2001, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
6 * ucnv_cb.h:
7 * External APIs for the ICU's codeset conversion library
8 * Helena Shih
9 *
10 * Modification History:
11 *
12 * Date Name Description
13 */
14
15 /**
16 * \file
17 * \brief C UConverter functions to aid the writers of callbacks
18 *
19 * <h2> Callback API for UConverter </h2>
20 *
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 !!
26 *
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.
32 *
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.
39 *
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]
48 * 0 1 2 3
49 * codePoint = "B" [the unassigned codepoint]
50 *
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
57 * pointer).
58 *
59 */
60
61 #ifndef UCNV_CB_H
62 #define UCNV_CB_H
63
64 #include "unicode/utypes.h"
65 #include "unicode/ucnv.h"
66 #include "unicode/ucnv_err.h"
67
68 /**
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.
71 *
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
80 * @stable ICU 2.0
81 */
82 U_CAPI void U_EXPORT2
83 ucnv_cbFromUWriteBytes (UConverterFromUnicodeArgs *args,
84 const char* source,
85 int32_t length,
86 int32_t offsetIndex,
87 UErrorCode * err);
88
89 /**
90 * ONLY used by FromU callback functions.
91 * This function will write out the correct substitution character sequence
92 * to the target.
93 *
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
100 * @stable ICU 2.0
101 */
102 U_CAPI void U_EXPORT2
103 ucnv_cbFromUWriteSub (UConverterFromUnicodeArgs *args,
104 int32_t offsetIndex,
105 UErrorCode * err);
106
107 /**
108 * ONLY used by fromU callback functions.
109 * This function will write out the error character(s) to the target UChar buffer.
110 *
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
117 * @stable ICU 2.0
118 */
119 U_CAPI void U_EXPORT2 ucnv_cbFromUWriteUChars(UConverterFromUnicodeArgs *args,
120 const UChar** source,
121 const UChar* sourceLimit,
122 int32_t offsetIndex,
123 UErrorCode * err);
124
125 /**
126 * ONLY used by ToU callback functions.
127 * This function will write out the specified characters to the target
128 * UChar buffer.
129 *
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
136 * @stable ICU 2.0
137 */
138 U_CAPI void U_EXPORT2 ucnv_cbToUWriteUChars (UConverterToUnicodeArgs *args,
139 const UChar* source,
140 int32_t length,
141 int32_t offsetIndex,
142 UErrorCode * err);
143
144 /**
145 * ONLY used by ToU callback functions.
146 * This function will write out the Unicode substitution character (U+FFFD).
147 *
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
152 * @stable ICU 2.0
153 */
154 U_CAPI void U_EXPORT2 ucnv_cbToUWriteSub (UConverterToUnicodeArgs *args,
155 int32_t offsetIndex,
156 UErrorCode * err);
157 #endif