]>
git.saurik.com Git - apple/icu.git/blob - icuSources/common/usc_impl.h
2 **********************************************************************
3 * Copyright (C) 1999-2011, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
9 * Modification History:
11 * Date Name Description
12 * 07/08/2002 Eric Mader Creation.
13 ******************************************************************************
18 #include "unicode/utypes.h"
19 #include "unicode/uscript.h"
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.
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.
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
37 * Here is an example of how to iterate over script runs:
40 * void printScriptRuns(const UChar *text, int32_t length)
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;
47 * while (uscript_nextRun(&start, &limit, &code)) {
48 * printf("Script '%s' from %d to %d.\n", uscript_getName(code), start, limit);
51 * uscript_closeRun(scriptRun);
57 typedef struct UScriptRun UScriptRun
;
60 * Create a <code>UScriptRun</code> object for iterating over the given text. This object must
61 * be freed using <code>uscript_closeRun()</code>. Note that this object does not copy the source text,
62 * only the pointer to it. You must make sure that the pointer remains valid until you call
63 * <code>uscript_closeRun()</code> or <code>uscript_setRunText()</code>.
65 * @param src is the address of the array of characters over which to iterate.
66 * if <code>src == NULL</code> and <code>length == 0</code>,
67 * an empty <code>UScriptRun</code> object will be returned.
69 * @param length is the number of characters over which to iterate.
71 * @param pErrorCode is a pointer to a valid <code>UErrorCode</code> value. If this value
72 * indicates a failure on entry, the function will immediately return.
73 * On exit the value will indicate the success of the operation.
75 * @return the address of <code>UScriptRun</code> object which will iterate over the text,
76 * or <code>NULL</code> if the operation failed.
78 U_CAPI UScriptRun
* U_EXPORT2
79 uscript_openRun(const UChar
*src
, int32_t length
, UErrorCode
*pErrorCode
);
82 * Frees the given <code>UScriptRun</code> object and any storage associated with it.
83 * On return, scriptRun no longer points to a valid <code>UScriptRun</code> object.
85 * @param scriptRun is the <code>UScriptRun</code> object which will be freed.
88 uscript_closeRun(UScriptRun
*scriptRun
);
91 * Reset the <code>UScriptRun</code> object so that it will start iterating from
94 * @param scriptRun is the address of the <code>UScriptRun</code> object to be reset.
97 uscript_resetRun(UScriptRun
*scriptRun
);
100 * Change the text over which the given <code>UScriptRun</code> object iterates.
102 * @param scriptRun is the <code>UScriptRun</code> object which will be changed.
104 * @param src is the address of the new array of characters over which to iterate.
105 * If <code>src == NULL</code> and <code>length == 0</code>,
106 * the <code>UScriptRun</code> object will become empty.
108 * @param length is the new number of characters over which to iterate
110 * @param pErrorCode is a pointer to a valid <code>UErrorCode</code> value. If this value
111 * indicates a failure on entry, the function will immediately return.
112 * On exit the value will indicate the success of the operation.
114 U_CAPI
void U_EXPORT2
115 uscript_setRunText(UScriptRun
*scriptRun
, const UChar
*src
, int32_t length
, UErrorCode
*pErrorCode
);
118 * Advance the <code>UScriptRun</code> object to the next script run, return the start and limit
119 * offsets, and the script of the run.
121 * @param scriptRun is the address of the <code>UScriptRun</code> object.
123 * @param pRunStart is a pointer to the variable to receive the starting offset of the next run.
124 * This pointer can be <code>NULL</code> if the value is not needed.
126 * @param pRunLimit is a pointer to the variable to receive the limit offset of the next run.
127 * This pointer can be <code>NULL</code> if the value is not needed.
129 * @param pRunScript is a pointer to the variable to receive the UScriptCode for the
130 * script of the current run. This pointer can be <code>NULL</code> if the value is not needed.
132 * @return true if there was another script run.
134 U_CAPI UBool U_EXPORT2
135 uscript_nextRun(UScriptRun
*scriptRun
, int32_t *pRunStart
, int32_t *pRunLimit
, UScriptCode
*pRunScript
);