Qt 6.x
The Qt SDK
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;
69
70 QString flagsAsString() const;
71 int captureCount() const { return subPatternCount + 1; }
72};
73Q_STATIC_ASSERT(std::is_trivial_v<RegExp>);
74
75}
76
77struct RegExp : public Managed
78{
83
84 QString pattern() const { return *d()->pattern; }
85 JSC::Yarr::BytecodePattern *byteCode() { return d()->byteCode; }
86#if ENABLE(YARR_JIT)
87 JSC::Yarr::YarrCodeBlock *jitCode() const { return d()->jitCode; }
88#endif
89 RegExpCache *cache() const { return d()->cache; }
90 int subPatternCount() const { return d()->subPatternCount; }
91 bool ignoreCase() const { return d()->ignoreCase(); }
92 bool multiLine() const { return d()->multiLine(); }
93 bool global() const { return d()->global(); }
94 bool unicode() const { return d()->unicode(); }
95 bool sticky() const { return d()->sticky(); }
96
98
99 bool isValid() const { return d()->valid; }
100
101 uint match(const QString& string, int start, uint *matchOffsets);
102
103 int captureCount() const { return subPatternCount() + 1; }
104
105 static QString getSubstitution(const QString &matched, const QString &str, int position, const Value *captures, int nCaptures, const QString &replacement);
106
107 friend class RegExpCache;
108};
109
111{
114 { }
115 explicit inline RegExpCacheKey(const RegExp::Data *re);
116
117 bool operator==(const RegExpCacheKey &other) const
118 { return pattern == other.pattern && flags == other.flags;; }
119 bool operator!=(const RegExpCacheKey &other) const
120 { return !operator==(other); }
121
124};
125
126inline RegExpCacheKey::RegExpCacheKey(const RegExp::Data *re)
127 : pattern(*re->pattern)
128 , flags(re->flags)
129{}
130
131inline size_t qHash(const RegExpCacheKey& key, size_t seed = 0) noexcept
132{ return qHash(key.pattern, seed); }
133
134class RegExpCache : public QHash<RegExpCacheKey, WeakValue>
135{
136public:
137 ~RegExpCache();
138};
139
140
141
142}
143
145
146#endif // QV4REGEXP_H
\inmodule QtCore
Definition qhash.h:818
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
QString str
[2]
Combined button and popup list for selecting options.
\qmltype Particle \inqmlmodule QtQuick.Particles
size_t qHash(const ObjectItem &i, size_t seed=0)
#define Q_STATIC_ASSERT(Condition)
Definition qassert.h:105
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:29
#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:71
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:94
int subPatternCount() const
Definition qv4regexp_p.h:90
RegExpCache * cache() const
Definition qv4regexp_p.h:89
static QString getSubstitution(const QString &matched, const QString &str, int position, const Value *captures, int nCaptures, const QString &replacement)
Definition qv4regexp.cpp:80
bool multiLine() const
Definition qv4regexp_p.h:92
bool isValid() const
Definition qv4regexp_p.h:99
bool sticky() const
Definition qv4regexp_p.h:95
int captureCount() const
JSC::Yarr::BytecodePattern * byteCode()
Definition qv4regexp_p.h:85
uint match(const QString &string, int start, uint *matchOffsets)
Definition qv4regexp.cpp:38
bool global() const
Definition qv4regexp_p.h:93
bool ignoreCase() const
Definition qv4regexp_p.h:91