urep.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. // © 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. ******************************************************************************
  5. * Copyright (C) 1997-2010, International Business Machines
  6. * Corporation and others. All Rights Reserved.
  7. ******************************************************************************
  8. * Date Name Description
  9. * 06/23/00 aliu Creation.
  10. ******************************************************************************
  11. */
  12. #ifndef __UREP_H
  13. #define __UREP_H
  14. #include "unicode/utypes.h"
  15. U_CDECL_BEGIN
  16. /********************************************************************
  17. * General Notes
  18. ********************************************************************
  19. * TODO
  20. * Add usage scenario
  21. * Add test code
  22. * Talk about pinning
  23. * Talk about "can truncate result if out of memory"
  24. */
  25. /********************************************************************
  26. * Data Structures
  27. ********************************************************************/
  28. /**
  29. * \file
  30. * \brief C API: Callbacks for UReplaceable
  31. */
  32. /**
  33. * An opaque replaceable text object. This will be manipulated only
  34. * through the caller-supplied UReplaceableFunctor struct. Related
  35. * to the C++ class Replaceable.
  36. * This is currently only used in the Transliterator C API, see utrans.h .
  37. * @stable ICU 2.0
  38. */
  39. typedef void* UReplaceable;
  40. /**
  41. * A set of function pointers that transliterators use to manipulate a
  42. * UReplaceable. The caller should supply the required functions to
  43. * manipulate their text appropriately. Related to the C++ class
  44. * Replaceable.
  45. * @stable ICU 2.0
  46. */
  47. typedef struct UReplaceableCallbacks {
  48. /**
  49. * Function pointer that returns the number of UChar code units in
  50. * this text.
  51. *
  52. * @param rep A pointer to "this" UReplaceable object.
  53. * @return The length of the text.
  54. * @stable ICU 2.0
  55. */
  56. int32_t (*length)(const UReplaceable* rep);
  57. /**
  58. * Function pointer that returns a UChar code units at the given
  59. * offset into this text; 0 <= offset < n, where n is the value
  60. * returned by (*length)(rep). See unistr.h for a description of
  61. * charAt() vs. char32At().
  62. *
  63. * @param rep A pointer to "this" UReplaceable object.
  64. * @param offset The index at which to fetch the UChar (code unit).
  65. * @return The UChar (code unit) at offset, or U+FFFF if the offset is out of bounds.
  66. * @stable ICU 2.0
  67. */
  68. UChar (*charAt)(const UReplaceable* rep,
  69. int32_t offset);
  70. /**
  71. * Function pointer that returns a UChar32 code point at the given
  72. * offset into this text. See unistr.h for a description of
  73. * charAt() vs. char32At().
  74. *
  75. * @param rep A pointer to "this" UReplaceable object.
  76. * @param offset The index at which to fetch the UChar32 (code point).
  77. * @return The UChar32 (code point) at offset, or U+FFFF if the offset is out of bounds.
  78. * @stable ICU 2.0
  79. */
  80. UChar32 (*char32At)(const UReplaceable* rep,
  81. int32_t offset);
  82. /**
  83. * Function pointer that replaces text between start and limit in
  84. * this text with the given text. Attributes (out of band info)
  85. * should be retained.
  86. *
  87. * @param rep A pointer to "this" UReplaceable object.
  88. * @param start the starting index of the text to be replaced,
  89. * inclusive.
  90. * @param limit the ending index of the text to be replaced,
  91. * exclusive.
  92. * @param text the new text to replace the UChars from
  93. * start..limit-1.
  94. * @param textLength the number of UChars at text, or -1 if text
  95. * is null-terminated.
  96. * @stable ICU 2.0
  97. */
  98. void (*replace)(UReplaceable* rep,
  99. int32_t start,
  100. int32_t limit,
  101. const UChar* text,
  102. int32_t textLength);
  103. /**
  104. * Function pointer that copies the characters in the range
  105. * [<tt>start</tt>, <tt>limit</tt>) into the array <tt>dst</tt>.
  106. *
  107. * @param rep A pointer to "this" UReplaceable object.
  108. * @param start offset of first character which will be copied
  109. * into the array
  110. * @param limit offset immediately following the last character to
  111. * be copied
  112. * @param dst array in which to copy characters. The length of
  113. * <tt>dst</tt> must be at least <tt>(limit - start)</tt>.
  114. * @stable ICU 2.1
  115. */
  116. void (*extract)(UReplaceable* rep,
  117. int32_t start,
  118. int32_t limit,
  119. UChar* dst);
  120. /**
  121. * Function pointer that copies text between start and limit in
  122. * this text to another index in the text. Attributes (out of
  123. * band info) should be retained. After this call, there will be
  124. * (at least) two copies of the characters originally located at
  125. * start..limit-1.
  126. *
  127. * @param rep A pointer to "this" UReplaceable object.
  128. * @param start the starting index of the text to be copied,
  129. * inclusive.
  130. * @param limit the ending index of the text to be copied,
  131. * exclusive.
  132. * @param dest the index at which the copy of the UChars should be
  133. * inserted.
  134. * @stable ICU 2.0
  135. */
  136. void (*copy)(UReplaceable* rep,
  137. int32_t start,
  138. int32_t limit,
  139. int32_t dest);
  140. } UReplaceableCallbacks;
  141. U_CDECL_END
  142. #endif