regexp_object.h
00001 // -*- c-basic-offset: 2 -*- 00002 /* 00003 * This file is part of the KDE libraries 00004 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org) 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 * 00020 */ 00021 00022 #ifndef _REGEXP_OBJECT_H_ 00023 #define _REGEXP_OBJECT_H_ 00024 00025 #include "internal.h" 00026 #include "function_object.h" 00027 #include "regexp.h" 00028 00029 namespace KJS { 00030 class ExecState; 00031 class RegExpPrototypeImp : public ObjectImp { 00032 public: 00033 RegExpPrototypeImp(ExecState *exec, 00034 ObjectPrototypeImp *objProto, 00035 FunctionPrototypeImp *funcProto); 00036 virtual const ClassInfo *classInfo() const { return &info; } 00037 static const ClassInfo info; 00038 }; 00039 00040 class RegExpProtoFuncImp : public InternalFunctionImp { 00041 public: 00042 RegExpProtoFuncImp(ExecState *exec, FunctionPrototypeImp *funcProto, int i, int len, 00043 const Identifier &_ident); 00044 00045 virtual bool implementsCall() const; 00046 virtual Value call(ExecState *exec, Object &thisObj, const List &args); 00047 00048 enum { Exec, Test, ToString, Compile }; 00049 private: 00050 int id; 00051 }; 00052 00053 class RegExpImp : public ObjectImp { 00054 public: 00055 RegExpImp(RegExpPrototypeImp *regexpProto); 00056 ~RegExpImp(); 00057 void setRegExp(RegExp *r); 00058 RegExp* regExp() { return reg; } 00059 00060 virtual const ClassInfo *classInfo() const { return &info; } 00061 static const ClassInfo info; 00062 private: 00063 RegExp *reg; 00064 }; 00065 00066 class RegExpObjectImp : public InternalFunctionImp { 00067 public: 00068 RegExpObjectImp(ExecState *exec, 00069 FunctionPrototypeImp *funcProto, 00070 RegExpPrototypeImp *regProto); 00071 virtual ~RegExpObjectImp(); 00072 virtual bool implementsConstruct() const; 00073 virtual Object construct(ExecState *exec, const List &args); 00074 virtual bool implementsCall() const; 00075 virtual Value call(ExecState *exec, Object &thisObj, const List &args); 00076 00077 Value get(ExecState *exec, const Identifier &p) const; 00078 bool hasProperty(ExecState *exec, const Identifier &propertyName) const; 00079 int ** registerRegexp( const RegExp* re, const UString& s ); 00080 void setSubPatterns(int num) { lastNrSubPatterns = num; } 00081 Object arrayOfMatches(ExecState *exec, const UString &result) const; 00082 00083 /* 00084 Attempts to create a new regular expression engine for the string p 00085 and the flags stored in flagsInput. If this succeeds, it returns the 00086 engine. If not, it returns 0, and raises an exception in exec 00087 */ 00088 static RegExp* makeEngine(ExecState *exec, const UString &p, const Value &flagsInput); 00089 private: 00090 UString lastString; 00091 int *lastOvector; 00092 unsigned int lastNrSubPatterns; 00093 }; 00094 00095 } // namespace 00096 00097 #endif