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