Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qv4regexp_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3#ifndef QV4REGEXP_H
4#define QV4REGEXP_H
5
6//
7// W A R N I N G
8// -------------
9//
10// This file is not part of the Qt API. It exists purely as an
11// implementation detail. This header file may change from version to
12// version without notice, or even be removed.
13//
14// We mean it.
15//
16
17#include <QString>
18#include <QVector>
19
20#include <wtf/RefPtr.h>
21#include <wtf/FastAllocBase.h>
22#include <wtf/BumpPointerAllocator.h>
23
24#include <limits.h>
25
26#include <yarr/Yarr.h>
27#include <yarr/YarrInterpreter.h>
28#include <yarr/YarrJIT.h>
29
30#include "qv4managed_p.h"
31#include "qv4engine_p.h"
32
34
35namespace QV4 {
36
37struct ExecutionEngine;
38struct RegExpCacheKey;
39
40namespace Heap {
41
42struct RegExp : Base {
44 void destroy();
45
47 JSC::Yarr::BytecodePattern *byteCode;
48#if ENABLE(YARR_JIT)
49 JSC::Yarr::YarrCodeBlock *jitCode;
50#endif
51 bool hasValidJITCode() const {
52#if ENABLE(YARR_JIT)
53 return jitCode && !jitCode->failureReason().has_value() && jitCode->has16BitCode();
54#else
55 return false;
56#endif
57 }
58
64
68 bool valid;
71
72 QString flagsAsString() const;
73 int captureCount() const { return subPatternCount + 1; }
74};
75Q_STATIC_ASSERT(std::is_trivial_v<RegExp>);
76
77}
78
79struct RegExp : public Managed
80{
85
86 QString pattern() const { return *d()->pattern; }
87 JSC::Yarr::BytecodePattern *byteCode() { return d()->byteCode; }
88#if ENABLE(YARR_JIT)
89 JSC::Yarr::YarrCodeBlock *jitCode() const { return d()->jitCode; }
90#endif
91 RegExpCache *cache() const { return d()->cache; }
92 int subPatternCount() const { return d()->subPatternCount; }
93 bool ignoreCase() const { return d()->ignoreCase(); }
94 bool multiLine() const { return d()->multiLine(); }
95 bool global() const { return d()->global(); }
96 bool unicode() const { return d()->unicode(); }
97 bool sticky() const { return d()->sticky(); }
98
100
101 bool isValid() const { return d()->valid; }
102
103 uint match(const QString& string, int start, uint *matchOffsets);
104
105 int captureCount() const { return subPatternCount() + 1; }
106
107 static QString getSubstitution(const QString &matched, const QString &str, int position, const Value *captures, int nCaptures, const QString &replacement);
108
109 friend class RegExpCache;
110};
111
113{
117 explicit inline RegExpCacheKey(const RegExp::Data *re);
118
119 bool operator==(const RegExpCacheKey &other) const
120 { return pattern == other.pattern && flags == other.flags;; }
121 bool operator!=(const RegExpCacheKey &other) const
122 { return !operator==(other); }
123
126};
127
128inline RegExpCacheKey::RegExpCacheKey(const RegExp::Data *re)
129 : pattern(*re->pattern)
130 , flags(re->flags)
131{}
132
133inline size_t qHash(const RegExpCacheKey& key, size_t seed = 0) noexcept
134{ return qHash(key.pattern, seed); }
135
136class RegExpCache : public QHash<RegExpCacheKey, WeakValue>
137{
138public:
139 ~RegExpCache();
140};
141
142
143
144}
145
147
148#endif // QV4REGEXP_H
\inmodule QtCore
Definition qhash.h:820
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QString str
[2]
Combined button and popup list for selecting options.
size_t qHash(const ObjectItem &i, size_t seed=0)
#define Q_STATIC_ASSERT(Condition)
Definition qassert.h:108
GLuint64 key
GLbitfield flags
GLuint start
GLubyte * pattern
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
static Q_CONSTINIT QBasicAtomicInteger< unsigned > seed
Definition qrandom.cpp:196
unsigned int uint
Definition qtypes.h:34
unsigned char quint8
Definition qtypes.h:46
#define V4_MANAGED(DataClass, superClass)
#define V4_NEEDS_DESTROY
#define Q_MANAGED_TYPE(type)
#define V4_INTERNALCLASS(c)
QSharedPointer< T > other(t)
[5]
view create()
QJSEngine engine
[0]
bool global() const
Definition qv4regexp_p.h:61
bool sticky() const
Definition qv4regexp_p.h:63
bool ignoreCase() const
Definition qv4regexp_p.h:59
bool multiLine() const
Definition qv4regexp_p.h:60
bool unicode() const
Definition qv4regexp_p.h:62
QString flagsAsString() const
bool hasValidJITCode() const
Definition qv4regexp_p.h:51
RegExpCache * cache
Definition qv4regexp_p.h:65
JSC::Yarr::BytecodePattern * byteCode
Definition qv4regexp_p.h:47
QString * pattern
Definition qv4regexp_p.h:46
int captureCount() const
Definition qv4regexp_p.h:73
ExecutionEngine * engine() const
RegExpCacheKey(const QString &pattern, uint flags)
bool operator!=(const RegExpCacheKey &other) const
bool operator==(const RegExpCacheKey &other) const
bool unicode() const
Definition qv4regexp_p.h:96
int subPatternCount() const
Definition qv4regexp_p.h:92
RegExpCache * cache() const
Definition qv4regexp_p.h:91
static QString getSubstitution(const QString &matched, const QString &str, int position, const Value *captures, int nCaptures, const QString &replacement)
bool multiLine() const
Definition qv4regexp_p.h:94
bool isValid() const
bool sticky() const
Definition qv4regexp_p.h:97
int captureCount() const
JSC::Yarr::BytecodePattern * byteCode()
Definition qv4regexp_p.h:87
uint match(const QString &string, int start, uint *matchOffsets)
Definition qv4regexp.cpp:42
bool global() const
Definition qv4regexp_p.h:95
bool ignoreCase() const
Definition qv4regexp_p.h:93