ReactOS 0.4.16-dev-297-gc569aee
regexp.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  RECapture
 
struct  match_state_t
 
struct  regexp_t
 

Macros

#define REG_FOLD   0x01 /* fold uppercase to lowercase */
 
#define REG_GLOB   0x02 /* global exec, creates array of matches */
 
#define REG_MULTILINE   0x04 /* treat ^ and $ as begin and end of line */
 
#define REG_STICKY   0x08 /* only match starting at lastIndex */
 

Typedefs

typedef struct RECapture RECapture
 
typedef struct match_state_t match_state_t
 
typedef BYTE jsbytecode
 
typedef struct regexp_t regexp_t
 

Functions

regexp_tregexp_new (void *, heap_pool_t *, const WCHAR *, DWORD, WORD, BOOL) DECLSPEC_HIDDEN
 
void regexp_destroy (regexp_t *) DECLSPEC_HIDDEN
 
HRESULT regexp_execute (regexp_t *, void *, heap_pool_t *, const WCHAR *, DWORD, match_state_t *) DECLSPEC_HIDDEN
 
static match_state_talloc_match_state (regexp_t *regexp, heap_pool_t *pool, const WCHAR *pos)
 

Macro Definition Documentation

◆ REG_FOLD

#define REG_FOLD   0x01 /* fold uppercase to lowercase */

Definition at line 36 of file regexp.h.

◆ REG_GLOB

#define REG_GLOB   0x02 /* global exec, creates array of matches */

Definition at line 37 of file regexp.h.

◆ REG_MULTILINE

#define REG_MULTILINE   0x04 /* treat ^ and $ as begin and end of line */

Definition at line 38 of file regexp.h.

◆ REG_STICKY

#define REG_STICKY   0x08 /* only match starting at lastIndex */

Definition at line 39 of file regexp.h.

Typedef Documentation

◆ jsbytecode

typedef BYTE jsbytecode

Definition at line 54 of file regexp.h.

◆ match_state_t

◆ RECapture

◆ regexp_t

Function Documentation

◆ alloc_match_state()

static match_state_t * alloc_match_state ( regexp_t regexp,
heap_pool_t pool,
const WCHAR pos 
)
inlinestatic

Definition at line 71 of file regexp.h.

73{
74 size_t size = offsetof(match_state_t, parens) + regexp->parenCount*sizeof(RECapture);
76
78 if(!ret)
79 return NULL;
80
81 ret->cp = pos;
82 return ret;
83}
static void * heap_alloc(size_t len)
Definition: appwiz.h:66
#define NULL
Definition: types.h:112
GLsizeiptr size
Definition: glext.h:5919
struct RECapture RECapture
void * heap_pool_alloc(heap_pool_t *, DWORD) __WINE_ALLOC_SIZE(2) DECLSPEC_HIDDEN
Definition: jsutils.c:77
#define offsetof(TYPE, MEMBER)
size_t parenCount
Definition: regexp.h:58
int ret

Referenced by RegExp2_Execute(), RegExp2_Test(), regexp_match(), regexp_match_next(), regexp_string_match(), and run_exec().

◆ regexp_destroy()

void regexp_destroy ( regexp_t re)

Definition at line 3181 of file regexp.c.

3182{
3183 if (re->classList) {
3184 UINT i;
3185 for (i = 0; i < re->classCount; i++) {
3186 if (re->classList[i].converted)
3187 heap_free(re->classList[i].u.bits);
3188 re->classList[i].u.bits = NULL;
3189 }
3190 heap_free(re->classList);
3191 }
3192 heap_free(re);
3193}
static BOOL heap_free(void *mem)
Definition: appwiz.h:76
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned int UINT
Definition: ndis.h:50
struct RECharSet * classList
Definition: regexp.h:60
size_t classCount
Definition: regexp.h:59

◆ regexp_execute()

HRESULT regexp_execute ( regexp_t regexp,
void cx,
heap_pool_t pool,
const WCHAR str,
DWORD  str_len,
match_state_t result 
)

Definition at line 3140 of file regexp.c.

3142{
3144 REGlobalData gData;
3146 const WCHAR *str_beg = result->cp;
3147 HRESULT hres;
3148
3149 assert(result->cp != NULL);
3150
3151 gData.cpbegin = str;
3152 gData.cpend = str+str_len;
3153 gData.start = result->cp-str;
3154 gData.skipped = 0;
3155 gData.pool = pool;
3156
3157 hres = InitMatch(regexp, cx, pool, &gData);
3158 if(FAILED(hres)) {
3159 WARN("InitMatch failed\n");
3160 heap_pool_clear(mark);
3161 return hres;
3162 }
3163
3164 res = MatchRegExp(&gData, result);
3165 heap_pool_clear(mark);
3166 if(!gData.ok) {
3167 WARN("MatchRegExp failed\n");
3168 return E_FAIL;
3169 }
3170
3171 if(!res) {
3172 result->match_len = 0;
3173 return S_FALSE;
3174 }
3175
3176 result->match_len = (result->cp-str_beg) - gData.skipped;
3177 result->paren_count = regexp->parenCount;
3178 return S_OK;
3179}
#define WARN(fmt,...)
Definition: precomp.h:61
#define E_FAIL
Definition: ddrawi.h:102
#define assert(x)
Definition: debug.h:53
GLuint res
Definition: glext.h:9613
GLuint64EXT * result
Definition: glext.h:11304
#define S_OK
Definition: intsafe.h:52
#define FAILED(hr)
Definition: intsafe.h:51
static HRESULT InitMatch(regexp_t *re, void *cx, heap_pool_t *pool, REGlobalData *gData)
Definition: regexp.c:3100
static match_state_t * MatchRegExp(REGlobalData *gData, match_state_t *x)
Definition: regexp.c:3073
void heap_pool_clear(heap_pool_t *) DECLSPEC_HIDDEN
Definition: jsutils.c:146
heap_pool_t * heap_pool_mark(heap_pool_t *) DECLSPEC_HIDDEN
Definition: jsutils.c:182
HRESULT hres
Definition: protocol.c:465
_Out_opt_ int * cx
Definition: commctrl.h:585
const WCHAR * str
size_t start
Definition: regexp.c:238
const WCHAR * cpbegin
Definition: regexp.c:240
const WCHAR * cpend
Definition: regexp.c:241
BOOL ok
Definition: regexp.c:237
heap_pool_t * pool
Definition: regexp.c:254
ptrdiff_t skipped
Definition: regexp.c:239
#define str_len
Definition: treelist.c:89
#define S_FALSE
Definition: winerror.h:2357
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ regexp_new()

regexp_t * regexp_new ( void cx,
heap_pool_t pool,
const WCHAR str,
DWORD  str_len,
WORD  flags,
BOOL  flat 
)

Definition at line 3195 of file regexp.c.

3197{
3198 regexp_t *re;
3199 heap_pool_t *mark;
3201 size_t resize;
3202 jsbytecode *endPC;
3203 UINT i;
3204 size_t len;
3205
3206 re = NULL;
3207 mark = heap_pool_mark(pool);
3208 len = str_len;
3209
3210 state.context = cx;
3211 state.pool = pool;
3212 state.cp = str;
3213 if (!state.cp)
3214 goto out;
3215 state.cpbegin = state.cp;
3216 state.cpend = state.cp + len;
3217 state.flags = flags;
3218 state.parenCount = 0;
3219 state.classCount = 0;
3220 state.progLength = 0;
3221 state.treeDepth = 0;
3222 state.classBitmapsMem = 0;
3223 for (i = 0; i < CLASS_CACHE_SIZE; i++)
3224 state.classCache[i].start = NULL;
3225
3226 if (len != 0 && flat) {
3227 state.result = NewRENode(&state, REOP_FLAT);
3228 if (!state.result)
3229 goto out;
3230 state.result->u.flat.chr = *state.cpbegin;
3231 state.result->u.flat.length = len;
3232 state.result->kid = (void *) state.cpbegin;
3233 /* Flat bytecode: REOP_FLAT compact(string_offset) compact(len). */
3234 state.progLength += 1 + GetCompactIndexWidth(0)
3236 } else {
3237 if (!ParseRegExp(&state))
3238 goto out;
3239 }
3240 resize = offsetof(regexp_t, program) + state.progLength + 1;
3241 re = heap_alloc(resize);
3242 if (!re)
3243 goto out;
3244
3245 assert(state.classBitmapsMem <= CLASS_BITMAPS_MEM_LIMIT);
3246 re->classCount = state.classCount;
3247 if (re->classCount) {
3248 re->classList = heap_alloc(re->classCount * sizeof(RECharSet));
3249 if (!re->classList) {
3250 regexp_destroy(re);
3251 re = NULL;
3252 goto out;
3253 }
3254 for (i = 0; i < re->classCount; i++)
3255 re->classList[i].converted = FALSE;
3256 } else {
3257 re->classList = NULL;
3258 }
3259 endPC = EmitREBytecode(&state, re, state.treeDepth, re->program, state.result);
3260 if (!endPC) {
3261 regexp_destroy(re);
3262 re = NULL;
3263 goto out;
3264 }
3265 *endPC++ = REOP_END;
3266 /*
3267 * Check whether size was overestimated and shrink using realloc.
3268 * This is safe since no pointers to newly parsed regexp or its parts
3269 * besides re exist here.
3270 */
3271 if ((size_t)(endPC - re->program) != state.progLength + 1) {
3272 regexp_t *tmp;
3273 assert((size_t)(endPC - re->program) < state.progLength + 1);
3274 resize = offsetof(regexp_t, program) + (endPC - re->program);
3275 tmp = heap_realloc(re, resize);
3276 if (tmp)
3277 re = tmp;
3278 }
3279
3280 re->flags = flags;
3281 re->parenCount = state.parenCount;
3282 re->source = str;
3283 re->source_len = str_len;
3284
3285out:
3286 heap_pool_clear(mark);
3287 return re;
3288}
static int state
Definition: maze.c:121
static void * heap_realloc(void *mem, size_t len)
Definition: appwiz.h:71
#define FALSE
Definition: types.h:117
GLuint program
Definition: glext.h:6723
GLbitfield flags
Definition: glext.h:7161
GLenum GLsizei len
Definition: glext.h:6722
static size_t GetCompactIndexWidth(size_t index)
Definition: regexp.c:363
static BOOL ParseRegExp(CompilerState *)
Definition: regexp.c:1651
static jsbytecode * EmitREBytecode(CompilerState *state, regexp_t *re, size_t treeDepth, jsbytecode *pc, RENode *t)
Definition: regexp.c:475
#define CLASS_BITMAPS_MEM_LIMIT
Definition: regexp.c:353
void regexp_destroy(regexp_t *re)
Definition: regexp.c:3181
@ REOP_END
Definition: regexp.c:143
@ REOP_FLAT
Definition: regexp.c:108
#define CLASS_CACHE_SIZE
Definition: regexp.c:292
static RENode * NewRENode(CompilerState *state, REOp op)
Definition: regexp.c:409
BYTE jsbytecode
Definition: regexp.h:54
if(dx< 0)
Definition: linetemp.h:194
static FILE * out
Definition: regtests2xml.c:44
jsbytecode program[1]
Definition: regexp.h:63
const WCHAR * source
Definition: regexp.h:61
DWORD source_len
Definition: regexp.h:62
WORD flags
Definition: regexp.h:57