webengine/osswebengine/JavaScriptCore/kjs/regexp_object.h
changeset 0 dd21522fd290
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 // -*- c-basic-offset: 2 -*-
       
     2 /*
       
     3  *  This file is part of the KDE libraries
       
     4  *  Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
       
     5  *
       
     6  *  This library is free software; you can redistribute it and/or
       
     7  *  modify it under the terms of the GNU Lesser General Public
       
     8  *  License as published by the Free Software Foundation; either
       
     9  *  version 2 of the License, or (at your option) any later version.
       
    10  *
       
    11  *  This library is distributed in the hope that it will be useful,
       
    12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    14  *  Lesser General Public License for more details.
       
    15  *
       
    16  *  You should have received a copy of the GNU Lesser General Public
       
    17  *  License along with this library; if not, write to the Free Software
       
    18  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
       
    19  *
       
    20  */
       
    21 
       
    22 #ifndef REGEXP_OBJECT_H_
       
    23 #define REGEXP_OBJECT_H_
       
    24 
       
    25 #include "function_object.h"
       
    26 #include "regexp.h"
       
    27 
       
    28 namespace KJS {
       
    29   class ExecState;
       
    30   class RegExpPrototype : public JSObject {
       
    31   public:
       
    32     RegExpPrototype(ExecState *exec,
       
    33                        ObjectPrototype *objProto,
       
    34                        FunctionPrototype *funcProto);
       
    35     virtual const ClassInfo *classInfo() const { return &info; }
       
    36     static const ClassInfo info;
       
    37   };
       
    38 
       
    39   class RegExpProtoFunc : public InternalFunctionImp {
       
    40   public:
       
    41     RegExpProtoFunc(ExecState*, FunctionPrototype*, int i, int len, const Identifier&);
       
    42 
       
    43     virtual JSValue *callAsFunction(ExecState *exec, JSObject *thisObj, const List &args);
       
    44 
       
    45     enum { Exec, Test, ToString };
       
    46   private:
       
    47     int id;
       
    48   };
       
    49 
       
    50   class RegExpImp : public JSObject {
       
    51   public:
       
    52     RegExpImp(RegExpPrototype *regexpProto);
       
    53     ~RegExpImp();
       
    54     void setRegExp(RegExp *r) { reg = r; }
       
    55     RegExp* regExp() const { return reg; }
       
    56 
       
    57     virtual const ClassInfo *classInfo() const { return &info; }
       
    58     static const ClassInfo info;
       
    59   private:
       
    60     RegExp *reg;
       
    61   };
       
    62 
       
    63   struct RegExpObjectImpPrivate;
       
    64 
       
    65   class RegExpObjectImp : public InternalFunctionImp {
       
    66   public:
       
    67     enum { Dollar1, Dollar2, Dollar3, Dollar4, Dollar5, Dollar6, Dollar7, Dollar8, Dollar9, 
       
    68            Input, Multiline, LastMatch, LastParen, LeftContext, RightContext };
       
    69     
       
    70     RegExpObjectImp(ExecState *exec,
       
    71                     FunctionPrototype *funcProto,
       
    72                     RegExpPrototype *regProto);
       
    73     virtual bool implementsConstruct() const;
       
    74     virtual JSObject *construct(ExecState *exec, const List &args);
       
    75     virtual JSValue *callAsFunction(ExecState *exec, JSObject *thisObj, const List &args);
       
    76 
       
    77     virtual void put(ExecState *, const Identifier &, JSValue *, int attr = None);
       
    78     void putValueProperty(ExecState *, int token, JSValue *, int attr);
       
    79     virtual bool getOwnPropertySlot(ExecState *, const Identifier&, PropertySlot&);
       
    80     JSValue *getValueProperty(ExecState *, int token) const;
       
    81     UString performMatch(RegExp *, const UString&, int startOffset = 0, int *endOffset = 0, int **ovector = 0);
       
    82     JSObject *arrayOfMatches(ExecState *exec, const UString &result) const;
       
    83     
       
    84     virtual const ClassInfo *classInfo() const { return &info; }
       
    85   private:
       
    86     JSValue *getBackref(unsigned) const;
       
    87     JSValue *getLastMatch() const;
       
    88     JSValue *getLastParen() const;
       
    89     JSValue *getLeftContext() const;
       
    90     JSValue *getRightContext() const;
       
    91 
       
    92     OwnPtr<RegExpObjectImpPrivate> d;
       
    93     
       
    94     static const ClassInfo info;
       
    95   };
       
    96 
       
    97 } // namespace
       
    98 
       
    99 #endif