2009-06-10 18:29:44 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2007-03-22 10:30:00 -07:00
|
|
|
*
|
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code, released
|
|
|
|
* March 31, 1998.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#ifndef jsregexp_h___
|
|
|
|
#define jsregexp_h___
|
|
|
|
/*
|
|
|
|
* JS regular expression interface.
|
|
|
|
*/
|
|
|
|
#include <stddef.h>
|
|
|
|
#include "jspubtd.h"
|
|
|
|
#include "jsstr.h"
|
|
|
|
|
|
|
|
#ifdef JS_THREADSAFE
|
|
|
|
#include "jsdhash.h"
|
|
|
|
#endif
|
|
|
|
|
2007-07-05 13:37:47 -07:00
|
|
|
JS_BEGIN_EXTERN_C
|
|
|
|
|
2010-03-29 12:24:03 -07:00
|
|
|
namespace js { class AutoValueRooter; }
|
|
|
|
|
2009-04-14 19:32:17 -07:00
|
|
|
extern JS_FRIEND_API(void)
|
2009-08-27 18:07:44 -07:00
|
|
|
js_SaveAndClearRegExpStatics(JSContext *cx, JSRegExpStatics *statics,
|
2010-03-29 12:24:03 -07:00
|
|
|
js::AutoValueRooter *tvr);
|
2009-04-14 19:32:17 -07:00
|
|
|
|
|
|
|
extern JS_FRIEND_API(void)
|
|
|
|
js_RestoreRegExpStatics(JSContext *cx, JSRegExpStatics *statics,
|
2010-03-29 12:24:03 -07:00
|
|
|
js::AutoValueRooter *tvr);
|
2009-04-14 19:32:17 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
|
|
|
* This struct holds a bitmap representation of a class from a regexp.
|
|
|
|
* There's a list of these referenced by the classList field in the JSRegExp
|
|
|
|
* struct below. The initial state has startIndex set to the offset in the
|
|
|
|
* original regexp source of the beginning of the class contents. The first
|
|
|
|
* use of the class converts the source representation into a bitmap.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
typedef struct RECharSet {
|
|
|
|
JSPackedBool converted;
|
|
|
|
JSPackedBool sense;
|
|
|
|
uint16 length;
|
|
|
|
union {
|
|
|
|
uint8 *bits;
|
|
|
|
struct {
|
|
|
|
size_t startIndex;
|
|
|
|
size_t length;
|
|
|
|
} src;
|
|
|
|
} u;
|
|
|
|
} RECharSet;
|
|
|
|
|
|
|
|
typedef struct RENode RENode;
|
|
|
|
|
|
|
|
struct JSRegExp {
|
|
|
|
jsrefcount nrefs; /* reference count */
|
|
|
|
uint16 flags; /* flags, see jsapi.h's JSREG_* defines */
|
|
|
|
size_t parenCount; /* number of parenthesized submatches */
|
|
|
|
size_t classCount; /* count [...] bitmaps */
|
|
|
|
RECharSet *classList; /* list of [...] bitmaps */
|
|
|
|
JSString *source; /* locked source string, sans // */
|
2008-11-10 12:49:56 -08:00
|
|
|
jsbytecode program[1]; /* regular expression bytecode */
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
extern JSRegExp *
|
2010-03-21 16:07:48 -07:00
|
|
|
js_NewRegExp(JSContext *cx, js::TokenStream *ts,
|
2007-03-22 10:30:00 -07:00
|
|
|
JSString *str, uintN flags, JSBool flat);
|
|
|
|
|
|
|
|
extern JSRegExp *
|
2007-11-13 14:18:17 -08:00
|
|
|
js_NewRegExpOpt(JSContext *cx, JSString *str, JSString *opt, JSBool flat);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#define HOLD_REGEXP(cx, re) JS_ATOMIC_INCREMENT(&(re)->nrefs)
|
|
|
|
#define DROP_REGEXP(cx, re) js_DestroyRegExp(cx, re)
|
|
|
|
|
|
|
|
extern void
|
|
|
|
js_DestroyRegExp(JSContext *cx, JSRegExp *re);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Execute re on input str at *indexp, returning null in *rval on mismatch.
|
|
|
|
* On match, return true if test is true, otherwise return an array object.
|
|
|
|
* Update *indexp and cx->regExpStatics always on match.
|
|
|
|
*/
|
|
|
|
extern JSBool
|
|
|
|
js_ExecuteRegExp(JSContext *cx, JSRegExp *re, JSString *str, size_t *indexp,
|
|
|
|
JSBool test, jsval *rval);
|
|
|
|
|
2008-12-18 12:06:45 -08:00
|
|
|
extern void
|
|
|
|
js_InitRegExpStatics(JSContext *cx);
|
|
|
|
|
|
|
|
extern void
|
|
|
|
js_TraceRegExpStatics(JSTracer *trc, JSContext *acx);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
extern void
|
2008-12-18 12:06:45 -08:00
|
|
|
js_FreeRegExpStatics(JSContext *cx);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-08-12 18:52:28 -07:00
|
|
|
#define VALUE_IS_REGEXP(cx, v) \
|
2009-12-30 13:49:26 -08:00
|
|
|
(!JSVAL_IS_PRIMITIVE(v) && JSVAL_TO_OBJECT(v)->isRegExp())
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
extern JSClass js_RegExpClass;
|
|
|
|
|
2009-12-30 13:49:26 -08:00
|
|
|
inline bool
|
|
|
|
JSObject::isRegExp() const
|
|
|
|
{
|
|
|
|
return getClass() == &js_RegExpClass;
|
|
|
|
}
|
|
|
|
|
2010-03-17 12:55:45 -07:00
|
|
|
extern JS_FRIEND_API(JSBool)
|
|
|
|
js_ObjectIsRegExp(JSObject *obj);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
extern JSObject *
|
|
|
|
js_InitRegExpClass(JSContext *cx, JSObject *obj);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Export js_regexp_toString to the decompiler.
|
|
|
|
*/
|
|
|
|
extern JSBool
|
2007-08-01 21:33:52 -07:00
|
|
|
js_regexp_toString(JSContext *cx, JSObject *obj, jsval *vp);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Create, serialize/deserialize, or clone a RegExp object.
|
|
|
|
*/
|
|
|
|
extern JSObject *
|
2010-03-21 16:07:48 -07:00
|
|
|
js_NewRegExpObject(JSContext *cx, js::TokenStream *ts,
|
2010-03-15 16:42:06 -07:00
|
|
|
const jschar *chars, size_t length, uintN flags);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
extern JSBool
|
2009-05-06 16:03:10 -07:00
|
|
|
js_XDRRegExpObject(JSXDRState *xdr, JSObject **objp);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-17 12:55:45 -07:00
|
|
|
extern JS_FRIEND_API(JSObject *) JS_FASTCALL
|
2010-02-19 09:44:23 -08:00
|
|
|
js_CloneRegExpObject(JSContext *cx, JSObject *obj, JSObject *proto);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-09-23 08:54:50 -07:00
|
|
|
/* Return whether the given character array contains RegExp meta-characters. */
|
|
|
|
extern bool
|
|
|
|
js_ContainsRegExpMetaChars(const jschar *chars, size_t length);
|
|
|
|
|
2007-07-05 13:37:47 -07:00
|
|
|
JS_END_EXTERN_C
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif /* jsregexp_h___ */
|