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) Q_DECL_NOTHROW;
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#ifdef Q_COMPILER_RVALUE_REFS
77 QRegExp &operator=(QRegExp &&other) Q_DECL_NOTHROW { swap(other); return *this; }
78#endif
79 void swap(QRegExp &other) Q_DECL_NOTHROW { qSwap(priv, other.priv); }
80
81 bool operator==(const QRegExp &rx) const;
82 inline bool operator!=(const QRegExp &rx) const { return !operator==(rx); }
83
84 bool isEmpty() const;
85 bool isValid() const;
86 QString pattern() const;
87 void setPattern(const QString &pattern);
88 Qt::CaseSensitivity caseSensitivity() const;
89 void setCaseSensitivity(Qt::CaseSensitivity cs);
90 PatternSyntax patternSyntax() const;
91 void setPatternSyntax(PatternSyntax syntax);
92
93 bool isMinimal() const;
94 void setMinimal(bool minimal);
95
96 bool exactMatch(const QString &str) const;
97
98 int indexIn(const QString &str, int offset = 0, CaretMode caretMode = CaretAtZero) const;
99 int lastIndexIn(const QString &str, int offset = -1, CaretMode caretMode = CaretAtZero) const;
100 int matchedLength() const;
101#ifndef QT_NO_REGEXP_CAPTURE
102 int captureCount() const;
103 QStringList capturedTexts() const;
104 QStringList capturedTexts();
105 QString cap(int nth = 0) const;
106 QString cap(int nth = 0);
107 int pos(int nth = 0) const;
108 int pos(int nth = 0);
109 QString errorString() const;
110 QString errorString();
111#endif
112
113 static QString escape(const QString &str);
114
115 friend Q_CORE_EXPORT uint qHash(const QRegExp &key, uint seed) Q_DECL_NOTHROW;
116
117private:
118 QRegExpPrivate *priv;
119};
120
121Q_DECLARE_TYPEINFO(QRegExp, Q_MOVABLE_TYPE);
122
123#ifndef QT_NO_DATASTREAM
124Q_CORE_EXPORT QDataStream &operator<<(QDataStream &out, const QRegExp &regExp);
125Q_CORE_EXPORT QDataStream &operator>>(QDataStream &in, QRegExp &regExp);
126#endif
127
128#ifndef QT_NO_DEBUG_STREAM
129Q_CORE_EXPORT QDebug operator<<(QDebug, const QRegExp &);
130#endif
131
132QT_END_NAMESPACE
133
134#endif // QT_NO_REGEXP
135
136#endif // QREGEXP_H
137