source: webkit/trunk/JavaScriptCore/runtime/RegExp.h@ 38603

Last change on this file since 38603 was 38603, checked in by [email protected], 17 years ago

JavaScriptCore:

2008-11-19 Geoffrey Garen <[email protected]>

Reviewed by Darin Adler.


https://bugs.webkit.org/show_bug.cgi?id=22361
A little more RegExp refactoring.


Consistently named variables holding the starting position at which
regexp matching should begin to "startOffset".


A few more "regExpObject" => "regExpConstructor" changes.


Refactored RegExpObject::match for clarity, and replaced a slow "get"
of the "global" property with a fast access to the global bit.


Made the error message you see when RegExpObject::match has no input a
little more informative, as in Firefox.

  • runtime/RegExp.cpp: (JSC::RegExp::match):
  • runtime/RegExp.h:
  • runtime/RegExpObject.cpp: (JSC::RegExpObject::match):
  • runtime/StringPrototype.cpp: (JSC::stringProtoFuncReplace): (JSC::stringProtoFuncMatch): (JSC::stringProtoFuncSearch):

LayoutTests:

2008-11-19 Geoffrey Garen <[email protected]>

Reviewed by Darin Adler.


Test for https://bugs.webkit.org/show_bug.cgi?id=22361
A little more RegExp refactoring

  • fast/js/regexp-test-null-string.html: Added.
  • fast/js/regexp-test-null-expected.txt: Added.
  • Property svn:eol-style set to native
File size: 2.5 KB
Line 
1/*
2 * Copyright (C) 1999-2000 Harri Porten ([email protected])
3 * Copyright (C) 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 KJS_REGEXP_H
22#define KJS_REGEXP_H
23
24#include "UString.h"
25#include "WREC.h"
26#include <wtf/Forward.h>
27#include <wtf/RefCounted.h>
28
29struct JSRegExp;
30
31namespace JSC {
32
33 class JSGlobalData;
34
35 class RegExp : public RefCounted<RegExp> {
36 public:
37 static PassRefPtr<RegExp> create(JSGlobalData*, const UString& pattern);
38 static PassRefPtr<RegExp> create(JSGlobalData*, const UString& pattern, const UString& flags);
39 ~RegExp();
40
41 bool global() const { return m_flagBits & Global; }
42 bool ignoreCase() const { return m_flagBits & IgnoreCase; }
43 bool multiline() const { return m_flagBits & Multiline; }
44
45 const UString& pattern() const { return m_pattern; }
46 const UString& flags() const { return m_flags; }
47
48 bool isValid() const { return !m_constructionError; }
49 const char* errorMessage() const { return m_constructionError; }
50
51 int match(const UString&, int startOffset, OwnArrayPtr<int>* ovector = 0);
52 unsigned numSubpatterns() const { return m_numSubpatterns; }
53
54 private:
55 RegExp(JSGlobalData*, const UString& pattern);
56 RegExp(JSGlobalData*, const UString& pattern, const UString& flags);
57
58 void compile();
59
60 enum FlagBits { Global = 1, IgnoreCase = 2, Multiline = 4 };
61
62 UString m_pattern; // FIXME: Just decompile m_regExp instead of storing this.
63 UString m_flags; // FIXME: Just decompile m_regExp instead of storing this.
64 int m_flagBits;
65 JSRegExp* m_regExp;
66 const char* m_constructionError;
67 unsigned m_numSubpatterns;
68
69#if ENABLE(WREC)
70 WREC::CompiledRegExp m_wrecFunction;
71#endif
72 };
73
74} // namespace JSC
75
76#endif // KJS_REGEXP_H
Note: See TracBrowser for help on using the repository browser.