1/****************************************************************************
2**
3** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4** Contact: http://www.qt-project.org/legal
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 Digia. For licensing terms and
14** conditions see http://qt.digia.com/licensing. For further information
15** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 2.1 requirements
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24**
25** In addition, as a special exception, Digia gives you certain additional
26** rights. These rights are described in the Digia Qt LGPL Exception
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28**
29** GNU General Public License Usage
30** Alternatively, this file may be used under the terms of the GNU
31** General Public License version 3.0 as published by the Free Software
32** Foundation and appearing in the file LICENSE.GPL included in the
33** packaging of this file. Please review the following information to
34** ensure the GNU General Public License version 3.0 requirements will be
35** met: http://www.gnu.org/copyleft/gpl.html.
36**
37**
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QREGEXP_H
43#define QREGEXP_H
44
45#ifndef QT_NO_REGEXP
46
47#include <QtCore/qstring.h>
48#ifdef QT3_SUPPORT
49#include <new>
50#endif
51
52QT_BEGIN_HEADER
53
54QT_BEGIN_NAMESPACE
55
56QT_MODULE(Core)
57
58struct QRegExpPrivate;
59class QStringList;
60
61class Q_CORE_EXPORT QRegExp
62{
63public:
64 enum PatternSyntax {
65 RegExp,
66 Wildcard,
67 FixedString,
68 RegExp2,
69 WildcardUnix,
70 W3CXmlSchema11 };
71 enum CaretMode { CaretAtZero, CaretAtOffset, CaretWontMatch };
72
73 QRegExp();
74 explicit QRegExp(const QString &pattern, Qt::CaseSensitivity cs = Qt::CaseSensitive,
75 PatternSyntax syntax = RegExp);
76 QRegExp(const QRegExp &rx);
77 ~QRegExp();
78 QRegExp &operator=(const QRegExp &rx);
79#ifdef Q_COMPILER_RVALUE_REFS
80 inline QRegExp &operator=(QRegExp &&other)
81 { qSwap(priv,other.priv); return *this; }
82#endif
83 inline void swap(QRegExp &other) { qSwap(priv, other.priv); }
84
85 bool operator==(const QRegExp &rx) const;
86 inline bool operator!=(const QRegExp &rx) const { return !operator==(rx); }
87
88 bool isEmpty() const;
89 bool isValid() const;
90 QString pattern() const;
91 void setPattern(const QString &pattern);
92 Qt::CaseSensitivity caseSensitivity() const;
93 void setCaseSensitivity(Qt::CaseSensitivity cs);
94#ifdef QT3_SUPPORT
95 inline QT3_SUPPORT bool caseSensitive() const { return caseSensitivity() == Qt::CaseSensitive; }
96 inline QT3_SUPPORT void setCaseSensitive(bool sensitive)
97 { setCaseSensitivity(sensitive ? Qt::CaseSensitive : Qt::CaseInsensitive); }
98#endif
99 PatternSyntax patternSyntax() const;
100 void setPatternSyntax(PatternSyntax syntax);
101#ifdef QT3_SUPPORT
102 inline QT3_SUPPORT bool wildcard() const { return patternSyntax() == Wildcard; }
103 inline QT3_SUPPORT void setWildcard(bool aWildcard)
104 { setPatternSyntax(aWildcard ? Wildcard : RegExp); }
105#endif
106
107 bool isMinimal() const;
108 void setMinimal(bool minimal);
109#ifdef QT3_SUPPORT
110 inline QT3_SUPPORT bool minimal() const { return isMinimal(); }
111#endif
112
113 bool exactMatch(const QString &str) const;
114
115 int indexIn(const QString &str, int offset = 0, CaretMode caretMode = CaretAtZero) const;
116 int lastIndexIn(const QString &str, int offset = -1, CaretMode caretMode = CaretAtZero) const;
117#ifdef QT3_SUPPORT
118 inline QT3_SUPPORT int search(const QString &str, int from = 0,
119 CaretMode caretMode = CaretAtZero) const
120 { return indexIn(str, from, caretMode); }
121 inline QT3_SUPPORT int searchRev(const QString &str, int from = -1,
122 CaretMode caretMode = CaretAtZero) const
123 { return lastIndexIn(str, from, caretMode); }
124#endif
125 int matchedLength() const;
126#ifndef QT_NO_REGEXP_CAPTURE
127#ifdef QT_DEPRECATED
128 QT_DEPRECATED int numCaptures() const;
129#endif
130 int captureCount() const;
131 QStringList capturedTexts() const;
132 QStringList capturedTexts();
133 QString cap(int nth = 0) const;
134 QString cap(int nth = 0);
135 int pos(int nth = 0) const;
136 int pos(int nth = 0);
137 QString errorString() const;
138 QString errorString();
139#endif
140
141 static QString escape(const QString &str);
142
143#ifdef QT3_SUPPORT
144 inline QT3_SUPPORT_CONSTRUCTOR QRegExp(const QString &aPattern, bool cs, bool aWildcard = false)
145 {
146 new (this)
147 QRegExp(aPattern, cs ? Qt::CaseSensitive : Qt::CaseInsensitive,
148 aWildcard ? Wildcard : RegExp);
149 }
150#endif
151
152private:
153 QRegExpPrivate *priv;
154};
155
156Q_DECLARE_TYPEINFO(QRegExp, Q_MOVABLE_TYPE);
157
158#ifndef QT_NO_DATASTREAM
159Q_CORE_EXPORT QDataStream &operator<<(QDataStream &out, const QRegExp &regExp);
160Q_CORE_EXPORT QDataStream &operator>>(QDataStream &in, QRegExp &regExp);
161#endif
162
163QT_END_NAMESPACE
164
165QT_END_HEADER
166
167#endif // QT_NO_REGEXP
168
169#endif // QREGEXP_H
170