1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtCore module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QREGEXP_H
41#define QREGEXP_H
42
43#include <QtCore/qglobal.h>
44
45#ifndef QT_NO_REGEXP
46
47#include <QtCore/qstring.h>
48
49QT_BEGIN_NAMESPACE
50
51
52struct QRegExpPrivate;
53class QStringList;
54class QRegExp;
55
56Q_CORE_EXPORT uint qHash(const QRegExp &key, uint seed = 0) noexcept;
57
58class Q_CORE_EXPORT QRegExp
59{
60public:
61 enum PatternSyntax {
62 RegExp,
63 Wildcard,
64 FixedString,
65 RegExp2,
66 WildcardUnix,
67 W3CXmlSchema11 };
68 enum CaretMode { CaretAtZero, CaretAtOffset, CaretWontMatch };
69
70 QRegExp();
71 explicit QRegExp(const QString &pattern, Qt::CaseSensitivity cs = Qt::CaseSensitive,
72 PatternSyntax syntax = RegExp);
73 QRegExp(const QRegExp &rx);
74 ~QRegExp();
75 QRegExp &operator=(const QRegExp &rx);
76 QRegExp &operator=(QRegExp &&other) noexcept { swap(other); return *this; }
77 void swap(QRegExp &other) noexcept { qSwap(value1&: priv, value2&: other.priv); }
78
79 bool operator==(const QRegExp &rx) const;
80 inline bool operator!=(const QRegExp &rx) const { return !operator==(rx); }
81
82 bool isEmpty() const;
83 bool isValid() const;
84 QString pattern() const;
85 void setPattern(const QString &pattern);
86 Qt::CaseSensitivity caseSensitivity() const;
87 void setCaseSensitivity(Qt::CaseSensitivity cs);
88 PatternSyntax patternSyntax() const;
89 void setPatternSyntax(PatternSyntax syntax);
90
91 bool isMinimal() const;
92 void setMinimal(bool minimal);
93
94 bool exactMatch(const QString &str) const;
95
96 int indexIn(const QString &str, int offset = 0, CaretMode caretMode = CaretAtZero) const;
97 int lastIndexIn(const QString &str, int offset = -1, CaretMode caretMode = CaretAtZero) const;
98 int matchedLength() const;
99#ifndef QT_NO_REGEXP_CAPTURE
100 int captureCount() const;
101 QStringList capturedTexts() const;
102 QStringList capturedTexts();
103 QString cap(int nth = 0) const;
104 QString cap(int nth = 0);
105 int pos(int nth = 0) const;
106 int pos(int nth = 0);
107 QString errorString() const;
108 QString errorString();
109#endif
110
111 static QString escape(const QString &str);
112
113 friend Q_CORE_EXPORT uint qHash(const QRegExp &key, uint seed) noexcept;
114
115private:
116 QRegExpPrivate *priv;
117};
118
119Q_DECLARE_TYPEINFO(QRegExp, Q_MOVABLE_TYPE);
120
121#ifndef QT_NO_DATASTREAM
122Q_CORE_EXPORT QDataStream &operator<<(QDataStream &out, const QRegExp &regExp);
123Q_CORE_EXPORT QDataStream &operator>>(QDataStream &in, QRegExp &regExp);
124#endif
125
126#ifndef QT_NO_DEBUG_STREAM
127Q_CORE_EXPORT QDebug operator<<(QDebug, const QRegExp &);
128#endif
129
130QT_END_NAMESPACE
131
132#endif // QT_NO_REGEXP
133
134#endif // QREGEXP_H
135

source code of qtbase/src/corelib/text/qregexp.h