source: trunk/src/corelib/tools/qregexp.h@ 437

Last change on this file since 437 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 5.2 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtCore module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
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 { RegExp, Wildcard, FixedString, RegExp2 };
65 enum CaretMode { CaretAtZero, CaretAtOffset, CaretWontMatch };
66
67 QRegExp();
68 explicit QRegExp(const QString &pattern, Qt::CaseSensitivity cs = Qt::CaseSensitive,
69 PatternSyntax syntax = RegExp);
70 QRegExp(const QRegExp &rx);
71 ~QRegExp();
72 QRegExp &operator=(const QRegExp &rx);
73
74 bool operator==(const QRegExp &rx) const;
75 inline bool operator!=(const QRegExp &rx) const { return !operator==(rx); }
76
77 bool isEmpty() const;
78 bool isValid() const;
79 QString pattern() const;
80 void setPattern(const QString &pattern);
81 Qt::CaseSensitivity caseSensitivity() const;
82 void setCaseSensitivity(Qt::CaseSensitivity cs);
83#ifdef QT3_SUPPORT
84 inline QT3_SUPPORT bool caseSensitive() const { return caseSensitivity() == Qt::CaseSensitive; }
85 inline QT3_SUPPORT void setCaseSensitive(bool sensitive)
86 { setCaseSensitivity(sensitive ? Qt::CaseSensitive : Qt::CaseInsensitive); }
87#endif
88 PatternSyntax patternSyntax() const;
89 void setPatternSyntax(PatternSyntax syntax);
90#ifdef QT3_SUPPORT
91 inline QT3_SUPPORT bool wildcard() const { return patternSyntax() == Wildcard; }
92 inline QT3_SUPPORT void setWildcard(bool aWildcard)
93 { setPatternSyntax(aWildcard ? Wildcard : RegExp); }
94#endif
95
96 bool isMinimal() const;
97 void setMinimal(bool minimal);
98#ifdef QT3_SUPPORT
99 inline QT3_SUPPORT bool minimal() const { return isMinimal(); }
100#endif
101
102 bool exactMatch(const QString &str) const;
103
104 int indexIn(const QString &str, int offset = 0, CaretMode caretMode = CaretAtZero) const;
105 int lastIndexIn(const QString &str, int offset = -1, CaretMode caretMode = CaretAtZero) const;
106#ifdef QT3_SUPPORT
107 inline QT3_SUPPORT int search(const QString &str, int from = 0,
108 CaretMode caretMode = CaretAtZero) const
109 { return indexIn(str, from, caretMode); }
110 inline QT3_SUPPORT int searchRev(const QString &str, int from = -1,
111 CaretMode caretMode = CaretAtZero) const
112 { return lastIndexIn(str, from, caretMode); }
113#endif
114 int matchedLength() const;
115#ifndef QT_NO_REGEXP_CAPTURE
116 int numCaptures() const;
117 QStringList capturedTexts() const;
118 QStringList capturedTexts();
119 QString cap(int nth = 0) const;
120 QString cap(int nth = 0);
121 int pos(int nth = 0) const;
122 int pos(int nth = 0);
123 QString errorString() const;
124 QString errorString();
125#endif
126
127 static QString escape(const QString &str);
128
129#ifdef QT3_SUPPORT
130 inline QT3_SUPPORT_CONSTRUCTOR QRegExp(const QString &aPattern, bool cs, bool aWildcard = false)
131 {
132 new (this)
133 QRegExp(aPattern, cs ? Qt::CaseSensitive : Qt::CaseInsensitive,
134 aWildcard ? Wildcard : RegExp);
135 }
136#endif
137
138private:
139 QRegExpPrivate *priv;
140};
141
142Q_DECLARE_TYPEINFO(QRegExp, Q_MOVABLE_TYPE);
143
144#ifndef QT_NO_DATASTREAM
145Q_CORE_EXPORT QDataStream &operator<<(QDataStream &out, const QRegExp &regExp);
146Q_CORE_EXPORT QDataStream &operator>>(QDataStream &in, QRegExp &regExp);
147#endif
148
149QT_END_NAMESPACE
150
151QT_END_HEADER
152
153#endif // QT_NO_REGEXP
154
155#endif // QREGEXP_H
Note: See TracBrowser for help on using the repository browser.