usc_impl.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // © 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. **********************************************************************
  5. * Copyright (C) 1999-2011, International Business Machines
  6. * Corporation and others. All Rights Reserved.
  7. **********************************************************************
  8. *
  9. * File USC_IMPL.H
  10. *
  11. * Modification History:
  12. *
  13. * Date Name Description
  14. * 07/08/2002 Eric Mader Creation.
  15. ******************************************************************************
  16. */
  17. #ifndef USC_IMPL_H
  18. #define USC_IMPL_H
  19. #include "unicode/utypes.h"
  20. #include "unicode/uscript.h"
  21. /**
  22. * <code>UScriptRun</code> is used to find runs of characters in
  23. * the same script. It implements a simple iterator over an array
  24. * of characters. The iterator will resolve script-neutral characters
  25. * like punctuation into the script of the surrounding characters.
  26. *
  27. * The iterator will try to match paired punctuation. If it sees an
  28. * opening punctuation character, it will remember the script that
  29. * was assigned to that character, and assign the same script to the
  30. * matching closing punctuation.
  31. *
  32. * Scripts are chosen based on the <code>UScriptCode</code> enumeration.
  33. * No attempt is made to combine related scripts into a single run. In
  34. * particular, Hiragana, Katakana, and Han characters will appear in separate
  35. * runs.
  36. * Here is an example of how to iterate over script runs:
  37. * <pre>
  38. * \code
  39. * void printScriptRuns(const UChar *text, int32_t length)
  40. * {
  41. * UErrorCode error = U_ZERO_ERROR;
  42. * UScriptRun *scriptRun = uscript_openRun(text, testLength, &error);
  43. * int32_t start = 0, limit = 0;
  44. * UScriptCode code = USCRIPT_INVALID_CODE;
  45. *
  46. * while (uscript_nextRun(&start, &limit, &code)) {
  47. * printf("Script '%s' from %d to %d.\n", uscript_getName(code), start, limit);
  48. * }
  49. *
  50. * uscript_closeRun(scriptRun);
  51. * }
  52. * </pre>
  53. */
  54. struct UScriptRun;
  55. typedef struct UScriptRun UScriptRun;
  56. /**
  57. * Create a <code>UScriptRun</code> object for iterating over the given text. This object must
  58. * be freed using <code>uscript_closeRun()</code>. Note that this object does not copy the source text,
  59. * only the pointer to it. You must make sure that the pointer remains valid until you call
  60. * <code>uscript_closeRun()</code> or <code>uscript_setRunText()</code>.
  61. *
  62. * @param src is the address of the array of characters over which to iterate.
  63. * if <code>src == NULL</code> and <code>length == 0</code>,
  64. * an empty <code>UScriptRun</code> object will be returned.
  65. *
  66. * @param length is the number of characters over which to iterate.
  67. *
  68. * @param pErrorCode is a pointer to a valid <code>UErrorCode</code> value. If this value
  69. * indicates a failure on entry, the function will immediately return.
  70. * On exit the value will indicate the success of the operation.
  71. *
  72. * @return the address of <code>UScriptRun</code> object which will iterate over the text,
  73. * or <code>NULL</code> if the operation failed.
  74. */
  75. U_CAPI UScriptRun * U_EXPORT2
  76. uscript_openRun(const UChar *src, int32_t length, UErrorCode *pErrorCode);
  77. /**
  78. * Frees the given <code>UScriptRun</code> object and any storage associated with it.
  79. * On return, scriptRun no longer points to a valid <code>UScriptRun</code> object.
  80. *
  81. * @param scriptRun is the <code>UScriptRun</code> object which will be freed.
  82. */
  83. U_CAPI void U_EXPORT2
  84. uscript_closeRun(UScriptRun *scriptRun);
  85. /**
  86. * Reset the <code>UScriptRun</code> object so that it will start iterating from
  87. * the beginning.
  88. *
  89. * @param scriptRun is the address of the <code>UScriptRun</code> object to be reset.
  90. */
  91. U_CAPI void U_EXPORT2
  92. uscript_resetRun(UScriptRun *scriptRun);
  93. /**
  94. * Change the text over which the given <code>UScriptRun</code> object iterates.
  95. *
  96. * @param scriptRun is the <code>UScriptRun</code> object which will be changed.
  97. *
  98. * @param src is the address of the new array of characters over which to iterate.
  99. * If <code>src == NULL</code> and <code>length == 0</code>,
  100. * the <code>UScriptRun</code> object will become empty.
  101. *
  102. * @param length is the new number of characters over which to iterate
  103. *
  104. * @param pErrorCode is a pointer to a valid <code>UErrorCode</code> value. If this value
  105. * indicates a failure on entry, the function will immediately return.
  106. * On exit the value will indicate the success of the operation.
  107. */
  108. U_CAPI void U_EXPORT2
  109. uscript_setRunText(UScriptRun *scriptRun, const UChar *src, int32_t length, UErrorCode *pErrorCode);
  110. /**
  111. * Advance the <code>UScriptRun</code> object to the next script run, return the start and limit
  112. * offsets, and the script of the run.
  113. *
  114. * @param scriptRun is the address of the <code>UScriptRun</code> object.
  115. *
  116. * @param pRunStart is a pointer to the variable to receive the starting offset of the next run.
  117. * This pointer can be <code>NULL</code> if the value is not needed.
  118. *
  119. * @param pRunLimit is a pointer to the variable to receive the limit offset of the next run.
  120. * This pointer can be <code>NULL</code> if the value is not needed.
  121. *
  122. * @param pRunScript is a pointer to the variable to receive the UScriptCode for the
  123. * script of the current run. This pointer can be <code>NULL</code> if the value is not needed.
  124. *
  125. * @return true if there was another script run.
  126. */
  127. U_CAPI UBool U_EXPORT2
  128. uscript_nextRun(UScriptRun *scriptRun, int32_t *pRunStart, int32_t *pRunLimit, UScriptCode *pRunScript);
  129. #endif