src/corelib/tools/qregexp.h
changeset 0 1918ee327afb
child 3 41300fa6a67c
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the QtCore module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    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 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    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 #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     int numCaptures() const;
       
   123     QStringList capturedTexts() const;
       
   124     QStringList capturedTexts();
       
   125     QString cap(int nth = 0) const;
       
   126     QString cap(int nth = 0);
       
   127     int pos(int nth = 0) const;
       
   128     int pos(int nth = 0);
       
   129     QString errorString() const;
       
   130     QString errorString();
       
   131 #endif
       
   132 
       
   133     static QString escape(const QString &str);
       
   134 
       
   135 #ifdef QT3_SUPPORT
       
   136     inline QT3_SUPPORT_CONSTRUCTOR QRegExp(const QString &aPattern, bool cs, bool aWildcard = false)
       
   137     {
       
   138         new (this)
       
   139             QRegExp(aPattern, cs ? Qt::CaseSensitive : Qt::CaseInsensitive,
       
   140                     aWildcard ? Wildcard : RegExp);
       
   141     }
       
   142 #endif
       
   143 
       
   144 private:
       
   145     QRegExpPrivate *priv;
       
   146 };
       
   147 
       
   148 Q_DECLARE_TYPEINFO(QRegExp, Q_MOVABLE_TYPE);
       
   149 
       
   150 #ifndef QT_NO_DATASTREAM
       
   151 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &out, const QRegExp &regExp);
       
   152 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &in, QRegExp &regExp);
       
   153 #endif
       
   154 
       
   155 QT_END_NAMESPACE
       
   156 
       
   157 QT_END_HEADER
       
   158 
       
   159 #endif // QT_NO_REGEXP
       
   160 
       
   161 #endif // QREGEXP_H