ucnv_cb.h 6.5 KB

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