1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). 4 ** Contact: http://www.qt-project.org/legal 5 ** 6 ** This file is part of the Qt Solutions component. 7 ** 8 ** $QT_BEGIN_LICENSE:BSD$ 9 ** You may use this file under the terms of the BSD license as follows: 10 ** 11 ** "Redistribution and use in source and binary forms, with or without 12 ** modification, are permitted provided that the following conditions are 13 ** met: 14 ** * Redistributions of source code must retain the above copyright 15 ** notice, this list of conditions and the following disclaimer. 16 ** * Redistributions in binary form must reproduce the above copyright 17 ** notice, this list of conditions and the following disclaimer in 18 ** the documentation and/or other materials provided with the 19 ** distribution. 20 ** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names 21 ** of its contributors may be used to endorse or promote products derived 22 ** from this software without specific prior written permission. 23 ** 24 ** 25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 36 ** 37 ** $QT_END_LICENSE$ 38 ** 39 ****************************************************************************/ 40 41 42 #ifndef QSCRIPTECMAREGEXP_P_H 43 #define QSCRIPTECMAREGEXP_P_H 44 45 // 46 // W A R N I N G 47 // ------------- 48 // 49 // This file is not part of the Qt API. It exists purely as an 50 // implementation detail. This header file may change from version to 51 // version without notice, or even be removed. 52 // 53 // We mean it. 54 // 55 56 #include <QRegExp> 57 58 59 #include "qscriptecmacore_p.h" 60 61 QT_BEGIN_NAMESPACE 62 63 namespace QScript { namespace Ecma { 64 65 class RegExp: public Core 66 { 67 public: 68 enum RegExpFlag { 69 Global = 0x01, 70 IgnoreCase = 0x02, 71 Multiline = 0x04 72 }; 73 74 RegExp(QScriptEnginePrivate *engine); 75 virtual ~RegExp(); 76 77 virtual void execute(QScriptContextPrivate *context); 78 79 class Instance: public QScriptObjectData { 80 public: Instance()81 Instance() : flags(0) {} ~Instance()82 virtual ~Instance() {} 83 84 static Instance *get(const QScriptValueImpl &object, 85 QScriptClassInfo *klass); 86 87 public: // attributes 88 #ifndef QT_NO_REGEXP 89 QRegExp value; 90 #else 91 QString pattern; 92 #endif 93 int flags; 94 }; 95 get(const QScriptValueImpl & object)96 inline Instance *get(const QScriptValueImpl &object) const 97 { return Instance::get(object, classInfo()); } 98 99 void newRegExp(QScriptValueImpl *result, const QString &pattern, 100 int flags); 101 #ifndef QT_NO_REGEXP 102 void newRegExp(QScriptValueImpl *result, const QRegExp &rx, 103 int flags = 0); 104 QRegExp toRegExp(const QScriptValueImpl &value) const; 105 static QRegExp toRegExp(const QString &pattern, int flags); 106 #endif 107 108 static int flagFromChar(const QChar &ch); 109 static QString flagsToString(int flags); 110 111 protected: 112 static QScriptValueImpl method_exec(QScriptContextPrivate *context, 113 QScriptEnginePrivate *eng, 114 QScriptClassInfo *classInfo); 115 static QScriptValueImpl method_test(QScriptContextPrivate *context, 116 QScriptEnginePrivate *eng, 117 QScriptClassInfo *classInfo); 118 static QScriptValueImpl method_toString(QScriptContextPrivate *context, 119 QScriptEnginePrivate *eng, 120 QScriptClassInfo *classInfo); 121 122 private: 123 #ifndef QT_NO_REGEXP 124 void newRegExp_helper(QScriptValueImpl *result, const QRegExp &rx, 125 int flags); 126 #endif 127 void initRegExp(QScriptValueImpl *result, 128 #ifndef QT_NO_REGEXP 129 const QRegExp &rx, 130 #else 131 const QString &pattern, 132 #endif 133 int flags); 134 }; 135 136 } } // namespace QScript::Ecma 137 138 QT_END_NAMESPACE 139 140 #endif // QSCRIPTECMAREGEXP_P_H 141