• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 struct ScriptRecord
24 {
25     UChar32 startChar;
26     UChar32 endChar;
27     UScriptCode scriptCode;
28 };
29 
30 struct ParenStackEntry
31 {
32     int32_t pairIndex;
33     UScriptCode scriptCode;
34 };
35 
36 class ScriptRun : public UObject {
37 public:
38     ScriptRun();
39 
40     ScriptRun(const UChar chars[], int32_t length);
41 
42     ScriptRun(const UChar chars[], int32_t start, int32_t length);
43 
44     void reset();
45 
46     void reset(int32_t start, int32_t count);
47 
48     void reset(const UChar chars[], int32_t start, int32_t length);
49 
50     int32_t getScriptStart();
51 
52     int32_t getScriptEnd();
53 
54     UScriptCode getScriptCode();
55 
56     UBool next();
57 
58     /**
59      * ICU "poor man's RTTI", returns a UClassID for the actual class.
60      *
61      * @stable ICU 2.2
62      */
getDynamicClassID()63     virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); }
64 
65     /**
66      * ICU "poor man's RTTI", returns a UClassID for this class.
67      *
68      * @stable ICU 2.2
69      */
getStaticClassID()70     static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; }
71 
72 private:
73 
74     static UBool sameScript(int32_t scriptOne, int32_t scriptTwo);
75 
76     int32_t charStart;
77     int32_t charLimit;
78     const UChar *charArray;
79 
80     int32_t scriptStart;
81     int32_t scriptEnd;
82     UScriptCode scriptCode;
83 
84     ParenStackEntry parenStack[128];
85     int32_t parenSP;
86 
87     static int8_t highBit(int32_t value);
88     static int32_t getPairIndex(UChar32 ch);
89 
90     static UChar32 pairedChars[];
91     static const int32_t pairedCharCount;
92     static const int32_t pairedCharPower;
93     static const int32_t pairedCharExtra;
94 
95     /**
96      * The address of this static class variable serves as this class's ID
97      * for ICU "poor man's RTTI".
98      */
99     static const char fgClassID;
100 };
101 
ScriptRun()102 inline ScriptRun::ScriptRun()
103 {
104     reset(NULL, 0, 0);
105 }
106 
ScriptRun(const UChar chars[],int32_t length)107 inline ScriptRun::ScriptRun(const UChar chars[], int32_t length)
108 {
109     reset(chars, 0, length);
110 }
111 
ScriptRun(const UChar chars[],int32_t start,int32_t length)112 inline ScriptRun::ScriptRun(const UChar chars[], int32_t start, int32_t length)
113 {
114     reset(chars, start, length);
115 }
116 
getScriptStart()117 inline int32_t ScriptRun::getScriptStart()
118 {
119     return scriptStart;
120 }
121 
getScriptEnd()122 inline int32_t ScriptRun::getScriptEnd()
123 {
124     return scriptEnd;
125 }
126 
getScriptCode()127 inline UScriptCode ScriptRun::getScriptCode()
128 {
129     return scriptCode;
130 }
131 
reset()132 inline void ScriptRun::reset()
133 {
134     scriptStart = charStart;
135     scriptEnd   = charStart;
136     scriptCode  = USCRIPT_INVALID_CODE;
137     parenSP     = -1;
138 }
139 
reset(int32_t start,int32_t length)140 inline void ScriptRun::reset(int32_t start, int32_t length)
141 {
142     charStart = start;
143     charLimit = start + length;
144 
145     reset();
146 }
147 
reset(const UChar chars[],int32_t start,int32_t length)148 inline void ScriptRun::reset(const UChar chars[], int32_t start, int32_t length)
149 {
150     charArray = chars;
151 
152     reset(start, length);
153 }
154 
155 
156 #endif
157