1 /* 2 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org) 3 * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved. 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public 7 * License as published by the Free Software Foundation; either 8 * version 2 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public 16 * License along with this library; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 * 19 */ 20 21 #ifndef RegExp_h 22 #define RegExp_h 23 24 #include "UString.h" 25 #include "WREC.h" 26 #include "ExecutableAllocator.h" 27 #include <wtf/Forward.h> 28 #include <wtf/RefCounted.h> 29 30 struct JSRegExp; 31 32 namespace JSC { 33 34 class JSGlobalData; 35 36 class RegExp : public RefCounted<RegExp> { 37 public: 38 static PassRefPtr<RegExp> create(JSGlobalData* globalData, const UString& pattern); 39 static PassRefPtr<RegExp> create(JSGlobalData* globalData, const UString& pattern, const UString& flags); 40 ~RegExp(); 41 global()42 bool global() const { return m_flagBits & Global; } ignoreCase()43 bool ignoreCase() const { return m_flagBits & IgnoreCase; } multiline()44 bool multiline() const { return m_flagBits & Multiline; } 45 pattern()46 const UString& pattern() const { return m_pattern; } flags()47 const UString& flags() const { return m_flags; } 48 isValid()49 bool isValid() const { return !m_constructionError; } errorMessage()50 const char* errorMessage() const { return m_constructionError; } 51 52 int match(const UString&, int startOffset, OwnArrayPtr<int>* ovector = 0); numSubpatterns()53 unsigned numSubpatterns() const { return m_numSubpatterns; } 54 55 private: 56 RegExp(JSGlobalData* globalData, const UString& pattern); 57 RegExp(JSGlobalData* globalData, const UString& pattern, const UString& flags); 58 59 void compile(); 60 61 enum FlagBits { Global = 1, IgnoreCase = 2, Multiline = 4 }; 62 63 UString m_pattern; // FIXME: Just decompile m_regExp instead of storing this. 64 UString m_flags; // FIXME: Just decompile m_regExp instead of storing this. 65 int m_flagBits; 66 JSRegExp* m_regExp; 67 const char* m_constructionError; 68 unsigned m_numSubpatterns; 69 70 #if ENABLE(WREC) 71 WREC::CompiledRegExp m_wrecFunction; 72 RefPtr<ExecutablePool> m_executablePool; 73 #endif 74 }; 75 76 } // namespace JSC 77 78 #endif // RegExp_h 79