1 /* 2 ********************************************************************** 3 * Copyright (C) 1999-2002, International Business Machines 4 * Corporation and others. All Rights Reserved. 5 ********************************************************************** 6 * 7 * File USC_IMPL.H 8 * 9 * Modification History: 10 * 11 * Date Name Description 12 * 07/08/2002 Eric Mader Creation. 13 ****************************************************************************** 14 */ 15 16 #ifndef USC_IMPL_H 17 #define USC_IMPL_H 18 #include "unicode/utypes.h" 19 #include "unicode/uscript.h" 20 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 seperate 35 * runs. 36 37 * Here is an example of how to iterate over script runs: 38 * <pre> 39 * \code 40 * void printScriptRuns(const UChar *text, int32_t length) 41 * { 42 * UErrorCode error = U_ZERO_ERROR; 43 * UScriptRun *scriptRun = uscript_openRun(text, testLength, &error); 44 * int32_t start = 0, limit = 0; 45 * UScriptCode code = USCRIPT_INVALID_CODE; 46 * 47 * while (uscript_nextRun(&start, &limit, &code)) { 48 * printf("Script '%s' from %d to %d.\n", uscript_getName(code), start, limit); 49 * } 50 * 51 * uscript_closeRun(scriptRun); 52 * } 53 * </pre> 54 * 55 * @draft ICU 2.2 56 */ 57 struct UScriptRun; 58 59 typedef struct UScriptRun UScriptRun; 60 61 /** 62 * Create a <code>UScriptRun</code> object for iterating over the given text. This object must 63 * be freed using <code>uscript_closeRun()</code>. Note that this object does not copy the source text, 64 * only the pointer to it. You must make sure that the pointer remains valid until you call 65 * <code>uscript_closeRun()</code> or <code>uscript_setRunText()</code>. 66 * 67 * @param src is the address of the array of characters over which to iterate. 68 * if <code>src == NULL</code> and <code>length == 0</code>, 69 * an empty <code>UScriptRun</code> object will be returned. 70 * 71 * @param length is the number of characters over which to iterate. 72 * 73 * @param pErrorCode is a pointer to a valid <code>UErrorCode</code> value. If this value 74 * indicates a failure on entry, the function will immediately return. 75 * On exit the value will indicate the success of the operation. 76 * 77 * @return the address of <code>UScriptRun</code> object which will iterate over the text, 78 * or <code>NULL</code> if the operation failed. 79 * 80 * @draft ICU 2.2 81 */ 82 U_CAPI UScriptRun * U_EXPORT2 83 uscript_openRun(const UChar *src, int32_t length, UErrorCode *pErrorCode); 84 85 /** 86 * Frees the given <code>UScriptRun</code> object and any storage associated with it. 87 * On return, scriptRun no longer points to a valid <code>UScriptRun</code> object. 88 * 89 * @param scriptRun is the <code>UScriptRun</code> object which will be freed. 90 * 91 * @draft ICU 2.2 92 */ 93 U_CAPI void U_EXPORT2 94 uscript_closeRun(UScriptRun *scriptRun); 95 96 /** 97 * Reset the <code>UScriptRun</code> object so that it will start iterating from 98 * the beginning. 99 * 100 * @param scriptRun is the address of the <code>UScriptRun</code> object to be reset. 101 * 102 * @draft ICU 2.2 103 */ 104 U_CAPI void U_EXPORT2 105 uscript_resetRun(UScriptRun *scriptRun); 106 107 /** 108 * Change the text over which the given <code>UScriptRun</code> object iterates. 109 * 110 * @param scriptRun is the <code>UScriptRun</code> object which will be changed. 111 * 112 * @param src is the address of the new array of characters over which to iterate. 113 * If <code>src == NULL</code> and <code>length == 0</code>, 114 * the <code>UScriptRun</code> object will become empty. 115 * 116 * @param length is the new number of characters over which to iterate 117 * 118 * @param pErrorCode is a pointer to a valid <code>UErrorCode</code> value. If this value 119 * indicates a failure on entry, the function will immediately return. 120 * On exit the value will indicate the success of the operation. 121 * 122 * @draft ICU 2.2 123 */ 124 U_CAPI void U_EXPORT2 125 uscript_setRunText(UScriptRun *scriptRun, const UChar *src, int32_t length, UErrorCode *pErrorCode); 126 127 /** 128 * Advance the <code>UScriptRun</code> object to the next script run, return the start and limit 129 * offsets, and the script of the run. 130 * 131 * @param scriptRun is the address of the <code>UScriptRun</code> object. 132 * 133 * @param pRunStart is a pointer to the variable to receive the starting offset of the next run. 134 * This pointer can be <code>NULL</code> if the value is not needed. 135 * 136 * @param pRunLimit is a pointer to the variable to receive the limit offset of the next run. 137 * This pointer can be <code>NULL</code> if the value is not needed. 138 * 139 * @param pRunScript is a pointer to the variable to receive the UScriptCode for the 140 * script of the current run. This pointer can be <code>NULL</code> if the value is not needed. 141 * 142 * @return true if there was another script run. 143 * 144 * @draft ICU 2.2 145 */ 146 U_CAPI UBool U_EXPORT2 147 uscript_nextRun(UScriptRun *scriptRun, int32_t *pRunStart, int32_t *pRunLimit, UScriptCode *pRunScript); 148 149 #endif 150