|
|
1.1 ! root 1: /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- ! 2: * ! 3: * The contents of this file are subject to the Netscape Public ! 4: * License Version 1.1 (the "License"); you may not use this file ! 5: * except in compliance with the License. You may obtain a copy of ! 6: * the License at http://www.mozilla.org/NPL/ ! 7: * ! 8: * Software distributed under the License is distributed on an "AS ! 9: * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or ! 10: * implied. See the License for the specific language governing ! 11: * rights and limitations under the License. ! 12: * ! 13: * The Original Code is Mozilla Communicator client code, released ! 14: * March 31, 1998. ! 15: * ! 16: * The Initial Developer of the Original Code is Netscape ! 17: * Communications Corporation. Portions created by Netscape are ! 18: * Copyright (C) 1998 Netscape Communications Corporation. All ! 19: * Rights Reserved. ! 20: * ! 21: * Contributor(s): ! 22: * ! 23: * Alternatively, the contents of this file may be used under the ! 24: * terms of the GNU Public License (the "GPL"), in which case the ! 25: * provisions of the GPL are applicable instead of those above. ! 26: * If you wish to allow use of your version of this file only ! 27: * under the terms of the GPL and not to allow others to use your ! 28: * version of this file under the NPL, indicate your decision by ! 29: * deleting the provisions above and replace them with the notice ! 30: * and other provisions required by the GPL. If you do not delete ! 31: * the provisions above, a recipient may use your version of this ! 32: * file under either the NPL or the GPL. ! 33: */ ! 34: ! 35: #ifndef jsregexp_h___ ! 36: #define jsregexp_h___ ! 37: /* ! 38: * JS regular expression interface. ! 39: */ ! 40: #include <stddef.h> ! 41: #include "jspubtd.h" ! 42: #include "jsstr.h" ! 43: ! 44: struct JSRegExpStatics { ! 45: JSString *input; /* input string to match (perl $_, GC root) */ ! 46: JSBool multiline; /* whether input contains newlines (perl $*) */ ! 47: uintN parenCount; /* number of valid elements in parens[] */ ! 48: uintN moreLength; /* number of allocated elements in moreParens */ ! 49: JSSubString parens[9]; /* last set of parens matched (perl $1, $2) */ ! 50: JSSubString *moreParens; /* null or realloc'd vector for $10, etc. */ ! 51: JSSubString lastMatch; /* last string matched (perl $&) */ ! 52: JSSubString lastParen; /* last paren matched (perl $+) */ ! 53: JSSubString leftContext; /* input to left of last match (perl $`) */ ! 54: JSSubString rightContext; /* input to right of last match (perl $') */ ! 55: }; ! 56: ! 57: /* ! 58: * This macro is safe because moreParens is guaranteed to be allocated and big ! 59: * enough to hold parenCount, or else be null when parenCount is 0. ! 60: */ ! 61: #define REGEXP_PAREN_SUBSTRING(res, num) \ ! 62: (((jsuint)(num) < (jsuint)(res)->parenCount) \ ! 63: ? ((jsuint)(num) < 9) \ ! 64: ? &(res)->parens[num] \ ! 65: : &(res)->moreParens[(num) - 9] \ ! 66: : &js_EmptySubString) ! 67: ! 68: typedef struct RENode RENode; ! 69: ! 70: struct JSRegExp { ! 71: jsrefcount nrefs; /* reference count */ ! 72: uint32 parenCount:24, /* number of parenthesized submatches */ ! 73: flags:8; /* flags, see jsapi.h's JSREG_* defines */ ! 74: RENode *ren; /* regular expression tree root */ ! 75: JSString *source; /* locked source string, sans // */ ! 76: }; ! 77: ! 78: extern JSRegExp * ! 79: js_NewRegExp(JSContext *cx, JSTokenStream *ts, ! 80: JSString *str, uintN flags, JSBool flat); ! 81: ! 82: extern JSRegExp * ! 83: js_NewRegExpOpt(JSContext *cx, JSTokenStream *ts, ! 84: JSString *str, JSString *opt, JSBool flat); ! 85: ! 86: extern void ! 87: js_DestroyRegExp(JSContext *cx, JSRegExp *re); ! 88: ! 89: /* ! 90: * Execute re on input str at *indexp, returning null in *rval on mismatch. ! 91: * On match, return true if test is true, otherwise return an array object. ! 92: * Update *indexp and cx->regExpStatics always on match. ! 93: */ ! 94: extern JSBool ! 95: js_ExecuteRegExp(JSContext *cx, JSRegExp *re, JSString *str, size_t *indexp, ! 96: JSBool test, jsval *rval); ! 97: ! 98: /* ! 99: * These two add and remove GC roots, respectively, so their calls must be ! 100: * well-ordered. ! 101: */ ! 102: extern JSBool ! 103: js_InitRegExpStatics(JSContext *cx, JSRegExpStatics *res); ! 104: ! 105: extern void ! 106: js_FreeRegExpStatics(JSContext *cx, JSRegExpStatics *res); ! 107: ! 108: #define JSVAL_IS_REGEXP(cx, v) \ ! 109: (JSVAL_IS_OBJECT(v) && JSVAL_TO_OBJECT(v) && \ ! 110: OBJ_GET_CLASS(cx, JSVAL_TO_OBJECT(v)) == &js_RegExpClass) ! 111: ! 112: extern JSClass js_RegExpClass; ! 113: ! 114: extern JSObject * ! 115: js_InitRegExpClass(JSContext *cx, JSObject *obj); ! 116: ! 117: /* ! 118: * Create a new RegExp object. ! 119: */ ! 120: extern JSObject * ! 121: js_NewRegExpObject(JSContext *cx, JSTokenStream *ts, ! 122: jschar *chars, size_t length, uintN flags); ! 123: ! 124: extern JSObject * ! 125: js_CloneRegExpObject(JSContext *cx, JSObject *obj, JSObject *parent); ! 126: ! 127: extern JSBool ! 128: js_GetLastIndex(JSContext *cx, JSObject *obj, jsdouble *lastIndex); ! 129: ! 130: extern JSBool ! 131: js_SetLastIndex(JSContext *cx, JSObject *obj, jsdouble lastIndex); ! 132: ! 133: #endif /* jsregexp_h___ */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.