source: webkit/trunk/JavaScriptCore/kjs/regexp.h@ 20204

Last change on this file since 20204 was 18182, checked in by ap, 18 years ago

Reviewed by Geoff. Based on a patch by Maks Orlovich.

http://bugs.webkit.org/show_bug.cgi?id=6257
Throw errors on invalid expressions (KJS merge)

JavaScriptCore:

  • kjs/regexp.cpp: (KJS::RegExp::RegExp): (KJS::RegExp::~RegExp): (KJS::RegExp::match):
  • kjs/regexp.h: (KJS::RegExp::flags): (KJS::RegExp::isValid): (KJS::RegExp::errorMessage): (KJS::RegExp::subPatterns): Remember and report RegExp construction failures. Renamed data members not to start with underscores.
  • kjs/regexp_object.cpp: (RegExpObjectImp::construct): Raise an exception if RegExp construction fails. (RegExpObjectImp::callAsFunction): Removed an obsolete comment.
  • tests/mozilla/ecma_3/RegExp/regress-119909.js: Reduced the number of nested parentheses to a value supported by PCRE.

LayoutTests:

  • fast/js/kde/RegExp-expected.txt: One more test passes.
  • Property svn:eol-style set to native
File size: 2.1 KB
Line 
1// -*- c-basic-offset: 2 -*-
2/*
3 * This file is part of the KDE libraries
4 * Copyright (C) 1999-2000 Harri Porten ([email protected])
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 _KJS_REGEXP_H_
23#define _KJS_REGEXP_H_
24
25#include <sys/types.h>
26
27#include "config.h"
28
29#if HAVE(PCREPOSIX)
30#include <pcre.h>
31#else // POSIX regex - not so good...
32extern "C" { // bug with some libc5 distributions
33#include <regex.h>
34}
35#endif // HAVE(PCREPOSIX)
36
37#include "ustring.h"
38
39namespace KJS {
40
41 class RegExp {
42 public:
43 enum { None = 0, Global = 1, IgnoreCase = 2, Multiline = 4 };
44
45 RegExp(const UString &pattern, int flags = None);
46 ~RegExp();
47
48 int flags() const { return m_flags; }
49 bool isValid() const { return !m_constructionError; }
50 const char* errorMessage() const { return m_constructionError; }
51
52 UString match(const UString &s, int i, int *pos = 0, int **ovector = 0);
53 unsigned subPatterns() const { return m_numSubPatterns; }
54
55 private:
56#if HAVE(PCREPOSIX)
57 pcre *m_regex;
58#else
59 regex_t m_regex;
60#endif
61 int m_flags;
62 char* m_constructionError;
63 unsigned m_numSubPatterns;
64
65 RegExp(const RegExp &);
66 RegExp &operator=(const RegExp &);
67
68 static UString sanitizePattern(const UString&);
69
70 static bool isHexDigit(UChar);
71 static unsigned char convertHex(int);
72 static unsigned char convertHex(int, int);
73 static UChar convertUnicode(UChar, UChar, UChar, UChar);
74 };
75
76} // namespace
77
78#endif
Note: See TracBrowser for help on using the repository browser.