| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
|---|
| 6 | **
|
|---|
| 7 | ** This file is part of the QtCore module of the Qt Toolkit.
|
|---|
| 8 | **
|
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 10 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 14 | ** a written agreement between you and Nokia.
|
|---|
| 15 | **
|
|---|
| 16 | ** GNU Lesser General Public License Usage
|
|---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 20 | ** packaging of this file. Please review the following information to
|
|---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 23 | **
|
|---|
| 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
|---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
|---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this 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 have questions regarding the use of this file, please contact
|
|---|
| 37 | ** Nokia 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 |
|
|---|
| 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 |
|
|---|
| 80 | bool operator==(const QRegExp &rx) const;
|
|---|
| 81 | inline bool operator!=(const QRegExp &rx) const { return !operator==(rx); }
|
|---|
| 82 |
|
|---|
| 83 | bool isEmpty() const;
|
|---|
| 84 | bool isValid() const;
|
|---|
| 85 | QString pattern() const;
|
|---|
| 86 | void setPattern(const QString &pattern);
|
|---|
| 87 | Qt::CaseSensitivity caseSensitivity() const;
|
|---|
| 88 | void setCaseSensitivity(Qt::CaseSensitivity cs);
|
|---|
| 89 | #ifdef QT3_SUPPORT
|
|---|
| 90 | inline QT3_SUPPORT bool caseSensitive() const { return caseSensitivity() == Qt::CaseSensitive; }
|
|---|
| 91 | inline QT3_SUPPORT void setCaseSensitive(bool sensitive)
|
|---|
| 92 | { setCaseSensitivity(sensitive ? Qt::CaseSensitive : Qt::CaseInsensitive); }
|
|---|
| 93 | #endif
|
|---|
| 94 | PatternSyntax patternSyntax() const;
|
|---|
| 95 | void setPatternSyntax(PatternSyntax syntax);
|
|---|
| 96 | #ifdef QT3_SUPPORT
|
|---|
| 97 | inline QT3_SUPPORT bool wildcard() const { return patternSyntax() == Wildcard; }
|
|---|
| 98 | inline QT3_SUPPORT void setWildcard(bool aWildcard)
|
|---|
| 99 | { setPatternSyntax(aWildcard ? Wildcard : RegExp); }
|
|---|
| 100 | #endif
|
|---|
| 101 |
|
|---|
| 102 | bool isMinimal() const;
|
|---|
| 103 | void setMinimal(bool minimal);
|
|---|
| 104 | #ifdef QT3_SUPPORT
|
|---|
| 105 | inline QT3_SUPPORT bool minimal() const { return isMinimal(); }
|
|---|
| 106 | #endif
|
|---|
| 107 |
|
|---|
| 108 | bool exactMatch(const QString &str) const;
|
|---|
| 109 |
|
|---|
| 110 | int indexIn(const QString &str, int offset = 0, CaretMode caretMode = CaretAtZero) const;
|
|---|
| 111 | int lastIndexIn(const QString &str, int offset = -1, CaretMode caretMode = CaretAtZero) const;
|
|---|
| 112 | #ifdef QT3_SUPPORT
|
|---|
| 113 | inline QT3_SUPPORT int search(const QString &str, int from = 0,
|
|---|
| 114 | CaretMode caretMode = CaretAtZero) const
|
|---|
| 115 | { return indexIn(str, from, caretMode); }
|
|---|
| 116 | inline QT3_SUPPORT int searchRev(const QString &str, int from = -1,
|
|---|
| 117 | CaretMode caretMode = CaretAtZero) const
|
|---|
| 118 | { return lastIndexIn(str, from, caretMode); }
|
|---|
| 119 | #endif
|
|---|
| 120 | int matchedLength() const;
|
|---|
| 121 | #ifndef QT_NO_REGEXP_CAPTURE
|
|---|
| 122 | #ifdef QT_DEPRECATED
|
|---|
| 123 | QT_DEPRECATED int numCaptures() const;
|
|---|
| 124 | #endif
|
|---|
| 125 | int captureCount() const;
|
|---|
| 126 | QStringList capturedTexts() const;
|
|---|
| 127 | QStringList capturedTexts();
|
|---|
| 128 | QString cap(int nth = 0) const;
|
|---|
| 129 | QString cap(int nth = 0);
|
|---|
| 130 | int pos(int nth = 0) const;
|
|---|
| 131 | int pos(int nth = 0);
|
|---|
| 132 | QString errorString() const;
|
|---|
| 133 | QString errorString();
|
|---|
| 134 | #endif
|
|---|
| 135 |
|
|---|
| 136 | static QString escape(const QString &str);
|
|---|
| 137 |
|
|---|
| 138 | #ifdef QT3_SUPPORT
|
|---|
| 139 | inline QT3_SUPPORT_CONSTRUCTOR QRegExp(const QString &aPattern, bool cs, bool aWildcard = false)
|
|---|
| 140 | {
|
|---|
| 141 | new (this)
|
|---|
| 142 | QRegExp(aPattern, cs ? Qt::CaseSensitive : Qt::CaseInsensitive,
|
|---|
| 143 | aWildcard ? Wildcard : RegExp);
|
|---|
| 144 | }
|
|---|
| 145 | #endif
|
|---|
| 146 |
|
|---|
| 147 | private:
|
|---|
| 148 | QRegExpPrivate *priv;
|
|---|
| 149 | };
|
|---|
| 150 |
|
|---|
| 151 | Q_DECLARE_TYPEINFO(QRegExp, Q_MOVABLE_TYPE);
|
|---|
| 152 |
|
|---|
| 153 | #ifndef QT_NO_DATASTREAM
|
|---|
| 154 | Q_CORE_EXPORT QDataStream &operator<<(QDataStream &out, const QRegExp ®Exp);
|
|---|
| 155 | Q_CORE_EXPORT QDataStream &operator>>(QDataStream &in, QRegExp ®Exp);
|
|---|
| 156 | #endif
|
|---|
| 157 |
|
|---|
| 158 | QT_END_NAMESPACE
|
|---|
| 159 |
|
|---|
| 160 | QT_END_HEADER
|
|---|
| 161 |
|
|---|
| 162 | #endif // QT_NO_REGEXP
|
|---|
| 163 |
|
|---|
| 164 | #endif // QREGEXP_H
|
|---|