]> git.saurik.com Git - apple/javascriptcore.git/blob - kjs/regexp_object.h
JavaScriptCore-466.1.tar.gz
[apple/javascriptcore.git] / kjs / regexp_object.h
1 /*
2 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
3 * Copyright (C) 2003, 2007, 2008 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_OBJECT_H_
22 #define REGEXP_OBJECT_H_
23
24 #include "function_object.h"
25 #include "regexp.h"
26
27 namespace KJS {
28
29 struct RegExpObjectImpPrivate;
30
31 class RegExpPrototype : public JSObject {
32 public:
33 RegExpPrototype(ExecState*, ObjectPrototype*, FunctionPrototype*);
34
35 virtual const ClassInfo* classInfo() const { return &info; }
36 static const ClassInfo info;
37 };
38
39 class RegExpImp : public JSObject {
40 public:
41 enum { Global, IgnoreCase, Multiline, Source, LastIndex };
42
43 RegExpImp(RegExpPrototype*, PassRefPtr<RegExp>);
44 virtual ~RegExpImp();
45
46 void setRegExp(PassRefPtr<RegExp> r) { m_regExp = r; }
47 RegExp* regExp() const { return m_regExp.get(); }
48
49 JSValue* test(ExecState*, const List& args);
50 JSValue* exec(ExecState*, const List& args);
51
52 virtual bool implementsCall() const;
53 virtual JSValue* callAsFunction(ExecState*, JSObject*, const List&);
54 bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
55 JSValue* getValueProperty(ExecState*, int token) const;
56 void put(ExecState*, const Identifier&, JSValue*, int attributes = None);
57 void putValueProperty(ExecState*, int token, JSValue*, int attributes);
58
59 virtual const ClassInfo* classInfo() const { return &info; }
60 static const ClassInfo info;
61
62 void setLastIndex(double lastIndex) { m_lastIndex = lastIndex; }
63
64 private:
65 bool match(ExecState*, const List& args);
66
67 RefPtr<RegExp> m_regExp;
68 double m_lastIndex;
69 };
70
71 class RegExpObjectImp : public InternalFunctionImp {
72 public:
73 enum { Dollar1, Dollar2, Dollar3, Dollar4, Dollar5, Dollar6, Dollar7, Dollar8, Dollar9,
74 Input, Multiline, LastMatch, LastParen, LeftContext, RightContext };
75
76 RegExpObjectImp(ExecState*, FunctionPrototype*, RegExpPrototype*);
77
78 virtual bool implementsConstruct() const;
79 virtual JSObject* construct(ExecState*, const List&);
80 JSObject* createRegExpImp(ExecState*, PassRefPtr<RegExp>);
81 virtual JSValue* callAsFunction(ExecState*, JSObject*, const List&);
82 virtual void put(ExecState*, const Identifier&, JSValue*, int attributes = None);
83 void putValueProperty(ExecState*, int token, JSValue*, int attributes);
84 virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
85 JSValue* getValueProperty(ExecState*, int token) const;
86 virtual const ClassInfo* classInfo() const { return &info; }
87
88 void performMatch(RegExp*, const UString&, int startOffset, int& position, int& length, int** ovector = 0);
89 JSObject* arrayOfMatches(ExecState*) const;
90 const UString& input() const;
91
92 private:
93 JSValue* getBackref(unsigned) const;
94 JSValue* getLastParen() const;
95 JSValue* getLeftContext() const;
96 JSValue* getRightContext() const;
97
98 OwnPtr<RegExpObjectImpPrivate> d;
99
100 static const ClassInfo info;
101 };
102
103 } // namespace
104
105 #endif