annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/include/unicode/ucnv_cb.h @ 69:33d812a61356

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