Imported Upstream version 58.1
[platform/upstream/icu.git] / source / common / usc_impl.h
1 // Copyright (C) 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
18 #ifndef USC_IMPL_H
19 #define USC_IMPL_H
20 #include "unicode/utypes.h"
21 #include "unicode/uscript.h"
22
23 /**
24  * <code>UScriptRun</code> is used to find runs of characters in
25  * the same script. It implements a simple iterator over an array
26  * of characters. The iterator will resolve script-neutral characters
27  * like punctuation into the script of the surrounding characters.
28  *
29  * The iterator will try to match paired punctuation. If it sees an
30  * opening punctuation character, it will remember the script that
31  * was assigned to that character, and assign the same script to the
32  * matching closing punctuation.
33  *
34  * Scripts are chosen based on the <code>UScriptCode</code> enumeration.
35  * No attempt is made to combine related scripts into a single run. In
36  * particular, Hiragana, Katakana, and Han characters will appear in seperate
37  * runs.
38
39  * Here is an example of how to iterate over script runs:
40  * <pre>
41  * \code
42  * void printScriptRuns(const UChar *text, int32_t length)
43  * {
44  *     UErrorCode error = U_ZERO_ERROR;
45  *     UScriptRun *scriptRun = uscript_openRun(text, testLength, &error);
46  *     int32_t start = 0, limit = 0;
47  *     UScriptCode code = USCRIPT_INVALID_CODE;
48  *
49  *     while (uscript_nextRun(&start, &limit, &code)) {
50  *         printf("Script '%s' from %d to %d.\n", uscript_getName(code), start, limit);
51  *     }
52  *
53  *     uscript_closeRun(scriptRun);
54  *  }
55  * </pre>
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 U_CAPI UScriptRun * U_EXPORT2
81 uscript_openRun(const UChar *src, int32_t length, UErrorCode *pErrorCode);
82
83 /**
84  * Frees the given <code>UScriptRun</code> object and any storage associated with it.
85  * On return, scriptRun no longer points to a valid <code>UScriptRun</code> object.
86  *
87  * @param scriptRun is the <code>UScriptRun</code> object which will be freed.
88  */
89 U_CAPI void U_EXPORT2
90 uscript_closeRun(UScriptRun *scriptRun);
91
92 /**
93  * Reset the <code>UScriptRun</code> object so that it will start iterating from
94  * the beginning.
95  *
96  * @param scriptRun is the address of the <code>UScriptRun</code> object to be reset.
97  */
98 U_CAPI void U_EXPORT2
99 uscript_resetRun(UScriptRun *scriptRun);
100
101 /**
102  * Change the text over which the given <code>UScriptRun</code> object iterates.
103  *
104  * @param scriptRun is the <code>UScriptRun</code> object which will be changed.
105  *
106  * @param src is the address of the new array of characters over which to iterate.
107  *        If <code>src == NULL</code> and <code>length == 0</code>,
108  *        the <code>UScriptRun</code> object will become empty.
109  *
110  * @param length is the new number of characters over which to iterate
111  *
112  * @param pErrorCode is a pointer to a valid <code>UErrorCode</code> value. If this value
113  *        indicates a failure on entry, the function will immediately return.
114  *        On exit the value will indicate the success of the operation.
115  */
116 U_CAPI void U_EXPORT2
117 uscript_setRunText(UScriptRun *scriptRun, const UChar *src, int32_t length, UErrorCode *pErrorCode);
118
119 /**
120  * Advance the <code>UScriptRun</code> object to the next script run, return the start and limit
121  * offsets, and the script of the run.
122  *
123  * @param scriptRun is the address of the <code>UScriptRun</code> object.
124  *
125  * @param pRunStart is a pointer to the variable to receive the starting offset of the next run.
126  *        This pointer can be <code>NULL</code> if the value is not needed.
127  *
128  * @param pRunLimit is a pointer to the variable to receive the limit offset of the next run.
129  *        This pointer can be <code>NULL</code> if the value is not needed.
130  *
131  * @param pRunScript is a pointer to the variable to receive the UScriptCode for the
132  *        script of the current run. This pointer can be <code>NULL</code> if the value is not needed.
133  *
134  * @return true if there was another script run.
135  */
136 U_CAPI UBool U_EXPORT2
137 uscript_nextRun(UScriptRun *scriptRun, int32_t *pRunStart, int32_t *pRunLimit, UScriptCode *pRunScript);
138
139 #endif