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 |
| 25 // this object. Typically data is a singleton that exists for the life of |
| 26 // the process. |
| 27 ScriptRunIterator(const UChar* text, size_t length, const ScriptData*); |
| 28 |
| 29 bool consume(unsigned& limit, UScriptCode&); |
| 30 |
| 31 private: |
| 32 struct BracketRec { |
| 33 UChar32 ch; |
| 34 UScriptCode script; |
| 35 }; |
| 36 void openBracket(UChar32); |
| 37 void closeBracket(UChar32); |
| 38 bool mergeSets(); |
| 39 void fixupStack(UScriptCode resolvedScript); |
| 40 bool fetch(size_t* pos, UChar32*); |
| 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 // Limit max brackets so that the bracket tracking buffer does not grow |
| 50 // excessively large when processing long runs of text. |
| 51 static const int kMaxBrackets = 32; |
| 52 |
| 53 Vector<UScriptCode> m_currentSet; |
| 54 Vector<UScriptCode> m_nextSet; |
| 55 Vector<UScriptCode> m_aheadSet; |
| 56 |
| 57 UChar32 m_aheadCharacter; |
| 58 size_t m_aheadPos; |
| 59 |
| 60 UScriptCode m_commonPreferred; |
| 61 |
| 62 const ScriptData* m_scriptData; |
| 63 |
| 64 DISALLOW_COPY_AND_ASSIGN(ScriptRunIterator); |
| 65 }; |
| 66 |
| 67 class PLATFORM_EXPORT ScriptData { |
| 68 protected: |
| 69 ScriptData() = default; |
| 70 |
| 71 public: |
| 72 virtual ~ScriptData(); |
| 73 |
| 74 enum PairedBracketType { |
| 75 BracketTypeNone, |
| 76 BracketTypeOpen, |
| 77 BracketTypeClose, |
| 78 BracketTypeCount |
| 79 }; |
| 80 |
| 81 static const int kMaxScriptCount = 20; |
| 82 |
| 83 virtual void getScripts(UChar32, Vector<UScriptCode>& dst) const = 0; |
| 84 |
| 85 virtual UChar32 getPairedBracket(UChar32) const = 0; |
| 86 |
| 87 virtual PairedBracketType getPairedBracketType(UChar32) const = 0; |
| 88 |
| 89 private: |
| 90 DISALLOW_COPY_AND_ASSIGN(ScriptData); |
| 91 }; |
| 92 |
| 93 class PLATFORM_EXPORT ICUScriptData : public ScriptData { |
| 94 public: |
| 95 ~ICUScriptData() override |
| 96 { |
| 97 } |
| 98 |
| 99 static const ICUScriptData* instance(); |
| 100 |
| 101 void getScripts(UChar32, Vector<UScriptCode>& dst) const override; |
| 102 |
| 103 UChar32 getPairedBracket(UChar32) const override; |
| 104 |
| 105 PairedBracketType getPairedBracketType(UChar32) const override; |
| 106 |
| 107 private: |
| 108 ICUScriptData() |
| 109 { |
| 110 } |
| 111 |
| 112 DISALLOW_COPY_AND_ASSIGN(ICUScriptData); |
| 113 }; |
| 114 } |
| 115 |
| 116 #endif |
OLD | NEW |