Merge remote-tracking branch 'origin/master' into api_changes
[profile/ivi/qtbase.git] / src / corelib / tools / qregexp.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
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
49 QT_BEGIN_HEADER
50
51 QT_BEGIN_NAMESPACE
52
53
54 struct QRegExpPrivate;
55 class QStringList;
56
57 class Q_CORE_EXPORT QRegExp
58 {
59 public:
60     enum PatternSyntax {
61         RegExp,
62         Wildcard,
63         FixedString,
64         RegExp2,
65         WildcardUnix,
66         W3CXmlSchema11 };
67     enum CaretMode { CaretAtZero, CaretAtOffset, CaretWontMatch };
68
69     QRegExp();
70     explicit QRegExp(const QString &pattern, Qt::CaseSensitivity cs = Qt::CaseSensitive,
71                      PatternSyntax syntax = RegExp);
72     QRegExp(const QRegExp &rx);
73     ~QRegExp();
74     QRegExp &operator=(const QRegExp &rx);
75 #ifdef Q_COMPILER_RVALUE_REFS
76     inline QRegExp &operator=(QRegExp &&other)
77     { qSwap(priv,other.priv); return *this; }
78 #endif
79     inline void swap(QRegExp &other) { 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 private:
116     QRegExpPrivate *priv;
117 };
118
119 Q_DECLARE_TYPEINFO(QRegExp, Q_MOVABLE_TYPE);
120
121 #ifndef QT_NO_DATASTREAM
122 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &out, const QRegExp &regExp);
123 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &in, QRegExp &regExp);
124 #endif
125
126 #ifndef QT_NO_DEBUG_STREAM
127 Q_CORE_EXPORT QDebug operator<<(QDebug, const QRegExp &);
128 #endif
129
130 QT_END_NAMESPACE
131
132 QT_END_HEADER
133
134 #endif // QT_NO_REGEXP
135
136 #endif // QREGEXP_H