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