~vaifrax/inkscape/bugfix170049

« back to all changes in this revision

Viewing changes to src/extension/script/js/jsregexp.h

  • Committer: mental
  • Date: 2006-01-16 02:36:01 UTC
  • Revision ID: mental@users.sourceforge.net-20060116023601-wkr0h7edl5veyudq
moving trunk for module inkscape

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 
2
 *
 
3
 * ***** BEGIN LICENSE BLOCK *****
 
4
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 
5
 *
 
6
 * The contents of this file are subject to the Mozilla Public License Version
 
7
 * 1.1 (the "License"); you may not use this file except in compliance with
 
8
 * the License. You may obtain a copy of the License at
 
9
 * http://www.mozilla.org/MPL/
 
10
 *
 
11
 * Software distributed under the License is distributed on an "AS IS" basis,
 
12
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
13
 * for the specific language governing rights and limitations under the
 
14
 * License.
 
15
 *
 
16
 * The Original Code is Mozilla Communicator client code, released
 
17
 * March 31, 1998.
 
18
 *
 
19
 * The Initial Developer of the Original Code is
 
20
 * Netscape Communications Corporation.
 
21
 * Portions created by the Initial Developer are Copyright (C) 1998
 
22
 * the Initial Developer. All Rights Reserved.
 
23
 *
 
24
 * Contributor(s):
 
25
 *
 
26
 * Alternatively, the contents of this file may be used under the terms of
 
27
 * either of the GNU General Public License Version 2 or later (the "GPL"),
 
28
 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
29
 * in which case the provisions of the GPL or the LGPL are applicable instead
 
30
 * of those above. If you wish to allow use of your version of this file only
 
31
 * under the terms of either the GPL or the LGPL, and not to allow others to
 
32
 * use your version of this file under the terms of the MPL, indicate your
 
33
 * decision by deleting the provisions above and replace them with the notice
 
34
 * and other provisions required by the GPL or the LGPL. If you do not delete
 
35
 * the provisions above, a recipient may use your version of this file under
 
36
 * the terms of any one of the MPL, the GPL or the LGPL.
 
37
 *
 
38
 * ***** END LICENSE BLOCK ***** */
 
39
 
 
40
#ifndef jsregexp_h___
 
41
#define jsregexp_h___
 
42
/*
 
43
 * JS regular expression interface.
 
44
 */
 
45
#include <stddef.h>
 
46
#include "jspubtd.h"
 
47
#include "jsstr.h"
 
48
 
 
49
#ifdef JS_THREADSAFE
 
50
#include "jsdhash.h"
 
51
#endif
 
52
 
 
53
struct JSRegExpStatics {
 
54
    JSString    *input;         /* input string to match (perl $_, GC root) */
 
55
    JSBool      multiline;      /* whether input contains newlines (perl $*) */
 
56
    uintN       parenCount;     /* number of valid elements in parens[] */
 
57
    uintN       moreLength;     /* number of allocated elements in moreParens */
 
58
    JSSubString parens[9];      /* last set of parens matched (perl $1, $2) */
 
59
    JSSubString *moreParens;    /* null or realloc'd vector for $10, etc. */
 
60
    JSSubString lastMatch;      /* last string matched (perl $&) */
 
61
    JSSubString lastParen;      /* last paren matched (perl $+) */
 
62
    JSSubString leftContext;    /* input to left of last match (perl $`) */
 
63
    JSSubString rightContext;   /* input to right of last match (perl $') */
 
64
};
 
65
 
 
66
/*
 
67
 * This struct holds a bitmap representation of a class from a regexp.
 
68
 * There's a list of these referenced by the classList field in the JSRegExp 
 
69
 * struct below. The initial state has startIndex set to the offset in the
 
70
 * original regexp source of the beginning of the class contents. The first 
 
71
 * use of the class converts the source representation into a bitmap.
 
72
 *
 
73
 */
 
74
typedef struct RECharSet {
 
75
    JSBool converted;
 
76
    JSBool sense;
 
77
    uint16 length;
 
78
    union {
 
79
        uint8 *bits;
 
80
        struct {
 
81
            uint16 startIndex;
 
82
            uint16 length;
 
83
        } src;
 
84
    } u;
 
85
} RECharSet;
 
86
 
 
87
/*
 
88
 * This macro is safe because moreParens is guaranteed to be allocated and big
 
89
 * enough to hold parenCount, or else be null when parenCount is 0.
 
90
 */
 
91
#define REGEXP_PAREN_SUBSTRING(res, num)                                      \
 
92
    (((jsuint)(num) < (jsuint)(res)->parenCount)                              \
 
93
     ? ((jsuint)(num) < 9)                                                    \
 
94
       ? &(res)->parens[num]                                                  \
 
95
       : &(res)->moreParens[(num) - 9]                                        \
 
96
     : &js_EmptySubString)
 
97
 
 
98
typedef struct RENode RENode;
 
99
 
 
100
struct JSRegExp {
 
101
    jsrefcount   nrefs;         /* reference count */
 
102
    uint32       parenCount:24, /* number of parenthesized submatches */
 
103
                 flags:8;       /* flags, see jsapi.h's JSREG_* defines */
 
104
    uint32       classCount;    /* count [...] bitmaps */
 
105
    RECharSet    *classList;    /* list of [...] bitmaps */
 
106
    JSString     *source;       /* locked source string, sans // */
 
107
    jsbytecode  program[1];     /* regular expression bytecode */
 
108
};
 
109
 
 
110
extern JSRegExp *
 
111
js_NewRegExp(JSContext *cx, JSTokenStream *ts,
 
112
             JSString *str, uintN flags, JSBool flat);
 
113
 
 
114
extern JSRegExp *
 
115
js_NewRegExpOpt(JSContext *cx, JSTokenStream *ts,
 
116
                JSString *str, JSString *opt, JSBool flat);
 
117
 
 
118
extern void
 
119
js_DestroyRegExp(JSContext *cx, JSRegExp *re);
 
120
 
 
121
/*
 
122
 * Execute re on input str at *indexp, returning null in *rval on mismatch.
 
123
 * On match, return true if test is true, otherwise return an array object.
 
124
 * Update *indexp and cx->regExpStatics always on match.
 
125
 */
 
126
extern JSBool
 
127
js_ExecuteRegExp(JSContext *cx, JSRegExp *re, JSString *str, size_t *indexp,
 
128
                 JSBool test, jsval *rval);
 
129
 
 
130
/*
 
131
 * These two add and remove GC roots, respectively, so their calls must be
 
132
 * well-ordered.
 
133
 */
 
134
extern JSBool
 
135
js_InitRegExpStatics(JSContext *cx, JSRegExpStatics *res);
 
136
 
 
137
extern void
 
138
js_FreeRegExpStatics(JSContext *cx, JSRegExpStatics *res);
 
139
 
 
140
#define JSVAL_IS_REGEXP(cx, v)                                                \
 
141
    (JSVAL_IS_OBJECT(v) && JSVAL_TO_OBJECT(v) &&                              \
 
142
     OBJ_GET_CLASS(cx, JSVAL_TO_OBJECT(v)) == &js_RegExpClass)
 
143
 
 
144
extern JSClass js_RegExpClass;
 
145
 
 
146
extern JSObject *
 
147
js_InitRegExpClass(JSContext *cx, JSObject *obj);
 
148
 
 
149
/*
 
150
 * Create a new RegExp object.
 
151
 */
 
152
extern JSObject *
 
153
js_NewRegExpObject(JSContext *cx, JSTokenStream *ts,
 
154
                   jschar *chars, size_t length, uintN flags);
 
155
 
 
156
extern JSBool
 
157
js_XDRRegExp(JSXDRState *xdr, JSObject **objp);
 
158
 
 
159
extern JSObject *
 
160
js_CloneRegExpObject(JSContext *cx, JSObject *obj, JSObject *parent);
 
161
 
 
162
extern JSBool
 
163
js_GetLastIndex(JSContext *cx, JSObject *obj, jsdouble *lastIndex);
 
164
 
 
165
extern JSBool
 
166
js_SetLastIndex(JSContext *cx, JSObject *obj, jsdouble lastIndex);
 
167
 
 
168
#endif /* jsregexp_h___ */