qregexp.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
00004 ** All rights reserved.
00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
00006 **
00007 ** This file is part of the QtCore module of the Qt Toolkit.
00008 **
00009 ** $QT_BEGIN_LICENSE:LGPL$
00010 ** Commercial Usage
00011 ** Licensees holding valid Qt Commercial licenses may use this file in
00012 ** accordance with the Qt Commercial License Agreement provided with the
00013 ** Software or, alternatively, in accordance with the terms contained in
00014 ** a written agreement between you and Nokia.
00015 **
00016 ** GNU Lesser General Public License Usage
00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
00018 ** General Public License version 2.1 as published by the Free Software
00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
00020 ** packaging of this file.  Please review the following information to
00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
00023 **
00024 ** In addition, as a special exception, Nokia gives you certain additional
00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
00027 **
00028 ** GNU General Public License Usage
00029 ** Alternatively, this file may be used under the terms of the GNU
00030 ** General Public License version 3.0 as published by the Free Software
00031 ** Foundation and appearing in the file LICENSE.GPL included in the
00032 ** packaging of this file.  Please review the following information to
00033 ** ensure the GNU General Public License version 3.0 requirements will be
00034 ** met: http://www.gnu.org/copyleft/gpl.html.
00035 **
00036 ** If you have questions regarding the use of this file, please contact
00037 ** Nokia at qt-info@nokia.com.
00038 ** $QT_END_LICENSE$
00039 **
00040 ****************************************************************************/
00041 
00042 #ifndef QREGEXP_H
00043 #define QREGEXP_H
00044 
00045 #ifndef QT_NO_REGEXP
00046 
00047 #include <QtCore/qstring.h>
00048 #ifdef QT3_SUPPORT
00049 #include <new>
00050 #endif
00051 
00052 QT_BEGIN_HEADER
00053 
00054 QT_BEGIN_NAMESPACE
00055 
00056 QT_MODULE(Core)
00057 
00058 struct QRegExpPrivate;
00059 class QStringList;
00060 
00061 class Q_CORE_EXPORT QRegExp
00062 {
00063 public:
00064     enum PatternSyntax {
00065         RegExp,
00066         Wildcard,
00067         FixedString,
00068         RegExp2,
00069         WildcardUnix,
00070         W3CXmlSchema11 };
00071     enum CaretMode { CaretAtZero, CaretAtOffset, CaretWontMatch };
00072 
00073     QRegExp();
00074     explicit QRegExp(const QString &pattern, Qt::CaseSensitivity cs = Qt::CaseSensitive,
00075              PatternSyntax syntax = RegExp);
00076     QRegExp(const QRegExp &rx);
00077     ~QRegExp();
00078     QRegExp &operator=(const QRegExp &rx);
00079 
00080     bool operator==(const QRegExp &rx) const;
00081     inline bool operator!=(const QRegExp &rx) const { return !operator==(rx); }
00082 
00083     bool isEmpty() const;
00084     bool isValid() const;
00085     QString pattern() const;
00086     void setPattern(const QString &pattern);
00087     Qt::CaseSensitivity caseSensitivity() const;
00088     void setCaseSensitivity(Qt::CaseSensitivity cs);
00089 #ifdef QT3_SUPPORT
00090     inline QT3_SUPPORT bool caseSensitive() const { return caseSensitivity() == Qt::CaseSensitive; }
00091     inline QT3_SUPPORT void setCaseSensitive(bool sensitive)
00092     { setCaseSensitivity(sensitive ? Qt::CaseSensitive : Qt::CaseInsensitive); }
00093 #endif
00094     PatternSyntax patternSyntax() const;
00095     void setPatternSyntax(PatternSyntax syntax);
00096 #ifdef QT3_SUPPORT
00097     inline QT3_SUPPORT bool wildcard() const { return patternSyntax() == Wildcard; }
00098     inline QT3_SUPPORT void setWildcard(bool aWildcard)
00099     { setPatternSyntax(aWildcard ? Wildcard : RegExp); }
00100 #endif
00101 
00102     bool isMinimal() const;
00103     void setMinimal(bool minimal);
00104 #ifdef QT3_SUPPORT
00105     inline QT3_SUPPORT bool minimal() const { return isMinimal(); }
00106 #endif
00107 
00108     bool exactMatch(const QString &str) const;
00109 
00110     int indexIn(const QString &str, int offset = 0, CaretMode caretMode = CaretAtZero) const;
00111     int lastIndexIn(const QString &str, int offset = -1, CaretMode caretMode = CaretAtZero) const;
00112 #ifdef QT3_SUPPORT
00113     inline QT3_SUPPORT int search(const QString &str, int from = 0,
00114                                 CaretMode caretMode = CaretAtZero) const
00115     { return indexIn(str, from, caretMode); }
00116     inline QT3_SUPPORT int searchRev(const QString &str, int from = -1,
00117                                    CaretMode caretMode = CaretAtZero) const
00118     { return lastIndexIn(str, from, caretMode); }
00119 #endif
00120     int matchedLength() const;
00121 #ifndef QT_NO_REGEXP_CAPTURE
00122 #ifdef QT_DEPRECATED
00123     QT_DEPRECATED int numCaptures() const;
00124 #endif
00125     int captureCount() const;
00126     QStringList capturedTexts() const;
00127     QStringList capturedTexts();
00128     QString cap(int nth = 0) const;
00129     QString cap(int nth = 0);
00130     int pos(int nth = 0) const;
00131     int pos(int nth = 0);
00132     QString errorString() const;
00133     QString errorString();
00134 #endif
00135 
00136     static QString escape(const QString &str);
00137 
00138 #ifdef QT3_SUPPORT
00139     inline QT3_SUPPORT_CONSTRUCTOR QRegExp(const QString &aPattern, bool cs, bool aWildcard = false)
00140     {
00141         new (this)
00142             QRegExp(aPattern, cs ? Qt::CaseSensitive : Qt::CaseInsensitive,
00143                     aWildcard ? Wildcard : RegExp);
00144     }
00145 #endif
00146 
00147 private:
00148     QRegExpPrivate *priv;
00149 };
00150 
00151 Q_DECLARE_TYPEINFO(QRegExp, Q_MOVABLE_TYPE);
00152 
00153 #ifndef QT_NO_DATASTREAM
00154 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &out, const QRegExp &regExp);
00155 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &in, QRegExp &regExp);
00156 #endif
00157 
00158 QT_END_NAMESPACE
00159 
00160 QT_END_HEADER
00161 
00162 #endif // QT_NO_REGEXP
00163 
00164 #endif // QREGEXP_H