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