1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://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 http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://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 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file.  Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
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 
52 QT_BEGIN_HEADER
53 
54 QT_BEGIN_NAMESPACE
55 
56 QT_MODULE(Core)
57 
58 struct QRegExpPrivate;
59 class QStringList;
60 
61 class Q_CORE_EXPORT QRegExp
62 {
63 public:
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
swap(QRegExp & other)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
caseSensitive()95     inline QT3_SUPPORT bool caseSensitive() const { return caseSensitivity() == Qt::CaseSensitive; }
setCaseSensitive(bool sensitive)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
wildcard()102     inline QT3_SUPPORT bool wildcard() const { return patternSyntax() == Wildcard; }
setWildcard(bool aWildcard)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
minimal()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 
152 private:
153     QRegExpPrivate *priv;
154 };
155 
156 Q_DECLARE_TYPEINFO(QRegExp, Q_MOVABLE_TYPE);
157 
158 #ifndef QT_NO_DATASTREAM
159 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &out, const QRegExp &regExp);
160 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &in, QRegExp &regExp);
161 #endif
162 
163 QT_END_NAMESPACE
164 
165 QT_END_HEADER
166 
167 #endif // QT_NO_REGEXP
168 
169 #endif // QREGEXP_H
170