Ignore:
Timestamp:
Oct 11, 2005, 1:43:49 PM (20 years ago)
Author:
ggaren
Message:
  • Implemented caching of match state inside the global RegExp object (lastParen, leftContext, rightContext, lastMatch, input).

exec(), test(), match(), search(), and replace() now dipatch regular
expression matching through the RegExp object's performMatch function,
to facilitate caching. This replaces registerRegexp and
setSubPatterns.

  • Implemented the special '$' aliases (e.g. RegExp.input aliases to RegExp.$_).
  • Moved support for backreferences into the new static hash table used for other special RegExp properties. Truncated backreferences at $9 to match IE, FF, and the "What's New in Netscape 1.2?" doc. (String.replace still supports double-digit backreferences.)
  • Tweaked RegExp.prototype.exec to handle ginormous values in lastIndex.

Fixes 11 -- count em, 11 -- JavaScriptCore tests.

Reviewed by NOBODY (OOPS!).

  • JavaScriptCore.xcodeproj/project.pbxproj: Added regexp_object.lut.h
  • kjs/create_hash_table: Tweaked to allow for more exotic characters.

We now rely on the compiler to catch illegal
identifiers.

  • kjs/regexp.cpp: (KJS::RegExp::RegExp):
  • kjs/regexp_object.cpp: (RegExpProtoFuncImp::callAsFunction): (RegExpObjectImp::RegExpObjectImp): (RegExpObjectImp::performMatch): (RegExpObjectImp::arrayOfMatches): (RegExpObjectImp::backrefGetter): (RegExpObjectImp::getLastMatch): (RegExpObjectImp::getLastParen): (RegExpObjectImp::getLeftContext): (RegExpObjectImp::getRightContext): (RegExpObjectImp::getOwnPropertySlot): (RegExpObjectImp::getValueProperty): (RegExpObjectImp::put): (RegExpObjectImp::putValueProperty):
  • kjs/regexp_object.h: (KJS::RegExpObjectImp::):
  • kjs/string_object.cpp: (substituteBackreferences): (replace): (StringProtoFuncImp::callAsFunction):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/regexp_object.h

    r10456 r10818  
    6666  class RegExpObjectImp : public InternalFunctionImp {
    6767  public:
     68    enum { Dollar1, Dollar2, Dollar3, Dollar4, Dollar5, Dollar6, Dollar7, Dollar8, Dollar9,
     69           Input, Multiline, LastMatch, LastParen, LeftContext, RightContext };
     70   
    6871    RegExpObjectImp(ExecState *exec,
    6972                    FunctionPrototypeImp *funcProto,
     
    7578    virtual ValueImp *callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args);
    7679
     80    virtual void put(ExecState *, const Identifier &, ValueImp *, int attr = None);
     81    void putValueProperty(ExecState *, int token, ValueImp *, int attr);
    7782    virtual bool getOwnPropertySlot(ExecState *, const Identifier&, PropertySlot&);
    78     int ** registerRegexp( const RegExp* re, const UString& s );
    79     void setSubPatterns(int num) { lastNrSubPatterns = num; }
     83    ValueImp *getValueProperty(ExecState *, int token) const;
     84    UString performMatch(RegExp *, const UString&, int startOffset = 0, int *endOffset = 0, int **ovector = 0);
    8085    ObjectImp *arrayOfMatches(ExecState *exec, const UString &result) const;
     86   
     87    virtual const ClassInfo *classInfo() const { return &info; }
    8188  private:
    82     static ValueImp *backrefGetter(ExecState *exec, const Identifier&, const PropertySlot& slot);
    83  
    84     UString lastString;
     89    ValueImp *getBackref(unsigned) const;
     90    ValueImp *getLastMatch() const;
     91    ValueImp *getLastParen() const;
     92    ValueImp *getLeftContext() const;
     93    ValueImp *getRightContext() const;
     94
     95    // Global search cache / settings
     96    bool multiline;
     97    UString lastInput;
    8598    int *lastOvector;
    86     unsigned lastNrSubPatterns;
     99    unsigned lastNumSubPatterns;
     100   
     101    static const ClassInfo info;
    87102  };
    88103
Note: See TracChangeset for help on using the changeset viewer.