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