1 | /*
|
---|
2 | * Copyright (C) 1999-2000 Harri Porten ([email protected])
|
---|
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 RegExpObject_h
|
---|
22 | #define RegExpObject_h
|
---|
23 |
|
---|
24 | #include "FunctionPrototype.h"
|
---|
25 | #include "regexp.h"
|
---|
26 |
|
---|
27 | namespace KJS {
|
---|
28 |
|
---|
29 | struct RegExpConstructorPrivate;
|
---|
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 RegExpObject : public JSObject {
|
---|
40 | public:
|
---|
41 | enum { Global, IgnoreCase, Multiline, Source, LastIndex };
|
---|
42 |
|
---|
43 | RegExpObject(RegExpPrototype*, PassRefPtr<RegExp>);
|
---|
44 | virtual ~RegExpObject();
|
---|
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 CallType getCallData(CallData&);
|
---|
53 | virtual JSValue* callAsFunction(ExecState*, JSObject*, const List&);
|
---|
54 |
|
---|
55 | bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
|
---|
56 | JSValue* getValueProperty(ExecState*, int token) const;
|
---|
57 | void put(ExecState*, const Identifier&, JSValue*);
|
---|
58 | void putValueProperty(ExecState*, int token, JSValue*);
|
---|
59 |
|
---|
60 | virtual const ClassInfo* classInfo() const { return &info; }
|
---|
61 | static const ClassInfo info;
|
---|
62 |
|
---|
63 | void setLastIndex(double lastIndex) { m_lastIndex = lastIndex; }
|
---|
64 |
|
---|
65 | private:
|
---|
66 | bool match(ExecState*, const List& args);
|
---|
67 |
|
---|
68 | RefPtr<RegExp> m_regExp;
|
---|
69 | double m_lastIndex;
|
---|
70 | };
|
---|
71 |
|
---|
72 | class RegExpConstructor : public InternalFunction {
|
---|
73 | public:
|
---|
74 | enum { Dollar1, Dollar2, Dollar3, Dollar4, Dollar5, Dollar6, Dollar7, Dollar8, Dollar9,
|
---|
75 | Input, Multiline, LastMatch, LastParen, LeftContext, RightContext };
|
---|
76 |
|
---|
77 | RegExpConstructor(ExecState*, FunctionPrototype*, RegExpPrototype*);
|
---|
78 |
|
---|
79 | virtual ConstructType getConstructData(ConstructData&);
|
---|
80 | virtual JSObject* construct(ExecState*, const List&);
|
---|
81 |
|
---|
82 | virtual JSValue* callAsFunction(ExecState*, JSObject*, const List&);
|
---|
83 |
|
---|
84 | virtual void put(ExecState*, const Identifier&, JSValue*);
|
---|
85 | void putValueProperty(ExecState*, int token, JSValue*);
|
---|
86 | virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
|
---|
87 | JSValue* getValueProperty(ExecState*, int token) const;
|
---|
88 |
|
---|
89 | virtual const ClassInfo* classInfo() const { return &info; }
|
---|
90 | static const ClassInfo info;
|
---|
91 |
|
---|
92 | void performMatch(RegExp*, const UString&, int startOffset, int& position, int& length, int** ovector = 0);
|
---|
93 | JSObject* arrayOfMatches(ExecState*) const;
|
---|
94 | const UString& input() const;
|
---|
95 |
|
---|
96 | private:
|
---|
97 | JSValue* getBackref(unsigned) const;
|
---|
98 | JSValue* getLastParen() const;
|
---|
99 | JSValue* getLeftContext() const;
|
---|
100 | JSValue* getRightContext() const;
|
---|
101 |
|
---|
102 | OwnPtr<RegExpConstructorPrivate> d;
|
---|
103 | };
|
---|
104 |
|
---|
105 | } // namespace
|
---|
106 |
|
---|
107 | #endif
|
---|