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.
5 #ifndef ScriptRunIterator_h
6 #define ScriptRunIterator_h
8 #include "platform/PlatformExport.h"
10 #include "wtf/Vector.h"
11 #include "wtf/dtoa/utils.h"
13 #include <unicode/uchar.h>
14 #include <unicode/uscript.h>
20 class PLATFORM_EXPORT ScriptRunIterator
{
22 ScriptRunIterator(const UChar
* text
, size_t length
);
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
27 ScriptRunIterator(const UChar
* text
, size_t length
, const ScriptData
*);
29 bool consume(unsigned& limit
, UScriptCode
&);
36 void openBracket(UChar32
);
37 void closeBracket(UChar32
);
39 void fixupStack(UScriptCode resolvedScript
);
40 bool fetch(size_t* pos
, UChar32
*);
42 UScriptCode
resolveCurrentScript() const;
45 const size_t m_length
;
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;
53 Vector
<UScriptCode
> m_currentSet
;
54 Vector
<UScriptCode
> m_nextSet
;
55 Vector
<UScriptCode
> m_aheadSet
;
57 UChar32 m_aheadCharacter
;
60 UScriptCode m_commonPreferred
;
62 const ScriptData
* m_scriptData
;
64 DISALLOW_COPY_AND_ASSIGN(ScriptRunIterator
);
67 // ScriptData is a wrapper which returns a set of scripts for a particular
68 // character retrieved from the character's primary script and script extensions,
69 // as per ICU / Unicode data. ScriptData maintains a certain priority order of
70 // the returned values, which are essential for mergeSets method to work
72 class PLATFORM_EXPORT ScriptData
{
74 ScriptData() = default;
77 virtual ~ScriptData();
79 enum PairedBracketType
{
86 static const int kMaxScriptCount
;
88 virtual void getScripts(UChar32
, Vector
<UScriptCode
>& dst
) const = 0;
90 virtual UChar32
getPairedBracket(UChar32
) const = 0;
92 virtual PairedBracketType
getPairedBracketType(UChar32
) const = 0;
95 DISALLOW_COPY_AND_ASSIGN(ScriptData
);
98 class PLATFORM_EXPORT ICUScriptData
: public ScriptData
{
100 ~ICUScriptData() override
104 static const ICUScriptData
* instance();
106 void getScripts(UChar32
, Vector
<UScriptCode
>& dst
) const override
;
108 UChar32
getPairedBracket(UChar32
) const override
;
110 PairedBracketType
getPairedBracketType(UChar32
) const override
;
117 DISALLOW_COPY_AND_ASSIGN(ICUScriptData
);