]>
Commit | Line | Data |
---|---|---|
1 | // © 2016 and later: Unicode, Inc. and others. | |
2 | // License & terms of use: http://www.unicode.org/copyright.html | |
3 | /* | |
4 | ******************************************************************************* | |
5 | * | |
6 | * Copyright (C) 1999-2003, International Business Machines | |
7 | * Corporation and others. All Rights Reserved. | |
8 | * | |
9 | ******************************************************************************* | |
10 | * file name: scrptrun.h | |
11 | * | |
12 | * created on: 10/17/2001 | |
13 | * created by: Eric R. Mader | |
14 | */ | |
15 | ||
16 | #ifndef __SCRPTRUN_H | |
17 | #define __SCRPTRUN_H | |
18 | ||
19 | #include "unicode/utypes.h" | |
20 | #include "unicode/uobject.h" | |
21 | #include "unicode/uscript.h" | |
22 | ||
23 | U_NAMESPACE_BEGIN | |
24 | ||
25 | struct ScriptRecord | |
26 | { | |
27 | UChar32 startChar; | |
28 | UChar32 endChar; | |
29 | UScriptCode scriptCode; | |
30 | }; | |
31 | ||
32 | struct ParenStackEntry | |
33 | { | |
34 | int32_t pairIndex; | |
35 | UScriptCode scriptCode; | |
36 | }; | |
37 | ||
38 | class ScriptRun : public UObject { | |
39 | public: | |
40 | ScriptRun(); | |
41 | ||
42 | ScriptRun(const UChar chars[], int32_t length); | |
43 | ||
44 | ScriptRun(const UChar chars[], int32_t start, int32_t length); | |
45 | ||
46 | void reset(); | |
47 | ||
48 | void reset(int32_t start, int32_t count); | |
49 | ||
50 | void reset(const UChar chars[], int32_t start, int32_t length); | |
51 | ||
52 | int32_t getScriptStart(); | |
53 | ||
54 | int32_t getScriptEnd(); | |
55 | ||
56 | UScriptCode getScriptCode(); | |
57 | ||
58 | UBool next(); | |
59 | ||
60 | /** | |
61 | * ICU "poor man's RTTI", returns a UClassID for the actual class. | |
62 | * | |
63 | * @stable ICU 2.2 | |
64 | */ | |
65 | virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); } | |
66 | ||
67 | /** | |
68 | * ICU "poor man's RTTI", returns a UClassID for this class. | |
69 | * | |
70 | * @stable ICU 2.2 | |
71 | */ | |
72 | static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; } | |
73 | ||
74 | private: | |
75 | ||
76 | static UBool sameScript(int32_t scriptOne, int32_t scriptTwo); | |
77 | ||
78 | int32_t charStart; | |
79 | int32_t charLimit; | |
80 | const UChar *charArray; | |
81 | ||
82 | int32_t scriptStart; | |
83 | int32_t scriptEnd; | |
84 | UScriptCode scriptCode; | |
85 | ||
86 | ParenStackEntry parenStack[128]; | |
87 | int32_t parenSP; | |
88 | ||
89 | static int8_t highBit(int32_t value); | |
90 | static int32_t getPairIndex(UChar32 ch); | |
91 | ||
92 | static UChar32 pairedChars[]; | |
93 | static const int32_t pairedCharCount; | |
94 | static const int32_t pairedCharPower; | |
95 | static const int32_t pairedCharExtra; | |
96 | ||
97 | /** | |
98 | * The address of this static class variable serves as this class's ID | |
99 | * for ICU "poor man's RTTI". | |
100 | */ | |
101 | static const char fgClassID; | |
102 | }; | |
103 | ||
104 | inline ScriptRun::ScriptRun() | |
105 | { | |
106 | reset(NULL, 0, 0); | |
107 | } | |
108 | ||
109 | inline ScriptRun::ScriptRun(const UChar chars[], int32_t length) | |
110 | { | |
111 | reset(chars, 0, length); | |
112 | } | |
113 | ||
114 | inline ScriptRun::ScriptRun(const UChar chars[], int32_t start, int32_t length) | |
115 | { | |
116 | reset(chars, start, length); | |
117 | } | |
118 | ||
119 | inline int32_t ScriptRun::getScriptStart() | |
120 | { | |
121 | return scriptStart; | |
122 | } | |
123 | ||
124 | inline int32_t ScriptRun::getScriptEnd() | |
125 | { | |
126 | return scriptEnd; | |
127 | } | |
128 | ||
129 | inline UScriptCode ScriptRun::getScriptCode() | |
130 | { | |
131 | return scriptCode; | |
132 | } | |
133 | ||
134 | inline void ScriptRun::reset() | |
135 | { | |
136 | scriptStart = charStart; | |
137 | scriptEnd = charStart; | |
138 | scriptCode = USCRIPT_INVALID_CODE; | |
139 | parenSP = -1; | |
140 | } | |
141 | ||
142 | inline void ScriptRun::reset(int32_t start, int32_t length) | |
143 | { | |
144 | charStart = start; | |
145 | charLimit = start + length; | |
146 | ||
147 | reset(); | |
148 | } | |
149 | ||
150 | inline void ScriptRun::reset(const UChar chars[], int32_t start, int32_t length) | |
151 | { | |
152 | charArray = chars; | |
153 | ||
154 | reset(start, length); | |
155 | } | |
156 | ||
157 | U_NAMESPACE_END | |
158 | ||
159 | #endif |