OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef ScriptRunIterator_h | |
6 #define ScriptRunIterator_h | |
7 | |
8 #include "platform/PlatformExport.h" | |
9 #include "wtf/Deque.h" | |
10 #include "wtf/Vector.h" | |
11 #include "wtf/dtoa/utils.h" | |
12 | |
13 #include <unicode/uchar.h> | |
14 #include <unicode/uscript.h> | |
15 | |
16 namespace blink { | |
17 | |
18 class ScriptData; | |
19 | |
20 class PLATFORM_EXPORT ScriptRunIterator { | |
21 public: | |
22 ScriptRunIterator(const UChar* text, size_t length); | |
23 | |
24 // This maintains a reference to data. It must exist for the lifetime of thi s | |
eae
2015/08/28 21:10:24
Wrap at 80 col.
| |
25 // object. Typically data is a singleton that exists for the life of the | |
26 // process. | |
27 ScriptRunIterator(const UChar* text, size_t length, const ScriptData* data); | |
28 | |
29 bool consume(unsigned& limit, UScriptCode& script); | |
30 | |
31 private: | |
32 struct BracketRec { | |
33 UChar32 ch; | |
34 UScriptCode script; | |
35 }; | |
36 void openBracket(UChar32 ch); | |
37 void closeBracket(UChar32 ch); | |
38 bool mergeSets(); | |
39 void fixupStack(UScriptCode resolve_code); | |
40 bool fetch(size_t* pos, UChar32* ch); | |
41 | |
42 UScriptCode resolveCurrentScript() const; | |
43 | |
44 const UChar* m_text; | |
45 const size_t m_length; | |
46 | |
47 Deque<BracketRec> m_brackets; | |
48 size_t m_bracketsFixupDepth; | |
49 static const int kMaxBrackets = 32; | |
eae
2015/08/28 21:10:24
Could you please add a comment explaining why we l
| |
50 | |
51 Vector<UScriptCode> m_currentSet; | |
52 Vector<UScriptCode> m_nextSet; | |
53 Vector<UScriptCode> m_aheadSet; | |
54 | |
55 UChar32 m_aheadCharacter; | |
56 size_t m_aheadPos; | |
57 | |
58 UScriptCode m_commonPreferred; | |
59 | |
60 const ScriptData* m_scriptData; | |
61 | |
62 DISALLOW_COPY_AND_ASSIGN(ScriptRunIterator); | |
63 }; | |
64 | |
65 class PLATFORM_EXPORT ScriptData { | |
eae
2015/08/28 21:10:24
What's the relationship between ScriptRunIterator
| |
66 protected: | |
67 ScriptData() = default; | |
68 | |
69 public: | |
70 virtual ~ScriptData(); | |
71 | |
72 enum PairedBracketType { | |
73 NONE, | |
74 OPEN, | |
75 CLOSE, | |
76 COUNT | |
77 }; | |
78 | |
79 static const int kMaxScriptCount = 20; | |
80 | |
81 virtual void getScripts(UChar32 ch, Vector<UScriptCode>& dst) const = 0; | |
82 | |
83 virtual UChar32 getPairedBracket(UChar32 ch) const = 0; | |
84 | |
85 virtual PairedBracketType getPairedBracketType(UChar32 ch) const = 0; | |
86 | |
87 private: | |
88 DISALLOW_COPY_AND_ASSIGN(ScriptData); | |
89 }; | |
90 | |
91 class PLATFORM_EXPORT ICUScriptData : public ScriptData { | |
92 public: | |
93 ~ICUScriptData() override | |
94 { | |
95 } | |
96 | |
97 static const ICUScriptData* instance(); | |
98 | |
99 void getScripts(UChar32 ch, Vector<UScriptCode>& dst) const override; | |
100 | |
101 UChar32 getPairedBracket(UChar32 ch) const override; | |
102 | |
103 PairedBracketType getPairedBracketType(UChar32 ch) const override; | |
104 | |
105 private: | |
106 ICUScriptData() | |
107 { | |
108 } | |
109 | |
110 DISALLOW_COPY_AND_ASSIGN(ICUScriptData); | |
111 }; | |
112 } | |
113 | |
114 #endif | |
OLD | NEW |