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// Qt-Security score:sensitive reason:trivial-impl-only
4
5#ifndef QREGEXP_H
6#define QREGEXP_H
7
8#include <QtCore5Compat/qcore5global.h>
9
10#include <QtCore/qglobal.h>
11#include <QtCore/qcontainerfwd.h>
12
13#include <QtCore/qstring.h>
14#include <QtCore/qvariant.h>
15
16QT_BEGIN_NAMESPACE
17
18
19struct QRegExpPrivate;
20class QRegExp;
21
22Q_CORE5COMPAT_EXPORT size_t qHash(const QRegExp &key, size_t seed = 0) noexcept;
23
24class Q_CORE5COMPAT_EXPORT QRegExp
25{
26public:
27 enum PatternSyntax {
28 RegExp,
29 Wildcard,
30 FixedString,
31 RegExp2,
32 WildcardUnix,
33 W3CXmlSchema11 };
34 enum CaretMode { CaretAtZero, CaretAtOffset, CaretWontMatch };
35
36 QRegExp();
37 explicit QRegExp(const QString &pattern, Qt::CaseSensitivity cs = Qt::CaseSensitive,
38 PatternSyntax syntax = RegExp);
39 QRegExp(const QRegExp &rx);
40 ~QRegExp();
41 QRegExp &operator=(const QRegExp &rx);
42 QRegExp &operator=(QRegExp &&other) noexcept { swap(other); return *this; }
43 void swap(QRegExp &other) noexcept { qt_ptr_swap(lhs&: priv, rhs&: other.priv); }
44
45 bool operator==(const QRegExp &rx) const;
46 inline bool operator!=(const QRegExp &rx) const { return !operator==(rx); }
47
48 bool isEmpty() const;
49 bool isValid() const;
50 QString pattern() const;
51 void setPattern(const QString &pattern);
52 Qt::CaseSensitivity caseSensitivity() const;
53 void setCaseSensitivity(Qt::CaseSensitivity cs);
54 PatternSyntax patternSyntax() const;
55 void setPatternSyntax(PatternSyntax syntax);
56
57 bool isMinimal() const;
58 void setMinimal(bool minimal);
59
60 bool exactMatch(const QString &str) const;
61
62 operator QVariant() const;
63
64 int indexIn(const QString &str, int offset = 0, CaretMode caretMode = CaretAtZero) const;
65 int lastIndexIn(const QString &str, int offset = -1, CaretMode caretMode = CaretAtZero) const;
66 int matchedLength() const;
67#ifndef QT_NO_REGEXP_CAPTURE
68 int captureCount() const;
69 QStringList capturedTexts() const;
70 QStringList capturedTexts();
71 QString cap(int nth = 0) const;
72 QString cap(int nth = 0);
73 int pos(int nth = 0) const;
74 int pos(int nth = 0);
75 QString errorString() const;
76 QString errorString();
77#endif
78
79 QString replaceIn(const QString &str, const QString &after) const;
80 QString removeIn(const QString &str) const
81 { return replaceIn(str, after: QString()); }
82 bool containedIn(const QString &str) const
83 { return indexIn(str) != -1; }
84 int countIn(const QString &str) const;
85
86 QStringList splitString(const QString &str, Qt::SplitBehavior behavior = Qt::KeepEmptyParts) const;
87
88 int indexIn(const QStringList &list, int from) const;
89 int lastIndexIn(const QStringList &list, int from) const;
90 QStringList replaceIn(const QStringList &stringList, const QString &after) const;
91 QStringList filterList(const QStringList &stringList) const;
92
93 static QString escape(const QString &str);
94
95 friend Q_CORE5COMPAT_EXPORT size_t qHash(const QRegExp &key, size_t seed) noexcept;
96
97private:
98 QRegExpPrivate *priv;
99};
100
101#ifndef QT_NO_DATASTREAM
102Q_CORE5COMPAT_EXPORT QDataStream &operator<<(QDataStream &out, const QRegExp &regExp);
103Q_CORE5COMPAT_EXPORT QDataStream &operator>>(QDataStream &in, QRegExp &regExp);
104#endif
105
106#ifndef QT_NO_DEBUG_STREAM
107Q_CORE5COMPAT_EXPORT QDebug operator<<(QDebug, const QRegExp &);
108#endif
109
110QT_END_NAMESPACE
111
112Q_DECLARE_METATYPE(QRegExp)
113
114#endif // QREGEXP_H
115

source code of qt5compat/src/core5/text/qregexp.h