Line data Source code
1 : /*
2 : *******************************************************************************
3 : *
4 : * Copyright (c) 1995-2013 International Business Machines Corporation and others
5 : *
6 : * All rights reserved.
7 : *
8 : * Permission is hereby granted, free of charge, to any person obtaining a copy of
9 : * this software and associated documentation files (the "Software"), to deal in
10 : * the Software without restriction, including without limitation the rights to
11 : * use, copy, modify, merge, publish, distribute, and/or sell copies of the
12 : * Software, and to permit persons to whom the Software is furnished to do so,
13 : * provided that the above copyright notice(s) and this permission notice appear
14 : * in all copies of the Software and that both the above copyright notice(s) and
15 : * this permission notice appear in supporting documentation.
16 : *
17 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 : * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN
20 : * NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE BE
21 : * LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY
22 : * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
23 : * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
24 : * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 : *
26 : * Except as contained in this notice, the name of a copyright holder shall not be
27 : * used in advertising or otherwise to promote the sale, use or other dealings in
28 : * this Software without prior written authorization of the copyright holder.
29 : *
30 : *******************************************************************************
31 : * file name: scrptrun.h
32 : *
33 : * created on: 10/17/2001
34 : * created by: Eric R. Mader
35 : */
36 :
37 : #ifndef __SCRPTRUN_H
38 : #define __SCRPTRUN_H
39 :
40 : #include <sal/config.h>
41 :
42 : #include <sal/types.h>
43 : #include "unicode/utypes.h"
44 : #include "unicode/uobject.h"
45 : #include "unicode/uscript.h"
46 :
47 : struct ScriptRecord
48 : {
49 : UChar32 startChar;
50 : UChar32 endChar;
51 : UScriptCode scriptCode;
52 : };
53 :
54 : struct ParenStackEntry
55 : {
56 : int32_t pairIndex;
57 : UScriptCode scriptCode;
58 : };
59 :
60 0 : class ScriptRun : public UObject {
61 : public:
62 : ScriptRun();
63 :
64 : ScriptRun(const UChar chars[], int32_t length);
65 :
66 : ScriptRun(const UChar chars[], int32_t start, int32_t length);
67 :
68 : void reset();
69 :
70 : void reset(int32_t start, int32_t count);
71 :
72 : void reset(const UChar chars[], int32_t start, int32_t length);
73 :
74 : int32_t getScriptStart();
75 :
76 : int32_t getScriptEnd();
77 :
78 : UScriptCode getScriptCode();
79 :
80 : UBool next();
81 :
82 : /**
83 : * ICU "poor man's RTTI", returns a UClassID for the actual class.
84 : *
85 : * @stable ICU 2.2
86 : */
87 0 : virtual inline UClassID getDynamicClassID() const SAL_OVERRIDE { return getStaticClassID(); }
88 :
89 : /**
90 : * ICU "poor man's RTTI", returns a UClassID for this class.
91 : *
92 : * @stable ICU 2.2
93 : */
94 0 : static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; }
95 :
96 : private:
97 :
98 : static UBool sameScript(int32_t scriptOne, int32_t scriptTwo);
99 :
100 : int32_t charStart;
101 : int32_t charLimit;
102 : const UChar *charArray;
103 :
104 : int32_t scriptStart;
105 : int32_t scriptEnd;
106 : UScriptCode scriptCode;
107 :
108 : ParenStackEntry parenStack[128];
109 : int32_t parenSP;
110 :
111 : static int8_t highBit(int32_t value);
112 : static int32_t getPairIndex(UChar32 ch);
113 :
114 : static UChar32 pairedChars[];
115 : static const int32_t pairedCharCount;
116 : static const int32_t pairedCharPower;
117 : static const int32_t pairedCharExtra;
118 :
119 : /**
120 : * The address of this static class variable serves as this class's ID
121 : * for ICU "poor man's RTTI".
122 : */
123 : static const char fgClassID;
124 : };
125 :
126 : inline ScriptRun::ScriptRun()
127 : {
128 : reset(NULL, 0, 0);
129 : }
130 :
131 0 : inline ScriptRun::ScriptRun(const UChar chars[], int32_t length)
132 : {
133 0 : reset(chars, 0, length);
134 0 : }
135 :
136 : inline ScriptRun::ScriptRun(const UChar chars[], int32_t start, int32_t length)
137 : {
138 : reset(chars, start, length);
139 : }
140 :
141 0 : inline int32_t ScriptRun::getScriptStart()
142 : {
143 0 : return scriptStart;
144 : }
145 :
146 0 : inline int32_t ScriptRun::getScriptEnd()
147 : {
148 0 : return scriptEnd;
149 : }
150 :
151 0 : inline UScriptCode ScriptRun::getScriptCode()
152 : {
153 0 : return scriptCode;
154 : }
155 :
156 0 : inline void ScriptRun::reset()
157 : {
158 0 : scriptStart = charStart;
159 0 : scriptEnd = charStart;
160 0 : scriptCode = USCRIPT_INVALID_CODE;
161 0 : parenSP = -1;
162 0 : }
163 :
164 0 : inline void ScriptRun::reset(int32_t start, int32_t length)
165 : {
166 0 : charStart = start;
167 0 : charLimit = start + length;
168 :
169 0 : reset();
170 0 : }
171 :
172 0 : inline void ScriptRun::reset(const UChar chars[], int32_t start, int32_t length)
173 : {
174 0 : charArray = chars;
175 :
176 0 : reset(start, length);
177 0 : }
178 :
179 : #endif
|